2424# - a remote branch or tag name, must specify "remote-name/branch".
2525#
2626# --offline
27- # when given, build.sh will stop with exit code 1 if the file is not already in
27+ # when given, build.sh will stop with exit code 1 if the file is not already
2828# in the download cache.
2929#
3030# --repo url
31- # specify an additional repo url to fetch in to the local repo other than the
31+ # specify an additional repo url to fetch in to the local repo other than the
3232# official https://github.com/freebasic/fbc.git repo.
3333#
3434# --remote name
35- # specifies the remote name to add and use when referring to the other repo url.
36- # remote name will default to 'other' if the --repo option was given.
35+ # specifies the remote name to add and use when referring to the other repo
36+ # url. remote name will default to 'other' if the --repo option was given.
3737# remote name will default to 'origin' if the --repo option was not given.
3838#
3939# --recipe name
40- # not used
40+ # specify which build recipe to use:
41+ # * -freebsd-13.0-x86
42+ # * -freebsd-13.0-x86_64
43+ #
44+ # Not all recipes are supported on all targets.
4145#
4246# Requirements:
4347# - gmake and other gnu tools
44- #
48+ #
4549set -e
4650
4751usage () {
48- echo " usage: ./build-bsd.sh freebsd-x86|freebsd-x86_64 <fbc commit id> [--offline] [--repo url] [--remote name] [--recipe name]"
52+ echo " usage: ./build.sh target <fbc commit id> [options]"
53+ echo " "
54+ echo " target:"
55+ echo " freebsd-x86|freebsd-x86_64"
56+ echo " "
57+ echo " <fbc commit id>:"
58+ echo " commit-id hash value of the commit"
59+ echo " name-id name of the branch or tag"
60+ echo " "
61+ echo " options:"
62+ echo " --offline only use cached files, don't download from net"
63+ echo " --repo url specify alternate name for repo to fetch from"
64+ echo " in addition to origin repo"
65+ echo " --remote name specify the name to use for the alternate remote"
66+ echo " --recipe name specify a build recipe to use"
4967 exit 1
5068}
5169
@@ -78,7 +96,7 @@ freebsd-x86|freebsd-x86_64)
7896* )
7997 fbccommit=" $1 "
8098 shift
81- ;;
99+ ;;
82100esac
83101done
84102
@@ -99,15 +117,49 @@ else
99117fi
100118
101119# check recipe name
102- # TODO: error on invalid combination of target and recipe
120+ # recipe_name is from the command line option, empty string if not given
121+ # user_recipe is either explicit (from command line) or automatic (below)
103122if [ ! -z " $recipe_name " ]; then
104- recipe=$recipe_name
123+ # recipe_name may be blank and optionally start with a dash '-'
124+ # user_recipe must be blank or start with a dash '-'
125+ case " $recipe_name " in
126+ " " |-* )
127+ user_recipe=$recipe_name
128+ ;;
129+ * )
130+ user_recipe=-$recipe_name
131+ ;;
132+ esac
105133else
106- recipe=" "
134+ # if no recipe given, set the default recipe for the main package
135+ user_recipe=
136+ case " $target " in
137+ win32|win64)
138+ named_recipe=-winlibs-gcc-9.3.0
139+ ;;
140+ linux-arm)
141+ # named recipe wasn't given, try and figure it out ...
142+ if [ -f /etc/os-release ]; then
143+ host_os_id=$( grep -oP ' (?<=^ID=).+' /etc/os-release | tr -d ' "' )
144+ host_os_ver=$( grep -oP ' (?<=^VERSION_ID=).+' /etc/os-release | tr -d ' "' )
145+ fi
146+ case " $host_os_id -$host_os_ver " in
147+ raspbian-9)
148+ named_recipe=-raspbian9-arm
149+ ;;
150+ esac
151+ ;;
152+ esac
107153fi
108154
109155echo " building FB-$target (uname = ` uname` , uname -m = ` uname -m` )"
110156echo " from repository: https://github.com/freebasic/fbc.git"
157+ if [ ! -z " $user_recipe " ]; then
158+ echo " user gave recipe '$user_recipe '"
159+ fi
160+ if [ ! -z " $named_recipe " ]; then
161+ echo " using named recipe '$named_recipe '"
162+ fi
111163if [ ! -z " $repo_url " ]; then
112164 echo " from repository: $repo_url "
113165fi
@@ -152,14 +204,16 @@ cd ../..
152204
153205cd build
154206
155- buildinfo=../output/buildinfo-$target$recipe .txt
207+ buildinfo=../output/buildinfo-$target$user_recipe .txt
208+ echo " buildinfo: $buildinfo "
156209echo " fbc $fbccommit $target , build based on:" > $buildinfo
210+ echo " named recipe: $named_recipe " >> $buildinfo
157211echo >> $buildinfo
158212
159213copyfile () {
160214 srcfile=" $1 "
161215 dstfile=" $2 "
162-
216+
163217 if [ -f " $dstfile " ]; then
164218 echo " cached $dstfile "
165219 else
@@ -191,21 +245,36 @@ download() {
191245 echo " download failed"
192246 rm -f " ../input/$filename "
193247 exit 1
194- fi
248+ fi
195249 fi
196250 fi
197251
198252 echo " $filename <$url >" >> $buildinfo
199253}
200254
201255
256+ BUILD_BOOTFBCFLAGS=
257+ AppendBOOTFBCFLAGS () {
258+ if [ ! -z " $1 " ]; then
259+ if [ -z " $BUILD_BOOTFBCFLAGS " ]; then
260+ BUILD_BOOTFBCFLAGS=" $1 "
261+ else
262+ BUILD_BOOTFBCFLAGS=" $BUILD_BOOTFBCFLAGS $1 "
263+ fi
264+ fi
265+ }
266+
202267# choose a bootstrap source for the target
203268case $fbtarget in
204269freebsd-x86|freebsd-x86_64)
205270 bootfb_title=FreeBASIC-1.09.0-$fbtarget
206271 ;;
207272esac
208273
274+ if [ ! -z " $named_recipe " ]; then
275+ AppendBOOTFBCFLAGS " FBPACKTARGET=${named_recipe# -} "
276+ fi
277+
209278case $fbtarget in
210279freebsd* )
211280 # Special case: freebsd builds use the host gcc toolchain
@@ -229,36 +298,20 @@ freebsdbuild() {
229298 echo
230299 echo " bootstrapping normal fbc"
231300 echo
232- gmake FBC=../$bootfb_title /bin/fbc FBSHA1=$FBSHA1
301+ gmake FBC=../$bootfb_title /bin/fbc FBSHA1=$FBSHA1 $BUILD_BOOTFBCFLAGS
233302 gmake install prefix=../tempinstall
234303 echo
235304 echo " rebuilding normal fbc"
236305 echo
237306 gmake clean-compiler
238- gmake FBC=../tempinstall/bin/fbc FBSHA1=$FBSHA1
307+ gmake FBC=../tempinstall/bin/fbc FBSHA1=$FBSHA1 $BUILD_BOOTFBCFLAGS
239308 cd ..
240309
241- cd fbc && gmake bindist FBSHA1=$FBSHA1 && cd ..
310+ cd fbc && gmake bindist FBSHA1=$FBSHA1 $BUILD_BOOTFBCFLAGS && cd ..
242311 cp fbc/* .tar.* ../output
243312 cp fbc/contrib/manifest/FreeBASIC-$fbtarget .lst ../output
244313}
245314
246- libffibuild () {
247- echo
248- echo " building libffi"
249- echo
250- libffi_build=" ${libffi_title} -build"
251- mkdir " $libffi_build "
252- cd " $libffi_build "
253- CFLAGS=-O2 ../$libffi_title /configure --disable-shared --enable-static
254- gmake
255- # stash some files in the input folder to make rebuilding faster
256- mkdir -p ../../input/$libffi_title /$target$recipe
257- cp include/ffi.h include/ffitarget.h ../../input/$libffi_title /$target$recipe
258- cp .libs/libffi.a ../../input/$libffi_title /$target$recipe
259- cd ..
260- }
261-
262315case $fbtarget in
263316freebsd* ) freebsdbuild | tee log.txt 2>&1 ;;
264317esac
0 commit comments