|
| 1 | +name: Common Build Steps for Windows, Linux and Macos |
| 2 | +inputs: |
| 3 | + arch: |
| 4 | + required: true |
| 5 | +runs: |
| 6 | + using: "composite" |
| 7 | + steps: |
| 8 | + - name: build |
| 9 | + shell: bash |
| 10 | + env: |
| 11 | + ARCH: ${{ inputs.arch }} |
| 12 | + BUILD_DIR: build |
| 13 | + OPENOCD_CONFIGURE_OPTS: "--disable-doxygen-html --enable-remote-bitbang" |
| 14 | + run: | |
| 15 | + mkdir -p $BUILD_DIR |
| 16 | + export PREFIX="$(realpath $BUILD_DIR)/opt" |
| 17 | + export DL_DIR="$(realpath $BUILD_DIR)/dl" |
| 18 | + mkdir -p $PREFIX $DL_DIR |
| 19 | +
|
| 20 | + if [[ "$ARCH" =~ macos ]]; then |
| 21 | + export LDFLAGS="-Wl,-framework,CoreFoundation -Wl,-framework,IOKit -Wl,-framework,Security" |
| 22 | + fi |
| 23 | +
|
| 24 | + # Set platform-specific variables |
| 25 | + if [[ "$ARCH" == "windows" ]]; then |
| 26 | + export CONF_HOST="i686-w64-mingw32" |
| 27 | + export HOST_CC="${CONF_HOST}-gcc" |
| 28 | + else |
| 29 | + export CONF_HOST="" |
| 30 | + export HOST_CC="gcc" |
| 31 | + fi |
| 32 | +
|
| 33 | + # LIBUSB |
| 34 | + export LIBUSB_VER=libusb-1.0.26 |
| 35 | + cd $DL_DIR && wget https://dl.espressif.com/dl/$LIBUSB_VER.tar.gz -O $LIBUSB_VER.tar.gz |
| 36 | + tar xzf $LIBUSB_VER.tar.gz && rm $LIBUSB_VER.tar.gz && pushd $LIBUSB_VER && ./bootstrap.sh |
| 37 | + ./configure --prefix="$PREFIX" --host=${CONF_HOST} --enable-shared=no --enable-static=yes CC=${HOST_CC} |
| 38 | + make install |
| 39 | + export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig |
| 40 | + popd |
| 41 | +
|
| 42 | + # HIDAPI |
| 43 | + export HIDAPI_VER=hidapi-0.14.0 |
| 44 | + cd $DL_DIR && wget https://dl.espressif.com/dl/hidapi-$HIDAPI_VER.tar.gz -O $HIDAPI_VER.tar.gz |
| 45 | + tar xzf $HIDAPI_VER.tar.gz && rm $HIDAPI_VER.tar.gz && pushd hidapi-$HIDAPI_VER && ./bootstrap |
| 46 | + ./configure --prefix="$PREFIX" --host=${CONF_HOST} --enable-shared=no --enable-static=yes --disable-testgui CC=${HOST_CC} CFLAGS=-std=gnu99 |
| 47 | + make install |
| 48 | + popd |
| 49 | +
|
| 50 | + # LIBJAYLINK |
| 51 | + export LIBJAYLINK_VER=libjaylink-0.3.1 |
| 52 | + cd $DL_DIR && wget https://dl.espressif.com/dl/$LIBJAYLINK_VER.tar.gz -O $LIBJAYLINK_VER.tar.gz |
| 53 | + tar xzf $LIBJAYLINK_VER.tar.gz && rm $LIBJAYLINK_VER.tar.gz && pushd $LIBJAYLINK_VER |
| 54 | + ./autogen.sh |
| 55 | + ./configure --prefix="$PREFIX" --host=${CONF_HOST} --disable-shared CC=${HOST_CC} |
| 56 | + make install |
| 57 | + popd |
| 58 | +
|
| 59 | + # ZLIB (Windows only) |
| 60 | + if [[ $ARCH == "windows" ]]; then |
| 61 | + export ZLIB_VER=zlib-1.2.11 |
| 62 | + cd $DL_DIR && wget https://dl.espressif.com/dl/$ZLIB_VER.tar.xz -O $ZLIB_VER.tar.xz |
| 63 | + tar xf $ZLIB_VER.tar.xz && rm $ZLIB_VER.tar.xz && pushd $ZLIB_VER |
| 64 | + make -f win32/Makefile.gcc BINARY_PATH=$PREFIX/lib INCLUDE_PATH=$PREFIX/include/zlib LIBRARY_PATH=$PREFIX/lib SHARED_MODE=1 PREFIX=${CONF_HOST}- install |
| 65 | + export CPPFLAGS="-I$PREFIX/include/zlib" |
| 66 | + export LDFLAGS="-L$PREFIX/lib" |
| 67 | + popd |
| 68 | + fi |
| 69 | +
|
| 70 | + # JIMTCL |
| 71 | + export JIMTCL_VER=jimtcl-0.83 |
| 72 | + cd $DL_DIR && wget https://dl.espressif.com/dl/$JIMTCL_VER.tar.gz -O $JIMTCL_VER.tar.gz |
| 73 | + tar xzf $JIMTCL_VER.tar.gz && rm $JIMTCL_VER.tar.gz && pushd $JIMTCL_VER |
| 74 | + ./configure --prefix="$PREFIX" --host=${CONF_HOST} --disable-shared CC=${HOST_CC} |
| 75 | + make |
| 76 | + # Running "make" does not create this file for static builds on Windows but "make install" still expects it |
| 77 | + touch build-jim-ext |
| 78 | + make install |
| 79 | + popd |
| 80 | +
|
| 81 | + cd $PREFIX/../.. |
| 82 | + ./bootstrap |
| 83 | + ./configure --prefix="$PREFIX/openocd" --host=${CONF_HOST} $OPENOCD_CONFIGURE_OPTS CC=${HOST_CC} |
| 84 | + make -j $(nproc) |
| 85 | + make install-strip |
| 86 | +
|
| 87 | + if [[ $ARCH == "windows" ]]; then |
| 88 | + cp $PREFIX/lib/zlib1.dll $PREFIX/openocd/bin |
| 89 | + cp `$HOST_CC --print-file-name=libgcc_s_dw2-1.dll` $PREFIX/openocd/bin/ |
| 90 | + fi |
| 91 | +
|
| 92 | + echo "ARTIFACT_PATH=$PREFIX/openocd" >> $GITHUB_ENV |
| 93 | +
|
| 94 | + - name: Upload artifact |
| 95 | + uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: openocd-${{ inputs.arch }} |
| 98 | + path: ${{ env.ARTIFACT_PATH }}/* |
0 commit comments