do_sysroot.sh 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. set -e
  3. libusb_ver=1.0.22
  4. rtlsdr_ver=0.6.0
  5. # from https://libusb.info/
  6. [ -e libusb-${libusb_ver}.7z ] || curl -L -O https://github.com/libusb/libusb/releases/download/v${libusb_ver}/libusb-${libusb_ver}.7z
  7. mkdir libusb
  8. 7zr x -olibusb -y libusb-${libusb_ver}.7z
  9. sysroot32=$(pwd)/sysroot32
  10. sysroot64=$(pwd)/sysroot64
  11. sysroot32static=$(pwd)/sysroot32static
  12. sysroot64static=$(pwd)/sysroot64static
  13. mkdir -p sysroot{32,64}{,static}/usr/{include,lib,bin}
  14. cp libusb/include/libusb-1.0/libusb.h $sysroot32/usr/include
  15. cp libusb/include/libusb-1.0/libusb.h $sysroot64/usr/include
  16. cp libusb/include/libusb-1.0/libusb.h $sysroot32static/usr/include
  17. cp libusb/include/libusb-1.0/libusb.h $sysroot64static/usr/include
  18. cp libusb/MinGW32/static/libusb-1.0.a $sysroot32static/usr/lib
  19. cp libusb/MinGW64/static/libusb-1.0.a $sysroot64static/usr/lib
  20. cp libusb/MinGW32/dll/libusb-1.0.dll $sysroot32/usr/bin
  21. cp libusb/MinGW32/dll/libusb-1.0.dll.a $sysroot32/usr/lib
  22. cp libusb/MinGW64/dll/libusb-1.0.dll $sysroot64/usr/bin
  23. cp libusb/MinGW64/dll/libusb-1.0.dll.a $sysroot64/usr/lib
  24. # or git clone https://github.com/osmocom/rtl-sdr.git
  25. [ -e rtl-sdr-${rtlsdr_ver}.tar.gz ] || curl -L -o rtl-sdr-${rtlsdr_ver}.tar.gz https://github.com/osmocom/rtl-sdr/archive/${rtlsdr_ver}.tar.gz
  26. tar xzf rtl-sdr-${rtlsdr_ver}.tar.gz
  27. cd rtl-sdr-${rtlsdr_ver}
  28. [ "$(uname)" = "Darwin" ] && export tools=/opt/local
  29. export CMAKE_SYSROOT=$sysroot32 ; echo $CMAKE_SYSROOT
  30. mkdir build-tmp ; cd build-tmp ; cmake -DCMAKE_TOOLCHAIN_FILE=../../cmake/Toolchain-gcc-mingw-w64-i686.cmake .. && make && make install ; cd ..
  31. rm -rf build-tmp
  32. mv $sysroot32/usr/lib/librtlsdr_static.a $sysroot32/usr/lib/librtlsdr.a
  33. export CMAKE_SYSROOT=$sysroot32static ; echo $CMAKE_SYSROOT
  34. mkdir build-tmp ; cd build-tmp ; cmake -DCMAKE_TOOLCHAIN_FILE=../../cmake/Toolchain-gcc-mingw-w64-i686.cmake -DBUILD_SHARED_LIBS:BOOL=OFF .. && make && make install ; cd ..
  35. rm -rf build-tmp
  36. mv $sysroot32static/usr/lib/librtlsdr_static.a $sysroot32static/usr/lib/librtlsdr.a
  37. rm $sysroot32static/usr/lib/librtlsdr.dll.a
  38. rm $sysroot32static/usr/bin/librtlsdr.dll
  39. export CMAKE_SYSROOT=$sysroot64 ; echo $CMAKE_SYSROOT
  40. mkdir build-tmp ; cd build-tmp ; cmake -DCMAKE_TOOLCHAIN_FILE=../../cmake/Toolchain-gcc-mingw-w64-x86-64.cmake .. && make && make install ; cd ..
  41. rm -rf build-tmp
  42. mv $sysroot64/usr/lib/librtlsdr_static.a $sysroot64/usr/lib/librtlsdr.a
  43. export CMAKE_SYSROOT=$sysroot64static ; echo $CMAKE_SYSROOT
  44. mkdir build-tmp ; cd build-tmp ; cmake -DCMAKE_TOOLCHAIN_FILE=../../cmake/Toolchain-gcc-mingw-w64-x86-64.cmake -DBUILD_SHARED_LIBS:BOOL=OFF .. && make && make install ; cd ..
  45. rm -rf build-tmp
  46. mv $sysroot64static/usr/lib/librtlsdr_static.a $sysroot64static/usr/lib/librtlsdr.a
  47. rm $sysroot64static/usr/lib/librtlsdr.dll.a
  48. rm $sysroot64static/usr/bin/librtlsdr.dll
  49. cd ..
  50. # build rtl_433
  51. export CMAKE_SYSROOT=$sysroot32 ; echo $CMAKE_SYSROOT
  52. mkdir build-tmp ; cd build-tmp ; cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-gcc-mingw-w64-i686.cmake .. && make && make install ; cd ..
  53. rm -rf build-tmp
  54. # Non-static 32-bit binary from w64 compiler is broken with
  55. # missing libgcc_s_sjlj-1.dll, libwinpthread-1.dll
  56. # neither CMAKE_EXE_LINKER_FLAGS="-static-libgcc"
  57. # nor target_link_libraries(rtl_433 -static-libgcc)
  58. # fix this. Ideas welcome.
  59. mv $sysroot32/usr/bin/rtl_433.exe $sysroot32/usr/bin/rtl_433_32bit_nonstatic_broken.exe
  60. export CMAKE_SYSROOT=$sysroot32static ; echo $CMAKE_SYSROOT
  61. mkdir build-tmp ; cd build-tmp ; cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-gcc-mingw-w64-i686.cmake .. && make && make install ; cd ..
  62. rm -rf build-tmp
  63. mv $sysroot32static/usr/bin/rtl_433.exe $sysroot32static/usr/bin/rtl_433_32bit_static.exe
  64. export CMAKE_SYSROOT=$sysroot64 ; echo $CMAKE_SYSROOT
  65. mkdir build-tmp ; cd build-tmp ; cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-gcc-mingw-w64-x86-64.cmake .. && make && make install ; cd ..
  66. rm -rf build-tmp
  67. export CMAKE_SYSROOT=$sysroot64static ; echo $CMAKE_SYSROOT
  68. mkdir build-tmp ; cd build-tmp ; cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-gcc-mingw-w64-x86-64.cmake .. && make && make install ; cd ..
  69. rm -rf build-tmp
  70. mv $sysroot64static/usr/bin/rtl_433.exe $sysroot64static/usr/bin/rtl_433_64bit_static.exe
  71. # collect package
  72. echo Packing rtl_433-win-x32.zip
  73. zip --junk-paths rtl_433-win-x32.zip sysroot32*/usr/bin/*.dll sysroot32*/usr/bin/rtl_433*.exe
  74. echo Packing rtl_433-win-x64.zip
  75. zip --junk-paths rtl_433-win-x64.zip sysroot64*/usr/bin/*.dll sysroot64*/usr/bin/rtl_433*.exe