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