]> gitweb.factorcode.org Git - factor.git/blob - build.sh
build: allow any GCC version
[factor.git] / build.sh
1 #!/usr/bin/env bash
2
3 # Programs returning != 0 will not cause script to exit
4 set +e
5
6 # Case insensitive string comparison
7 shopt -s nocaseglob
8 #shopt -s nocasematch
9
10 ECHO=echo
11 OS=
12 ARCH=
13 WORD=
14 GIT_PROTOCOL=${GIT_PROTOCOL:="git"}
15 GIT_URL=${GIT_URL:=$GIT_PROTOCOL"://factorcode.org/git/factor.git"}
16 SCRIPT_ARGS="$*"
17
18 # return 1 on found
19 test_program_installed() {
20     if ! [[ -n `type -p $1` ]] ; then
21         return 0;
22     fi
23     return 1;
24 }
25
26 # return 1 on found
27 test_programs_installed() {
28     installed=0;
29     $ECHO -n "Checking for all($*)..."
30     for i in $* ;
31     do
32         test_program_installed $i
33         if [[ $? -eq 1 ]]; then
34             installed=$(( $installed + 1 ))
35         fi
36     done
37     if [[ $installed -eq $# ]] ; then
38         $ECHO "found!"
39         return 1
40     else
41         $ECHO "all not found."
42         return 0
43     fi
44 }
45
46 exit_script() {
47     if [[ $FIND_MAKE_TARGET = true ]] ; then
48         # Must be echo not $ECHO
49         echo $MAKE_TARGET;
50     fi
51     exit $1
52 }
53
54 ensure_program_installed() {
55     installed=0;
56     $ECHO -n "Checking for any($*)..."
57     for i in $* ;
58     do
59         test_program_installed $i
60         if [[ $? -eq 1 ]]; then
61             $ECHO "found $i!"
62             installed=$(( $installed + 1 ))
63             return
64         fi
65     done
66     $ECHO "none found."
67     $ECHO -n "Install "
68     if [[ $# -eq 1 ]] ; then
69         $ECHO -n $1
70     else
71         $ECHO -n "any of [ $* ]"
72     fi
73     $ECHO " and try again."
74     if [[ $OS == macosx ]] ; then
75         $ECHO "If you have Xcode 4.3 or higher installed, you must install the"
76         $ECHO "Command Line Tools from Xcode Preferences > Downloads in order"
77         $ECHO "to build Factor."
78     fi
79     exit_script 1;
80 }
81
82 check_ret() {
83     RET=$?
84     if [[ $RET -ne 0 ]] ; then
85        $ECHO $1 failed
86        exit_script 2
87     fi
88 }
89
90 set_downloader() {
91     test_program_installed wget
92     if [[ $? -ne 0 ]] ; then
93         DOWNLOADER=wget
94         DOWNLOADER_NAME=wget
95         return
96     fi
97     test_program_installed curl
98     if [[ $? -ne 0 ]] ; then
99         DOWNLOADER="curl -f -O"
100         DOWNLOADER_NAME=curl
101         return
102     fi
103     $ECHO "error: wget or curl required"
104     exit_script 11
105 }
106
107 set_md5sum() {
108     test_program_installed md5sum
109     if [[ $? -ne 0 ]] ; then
110         MD5SUM=md5sum
111     else
112         MD5SUM="md5 -r"
113     fi
114 }
115
116 semver_into() {
117     RE_SEMVER="^([0-9]*)\.([0-9]*)\.([0-9]*)-?(.*)?$" # 3.3.3-5
118     CLANG_RE_OLD="^([0-9]*)\.([0-9]*)-?(.*)?$" # 3.3-5
119     if [[ $1 =~ $RE_SEMVER ]] ; then
120         export "$2=${BASH_REMATCH[1]}"
121         export "$3=${BASH_REMATCH[2]}"
122         export "$4=${BASH_REMATCH[3]}"
123         export "$5=${BASH_REMATCH[4]}"
124     elif [[ $1 =~ $CLANG_RE_OLD ]] ; then
125         export "$2=${BASH_REMATCH[1]}"
126         export "$3=${BASH_REMATCH[2]}"
127         export "$4=0"
128         export "$5=${BASH_REMATCH[3]}"
129     else
130         echo "unsupported version number, please report a bug: $1"
131         exit 123
132     fi
133 }
134
135 clang_version_ok() {
136     CLANG_VERSION=`clang --version | head -n1`
137     CLANG_VERSION_RE='^[a-zA-Z0-9 ]* version (.*)$' # 3.3-5
138     if [[ $CLANG_VERSION =~ $CLANG_VERSION_RE ]] ; then
139         export "CLANG_VERSION=${BASH_REMATCH[1]}"
140         local CLANG_MAJOR local CLANG_MINOR local CLANG_PATCH local CLANG_SPECIAL
141         semver_into "$CLANG_VERSION" CLANG_MAJOR CLANG_MINOR CLANG_PATCH CLANG_SPECIAL
142         if [[ $CLANG_MAJOR -lt 3
143             || ( $CLANG_MAJOR -eq 3 && $CLANG_MINOR -le 1 )
144             ]] ; then
145             echo "clang version required >= 3.1, got $CLANG_VERSION"
146             return 1
147         fi
148     else
149         return 1
150     fi
151     return 0
152 }
153
154 set_cc() {
155     test_programs_installed clang clang++
156     if [[ $? -ne 0 ]] && clang_version_ok ; then
157         [ -z "$CC" ] && CC=clang
158         [ -z "$CXX" ] && CXX=clang++
159         return
160     fi
161
162     test_programs_installed gcc g++
163     if [[ $? -ne 0 ]] ; then
164         [ -z "$CC" ] && CC=gcc
165         [ -z "$CXX" ] && CXX=g++
166         return
167     fi
168
169     $ECHO "error: high enough version of either (clang/clang++) or (gcc/g++) required!"
170     exit_script 10
171 }
172
173 set_make() {
174     MAKE='make'
175 }
176
177 check_installed_programs() {
178     ensure_program_installed chmod
179     ensure_program_installed uname
180     ensure_program_installed git
181     ensure_program_installed wget curl
182     ensure_program_installed clang gcc
183     ensure_program_installed clang++ g++ cl
184     ensure_program_installed make gmake
185     ensure_program_installed md5sum md5
186     ensure_program_installed cut
187 }
188
189 check_library_exists() {
190     GCC_TEST=factor-library-test.c
191     GCC_OUT=factor-library-test.out
192     $ECHO -n "Checking for library $1..."
193     $ECHO "int main(){return 0;}" > $GCC_TEST
194     $CC $GCC_TEST -o $GCC_OUT -l $1 2>&-
195     if [[ $? -ne 0 ]] ; then
196         $ECHO "not found."
197     else
198         $ECHO "found."
199     fi
200     $DELETE -f $GCC_TEST
201     check_ret $DELETE
202     $DELETE -f $GCC_OUT
203     check_ret $DELETE
204 }
205
206 check_X11_libraries() {
207     check_library_exists GL
208     check_library_exists X11
209     check_library_exists pango-1.0
210 }
211
212 check_gtk_libraries() {
213     check_library_exists gobject-2.0
214     check_library_exists gtk-x11-2.0
215     check_library_exists gdk-x11-2.0
216     check_library_exists gdk_pixbuf-2.0
217     check_library_exists gtkglext-x11-1.0
218     check_library_exists atk-1.0
219     check_library_exists gio-2.0
220     check_library_exists gdkglext-x11-1.0
221     check_library_exists pango-1.0
222 }
223
224
225 check_libraries() {
226     case $OS in
227             linux) check_X11_libraries
228                    check_gtk_libraries;;
229             unix) check_gtk_libraries;;
230     esac
231 }
232
233 check_factor_exists() {
234     if [[ -d "factor" ]] ; then
235         $ECHO "A directory called 'factor' already exists."
236         $ECHO "Rename or delete it and try again."
237         exit_script 4
238     fi
239 }
240
241 find_os() {
242     if [[ -n $OS ]] ; then return; fi
243     $ECHO "Finding OS..."
244     uname_s=`uname -s`
245     check_ret uname
246     case $uname_s in
247         CYGWIN_NT-5.2-WOW64) OS=windows;;
248         *CYGWIN_NT*) OS=windows;;
249         *CYGWIN*) OS=windows;;
250         MINGW32*) OS=windows;;
251         *darwin*) OS=macosx;;
252         *Darwin*) OS=macosx;;
253         *linux*) OS=linux;;
254         *Linux*) OS=linux;;
255     esac
256 }
257
258 find_architecture() {
259     if [[ -n $ARCH ]] ; then return; fi
260     $ECHO "Finding ARCH..."
261     uname_m=`uname -m`
262     check_ret uname
263     case $uname_m in
264        i386) ARCH=x86;;
265        i686) ARCH=x86;;
266        i86pc) ARCH=x86;;
267        amd64) ARCH=x86;;
268        ppc64) ARCH=ppc;;
269        *86) ARCH=x86;;
270        *86_64) ARCH=x86;;
271        "Power Macintosh") ARCH=ppc;;
272     esac
273 }
274
275 find_num_cores() {
276     $ECHO "Finding num cores..."
277     NUM_CORES=7ZZ
278     uname_s=`uname -s`
279     check_ret uname
280     case $uname_s in
281         CYGWIN_NT-5.2-WOW64 | *CYGWIN_NT* | *CYGWIN* | MINGW32*) NUM_CORES=$NUMBER_OF_PROCESSORS;;
282         *darwin* | *Darwin* | *linux* | *Linux*) NUM_CORES=$(getconf _NPROCESSORS_ONLN);;
283     esac
284 }
285
286 write_test_program() {
287     #! Must be 'echo'
288     echo "#include <stdio.h>" > $C_WORD.c
289     echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c
290 }
291
292 c_find_word_size() {
293     $ECHO "Finding WORD..."
294     C_WORD=factor-word-size
295     write_test_program
296     $CC -o $C_WORD $C_WORD.c
297     WORD=$(./$C_WORD)
298     check_ret $C_WORD
299     $DELETE -f $C_WORD*
300 }
301
302 intel_macosx_word_size() {
303     ensure_program_installed sysctl
304     $ECHO -n "Testing if your Intel Mac supports 64bit binaries..."
305     sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null
306     if [[ $? -eq 0 ]] ; then
307         WORD=64
308         $ECHO "yes!"
309     else
310         WORD=32
311         $ECHO "no."
312     fi
313 }
314
315 find_word_size() {
316     if [[ -n $WORD ]] ; then return; fi
317     if [[ $OS == macosx && $ARCH == x86 ]] ; then
318         intel_macosx_word_size
319     else
320         c_find_word_size
321     fi
322 }
323
324 set_factor_binary() {
325     case $OS in
326         windows) FACTOR_BINARY=factor.com;;
327         *) FACTOR_BINARY=factor;;
328     esac
329 }
330
331 set_factor_library() {
332     case $OS in
333         windows) FACTOR_LIBRARY=factor.dll;;
334         macosx) FACTOR_LIBRARY=libfactor.dylib;;
335         *) FACTOR_LIBRARY=libfactor.a;;
336     esac
337 }
338
339 set_factor_image() {
340     FACTOR_IMAGE=factor.image
341     FACTOR_IMAGE_FRESH=factor.image.fresh
342 }
343
344 echo_build_info() {
345     $ECHO OS=$OS
346     $ECHO ARCH=$ARCH
347     $ECHO NUM_CORES=$NUM_CORES
348     $ECHO WORD=$WORD
349     $ECHO DEBUG=$DEBUG
350     $ECHO CURRENT_BRANCH=$CURRENT_BRANCH
351     $ECHO FACTOR_BINARY=$FACTOR_BINARY
352     $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY
353     $ECHO FACTOR_IMAGE=$FACTOR_IMAGE
354     $ECHO MAKE_TARGET=$MAKE_TARGET
355     $ECHO BOOT_IMAGE=$BOOT_IMAGE
356     $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET
357     $ECHO GIT_PROTOCOL=$GIT_PROTOCOL
358     $ECHO GIT_URL=$GIT_URL
359     $ECHO DOWNLOADER=$DOWNLOADER
360     $ECHO CC=$CC
361     $ECHO CXX=$CXX
362     $ECHO MAKE=$MAKE
363     $ECHO COPY=$COPY
364     $ECHO DELETE=$DELETE
365 }
366
367 check_os_arch_word() {
368     if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then
369         $ECHO "OS: $OS"
370         $ECHO "ARCH: $ARCH"
371         $ECHO "WORD: $WORD"
372         $ECHO "OS, ARCH, or WORD is empty.  Please report this."
373
374         $ECHO $MAKE_TARGET
375         exit_script 5
376     fi
377 }
378
379 set_build_info() {
380     check_os_arch_word
381     if [[ $OS == linux && $ARCH == ppc ]] ; then
382         MAKE_IMAGE_TARGET=linux-ppc.32
383         MAKE_TARGET=linux-ppc-32
384     elif [[ $OS == windows && $ARCH == x86 && $WORD == 64 ]] ; then
385         MAKE_IMAGE_TARGET=windows-x86.64
386         MAKE_TARGET=windows-x86-64
387     elif [[ $OS == windows && $ARCH == x86 && $WORD == 32 ]] ; then
388         MAKE_IMAGE_TARGET=windows-x86.32
389         MAKE_TARGET=windows-x86-32
390     elif [[ $ARCH == x86 && $WORD == 64 ]] ; then
391         MAKE_IMAGE_TARGET=unix-x86.64
392         MAKE_TARGET=$OS-x86-64
393     elif [[ $ARCH == x86 && $WORD == 32 ]] ; then
394         MAKE_IMAGE_TARGET=unix-x86.32
395         MAKE_TARGET=$OS-x86-32
396     else
397         MAKE_IMAGE_TARGET=$ARCH.$WORD
398         MAKE_TARGET=$OS-$ARCH-$WORD
399     fi
400     BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image
401 }
402
403 parse_build_info() {
404     ensure_program_installed cut
405     $ECHO "Parsing make target from command line: $1"
406     OS=`echo $1 | cut -d '-' -f 1`
407     ARCH=`echo $1 | cut -d '-' -f 2`
408     WORD=`echo $1 | cut -d '-' -f 3`
409
410     if [[ $OS == linux && $ARCH == ppc ]] ; then WORD=32; fi
411     if [[ $OS == linux && $ARCH == arm ]] ; then WORD=32; fi
412     if [[ $OS == macosx && $ARCH == ppc ]] ; then WORD=32; fi
413
414     $ECHO "OS=$OS"
415     $ECHO "ARCH=$ARCH"
416     $ECHO "WORD=$WORD"
417 }
418
419 find_build_info() {
420     find_os
421     find_architecture
422     find_num_cores
423     set_cc
424     find_word_size
425     set_current_branch
426     set_factor_binary
427     set_factor_library
428     set_factor_image
429     set_build_info
430     set_downloader
431     set_make
432     echo_build_info
433 }
434
435 invoke_git() {
436     git $*
437     check_ret git
438 }
439
440 git_clone() {
441     $ECHO "Downloading the git repository from factorcode.org..."
442     invoke_git clone $GIT_URL
443 }
444
445 update_script_name() {
446     $ECHO `dirname $0`/_update.sh
447 }
448
449 update_script() {
450     update_script=`update_script_name`
451     bash_path=`which bash`
452     $ECHO "#!$bash_path" >"$update_script"
453     $ECHO "git pull \"$GIT_URL\" master" >>"$update_script"
454     $ECHO "if [[ \$? -eq 0 ]]; then exec \"$0\" $SCRIPT_ARGS; else echo \"git pull failed\"; exit 2; fi" \
455         >>"$update_script"
456     $ECHO "exit 0" >>"$update_script"
457
458     chmod 755 "$update_script"
459     exec "$update_script"
460 }
461
462 update_script_changed() {
463     invoke_git diff --stat `invoke_git merge-base HEAD FETCH_HEAD` FETCH_HEAD | grep 'build\.sh' >/dev/null
464 }
465
466 git_fetch_factorcode() {
467     $ECHO "Fetching the git repository from factorcode.org..."
468
469     rm -f `update_script_name`
470     invoke_git fetch "$GIT_URL" master
471
472     if update_script_changed; then
473         $ECHO "Updating and restarting the build.sh script..."
474         update_script
475     else
476         $ECHO "Updating the working tree..."
477         invoke_git pull "$GIT_URL" master
478     fi
479 }
480
481 cd_factor() {
482     cd factor
483     check_ret cd
484 }
485
486 set_copy() {
487     case $OS in
488         windows) COPY=cp;;
489         *) COPY=cp;;
490     esac
491 }
492
493 set_delete() {
494     case $OS in
495         windows) DELETE=rm;;
496         *) DELETE=rm;;
497     esac
498 }
499
500 backup_factor() {
501     $ECHO "Backing up factor..."
502     $COPY $FACTOR_BINARY $FACTOR_BINARY.bak
503     $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak
504     $COPY $BOOT_IMAGE $BOOT_IMAGE.bak
505     $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak
506     $ECHO "Done with backup."
507 }
508
509 check_makefile_exists() {
510     if [[ ! -e "GNUmakefile" ]] ; then
511         $ECHO ""
512         $ECHO "***GNUmakefile not found***"
513         $ECHO "You are likely in the wrong directory."
514         $ECHO "Run this script from your factor directory:"
515         $ECHO "     ./build.sh"
516         exit_script 6
517     fi
518 }
519
520 invoke_make() {
521     check_makefile_exists
522     $MAKE $MAKE_OPTS $*
523     check_ret $MAKE
524 }
525
526 make_clean() {
527     invoke_make clean
528 }
529
530 make_factor() {
531     $ECHO "Building factor with $NUM_CORES cores"
532     invoke_make CC=$CC CXX=$CXX $MAKE_TARGET -j$NUM_CORES
533 }
534
535 make_clean_factor() {
536     make_clean
537     make_factor
538 }
539
540 current_git_branch() {
541     git rev-parse --abbrev-ref HEAD
542 }
543
544 check_url() {
545     if [[ $DOWNLOADER_NAME == 'wget' ]]; then
546         if [[ `wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then
547             return 0
548         else
549             return 1
550         fi
551     elif [[ $DOWNLOADER_NAME == 'curl' ]]; then
552         code=`curl -sL -w "%{http_code}\\n" "$1" -o /dev/null`
553         if [[ $code -eq 200 ]]; then return 0; else return 1; fi
554     else
555         $ECHO "error: wget or curl required in check_url"
556         exit_script 12
557     fi
558 }
559
560 # If we are on a branch, first try to get a boot image for that branch.
561 # Otherwise, just use `master`
562 set_boot_image_vars() {
563     set_current_branch
564     url="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/checksums.txt"
565     check_url $url
566     if [[ $? -eq 0 ]]; then
567         CHECKSUM_URL="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/checksums.txt"
568         BOOT_IMAGE_URL="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/${BOOT_IMAGE}"
569     else
570         CHECKSUM_URL="http://downloads.factorcode.org/images/master/checksums.txt"
571         BOOT_IMAGE_URL="http://downloads.factorcode.org/images/master/${BOOT_IMAGE}"
572     fi
573 }
574
575 set_current_branch() {
576     if [ -n "${CI_BRANCH}" ]; then
577         CURRENT_BRANCH="${CI_BRANCH}"
578     else
579         CURRENT_BRANCH=$(current_git_branch)
580     fi
581 }
582
583 update_boot_image() {
584     set_boot_image_vars
585     $ECHO "Deleting old images..."
586     $DELETE checksums.txt* > /dev/null 2>&1
587     # delete boot images with one or two characters after the dot
588     $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1
589     $DELETE temp/staging.*.image > /dev/null 2>&1
590     if [[ -f $BOOT_IMAGE ]] ; then
591         get_url $CHECKSUM_URL
592         factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '`
593         set_md5sum
594         disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '`
595         $ECHO "Factorcode md5: $factorcode_md5";
596         $ECHO "Disk md5: $disk_md5";
597         if [[ "$factorcode_md5" == "$disk_md5" ]] ; then
598             $ECHO "Your disk boot image matches the one on factorcode.org."
599         else
600             $DELETE $BOOT_IMAGE > /dev/null 2>&1
601             get_boot_image
602         fi
603     else
604         get_boot_image
605     fi
606 }
607
608 get_boot_image() {
609     $ECHO "Downloading boot image $BOOT_IMAGE."
610     get_url "${BOOT_IMAGE_URL}"
611 }
612
613 get_url() {
614     if [[ -z $DOWNLOADER ]] ; then
615         set_downloader;
616     fi
617     $ECHO $DOWNLOADER $1 ;
618     $DOWNLOADER $1
619     check_ret $DOWNLOADER
620 }
621
622 get_config_info() {
623     find_build_info
624     check_installed_programs
625     check_libraries
626 }
627
628 copy_fresh_image() {
629     $ECHO "Copying $FACTOR_IMAGE to $FACTOR_IMAGE_FRESH..."
630     $COPY $FACTOR_IMAGE $FACTOR_IMAGE_FRESH
631 }
632
633 bootstrap() {
634     ./$FACTOR_BINARY -i=$BOOT_IMAGE
635     copy_fresh_image
636 }
637
638 install() {
639     check_factor_exists
640     get_config_info
641     git_clone
642     cd_factor
643     make_factor
644     set_boot_image_vars
645     get_boot_image
646     bootstrap
647 }
648
649 update() {
650     get_config_info
651     git_fetch_factorcode
652     backup_factor
653     make_clean_factor
654 }
655
656 download_and_bootstrap() {
657     update_boot_image
658     bootstrap
659 }
660
661 net_bootstrap_no_pull() {
662     get_config_info
663     make_clean_factor
664     download_and_bootstrap
665 }
666
667 refresh_image() {
668     ./$FACTOR_BINARY -script -e="USING: vocabs.loader vocabs.refresh system memory ; refresh-all save 0 exit"
669     check_ret factor
670 }
671
672 make_boot_image() {
673     ./$FACTOR_BINARY -script -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit"
674     check_ret factor
675 }
676
677 install_deps_apt() {
678     sudo apt install --yes libc6-dev libpango1.0-dev libx11-dev xorg-dev libgtk2.0-dev gtk2-engines-pixbuf libgtkglext1-dev wget git git-doc rlwrap clang gcc make screen tmux libssl-dev g++
679     check_ret sudo
680 }
681
682 install_deps_pacman() {
683     sudo pacman --noconfirm -S gcc clang make rlwrap git wget pango glibc gtk2 gtk3 gtkglext gtk-engines gdk-pixbuf2 libx11 screen tmux
684     check_ret sudo
685 }
686
687 install_deps_dnf() {
688     sudo dnf --assumeyes install gcc gcc-c++ glibc-devel binutils libX11-devel pango-devel gtk3-devel gdk-pixbuf2-devel gtkglext-devel tmux rlwrap wget
689     check_ret sudo
690 }
691
692
693 install_deps_macosx() {
694     test_program_installed git
695     if [[ $? -ne 1 ]] ; then
696         ensure_program_installed yes
697         $ECHO "git not found."
698         $ECHO "This script requires either git-core or port."
699         $ECHO "If it fails, install git-core or port and try again."
700         ensure_program_installed port
701         $ECHO "Installing git-core with port...this will take awhile."
702         yes | sudo port install git-core
703     fi
704 }
705
706 usage() {
707     $ECHO "usage: $0 command [optional-target]"
708     $ECHO "  install - git clone, compile, bootstrap"
709     $ECHO "  deps-apt - install required packages for Factor on Linux using apt"
710     $ECHO "  deps-pacman - install required packages for Factor on Linux using pacman"
711     $ECHO "  deps-dnf - install required packages for Factor on Linux using dnf"
712     $ECHO "  deps-macosx - install git on MacOSX using port"
713     $ECHO "  self-update - git pull, recompile, make local boot image, bootstrap"
714     $ECHO "  quick-update - git pull, refresh-all, save"
715     $ECHO "  update|latest - git pull, recompile, download a boot image, bootstrap"
716     $ECHO "  bootstrap - bootstrap with existing boot image"
717     $ECHO "  net-bootstrap - recompile, download a boot image, bootstrap"
718     $ECHO "  make-target - find and print the os-arch-cpu string"
719     $ECHO "  report - print the build variables"
720     $ECHO "  update-boot-image - get the boot image for the current branch of for master"
721     $ECHO ""
722     $ECHO "If you are behind a firewall, invoke as:"
723     $ECHO "env GIT_PROTOCOL=http $0 <command>"
724     $ECHO ""
725     $ECHO "Example for overriding the default target:"
726     $ECHO "    $0 update macosx-x86-32"
727 }
728
729 MAKE_TARGET=unknown
730
731 # -n is nonzero length, -z is zero length
732 if [[ -n "$2" ]] ; then
733     parse_build_info $2
734 fi
735
736 set_copy
737 set_delete
738
739 case "$1" in
740     install) install ;;
741     deps-apt) install_deps_apt ;;
742     deps-pacman) install_deps_pacman ;;
743     deps-macosx) install_deps_macosx ;;
744     deps-dnf) install_deps_dnf ;;
745     self-update) update; make_boot_image; bootstrap;;
746     quick-update) update; refresh_image ;;
747     update) update; download_and_bootstrap ;;
748     latest) update; download_and_bootstrap ;;
749     bootstrap) get_config_info; bootstrap ;;
750     net-bootstrap) net_bootstrap_no_pull ;;
751     make-target) FIND_MAKE_TARGET=true; ECHO=false; find_build_info; exit_script ;;
752     report) find_build_info ;;
753     full-report) find_build_info; check_installed_programs; check_libraries ;;
754     update-boot-image) find_build_info; check_installed_programs; update_boot_image;;
755     *) usage ;;
756 esac
757