9393set -e
9494
9595usage () {
96- echo " usage: ./build.sh dos|linux-x86|linux-x86_64|linux-arm|linux-aarch64|win32|win32-mingworg|win64 <fbc commit id> [--offline] [--repo url] [--remote name] [--recipe name]"
96+ echo " usage: ./build.sh target <fbc commit id> [options]"
97+ echo " "
98+ echo " target:"
99+ echo " linux-x86|linux-x86_64"
100+ echo " linux-arm|linux-aarch64"
101+ echo " dos|win32|win32-mingworg|win64"
102+ echo " "
103+ echo " <fbc commit id>:"
104+ echo " commit-id hash value of the commit"
105+ echo " name-id name of the branch or tag"
106+ echo " "
107+ echo " options:"
108+ echo " --offline only use cached files, don't download from net"
109+ echo " --repo url specify alternate name for repo to fetch from"
110+ echo " in addition to origin repo"
111+ echo " --remote name specify the name to use for the alternate remote"
112+ echo " --recipe name specify a build recipe to use"
113+ echo " --use-libffi-cache"
114+ echo " don't build libffi, just use the chaced files"
97115 exit 1
98116}
99117
@@ -118,6 +136,10 @@ case $arg in
118136 recipe_name=" $2 "
119137 shift ; shift
120138 ;;
139+ --use-libffi-cache)
140+ uselibfficache=Y
141+ shift
142+ ;;
121143dos|linux-x86|linux-x86_64|win32|win64|linux-arm|linux-aarch64)
122144 target=" $1 "
123145 fbtarget=$target
154176# check recipe name
155177# TODO: error on invalid combination of target and recipe
156178if [ ! -z " $recipe_name " ]; then
157- recipe=$recipe_name
179+ user_recipe=$recipe_name
180+ named_recipe=$recipe_name
158181else
159- recipe=" "
182+ # if no recipe given, set the default recipe for the main package
183+ user_recipe=
184+ named_recipe=-winlibs-gcc-9.3.0
160185fi
161186
162187echo " building FB-$target (uname = ` uname` , uname -m = ` uname -m` )"
@@ -205,8 +230,9 @@ cd ../..
205230
206231cd build
207232
208- buildinfo=../output/buildinfo-$target$recipe .txt
233+ buildinfo=../output/buildinfo-$target$user_recipe .txt
209234echo " fbc $fbccommit $target , build based on:" > $buildinfo
235+ echo " named recipe: $named_recipe " >> $buildinfo
210236echo >> $buildinfo
211237
212238copyfile () {
@@ -295,14 +321,15 @@ get_equation_toolchain() {
295321 arch=" $2 "
296322 toolchain=equation
297323
298- case " $recipe " in
324+ case " $named_recipe " in
299325 -equation-gcc-8.3.0)
300326 gccversion=8.3.0
301327 mingwbuildsrev=
302328 mingwruntime=
303329 ;;
304330 * )
305- echo " invalid recipe $receipe "
331+ echo " get_equation_toolchain(): invalid recipe $named_recipe "
332+ exit 1
306333 ;;
307334 esac
308335
@@ -340,7 +367,7 @@ get_winlibs_toolchain() {
340367 default_eh=seh
341368 fi
342369
343- case " $recipe " in
370+ case " $named_recipe " in
344371 -winlibs-gcc-10.3.0)
345372 gccversion=10.3.0
346373 llvmversion=11.1.0
@@ -366,14 +393,6 @@ get_winlibs_toolchain() {
366393# winlibsdir=$gccversion-$llvmversion-$mingwruntime-$mingwbuildsrev
367394# file=winlibs-$arch-posix-$default_eh-gcc-$gccversion-llvm-$llvmversion-mingw-w64-$mingwruntime-$mingwbuildsrev.7z
368395# ;;
369- -winlibs-gcc-9.3.0)
370- gccversion=9.3.0
371- llvmversion=
372- mingwruntime=7.0.0
373- mingwbuildsrev=r3
374- winlibsdir=$gccversion -$mingwruntime -sjlj-$mingwbuildsrev
375- file=winlibs-mingw-w64-$arch -$gccversion -$mingwruntime -$mingwbuildsrev -sjlj.7z
376- ;;
377396 -winlibs-gcc-9.3.0)
378397 gccversion=9.3.0
379398 llvmversion=
@@ -391,7 +410,8 @@ get_winlibs_toolchain() {
391410 file=mingw-w64-$arch -$gccversion -$mingwruntime .7z
392411 ;;
393412 * )
394- echo " invalid recipe $receipe "
413+ echo " get_winlibs_toolchain(): invalid recipe $named_recipe "
414+ exit 1
395415 ;;
396416 esac
397417
@@ -410,8 +430,8 @@ get_mingww64_toolchain() {
410430 bits=" $1 "
411431 arch=" $2 "
412432 toolchain=mingw-w64
413-
414- case " $recipe " in
433+
434+ case " $named_recipe " in
415435 -gcc-8.1.0)
416436 gccversion=8.1.0
417437 mingwbuildsrev=rev0
@@ -437,14 +457,8 @@ get_mingww64_toolchain() {
437457 mingwbuildsrev=rev0
438458 mingwruntime=v4
439459 ;;
440- " " )
441- # default build recipe
442- gccversion=8.1.0
443- mingwbuildsrev=rev0
444- mingwruntime=v6
445- ;;
446460 * )
447- echo " unknown recipe $recipe "
461+ echo " unknown recipe $named_recipe "
448462 exit 1
449463 esac
450464
@@ -467,16 +481,20 @@ get_windows_toolchain() {
467481 bits=" $1 "
468482 arch=" $2 "
469483
470- case " $recipe " in
484+ case " $named_recipe " in
471485 -winlibs-* )
472486 get_winlibs_toolchain $bits $arch
473487 ;;
474488 -equation-* )
475489 get_equation_toolchain $bits $arch
476490 ;;
477- * )
491+ -gcc- * )
478492 get_mingww64_toolchain $bits $arch
479493 ;;
494+ * )
495+ echo " get_windows_toolchain(): invalid recipe $named_recipe "
496+ exit 1
497+ ;;
480498 esac
481499}
482500
@@ -734,27 +752,29 @@ libffibuild() {
734752 # don't use any cached files when building the packages
735753 # commented out for future reference
736754 # do we already have the files we need?
737- # if [ -f "../input/$libffi_title/$target$recipe/ffi.h" ]; then
738- # if [ -f "../input/$libffi_title/$target$recipe/ffitarget.h" ]; then
739- # if [ -f "../input/$libffi_title/$target$recipe/libffi.a" ]; then
740- # echo
741- # echo "using cached libffi: $libffi_title/$target$recipe"
742- # echo
743- # return
744- # fi
745- # fi
746- # fi
755+ if [ " $uselibfficache " = " Y" ]; then
756+ if [ -f " ../input/$libffi_title /$target$named_recipe /ffi.h" ]; then
757+ if [ -f " ../input/$libffi_title /$target$named_recipe /ffitarget.h" ]; then
758+ if [ -f " ../input/$libffi_title /$target$named_recipe /libffi.a" ]; then
759+ echo
760+ echo " using cached libffi: $libffi_title /$target$named_recipe "
761+ echo
762+ return
763+ fi
764+ fi
765+ fi
766+ fi
747767
748768 # or just grab the files we need from the package?
749769 # we might copy in the files directly if we unable to build libffi ourselves
750770 # as was the case for libffi-3.2.1 and some gcc tool chains
751771 # so just leave this section commented out for reference
752- # case "$recipe " in
772+ # case "$named_recipe " in
753773# -gcc-7.1.0|-gcc-7.1.0r0|-gcc-7.1.0r2|-gcc-7.3.0|-gcc-8.1.0)
754- # mkdir -p ../input/$libffi_title/$target$recipe
755- # cp opt/lib/libffi-3.3/include/ffi.h ../input/$libffi_title/$target$recipe
756- # cp opt/lib/libffi-3.3/include/ffitarget.h ../input/$libffi_title/$target$recipe
757- # cp opt/lib/libffi.a ../input/$libffi_title/$target$recipe
774+ # mkdir -p ../input/$libffi_title/$target$named_recipe
775+ # cp opt/lib/libffi-3.3/include/ffi.h ../input/$libffi_title/$target$named_recipe
776+ # cp opt/lib/libffi-3.3/include/ffitarget.h ../input/$libffi_title/$target$named_recipe
777+ # cp opt/lib/libffi.a ../input/$libffi_title/$target$named_recipe
758778# return
759779# ;;
760780# esac
@@ -775,9 +795,9 @@ libffibuild() {
775795 fi
776796 make
777797 # stash some files in the input folder to make rebuilding faster
778- mkdir -p ../../input/$libffi_title /$target$recipe
779- cp include/ffi.h include/ffitarget.h ../../input/$libffi_title /$target$recipe
780- cp .libs/libffi.a ../../input/$libffi_title /$target$recipe
798+ mkdir -p ../../input/$libffi_title /$target$named_recipe
799+ cp include/ffi.h include/ffitarget.h ../../input/$libffi_title /$target$named_recipe
800+ cp .libs/libffi.a ../../input/$libffi_title /$target$named_recipe
781801 cd ..
782802}
783803
@@ -786,23 +806,25 @@ windowsbuild() {
786806 # its gcc and not one from the host
787807 origPATH=" $PATH "
788808 export PATH=" $PWD /bin:$PATH "
789-
790809 echo " Current Path: $PATH "
810+ echo " gcc version: ` gcc -dumpversion` "
811+ echo >> $buildinfo
812+ echo " gcc version: ` gcc -dumpversion` " >> $buildinfo
791813
792814 libffibuild
793815 # copy our stored files to the build
794816 case " $toolchain " in
795817 equation)
796818 case " $target " in
797- win32) cp ../input/$libffi_title /$target$recipe /ffi.h ../input/$libffi_title /$target$recipe /ffitarget.h ./i686-pc-mingw32/include;;
798- win64) cp ../input/$libffi_title /$target$recipe /ffi.h ../input/$libffi_title /$target$recipe /ffitarget.h ./x86_64-w64-mingw32/include;;
819+ win32) cp ../input/$libffi_title /$target$named_recipe /ffi.h ../input/$libffi_title /$target$named_recipe /ffitarget.h ./i686-pc-mingw32/include;;
820+ win64) cp ../input/$libffi_title /$target$named_recipe /ffi.h ../input/$libffi_title /$target$named_recipe /ffitarget.h ./x86_64-w64-mingw32/include;;
799821 esac
800822 ;;
801823 * )
802824 case " $target " in
803- win32) cp ../input/$libffi_title /$target$recipe /ffi.h ../input/$libffi_title /$target$recipe /ffitarget.h ./i686-w64-mingw32/include;;
804- win32-mingworg) cp ../input/$libffi_title /$target$recipe /ffi.h ../input/$libffi_title /$target$recipe /ffitarget.h ./include;;
805- win64) cp ../input/$libffi_title /$target$recipe /ffi.h ../input/$libffi_title /$target$recipe /ffitarget.h ./x86_64-w64-mingw32/include;;
825+ win32) cp ../input/$libffi_title /$target$named_recipe /ffi.h ../input/$libffi_title /$target$named_recipe /ffitarget.h ./i686-w64-mingw32/include;;
826+ win32-mingworg) cp ../input/$libffi_title /$target$named_recipe /ffi.h ../input/$libffi_title /$target$named_recipe /ffitarget.h ./include;;
827+ win64) cp ../input/$libffi_title /$target$named_recipe /ffi.h ../input/$libffi_title /$target$named_recipe /ffitarget.h ./x86_64-w64-mingw32/include;;
806828 esac
807829 ;;
808830 esac
@@ -858,7 +880,7 @@ windowsbuild() {
858880 cp bin/gprof.exe fbc/bin/$fbtarget
859881 cp bin/ld.exe fbc/bin/$fbtarget
860882
861- case " $recipe " in
883+ case " $named_recipe " in
862884 -equation-gcc-8.3.0)
863885 cp bin/gcc.exe fbc/bin/$target
864886 cp bin/gdb.exe fbc/bin/$target
@@ -873,7 +895,7 @@ windowsbuild() {
873895 cp --parents libexec/gcc/x86_64-w64-mingw32/$gccversion /cc1.exe fbc/bin
874896 ;;
875897 * )
876- echo " invalid target $target "
898+ echo " windowsbuild(): invalid target $target "
877899 exit 1
878900 ;;
879901 esac
@@ -913,7 +935,7 @@ windowsbuild() {
913935 cp bin/ld.exe fbc/bin/libexec/gcc/x86_64-w64-mingw32/$gccversion /ld.exe
914936 ;;
915937 * )
916- echo " invalid target $target "
938+ echo " windowsbuild(): invalid target $target "
917939 exit 1
918940 ;;
919941 esac
@@ -922,18 +944,21 @@ windowsbuild() {
922944 case " $target " in
923945 win32)
924946 # !!! TODO !!! re-evaluate the gdb used with later gcc versions
925- # !!! TODO !!! maybe package the 32-bit gcc too even for mingw-w64
926947 # Take MinGW.org's gdb, because the gdb from the MinGW-w64 toolchain has much more
927948 # dependencies (e.g. Python for scripting purposes) which we probably don't want/need.
928949 # (this should probably be reconsidered someday)
929- cp mingworg-gdb/bin/gdb.exe fbc/bin/win32
930- cp mingworg-gdb/bin/libgcc_s_dw2-1.dll fbc/bin/win32
931- cp mingworg-gdb/bin/zlib1.dll fbc/bin/win32
950+ cp mingworg-gdb/bin/gdb.exe fbc/bin/win32
951+ cp mingworg-gdb/bin/libgcc_s_dw2-1.dll fbc/bin/win32
952+ cp mingworg-gdb/bin/zlib1.dll fbc/bin/win32
953+
954+ cp bin/gcc.exe fbc/bin/win32
955+ cp --parents libexec/gcc/i686-w64-mingw32/$gccversion /cc1.exe fbc/bin
956+
932957 ;;
933958 win32-mingworg)
934- cp bin/gdb.exe fbc/bin/win32
935- cp bin/libgcc_s_dw2-1.dll fbc/bin/win32
936- cp bin/zlib1.dll fbc/bin/win32
959+ cp bin/gdb.exe fbc/bin/win32
960+ cp bin/libgcc_s_dw2-1.dll fbc/bin/win32
961+ cp bin/zlib1.dll fbc/bin/win32
937962 ;;
938963 win64)
939964 cp bin/gcc.exe fbc/bin/win64
@@ -949,7 +974,7 @@ windowsbuild() {
949974 cd fbc/lib/win32 && make && cd ../../..
950975 fi
951976
952- cp ../input/$libffi_title /$target$recipe /libffi.a fbc/lib/$fbtarget
977+ cp ../input/$libffi_title /$target$named_recipe /libffi.a fbc/lib/$fbtarget
953978
954979 # Reduce .exe sizes by dropping debug info
955980 # (this was at least needed for MinGW.org's gdb, and probably nothing else,
@@ -963,8 +988,8 @@ windowsbuild() {
963988 cd fbc
964989 case " $target " in
965990 win32|win64)
966- make bindist DISABLE_DOCS=1 FBPACKSUFFIX=$recipe FBSHA1=$FBSHA1
967- make bindist ENABLE_STANDALONE=1 FBPACKSUFFIX=$recipe FBSHA1=$FBSHA1
991+ make bindist DISABLE_DOCS=1 FBPACKSUFFIX=$user_recipe FBSHA1=$FBSHA1
992+ make bindist ENABLE_STANDALONE=1 FBPACKSUFFIX=$user_recipe FBSHA1=$FBSHA1
968993 ;;
969994 win32-mingworg)
970995 make bindist DISABLE_DOCS=1 FBPACKSUFFIX=-mingworg FBSHA1=$FBSHA1
@@ -975,7 +1000,7 @@ windowsbuild() {
9751000
9761001 # Only build the installer, if we are also
9771002 # building the default package
978- if [ -z " $recipe " ]; then
1003+ if [ -z " $user_recipe " ]; then
9791004 if [ " $target " = win32 ]; then
9801005 cd fbc/contrib/nsis-installer
9811006 cp ../../FreeBASIC-* -win32.zip .
@@ -986,8 +1011,8 @@ windowsbuild() {
9861011 fi
9871012
9881013 cp fbc/* .zip fbc/* .7z ../output
989- cp fbc/contrib/manifest/fbc-$target$recipe .lst ../output
990- cp fbc/contrib/manifest/FreeBASIC-$target$recipe .lst ../output
1014+ cp fbc/contrib/manifest/fbc-$target$user_recipe .lst ../output
1015+ cp fbc/contrib/manifest/FreeBASIC-$target$user_recipe .lst ../output
9911016
9921017 export PATH=" $origPATH "
9931018 cd ..
0 commit comments