From 7908b3add9ace1812973fe368509e47a99edad0e Mon Sep 17 00:00:00 2001 From: kautism Date: Sat, 7 Mar 2020 20:01:49 +0800 Subject: [PATCH 1/7] Add libftdi build and add mingw64 build. --- .../01-fix_ftdi_read_data_segfault_bugs.patch | 28 +++ avrdude-6.3.build.bash | 1 + libftdi-1.4.build.bash | 49 +++++ .../01-add_sharedlibs_flag.patch | 180 ++++++++++++++++++ package-avrdude.bash | 22 ++- 5 files changed, 273 insertions(+), 7 deletions(-) create mode 100644 avrdude-6.3-patches/01-fix_ftdi_read_data_segfault_bugs.patch create mode 100644 libftdi-1.4.build.bash create mode 100644 libftdi1-1.4-patches/01-add_sharedlibs_flag.patch diff --git a/avrdude-6.3-patches/01-fix_ftdi_read_data_segfault_bugs.patch b/avrdude-6.3-patches/01-fix_ftdi_read_data_segfault_bugs.patch new file mode 100644 index 0000000..086016d --- /dev/null +++ b/avrdude-6.3-patches/01-fix_ftdi_read_data_segfault_bugs.patch @@ -0,0 +1,28 @@ +diff -Naur a/ft245r.c b/ft245r.c +--- a/ft245r.c 2014-09-16 03:01:09.000000000 +0800 ++++ b/ft245r.c 2020-02-22 21:00:23.381036600 +0800 +@@ -653,14 +653,22 @@ + + + static void ft245r_close(PROGRAMMER * pgm) { ++ int retry_times = 0; + if (handle) { + // I think the switch to BB mode and back flushes the buffer. + ftdi_set_bitmode(handle, 0, BITMODE_SYNCBB); // set Synchronous BitBang, all in puts + ftdi_set_bitmode(handle, 0, BITMODE_RESET); // disable Synchronous BitBang + ftdi_usb_close(handle); +- ftdi_deinit (handle); +- pthread_cancel(readerthread); ++ while(pthread_cancel(readerthread) && retry_times < 100) { ++ retry_times++; ++ usleep(100); ++ } ++ if (retry_times >= 100) { ++ avrdude_message(MSG_INFO, "Too many retry to close reader thread\n"); ++ } ++ + pthread_join(readerthread, NULL); ++ ftdi_deinit (handle); + free(handle); + handle = NULL; + } diff --git a/avrdude-6.3.build.bash b/avrdude-6.3.build.bash index 6eb69c9..19e9dc7 100755 --- a/avrdude-6.3.build.bash +++ b/avrdude-6.3.build.bash @@ -25,6 +25,7 @@ git clone https://github.com/facchinm/avrdude.git avrdude-6.3 --depth 1 cd avrdude-6.3 patch -p1 < ../avrdude-6.3-patches/90* +patch -p1 < ../avrdude-6.3-patches/01-fix_ftdi_read_data_segfault_bugs.patch export CFLAGS="-I$PREFIX/include -I$PREFIX/include/hidapi -I$PREFIX/include/libelf -I$PREFIX/include/ncurses -I$PREFIX/include/ncursesw -I$PREFIX/include/readline -I$PREFIX/include/libusb-1.0 $CFLAGS" export LDFLAGS="-L$PREFIX/lib $LDFLAGS" diff --git a/libftdi-1.4.build.bash b/libftdi-1.4.build.bash new file mode 100644 index 0000000..b40bd6a --- /dev/null +++ b/libftdi-1.4.build.bash @@ -0,0 +1,49 @@ +#!/bin/bash -ex +# Copyright (c) 2014-2016 Arduino LLC +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +mkdir -p objdir +cd objdir +PREFIX=`pwd` +cd - + +if [[ ! -f libftdi1-1.4.tar.bz2 ]] ; +then + wget https://www.intra2net.com/en/developer/libftdi/download/libftdi1-1.4.tar.bz2 +fi + +tar xfv libftdi1-1.4.tar.bz2 + +rm -rf libftdi1-1.4/build +mkdir libftdi1-1.4/build + +cd libftdi1-1.4/ +if [[ $OS == "Msys" ]] ; then + patch -p1 < ../libftdi1-1.4-patches/01-add_sharedlibs_flag.patch +fi +cd build/ + +CMAKE_EXTRA_FLAG="" + +if [[ $OS == "Msys" ]] ; then + CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DBUILD_TESTS=OFF -DSHAREDLIBS=OFF" +fi + +cmake $CMAKE_EXTRA_FLAG -DCMAKE_INSTALL_PREFIX="$PREFIX" -DLIBUSB_INCLUDE_DIR="$PREFIX/include/libusb-1.0" -DLIBFTDI_LIBRARY_DIRS="$PREFIX/lib" -DLIBUSB_LIBRARIES="usb-1.0" ../ +make -j 1 +make install +cd ../.. + diff --git a/libftdi1-1.4-patches/01-add_sharedlibs_flag.patch b/libftdi1-1.4-patches/01-add_sharedlibs_flag.patch new file mode 100644 index 0000000..ad6b7ee --- /dev/null +++ b/libftdi1-1.4-patches/01-add_sharedlibs_flag.patch @@ -0,0 +1,180 @@ +diff -Naur a/CMakeLists.txt b/CMakeLists.txt +--- a/CMakeLists.txt 2020-03-07 12:26:19.922659700 +0800 ++++ b/CMakeLists.txt 2020-03-07 15:11:57.839140900 +0800 +@@ -46,6 +46,7 @@ + set(CPACK_COMPONENT_STATICLIBS_GROUP "Development") + set(CPACK_COMPONENT_HEADERS_GROUP "Development") + ++option ( SHAREDLIBS "Build ㄎ libraries" ON ) + option ( STATICLIBS "Build static libraries" ON ) + + # guess LIB_SUFFIX, don't take debian multiarch into account +diff -Naur a/examples/CMakeLists.txt b/examples/CMakeLists.txt +--- a/examples/CMakeLists.txt 2020-03-07 12:26:20.208196700 +0800 ++++ b/examples/CMakeLists.txt 2020-03-07 15:18:03.493009700 +0800 +@@ -8,29 +8,31 @@ + + message(STATUS "Building example programs.") + +- # Targets +- add_executable(simple simple.c) +- add_executable(bitbang bitbang.c) +- add_executable(bitbang2 bitbang2.c) +- add_executable(bitbang_cbus bitbang_cbus.c) +- add_executable(bitbang_ft2232 bitbang_ft2232.c) +- add_executable(find_all find_all.c) +- add_executable(serial_test serial_test.c) +- add_executable(baud_test baud_test.c) +- add_executable(stream_test stream_test.c) +- add_executable(eeprom eeprom.c) +- +- # Linkage +- target_link_libraries(simple ftdi1) +- target_link_libraries(bitbang ftdi1) +- target_link_libraries(bitbang2 ftdi1) +- target_link_libraries(bitbang_cbus ftdi1) +- target_link_libraries(bitbang_ft2232 ftdi1) +- target_link_libraries(find_all ftdi1) +- target_link_libraries(serial_test ftdi1) +- target_link_libraries(baud_test ftdi1) +- target_link_libraries(stream_test ftdi1) +- target_link_libraries(eeprom ftdi1) ++ if ( SHAREDLIBS ) ++ # Targets ++ add_executable(simple simple.c) ++ add_executable(bitbang bitbang.c) ++ add_executable(bitbang2 bitbang2.c) ++ add_executable(bitbang_cbus bitbang_cbus.c) ++ add_executable(bitbang_ft2232 bitbang_ft2232.c) ++ add_executable(find_all find_all.c) ++ add_executable(serial_test serial_test.c) ++ add_executable(baud_test baud_test.c) ++ add_executable(stream_test stream_test.c) ++ add_executable(eeprom eeprom.c) ++ ++ # Linkage ++ target_link_libraries(simple ftdi1) ++ target_link_libraries(bitbang ftdi1) ++ target_link_libraries(bitbang2 ftdi1) ++ target_link_libraries(bitbang_cbus ftdi1) ++ target_link_libraries(bitbang_ft2232 ftdi1) ++ target_link_libraries(find_all ftdi1) ++ target_link_libraries(serial_test ftdi1) ++ target_link_libraries(baud_test ftdi1) ++ target_link_libraries(stream_test ftdi1) ++ target_link_libraries(eeprom ftdi1) ++ endif() + + # libftdi++ examples + if(FTDI_BUILD_CPP) +@@ -39,11 +41,13 @@ + include_directories(BEFORE ${CMAKE_SOURCE_DIR}/ftdipp + ${Boost_INCLUDE_DIRS}) + +- # Target +- add_executable(find_all_pp find_all_pp.cpp) +- +- # Linkage +- target_link_libraries(find_all_pp ftdipp1) ++ if ( SHAREDLIBS ) ++ # Target ++ add_executable(find_all_pp find_all_pp.cpp) ++ ++ # Linkage ++ target_link_libraries(find_all_pp ftdipp1) ++ endif() + endif(Boost_FOUND) + endif(FTDI_BUILD_CPP) + +diff -Naur a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt +--- a/ftdipp/CMakeLists.txt 2020-03-07 12:26:20.229190200 +0800 ++++ b/ftdipp/CMakeLists.txt 2020-03-07 15:13:30.150838600 +0800 +@@ -22,25 +22,26 @@ + + set(FTDI_BUILD_CPP True PARENT_SCOPE) + message(STATUS "Building libftdi1++") +- +- # Shared library +- add_library(ftdipp1 SHARED ${cpp_sources}) +- +- math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases +- set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3) +- +- # Prevent clobbering each other during the build +- set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) +- +- # Dependencies +- target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES}) +- +- +- install ( TARGETS ftdipp1 +- RUNTIME DESTINATION bin +- LIBRARY DESTINATION lib${LIB_SUFFIX} +- ARCHIVE DESTINATION lib${LIB_SUFFIX} +- ) ++ if ( SHAREDLIBS ) ++ # Shared library ++ add_library(ftdipp1 SHARED ${cpp_sources}) ++ ++ math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases ++ set_target_properties(ftdipp1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 3) ++ ++ # Prevent clobbering each other during the build ++ set_target_properties(ftdipp1 PROPERTIES CLEAN_DIRECT_OUTPUT 1) ++ ++ # Dependencies ++ target_link_libraries(ftdipp1 ftdi1 ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES}) ++ ++ ++ install ( TARGETS ftdipp1 ++ RUNTIME DESTINATION bin ++ LIBRARY DESTINATION lib${LIB_SUFFIX} ++ ARCHIVE DESTINATION lib${LIB_SUFFIX} ++ ) ++ endif () + + # Static library + if ( STATICLIBS ) +diff -Naur a/src/CMakeLists.txt b/src/CMakeLists.txt +--- a/src/CMakeLists.txt 2020-03-07 12:26:20.257181000 +0800 ++++ b/src/CMakeLists.txt 2020-03-07 15:13:02.108714300 +0800 +@@ -21,22 +21,24 @@ + set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.c ${CMAKE_CURRENT_SOURCE_DIR}/ftdi_stream.c CACHE INTERNAL "List of c sources" ) + set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.h CACHE INTERNAL "List of c headers" ) + +-add_library(ftdi1 SHARED ${c_sources}) ++if ( SHAREDLIBS ) ++ add_library(ftdi1 SHARED ${c_sources}) + +-math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases +-set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2) +-# Prevent clobbering each other during the build +-set_target_properties ( ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1 ) +- +- +-# Dependencies +-target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES}) +- +-install ( TARGETS ftdi1 +- RUNTIME DESTINATION bin +- LIBRARY DESTINATION lib${LIB_SUFFIX} +- ARCHIVE DESTINATION lib${LIB_SUFFIX} +- ) ++ math(EXPR VERSION_FIXUP "${MAJOR_VERSION} + 1") # Compatiblity with previous releases ++ set_target_properties(ftdi1 PROPERTIES VERSION ${VERSION_FIXUP}.${MINOR_VERSION}.0 SOVERSION 2) ++ # Prevent clobbering each other during the build ++ set_target_properties ( ftdi1 PROPERTIES CLEAN_DIRECT_OUTPUT 1 ) ++ ++ ++ # Dependencies ++ target_link_libraries(ftdi1 ${LIBUSB_LIBRARIES}) ++ ++ install ( TARGETS ftdi1 ++ RUNTIME DESTINATION bin ++ LIBRARY DESTINATION lib${LIB_SUFFIX} ++ ARCHIVE DESTINATION lib${LIB_SUFFIX} ++ ) ++endif () + + if ( STATICLIBS ) + add_library(ftdi1-static STATIC ${c_sources}) diff --git a/package-avrdude.bash b/package-avrdude.bash index 1d15dce..26892af 100755 --- a/package-avrdude.bash +++ b/package-avrdude.bash @@ -65,12 +65,19 @@ elif [[ $OS == "Msys" || $OS == "Cygwin" ]] ; then echo you may experience build failure or weird behaviour echo ************************************************************* - export PATH=$PATH:/c/MinGW/bin/:/c/cygwin/bin/ - export CC="mingw32-gcc -m32" - export CXX="mingw32-g++ -m32" - export TARGET_OS="Windows" - OUTPUT_TAG=i686-mingw32 - +export MACHINE=`uname -m` + if [[ $MACHINE == "x86_64" ]] ; then + export CC="gcc" + export CXX="g++" + export TARGET_OS="Windows" + OUTPUT_TAG=x86_64-mingw64 + else + export PATH=$PATH:/c/MinGW/bin/:/c/cygwin/bin/ + export CC="mingw32-gcc -m32" + export CXX="mingw32-g++ -m32" + export TARGET_OS="Windows" + OUTPUT_TAG=i686-mingw32 + fi elif [[ $OS == "Darwin" ]] ; then export PATH=/opt/local/libexec/gnubin/:/opt/local/bin:$PATH @@ -92,13 +99,14 @@ rm -rf avrdude-6.3 libusb-1.0.20 libusb-compat-0.1.5 libusb-win32-bin-1.2.6.0 li ./libelf-0.8.13.build.bash ./libncurses-5.9.build.bash ./libhidapi.build.bash +./libftdi-1.4.build.bash ./avrdude-6.3.build.bash # if producing a windows build, compress as zip and # copy *toolchain-precompiled* content to any folder containing a .exe if [[ ${OUTPUT_TAG} == *"mingw"* ]] ; then - cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll objdir/bin/libusb0.dll + #cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll objdir/bin/libusb0.dll rm -f avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.zip cp -a objdir avrdude zip -r avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.zip avrdude/bin/ avrdude/etc/avrdude.conf From 1dd3ba4dad4e9e50a3a511cc280de91f10c53ea6 Mon Sep 17 00:00:00 2001 From: kautism Date: Mon, 9 Mar 2020 13:33:01 +0800 Subject: [PATCH 2/7] Prevent avrdude say: libwinpthread-1.dll no found error when build by mingw --- avrdude-6.3.build.bash | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/avrdude-6.3.build.bash b/avrdude-6.3.build.bash index 19e9dc7..d38c447 100755 --- a/avrdude-6.3.build.bash +++ b/avrdude-6.3.build.bash @@ -20,6 +20,7 @@ cd objdir PREFIX=`pwd` cd - +rm -rf avrdude-6.3 git clone https://github.com/facchinm/avrdude.git avrdude-6.3 --depth 1 cd avrdude-6.3 @@ -44,6 +45,11 @@ CFLAGS="-DHAVE_LIBHIDAPI $CFLAGS" LIBS="-lhidapi -lsetupapi" fi +if [[ $OS == "Msys" ]] ; then + CFLAGS="-DHAVE_LIBHIDAPI $CFLAGS" + LIBS="-lhidapi -lsetupapi -Wl,-Bstatic -lwinpthread" +fi + if [[ $OS == "Darwin" ]] ; then CFLAGS="-DHAVE_LIBHIDAPI $CFLAGS" LIBS="-lhidapi" From 51e1e4ac995ef66cf6e27964f502314e18c95707 Mon Sep 17 00:00:00 2001 From: kautism Date: Tue, 10 Mar 2020 23:05:52 +0800 Subject: [PATCH 3/7] Fix Cross compile failed in linux --- avrdude-6.3.build.bash | 2 +- libftdi-1.4.build.bash | 10 ++++------ libusb-compat-0.1.5.build.bash | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) mode change 100644 => 100755 libftdi-1.4.build.bash diff --git a/avrdude-6.3.build.bash b/avrdude-6.3.build.bash index d38c447..28b57c5 100755 --- a/avrdude-6.3.build.bash +++ b/avrdude-6.3.build.bash @@ -42,7 +42,7 @@ COMMON_FLAGS="" if [[ $CROSS_COMPILE == "mingw" ]] ; then CFLAGS="-DHAVE_LIBHIDAPI $CFLAGS" -LIBS="-lhidapi -lsetupapi" +LIBS="-lhidapi -lsetupapi -Wl,-Bstatic -lwinpthread" fi if [[ $OS == "Msys" ]] ; then diff --git a/libftdi-1.4.build.bash b/libftdi-1.4.build.bash old mode 100644 new mode 100755 index b40bd6a..e5aec72 --- a/libftdi-1.4.build.bash +++ b/libftdi-1.4.build.bash @@ -31,15 +31,13 @@ rm -rf libftdi1-1.4/build mkdir libftdi1-1.4/build cd libftdi1-1.4/ -if [[ $OS == "Msys" ]] ; then - patch -p1 < ../libftdi1-1.4-patches/01-add_sharedlibs_flag.patch -fi +patch -p1 < ../libftdi1-1.4-patches/01-add_sharedlibs_flag.patch cd build/ -CMAKE_EXTRA_FLAG="" +CMAKE_EXTRA_FLAG="-DSHAREDLIBS=OFF -DBUILD_TESTS=OFF" -if [[ $OS == "Msys" ]] ; then - CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DBUILD_TESTS=OFF -DSHAREDLIBS=OFF" +if [[ $OS == "GNU/Linux" ]] ; then + CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_TOOLCHAIN_FILE=./cmake/Toolchain-i686-w64-mingw32.cmake" fi cmake $CMAKE_EXTRA_FLAG -DCMAKE_INSTALL_PREFIX="$PREFIX" -DLIBUSB_INCLUDE_DIR="$PREFIX/include/libusb-1.0" -DLIBFTDI_LIBRARY_DIRS="$PREFIX/lib" -DLIBUSB_LIBRARIES="usb-1.0" ../ diff --git a/libusb-compat-0.1.5.build.bash b/libusb-compat-0.1.5.build.bash index 075edd0..a42523b 100755 --- a/libusb-compat-0.1.5.build.bash +++ b/libusb-compat-0.1.5.build.bash @@ -27,7 +27,8 @@ if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw wget http://download.sourceforge.net/project/libusb-win32/libusb-win32-releases/1.2.6.0/libusb-win32-bin-1.2.6.0.zip fi unzip libusb-win32-bin-1.2.6.0.zip - #cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll $PREFIX/bin/libusb0.dll + mkdir -p $PREFIX/bin/ + cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll $PREFIX/bin/libusb0.dll cp libusb-win32-bin-1.2.6.0/include/lusb0_usb.h $PREFIX/include cp libusb-win32-bin-1.2.6.0/lib/gcc/libusb.a $PREFIX/lib exit 0 From 2812d7e7e365eebbc3e808b423324df285e63910 Mon Sep 17 00:00:00 2001 From: kautism Date: Tue, 10 Mar 2020 23:07:03 +0800 Subject: [PATCH 4/7] Fix document typo --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 9a9770e..d3780c6 100644 --- a/Readme.md +++ b/Readme.md @@ -47,7 +47,7 @@ sudo apt-get install gcc-mingw-w64-i686 When building you must set the env var `CROSS_COMPILE` to `mingw` for example: ``` -CROSS_COMPILE=mingw ./package_avrdude.bash +CROSS_COMPILE=mingw ./package-avrdude.bash ``` cross compile with mingw has been tested on Ubuntu 14.04 (mingw-w64 4.8), different versions of mingw may behave differently and fail to build. From 24f2034c55054c4fd87c3f3c63547bfb82ac4daa Mon Sep 17 00:00:00 2001 From: kautism Date: Wed, 11 Mar 2020 00:50:43 +0800 Subject: [PATCH 5/7] Add docker build and add mingw64 cross compile --- Dockerfile | 9 +++++++++ Readme.md | 16 ++++++++++++++++ avrdude-6.3.build.bash | 7 +------ libftdi-1.4.build.bash | 6 +++++- libncurses-5.9.build.bash | 2 +- libusb-compat-0.1.5.build.bash | 2 +- package-avrdude.bash | 13 +++++++++++-- 7 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0257db5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM debian + +RUN apt-get update && apt-get install -y gcc-mingw-w64-i686 g++-mingw-w64-i686 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 libtool pkg-config bzip2 zip make autoconf wget patch git automake flex bison cmake xsltproc && rm -rf /var/lib/apt/lists/* + +COPY . /avrdude-build-script + +WORKDIR /avrdude-build-script + +ENTRYPOINT ["/avrdude-build-script/package-avrdude.bash"] \ No newline at end of file diff --git a/Readme.md b/Readme.md index d3780c6..ba7d09f 100644 --- a/Readme.md +++ b/Readme.md @@ -18,6 +18,22 @@ Just run: Setup has been done on partially set up development machines. If you find any package missing from the following list, please open an issue at once! +### Docker Building + +Run: +``` +mkdir dist +docker build . -t avrdude-builder +# cross compile i686 +docker run --rm -it -v $PWD/dist:/avrdude-build-script/dist -e CROSS_COMPILE=mingw avrdude-builder +# cross compile x86_64 +docker run --rm -it -v $PWD/dist:/avrdude-build-script/dist -e CROSS_COMPILE=mingw64 avrdude-builder +# remove container +docker rmi avrdude-builder +``` + +If you do not need cross compile, just remove `-e CROSS_COMPILE=mingw`. + #### Debian requirements ```bash diff --git a/avrdude-6.3.build.bash b/avrdude-6.3.build.bash index 28b57c5..c3ce985 100755 --- a/avrdude-6.3.build.bash +++ b/avrdude-6.3.build.bash @@ -40,12 +40,7 @@ fi COMMON_FLAGS="" -if [[ $CROSS_COMPILE == "mingw" ]] ; then -CFLAGS="-DHAVE_LIBHIDAPI $CFLAGS" -LIBS="-lhidapi -lsetupapi -Wl,-Bstatic -lwinpthread" -fi - -if [[ $OS == "Msys" ]] ; then +if [[ $CROSS_COMPILE == "mingw" || $CROSS_COMPILE == "mingw64" || $OS == "Msys" ]] ; then CFLAGS="-DHAVE_LIBHIDAPI $CFLAGS" LIBS="-lhidapi -lsetupapi -Wl,-Bstatic -lwinpthread" fi diff --git a/libftdi-1.4.build.bash b/libftdi-1.4.build.bash index e5aec72..2126035 100755 --- a/libftdi-1.4.build.bash +++ b/libftdi-1.4.build.bash @@ -36,10 +36,14 @@ cd build/ CMAKE_EXTRA_FLAG="-DSHAREDLIBS=OFF -DBUILD_TESTS=OFF" -if [[ $OS == "GNU/Linux" ]] ; then +if [[ $OS == "GNU/Linux" && $CROSS_COMPILE == "mingw" ]] ; then CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_TOOLCHAIN_FILE=./cmake/Toolchain-i686-w64-mingw32.cmake" fi +if [[ $OS == "GNU/Linux" && $CROSS_COMPILE == "mingw64" ]] ; then + CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_TOOLCHAIN_FILE=./cmake/Toolchain-x86_64-w64-mingw32.cmake" +fi + cmake $CMAKE_EXTRA_FLAG -DCMAKE_INSTALL_PREFIX="$PREFIX" -DLIBUSB_INCLUDE_DIR="$PREFIX/include/libusb-1.0" -DLIBFTDI_LIBRARY_DIRS="$PREFIX/lib" -DLIBUSB_LIBRARIES="usb-1.0" ../ make -j 1 make install diff --git a/libncurses-5.9.build.bash b/libncurses-5.9.build.bash index 3e5abe8..d08f3fc 100755 --- a/libncurses-5.9.build.bash +++ b/libncurses-5.9.build.bash @@ -20,7 +20,7 @@ cd objdir PREFIX=`pwd` cd - -if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw32" || $CROSS_COMPILE_HOST == "aarch64-linux-gnu" ]] ; then +if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw32" || $CROSS_COMPILE_HOST == "x86_64-w64-mingw32" || $CROSS_COMPILE_HOST == "aarch64-linux-gnu" ]] ; then #Avoid compiling ncurses in Windows platform exit 0 fi diff --git a/libusb-compat-0.1.5.build.bash b/libusb-compat-0.1.5.build.bash index a42523b..002eefb 100755 --- a/libusb-compat-0.1.5.build.bash +++ b/libusb-compat-0.1.5.build.bash @@ -41,7 +41,7 @@ fi tar xfv libusb-compat-0.1.5.tar.bz2 cd libusb-compat-0.1.5 -if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw32" ]] ; then +if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw32" || $CROSS_COMPILE_HOST == "x86_64-w64-mingw32" ]] ; then patch -p1 < ../libusb-compat-0.1.5-patches/01-mingw-build.patch autoreconf --force --install fi diff --git a/package-avrdude.bash b/package-avrdude.bash index 26892af..30703df 100755 --- a/package-avrdude.bash +++ b/package-avrdude.bash @@ -27,6 +27,13 @@ if [[ $CROSS_COMPILE == "mingw" ]] ; then export CROSS_COMPILE_HOST="i686-w64-mingw32" export TARGET_OS="Windows" OUTPUT_TAG=i686-w64-mingw32 +elif [[ $CROSS_COMPILE == "mingw64" ]] ; then + + export CC="x86_64-w64-mingw32-gcc" + export CXX="x86_64-w64-mingw32-g++" + export CROSS_COMPILE_HOST="x86_64-w64-mingw32" + export TARGET_OS="Windows" + OUTPUT_TAG=x86_64-w64-mingw32 elif [[ $CROSS_COMPILE == "arm64-cross" ]] ; then export CC="aarch64-linux-gnu-gcc" @@ -109,14 +116,16 @@ if [[ ${OUTPUT_TAG} == *"mingw"* ]] ; then #cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll objdir/bin/libusb0.dll rm -f avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.zip cp -a objdir avrdude - zip -r avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.zip avrdude/bin/ avrdude/etc/avrdude.conf + mkdir -p dist/ + zip -r dist/avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.zip avrdude/bin/ avrdude/etc/avrdude.conf rm -r avrdude else rm -f avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.tar.bz2 cp -a objdir avrdude - tar -cjvf avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.tar.bz2 avrdude/bin/avrdude avrdude/etc/avrdude.conf + mkdir -p dist/ + tar -cjvf dist/avrdude-${OUTPUT_VERSION}-${OUTPUT_TAG}.tar.bz2 avrdude/bin/avrdude avrdude/etc/avrdude.conf rm -r avrdude fi From d80c6b83c5e301d2aaf8c940e28d2700caf17c54 Mon Sep 17 00:00:00 2001 From: kautism Date: Wed, 11 Mar 2020 13:08:35 +0800 Subject: [PATCH 6/7] Add lost package for native linux binary build --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0257db5..d08a211 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM debian -RUN apt-get update && apt-get install -y gcc-mingw-w64-i686 g++-mingw-w64-i686 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 libtool pkg-config bzip2 zip make autoconf wget patch git automake flex bison cmake xsltproc && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y gcc-mingw-w64-i686 g++-mingw-w64-i686 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 libtool pkg-config bzip2 zip make autoconf gperf wget patch git gcc g++ automake flex bison cmake xsltproc && rm -rf /var/lib/apt/lists/* COPY . /avrdude-build-script From 3ef5f913388f0f04962cd3d1cf1f84682e3c86b0 Mon Sep 17 00:00:00 2001 From: kautism Date: Wed, 11 Mar 2020 23:18:26 +0800 Subject: [PATCH 7/7] Remove unneed dll --- libusb-compat-0.1.5.build.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libusb-compat-0.1.5.build.bash b/libusb-compat-0.1.5.build.bash index 002eefb..9c03b1a 100755 --- a/libusb-compat-0.1.5.build.bash +++ b/libusb-compat-0.1.5.build.bash @@ -27,8 +27,8 @@ if [[ $OS == "Msys" || $OS == "Cygwin" || $CROSS_COMPILE_HOST == "i686-w64-mingw wget http://download.sourceforge.net/project/libusb-win32/libusb-win32-releases/1.2.6.0/libusb-win32-bin-1.2.6.0.zip fi unzip libusb-win32-bin-1.2.6.0.zip - mkdir -p $PREFIX/bin/ - cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll $PREFIX/bin/libusb0.dll + #mkdir -p $PREFIX/bin/ + #cp libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll $PREFIX/bin/libusb0.dll cp libusb-win32-bin-1.2.6.0/include/lusb0_usb.h $PREFIX/include cp libusb-win32-bin-1.2.6.0/lib/gcc/libusb.a $PREFIX/lib exit 0