Skip to content

Instantly share code, notes, and snippets.

@sago35
Created September 16, 2020 12:57
Show Gist options
  • Save sago35/ba2705279a539490e487bf1e85da9755 to your computer and use it in GitHub Desktop.
Save sago35/ba2705279a539490e487bf1e85da9755 to your computer and use it in GitHub Desktop.
openocd-windows build script
set -e
BUILD_DIR=${HOME}/openocd-windows
LIBUSB1_BUILD_DIR=${BUILD_DIR}/libusb
LIBUSB0_BUILD_DIR=${BUILD_DIR}/libusb-compat
LIBCONFUSE_BUILD_DIR=${BUILD_DIR}/libconfuse
HIDAPI_BUILD_DIR=${BUILD_DIR}/hidapi
LIBFTDI_BUILD_DIR=${BUILD_DIR}/libftdi
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
rm -rf $LIBUSB1_BUILD_DIR
rm -rf $LIBUSB0_BUILD_DIR
rm -rf $LIBCONFUSE_BUILD_DIR
rm -rf $HIDAPI_BUILD_DIR
rm -rf $LIBFTDI_BUILD_DIR
rm -rf $BUILD_DIR/openocd-code
git clone https://github.com/libusb/libusb.git libusb
cd libusb
git checkout 178e433b7401776c37e475b17ee9667337a589c4
./bootstrap.sh
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared
make -j
cd ..
git clone https://github.com/libusb/libusb-compat-0.1.git libusb-compat
cd libusb-compat
./autogen.sh
LIBUSB_1_0_CFLAGS="-I${LIBUSB1_BUILD_DIR}/libusb" \
LIBUSB_1_0_LIBS="-L${LIBUSB1_BUILD_DIR}/libusb/.libs -lusb-1.0" \
PKG_CONFIG_PATH=${LIBUSB1_BUILD_DIR} \
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared
make -j
cd ..
git clone https://github.com/martinh/libconfuse.git libconfuse
cd libconfuse
git checkout 67e1207c8de440525a3fdde1448a586791ebc052
# 2020-04-18 21:37:22 build OK
#git checkout c0e7e74bc492a1791c044208d26502a559c03cb9
# 2020-06-22 05:51:16 build NG
#git checkout a24c7b19166709be872421087e6d6fe810cdf306
./autogen.sh
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared
make -j
cd ..
git clone git://developer.intra2net.com/libftdi libftdi
cd libftdi && mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-x86_64-w64-mingw32.cmake \
-DLIBUSB_LIBRARIES=${LIBUSB1_BUILD_DIR}/libusb/.libs/ \
-DLIBUSB_INCLUDE_DIR=${LIBUSB1_BUILD_DIR}/libusb \
-DCONFUSE_LIBRARY=${LIBCONFUSE_BUILD_DIR}/src/.libs/ \
-DCONFUSE_INCLUDE_DIR=${LIBCONFUSE_BUILD_DIR}/src/ ../
make ftdi1-static
cd ../..
git clone https://github.com/signal11/hidapi.git hidapi
cd hidapi
./bootstrap
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared
make -j
cd ..
#git clone https://git.code.sf.net/p/openocd/code openocd-code
#git clone https://github.com/sago35/openocd openocd-code
git clone https://github.com/ciniml/openocd openocd-code
cd openocd-code
perl -i -ape 's/ftdi_usb_purge_buffers/ftdi_tcioflush/g' src/jtag/drivers/openjtag.c
perl -i -ape 's/ftdi_usb_purge_buffers/ftdi_tcioflush/g' src/jtag/drivers/presto.c
perl -i -ape 's/#if defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME/#if 0/g' src/helper/replacements.c
./bootstrap
HIDAPI_CFLAGS="-I${HIDAPI_BUILD_DIR}/hidapi" \
HIDAPI_LIBS="-L${HIDAPI_BUILD_DIR}/windows/.libs -lhidapi" \
LIBUSB0_CFLAGS="-I${LIBUSB0_BUILD_DIR}/libusb" \
LIBUSB0_LIBS="-L${LIBUSB0_BUILD_DIR}/libusb/.libs -lusb" \
LIBUSB1_CFLAGS="-I${LIBUSB1_BUILD_DIR}/libusb" \
LIBUSB1_LIBS="-L${LIBUSB1_BUILD_DIR}/libusb/.libs -lusb-1.0" \
LIBFTDI_CFLAGS="-I${LIBFTDI_BUILD_DIR}/src " \
LIBFTDI_LIBS="-L${LIBFTDI_BUILD_DIR}/build/src -lftdi1" \
PKG_CONFIG_PATH=${HIDAPI_BUILD_DIR}/pc:${LIBUSB1_BUILD_DIR}:${LIBUSB0_BUILD_DIR}:${LIBFTDI_BUILD_DIR}/build \
libusb_CFLAGS="-I${LIBUSB1_BUILD_DIR}/libusb" \
libusb_LIBS="-L${LIBUSB1_BUILD_DIR}/libusb/.libs/ -lusb-1.0" \
./configure --host=x86_64-w64-mingw32 --prefix=$BUILD_DIR/openocd --enable-cmsis-dap --enable-cmsis-dap-v2
#./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared --prefix=$BUILD_DIR/openocd --enable-cmsis-dap --enable-cmsis-dap-v2
make -j 8
sed -i -e 's|-lftdi1|'${LIBFTDI_BUILD_DIR}'/build/src/libftdi1.a|' src/libopenocd.la
make -j
make install
cd ..
@sago35
Copy link
Author

sago35 commented Sep 16, 2020

以下のやり方を bash script 化したのみ。
一部古い version を使うように変更したりしています。

OpenOCDをwslでWindows用にクロスコンパイルする
https://qiita.com/qawsed477/items/2f93f2c1ff0de6fef038

@sago35
Copy link
Author

sago35 commented Sep 16, 2020

build 済み openocd windows 版は以下にあります。
https://drive.google.com/file/d/1MNxSCGhSGLsUbHMng53yfpCP9d5swkn1/view?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment