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