]> prime8.dev >> repos - ttyd.git/commitdiff
libuv: update cross build script
authorShuanglei Tao <tsl0922@gmail.com>
Sun, 8 Dec 2019 06:06:15 +0000 (14:06 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Sun, 8 Dec 2019 06:06:15 +0000 (14:06 +0800)
CMakeLists.txt
scripts/cross-build.sh

index 522f9f4364e468f601e529c46ae41f74d3d86612..d43d2194606e93ff53a76f6386892e69b359bc4b 100644 (file)
@@ -37,35 +37,27 @@ find_package(Libwebsockets ${LIBWEBSOCKETS_MIN_VERSION} QUIET)
 
 find_package(PkgConfig)
 
-if(Libwebsockets_FOUND)
-    set(LIBWEBSOCKETS_INCLUDE_DIR ${LIBWEBSOCKETS_INCLUDE_DIR} ${LIBWEBSOCKETS_INCLUDE_DIRS})
-else() # try to find libwebsockets with pkg-config
-    pkg_check_modules(Libwebsockets REQUIRED libwebsockets>=${LIBWEBSOCKETS_MIN_VERSION})
-    find_path(LIBWEBSOCKETS_INCLUDE_DIR libwebsockets.h
-            HINTS ${LIBWEBSOCKETS_INCLUDEDIR} ${LIBWEBSOCKETS_INCLUDE_DIRS})
-    find_library(LIBWEBSOCKETS_LIBRARIES NAMES websockets libwebsockets
-            HINTS ${LIBWEBSOCKETS_LIBDIR} ${LIBWEBSOCKETS_LIBRARY_DIRS})
+if(NOT Libwebsockets_FOUND)
+    pkg_check_modules(PC_LIBWEBSOCKETS REQUIRED libwebsockets>=${LIBWEBSOCKETS_MIN_VERSION})
+    find_path(LIBWEBSOCKETS_INCLUDE_DIRS libwebsockets.h HINTS ${PC_LIBWEBSOCKETS_INCLUDEDIR})
+    find_library(LIBWEBSOCKETS_LIBRARIES NAMES websockets libwebsockets HINTS ${PC_LIBWEBSOCKETS_LIBDIR})
     include(FindPackageHandleStandardArgs)
-    find_package_handle_standard_args(LIBWEBSOCKETS DEFAULT_MSG LIBWEBSOCKETS_LIBRARIES LIBWEBSOCKETS_INCLUDE_DIR)
-    mark_as_advanced(LIBWEBSOCKETS_INCLUDE_DIR LIBWEBSOCKETS_LIBRARIES)
+    find_package_handle_standard_args(LIBWEBSOCKETS DEFAULT_MSG LIBWEBSOCKETS_LIBRARIES LIBWEBSOCKETS_INCLUDE_DIRS)
+    mark_as_advanced(LIBWEBSOCKETS_INCLUDE_DIRS LIBWEBSOCKETS_LIBRARIES)
 endif()
 
 pkg_check_modules(PC_JSON-C REQUIRED json-c)
-find_path(JSON-C_INCLUDE_DIR json.h
-        HINTS ${PC_JSON-C_INCLUDEDIR} ${PC_JSON-C_INCLUDE_DIRS} PATH_SUFFIXES json-c json)
-find_library(JSON-C_LIBRARY NAMES json-c libjson-c
-        HINTS ${PC_JSON-C_LIBDIR} ${PC_JSON-C_LIBRARY_DIRS})
+find_path(JSON-C_INCLUDE_DIRS json.h HINTS ${PC_JSON-C_INCLUDEDIR} PATH_SUFFIXES json-c json)
+find_library(JSON-C_LIBRARIES NAMES json-c libjson-c HINTS ${PC_JSON-C_LIBDIR})
 include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(JSON-C DEFAULT_MSG JSON-C_LIBRARY JSON-C_INCLUDE_DIR)
-mark_as_advanced(JSON-C_INCLUDE_DIR JSON-C_LIBRARY)
+find_package_handle_standard_args(JSON-C DEFAULT_MSG JSON-C_LIBRARIES JSON-C_INCLUDE_DIRS)
+mark_as_advanced(JSON-C_INCLUDE_DIRS JSON-C_LIBRARIES)
 
-pkg_check_modules(LIBUV REQUIRED libuv>=1.0.0)
-find_path(LIBUV_INCLUDE_DIR NAMES uv.h
-        HINTS ${LIBUV_INCLUDEDIRS} ${LIBUV_INCLUDEDIR})
-find_library(LIBUV_LIBRARY NAMES uv libuv
-        HINTS ${LIBUV_LIBRARY_DIRS} ${LIBUV_LIBDIR})
-find_package_handle_standard_args(LIBUV DEFAULT_MSG LIBUV_LIBRARY LIBUV_INCLUDE_DIR)
-mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)
+pkg_check_modules(PC_LIBUV REQUIRED libuv>=1.0.0)
+find_path(LIBUV_INCLUDE_DIRS NAMES uv.h HINTS ${PC_LIBUV_INCLUDEDIR})
+find_library(LIBUV_LIBRARIES NAMES uv libuv HINTS ${PC_LIBUV_LIBDIR})
+find_package_handle_standard_args(LIBUV DEFAULT_MSG LIBUV_LIBRARIES LIBUV_INCLUDE_DIRS)
+mark_as_advanced(LIBUV_INCLUDE_DIRS LIBUV_LIBRARIES)
 
 find_program(CMAKE_XXD NAMES xxd)
 add_custom_command(OUTPUT html.h
@@ -74,8 +66,8 @@ add_custom_command(OUTPUT html.h
         COMMENT "Generating html.h from index.html")
 list(APPEND SOURCE_FILES html.h)
 
-set(INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR} ${LIBWEBSOCKETS_INCLUDE_DIR} ${JSON-C_INCLUDE_DIR} ${LIBUV_INCLUDE_DIR})
-set(LINK_LIBS ${OPENSSL_LIBRARIES} ${LIBWEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARY} ${LIBUV_LIBRARY})
+set(INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR} ${LIBWEBSOCKETS_INCLUDE_DIRS} ${JSON-C_INCLUDE_DIRS} ${LIBUV_INCLUDE_DIRS})
+set(LINK_LIBS ${OPENSSL_LIBRARIES} ${LIBWEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARIES} ${LIBUV_LIBRARIES})
 
 if(APPLE)
     # required for the new homebrew version of libwebsockets
index 7f3d3607c5fbfedb29dac91e070db4e68d3fdd8f..4dfcdaed963bbb16b3b0bcb17a90aa4bf8427b98 100755 (executable)
@@ -10,51 +10,58 @@ BUILD_ROOT="${BUILD_ROOT:-/opt/build}"
 
 ZLIB_VERSION="${ZLIB_VERSION:-1.2.11}"
 JSON_C_VERSION="${JSON_C_VERSION:-0.13.1}"
-OPENSSL_VERSION="${OPENSSL_VERSION:-1.0.2p}"
-LIBWEBSOCKETS_VERSION="${LIBWEBSOCKETS_VERSION:-3.1.0}"
+OPENSSL_VERSION="${OPENSSL_VERSION:-1.0.2t}"
+LIBUV_VERSION="${LIBUV_VERSION:-1.34.0}"
+LIBWEBSOCKETS_VERSION="${LIBWEBSOCKETS_VERSION:-3.2.0}"
 TTYD_VERSION="${TTYD_VERSION:-1.5.2}"
 
 build_zlib() {
-       echo "=== Building zlib ($TARGET)..."
-       curl -sLo- https://zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xz -C $BUILD_DIR
-       pushd $BUILD_DIR/zlib-$ZLIB_VERSION
-               env CHOST=$TARGET ./configure --static --archs="-fPIC" --prefix=$STAGE_DIR
+       echo "=== Building zlib-${ZLIB_VERSION} (${TARGET})..."
+       curl -sLo- https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz | tar xz -C ${BUILD_DIR}
+       pushd ${BUILD_DIR}/zlib-${ZLIB_VERSION}
+               env CHOST=${TARGET} ./configure --static --archs="-fPIC" --prefix=${STAGE_DIR}
                make install
        popd
 }
 
 build_json-c() {
-       echo "=== Building json-c ($TARGET)..."
-       curl -sLo- https://s3.amazonaws.com/json-c_releases/releases/json-c-$JSON_C_VERSION.tar.gz | tar xz -C $BUILD_DIR
-       pushd $BUILD_DIR/json-c-$JSON_C_VERSION
-               env CFLAGS=-fPIC ./configure --prefix=$STAGE_DIR --host $TARGET
+       echo "=== Building json-c-${JSON_C_VERSION} (${TARGET})..."
+       curl -sLo- https://s3.amazonaws.com/json-c_releases/releases/json-c-${JSON_C_VERSION}.tar.gz | tar xz -C ${BUILD_DIR}
+       pushd ${BUILD_DIR}/json-c-${JSON_C_VERSION}
+               env CFLAGS=-fPIC ./configure --disable-shared --enable-static --prefix=${STAGE_DIR} --host=${TARGET}
                make install
        popd
 }
 
 build_openssl() {
-       echo "=== Building openssl ($TARGET)..."
-       curl -sLo- https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz | tar xz -C $BUILD_DIR
-       pushd $BUILD_DIR/openssl-$OPENSSL_VERSION
-               env CC=$TARGET-gcc AR=$TARGET-ar RANLIB=$TARGET-ranlib C_INCLUDE_PATH=$STAGE_DIR/include \
-                       ./Configure dist -fPIC --prefix=/ --install_prefix=$STAGE_DIR
+       echo "=== Building openssl-${OPENSSL_VERSION} (${TARGET})..."
+       curl -sLo- https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz | tar xz -C ${BUILD_DIR}
+       pushd ${BUILD_DIR}/openssl-${OPENSSL_VERSION}
+               env CC=${TARGET}-gcc AR=${TARGET}-ar RANLIB=${TARGET}-ranlib C_INCLUDE_PATH=${STAGE_DIR}/include \
+                       ./Configure dist -fPIC --prefix=/ --install_prefix=${STAGE_DIR}
                make > /dev/null
                make install_sw
        popd
 }
 
-install_sys_queue_h() {
-       curl -sLo $CROSS_ROOT/$TARGET/include/sys/queue.h "https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=misc/sys/queue.h;hb=HEAD"
+build_libuv() {
+  echo "=== Building libuv-${LIBUV_VERSION} (${TARGET})..."
+       curl -sLo- https://dist.libuv.org/dist/v1.34.0/libuv-v${LIBUV_VERSION}.tar.gz | tar xz -C ${BUILD_DIR}
+       pushd ${BUILD_DIR}/libuv-v${LIBUV_VERSION}
+         ./autogen.sh
+               env CFLAGS=-fPIC ./configure --disable-shared --enable-static --prefix=${STAGE_DIR} --host=${TARGET}
+               make install
+       popd
 }
 
 install_cmake_cross_file() {
-       cat << EOF > $BUILD_DIR/cross-$TARGET.cmake
+       cat << EOF > ${BUILD_DIR}/cross-${TARGET}.cmake
 set(CMAKE_SYSTEM_NAME Linux)
 
-set(CMAKE_C_COMPILER "$TARGET-gcc")
-set(CMAKE_CXX_COMPILER "$TARGET-g++")
+set(CMAKE_C_COMPILER "${TARGET}-gcc")
+set(CMAKE_CXX_COMPILER "${TARGET}-g++")
 
-set(CMAKE_FIND_ROOT_PATH "$STAGE_DIR")
+set(CMAKE_FIND_ROOT_PATH "${STAGE_DIR}")
 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
@@ -62,54 +69,55 @@ EOF
 }
 
 build_libwebsockets() {
-       echo "=== Building libwebsockets ($TARGET)..."
-       curl -sLo- https://github.com/warmcat/libwebsockets/archive/v$LIBWEBSOCKETS_VERSION.tar.gz | tar xz -C $BUILD_DIR
-       pushd $BUILD_DIR/libwebsockets-$LIBWEBSOCKETS_VERSION
+       echo "=== Building libwebsockets-${LIBWEBSOCKETS_VERSION} (${TARGET})..."
+       curl -sLo- https://github.com/warmcat/libwebsockets/archive/v${LIBWEBSOCKETS_VERSION}.tar.gz | tar xz -C ${BUILD_DIR}
+       pushd ${BUILD_DIR}/libwebsockets-${LIBWEBSOCKETS_VERSION}
                sed -i '13s;^;\nSET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")\nSET(CMAKE_EXE_LINKER_FLAGS "-static")\n;' CMakeLists.txt
                sed -i 's/ websockets_shared//g' cmake/LibwebsocketsConfig.cmake.in
                mkdir build && cd build
                cmake -DLWS_WITHOUT_TESTAPPS=ON \
+                   -DLWS_WITH_LIBUV=ON \
                    -DLWS_STATIC_PIC=ON \
                    -DLWS_WITH_SHARED=OFF \
                    -DLWS_UNIX_SOCK=ON \
                    -DLWS_IPV6=ON \
-                   -DCMAKE_TOOLCHAIN_FILE=../../cross-$TARGET.cmake \
-                   -DCMAKE_INSTALL_PREFIX=$STAGE_DIR \
+                   -DCMAKE_TOOLCHAIN_FILE=../../cross-${TARGET}.cmake \
+                   -DCMAKE_INSTALL_PREFIX=${STAGE_DIR} \
                    ..
                make install
        popd
 }
 
 build_ttyd() {
-       echo "=== Building ttyd ($TARGET)..."
-       curl -sLo- https://github.com/tsl0922/ttyd/archive/$TTYD_VERSION.tar.gz | tar xz -C $BUILD_DIR
-       pushd $BUILD_DIR/ttyd-$TTYD_VERSION
+       echo "=== Building ttyd-${TTYD_VERSION} (${TARGET})..."
+       curl -sLo- https://github.com/tsl0922/ttyd/archive/${TTYD_VERSION}.tar.gz | tar xz -C ${BUILD_DIR}
+       pushd ${BUILD_DIR}/ttyd-${TTYD_VERSION}
                sed -i '5s;^;\nSET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")\nSET(CMAKE_EXE_LINKER_FLAGS "-static -no-pie -s")\n;' CMakeLists.txt
                mkdir build && cd build
-               cmake -DCMAKE_TOOLCHAIN_FILE=../../cross-$TARGET.cmake \
+               cmake -DCMAKE_TOOLCHAIN_FILE=../../cross-${TARGET}.cmake \
                    -DCMAKE_BUILD_TYPE=RELEASE \
                    ..
                make
        popd
-       cp $BUILD_DIR/ttyd-$TTYD_VERSION/build/ttyd bin/ttyd_linux.$ALIAS
+       cp ${BUILD_DIR}/ttyd-${TTYD_VERSION}/build/ttyd bin/ttyd_linux.${ALIAS}
 }
 
 build() {
        TARGET="$1"
        ALIAS="$2"
-       STAGE_DIR="$STAGE_ROOT/$TARGET"
-       BUILD_DIR="$BUILD_ROOT/$TARGET"
+       STAGE_DIR="${STAGE_ROOT}/${TARGET}"
+       BUILD_DIR="${BUILD_ROOT}/${TARGET}"
 
-       echo "=== Building target $ALIAS ($TARGET)..."
+       echo "=== Building target ${ALIAS} (${TARGET})..."
 
-       mkdir -p $STAGE_DIR $BUILD_DIR
-       export PKG_CONFIG_PATH="$STAGE_DIR/lib/pkgconfig"
+       mkdir -p ${STAGE_DIR} ${BUILD_DIR}
+       export PKG_CONFIG_PATH="${STAGE_DIR}/lib/pkgconfig"
 
        install_cmake_cross_file
-       install_sys_queue_h
 
        build_zlib
        build_json-c
+       build_libuv
        build_openssl
        build_libwebsockets
        build_ttyd
@@ -126,7 +134,7 @@ TARGETS=(
 )
 
 rm -rf bin && mkdir bin
-rm -rf $STAGE_ROOT $BUILD_ROOT
+rm -rf ${STAGE_ROOT} ${BUILD_ROOT}
 
 for ((i=0; i<${#TARGETS[@]}; i+=2)); do
        build "${TARGETS[$i+1]}" "${TARGETS[$i]}"