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