]> gitweb.factorcode.org Git - factor.git/blob - build.sh
build.sh: Add target for TravisCI Windows.
[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     local 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     local 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     local 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         x86_64-pc-windows-msvc) OS=windows;;
254         *darwin*) OS=macosx;;
255         *Darwin*) OS=macosx;;
256         *linux*) OS=linux;;
257         *Linux*) OS=linux;;
258     esac
259 }
260
261 find_architecture() {
262     if [[ -n $ARCH ]] ; then return; fi
263     $ECHO "Finding ARCH..."
264     uname_m=$(uname -m)
265     check_ret uname
266     case $uname_m in
267        i386) ARCH=x86;;
268        i686) ARCH=x86;;
269        i86pc) ARCH=x86;;
270        amd64) ARCH=x86;;
271        ppc64) ARCH=ppc;;
272        *86) ARCH=x86;;
273        *86_64) ARCH=x86;;
274        "Power Macintosh") ARCH=ppc;;
275     esac
276 }
277
278 find_num_cores() {
279     $ECHO "Finding num cores..."
280     NUM_CORES=7ZZ
281     uname_s=$(uname -s)
282     check_ret uname
283     case $uname_s in
284         CYGWIN_NT-5.2-WOW64 | *CYGWIN_NT* | *CYGWIN* | MINGW32*) NUM_CORES=$NUMBER_OF_PROCESSORS;;
285         *darwin* | *Darwin* | *linux* | *Linux*) NUM_CORES=$(getconf _NPROCESSORS_ONLN);;
286     esac
287 }
288
289 echo_test_program() {
290     #! Must be 'echo'
291     echo -e "int main(){ return (long)(8*sizeof(void*)); }"
292 }
293
294 c_find_word_size() {
295     $ECHO "Finding WORD..."
296     C_WORD="factor-word-size"
297     echo_test_program | $CC -o $C_WORD -xc -
298     check_ret $CC
299     ./$C_WORD
300     WORD=$?
301     $DELETE -f $C_WORD
302 }
303
304 intel_macosx_word_size() {
305     ensure_program_installed sysctl
306     $ECHO -n "Testing if your Intel Mac supports 64bit binaries..."
307     sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null
308     if [[ $? -eq 0 ]] ; then
309         WORD=64
310         $ECHO "yes!"
311     else
312         WORD=32
313         $ECHO "no."
314     fi
315 }
316
317 find_word_size() {
318     if [[ -n $WORD ]] ; then return; fi
319     if [[ $OS == macosx && $ARCH == x86 ]] ; then
320         intel_macosx_word_size
321     else
322         c_find_word_size
323     fi
324 }
325
326 set_factor_binary() {
327     case $OS in
328         windows) FACTOR_BINARY=factor.com;;
329         *) FACTOR_BINARY=factor;;
330     esac
331 }
332
333 set_factor_library() {
334     case $OS in
335         windows) FACTOR_LIBRARY=factor.dll;;
336         macosx) FACTOR_LIBRARY=libfactor.dylib;;
337         *) FACTOR_LIBRARY=libfactor.a;;
338     esac
339 }
340
341 set_factor_image() {
342     FACTOR_IMAGE=factor.image
343     FACTOR_IMAGE_FRESH=factor.image.fresh
344 }
345
346 echo_build_info() {
347     $ECHO OS=$OS
348     $ECHO ARCH=$ARCH
349     $ECHO NUM_CORES=$NUM_CORES
350     $ECHO WORD=$WORD
351     $ECHO DEBUG=$DEBUG
352     $ECHO CURRENT_BRANCH=$CURRENT_BRANCH
353     $ECHO FACTOR_BINARY=$FACTOR_BINARY
354     $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY
355     $ECHO FACTOR_IMAGE=$FACTOR_IMAGE
356     $ECHO MAKE_TARGET=$MAKE_TARGET
357     $ECHO BOOT_IMAGE=$BOOT_IMAGE
358     $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET
359     $ECHO GIT_PROTOCOL=$GIT_PROTOCOL
360     $ECHO GIT_URL=$GIT_URL
361     $ECHO DOWNLOADER=$DOWNLOADER
362     $ECHO CC=$CC
363     $ECHO CXX=$CXX
364     $ECHO MAKE=$MAKE
365     $ECHO COPY=$COPY
366     $ECHO DELETE=$DELETE
367 }
368
369 check_os_arch_word() {
370     if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then
371         $ECHO "OS: $OS"
372         $ECHO "ARCH: $ARCH"
373         $ECHO "WORD: $WORD"
374         $ECHO "OS, ARCH, or WORD is empty.  Please report this."
375
376         $ECHO $MAKE_TARGET
377         exit_script 5
378     fi
379 }
380
381 set_build_info() {
382     check_os_arch_word
383     if [[ $OS == linux && $ARCH == ppc ]] ; then
384         MAKE_IMAGE_TARGET=linux-ppc.32
385         MAKE_TARGET=linux-ppc-32
386     elif [[ $OS == windows && $ARCH == x86 && $WORD == 64 ]] ; then
387         MAKE_IMAGE_TARGET=windows-x86.64
388         MAKE_TARGET=windows-x86-64
389     elif [[ $OS == windows && $ARCH == x86 && $WORD == 32 ]] ; then
390         MAKE_IMAGE_TARGET=windows-x86.32
391         MAKE_TARGET=windows-x86-32
392     elif [[ $ARCH == x86 && $WORD == 64 ]] ; then
393         MAKE_IMAGE_TARGET=unix-x86.64
394         MAKE_TARGET=$OS-x86-64
395     elif [[ $ARCH == x86 && $WORD == 32 ]] ; then
396         MAKE_IMAGE_TARGET=unix-x86.32
397         MAKE_TARGET=$OS-x86-32
398     else
399         MAKE_IMAGE_TARGET=$ARCH.$WORD
400         MAKE_TARGET=$OS-$ARCH-$WORD
401     fi
402     BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image
403 }
404
405 parse_build_info() {
406     ensure_program_installed cut
407     $ECHO "Parsing make target from command line: $1"
408     OS=$(echo $1 | cut -d '-' -f 1)
409     ARCH=$(echo $1 | cut -d '-' -f 2)
410     WORD=$(echo $1 | cut -d '-' -f 3)
411
412     if [[ $OS == linux && $ARCH == ppc ]] ; then WORD=32; fi
413     if [[ $OS == linux && $ARCH == arm ]] ; then WORD=32; fi
414     if [[ $OS == macosx && $ARCH == ppc ]] ; then WORD=32; fi
415
416     $ECHO "OS=$OS"
417     $ECHO "ARCH=$ARCH"
418     $ECHO "WORD=$WORD"
419 }
420
421 find_build_info() {
422     find_os
423     find_architecture
424     find_num_cores
425     set_cc
426     find_word_size
427     set_current_branch
428     set_factor_binary
429     set_factor_library
430     set_factor_image
431     set_build_info
432     set_downloader
433     set_make
434     echo_build_info
435 }
436
437 invoke_git() {
438     git "$@"
439     check_ret git
440 }
441
442 git_clone() {
443     $ECHO "Downloading the git repository from factorcode.org..."
444     invoke_git clone $GIT_URL
445 }
446
447 update_script_name() {
448     $ECHO "$(dirname $0)/_update.sh"
449 }
450
451 update_script() {
452     local -r update_script=$(update_script_name)
453     local -r bash_path=$(which bash)
454     $ECHO "#!$bash_path" >"$update_script"
455     $ECHO "git pull \"$GIT_URL\" master" >>"$update_script"
456     $ECHO "if [[ \$? -eq 0 ]]; then exec \"$0\" $SCRIPT_ARGS; else echo \"git pull failed\"; exit 2; fi" \
457         >>"$update_script"
458     $ECHO "exit 0" >>"$update_script"
459
460     chmod 755 "$update_script"
461     exec "$update_script"
462 }
463
464 update_script_changed() {
465     invoke_git diff --stat "$(invoke_git merge-base HEAD FETCH_HEAD)" FETCH_HEAD | grep 'build\.sh' >/dev/null
466 }
467
468 git_fetch_factorcode() {
469     $ECHO "Fetching the git repository from factorcode.org..."
470
471     rm -f "$(update_script_name)"
472     invoke_git fetch "$GIT_URL" master
473
474     if update_script_changed; then
475         $ECHO "Updating and restarting the build.sh script..."
476         update_script
477     else
478         $ECHO "Updating the working tree..."
479         invoke_git pull "$GIT_URL" master
480     fi
481 }
482
483 cd_factor() {
484     cd "factor"
485     check_ret cd
486 }
487
488 set_copy() {
489     case $OS in
490         windows) COPY=cp;;
491         *) COPY=cp;;
492     esac
493 }
494
495 set_delete() {
496     case $OS in
497         windows) DELETE=rm;;
498         *) DELETE=rm;;
499     esac
500 }
501
502 backup_factor() {
503     $ECHO "Backing up factor..."
504     $COPY $FACTOR_BINARY $FACTOR_BINARY.bak
505     $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak
506     $COPY $BOOT_IMAGE $BOOT_IMAGE.bak
507     $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak
508     $ECHO "Done with backup."
509 }
510
511 check_makefile_exists() {
512     if [[ ! -e "GNUmakefile" ]] ; then
513         $ECHO ""
514         $ECHO "***GNUmakefile not found***"
515         $ECHO "You are likely in the wrong directory."
516         $ECHO "Run this script from your factor directory:"
517         $ECHO "     ./build.sh"
518         exit_script 6
519     fi
520 }
521
522 invoke_make() {
523     check_makefile_exists
524     $MAKE $MAKE_OPTS "$@"
525     check_ret $MAKE
526 }
527
528 make_clean() {
529     invoke_make clean
530 }
531
532 make_factor() {
533     $ECHO "Building factor with $NUM_CORES cores"
534     invoke_make CC=$CC CXX=$CXX $MAKE_TARGET -j$NUM_CORES
535 }
536
537 make_clean_factor() {
538     make_clean
539     make_factor
540 }
541
542 current_git_branch() {
543     git rev-parse --abbrev-ref HEAD
544 }
545
546 check_url() {
547     if [[ $DOWNLOADER_NAME == 'wget' ]]; then
548         if [[ $(wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then
549             return 0
550         else
551             return 1
552         fi
553     elif [[ $DOWNLOADER_NAME == 'curl' ]]; then
554         local code=$(curl -sL -w "%{http_code}\\n" "$1" -o /dev/null)
555         if [[ $code -eq 200 ]]; then return 0; else return 1; fi
556     else
557         $ECHO "error: wget or curl required in check_url"
558         exit_script 12
559     fi
560 }
561
562 # If we are on a branch, first try to get a boot image for that branch.
563 # Otherwise, just use `master`
564 set_boot_image_vars() {
565     set_current_branch
566     local url="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/checksums.txt"
567     check_url $url
568     if [[ $? -eq 0 ]]; then
569         CHECKSUM_URL="$url"
570         BOOT_IMAGE_URL="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/${BOOT_IMAGE}"
571     else
572         CHECKSUM_URL="http://downloads.factorcode.org/images/master/checksums.txt"
573         BOOT_IMAGE_URL="http://downloads.factorcode.org/images/master/${BOOT_IMAGE}"
574     fi
575 }
576
577 set_current_branch() {
578     if [ -n "${CI_BRANCH}" ]; then
579         CURRENT_BRANCH="${CI_BRANCH}"
580     else
581         CURRENT_BRANCH=$(current_git_branch)
582     fi
583 }
584
585 update_boot_image() {
586     set_boot_image_vars
587     $ECHO "Deleting old images..."
588     $DELETE checksums.txt* > /dev/null 2>&1
589     # delete boot images with one or two characters after the dot
590     $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1
591     $DELETE temp/staging.*.image > /dev/null 2>&1
592     if [[ -f $BOOT_IMAGE ]] ; then
593         get_url $CHECKSUM_URL
594         local factorcode_md5=$(cat checksums.txt | grep $BOOT_IMAGE | cut -f2 -d' ')
595         set_md5sum
596         local disk_md5=$($MD5SUM $BOOT_IMAGE | cut -f1 -d' ')
597         $ECHO "Factorcode md5: $factorcode_md5";
598         $ECHO "Disk md5: $disk_md5";
599         if [[ "$factorcode_md5" == "$disk_md5" ]] ; then
600             $ECHO "Your disk boot image matches the one on factorcode.org."
601         else
602             $DELETE $BOOT_IMAGE > /dev/null 2>&1
603             get_boot_image
604         fi
605     else
606         get_boot_image
607     fi
608 }
609
610 get_boot_image() {
611     $ECHO "Downloading boot image $BOOT_IMAGE."
612     get_url "${BOOT_IMAGE_URL}"
613 }
614
615 get_url() {
616     if [[ -z $DOWNLOADER ]] ; then
617         set_downloader;
618     fi
619     $ECHO $DOWNLOADER $1 ;
620     $DOWNLOADER $1
621     check_ret $DOWNLOADER
622 }
623
624 get_config_info() {
625     find_build_info
626     check_installed_programs
627     check_libraries
628 }
629
630 copy_fresh_image() {
631     $ECHO "Copying $FACTOR_IMAGE to $FACTOR_IMAGE_FRESH..."
632     $COPY $FACTOR_IMAGE $FACTOR_IMAGE_FRESH
633 }
634
635 bootstrap() {
636     ./$FACTOR_BINARY -i=$BOOT_IMAGE
637     copy_fresh_image
638 }
639
640 install() {
641     check_factor_exists
642     get_config_info
643     git_clone
644     cd_factor
645     make_factor
646     set_boot_image_vars
647     get_boot_image
648     bootstrap
649 }
650
651 update() {
652     get_config_info
653     git_fetch_factorcode
654     backup_factor
655     make_clean_factor
656 }
657
658 download_and_bootstrap() {
659     update_boot_image
660     bootstrap
661 }
662
663 net_bootstrap_no_pull() {
664     get_config_info
665     make_clean_factor
666     download_and_bootstrap
667 }
668
669 refresh_image() {
670     ./$FACTOR_BINARY -e="USING: vocabs.loader vocabs.refresh system memory ; refresh-all save 0 exit"
671     check_ret factor
672 }
673
674 make_boot_image() {
675     ./$FACTOR_BINARY -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit"
676     check_ret factor
677 }
678
679 install_deps_apt() {
680     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++
681     check_ret sudo
682 }
683
684 install_deps_pacman() {
685     sudo pacman --noconfirm -Syu gcc clang make rlwrap git wget pango glibc gtk2 gtk3 gtkglext gtk-engines gdk-pixbuf2 libx11 screen tmux
686     check_ret sudo
687 }
688
689 install_deps_dnf() {
690     sudo dnf --assumeyes install gcc gcc-c++ glibc-devel binutils libX11-devel pango-devel gtk3-devel gdk-pixbuf2-devel gtkglext-devel tmux rlwrap wget
691     check_ret sudo
692 }
693
694
695 install_deps_macosx() {
696     test_program_installed git
697     if [[ $? -ne 1 ]] ; then
698         ensure_program_installed yes
699         $ECHO "git not found."
700         $ECHO "This script requires either git-core or port."
701         $ECHO "If it fails, install git-core or port and try again."
702         ensure_program_installed port
703         $ECHO "Installing git-core with port...this will take awhile."
704         yes | sudo port install git-core
705     fi
706 }
707
708 usage() {
709     $ECHO "usage: $0 command [optional-target]"
710     $ECHO "  install - git clone, compile, bootstrap"
711     $ECHO "  deps-apt - install required packages for Factor on Linux using apt"
712     $ECHO "  deps-pacman - install required packages for Factor on Linux using pacman"
713     $ECHO "  deps-dnf - install required packages for Factor on Linux using dnf"
714     $ECHO "  deps-macosx - install git on MacOSX using port"
715     $ECHO "  self-update - git pull, recompile, make local boot image, bootstrap"
716     $ECHO "  quick-update - git pull, refresh-all, save"
717     $ECHO "  update|latest - git pull, recompile, download a boot image, bootstrap"
718     $ECHO "  bootstrap - bootstrap with existing boot image"
719     $ECHO "  net-bootstrap - recompile, download a boot image, bootstrap"
720     $ECHO "  make-target - find and print the os-arch-cpu string"
721     $ECHO "  report - print the build variables"
722     $ECHO "  update-boot-image - get the boot image for the current branch of for master"
723     $ECHO ""
724     $ECHO "If you are behind a firewall, invoke as:"
725     $ECHO "env GIT_PROTOCOL=http $0 <command>"
726     $ECHO ""
727     $ECHO "Example for overriding the default target:"
728     $ECHO "    $0 update macosx-x86-32"
729 }
730
731 MAKE_TARGET=unknown
732
733 # -n is nonzero length, -z is zero length
734 if [[ -n "$2" ]] ; then
735     parse_build_info $2
736 fi
737
738 set_copy
739 set_delete
740
741 case "$1" in
742     install) install ;;
743     deps-apt) install_deps_apt ;;
744     deps-pacman) install_deps_pacman ;;
745     deps-macosx) install_deps_macosx ;;
746     deps-dnf) install_deps_dnf ;;
747     self-update) update; make_boot_image; bootstrap;;
748     quick-update) update; refresh_image ;;
749     update) update; download_and_bootstrap ;;
750     latest) update; download_and_bootstrap ;;
751     bootstrap) get_config_info; bootstrap ;;
752     net-bootstrap) net_bootstrap_no_pull ;;
753     make-target) FIND_MAKE_TARGET=true; ECHO=false; find_build_info; exit_script ;;
754     report) find_build_info ;;
755     full-report) find_build_info; check_installed_programs; check_libraries ;;
756     update-boot-image) find_build_info; check_installed_programs; update_boot_image;;
757     *) usage ;;
758 esac
759