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