3 # Programs returning != 0 will not cause script to exit
6 # Case insensitive string comparison
15 GIT_PROTOCOL=${GIT_PROTOCOL:="git"}
16 GIT_URL=${GIT_URL:=$GIT_PROTOCOL"://factorcode.org/git/factor.git"}
19 test_program_installed() {
20 if ! [[ -n `type -p $1` ]] ; then
27 if [[ $FIND_MAKE_TARGET = true ]] ; then
28 # Must be echo not $ECHO
34 ensure_program_installed() {
38 $ECHO -n "Checking for $i..."
39 test_program_installed $i
40 if [[ $? -eq 0 ]]; then
43 installed=$(( $installed + 1 ))
47 if [[ $installed -eq 0 ]] ; then
49 if [[ $# -eq 1 ]] ; then
52 $ECHO -n "any of [ $* ]"
54 $ECHO " and try again."
61 if [[ $RET -ne 0 ]] ; then
68 test_program_installed wget curl
69 if [[ $? -ne 0 ]] ; then
72 DOWNLOADER="curl -f -O"
77 test_program_installed md5sum
78 if [[ $? -ne 0 ]] ; then
88 if xcodebuild -version | grep 'Xcode 4' >/dev/null; then
102 check_installed_programs() {
103 ensure_program_installed chmod
104 ensure_program_installed uname
105 ensure_program_installed git
106 ensure_program_installed wget curl
107 ensure_program_installed gcc
108 ensure_program_installed g++ cl
109 ensure_program_installed make gmake
110 ensure_program_installed md5sum md5
111 ensure_program_installed cut
114 check_library_exists() {
115 GCC_TEST=factor-library-test.c
116 GCC_OUT=factor-library-test.out
117 $ECHO -n "Checking for library $1..."
118 $ECHO "int main(){return 0;}" > $GCC_TEST
119 $CC $GCC_TEST -o $GCC_OUT -l $1 2>&-
120 if [[ $? -ne 0 ]] ; then
122 $ECHO "***Factor will compile NO_UI=1"
133 check_X11_libraries() {
134 if [ -z "$NO_UI" ]; then
135 check_library_exists GL
136 check_library_exists X11
137 check_library_exists pango-1.0
141 check_gtk_libraries() {
142 if [ -z "$NO_UI" ]; then
143 check_library_exists gobject-2.0
144 check_library_exists gtk-x11-2.0
145 check_library_exists gdk-x11-2.0
146 check_library_exists gdk_pixbuf-2.0
147 check_library_exists gtkglext-x11-1.0
148 check_library_exists atk-1.0
149 check_library_exists gio-2.0
150 check_library_exists gdkglext-x11-1.0
151 check_library_exists pango-1.0
158 linux) check_X11_libraries
159 check_gtk_libraries;;
160 unix) check_gtk_libraries;;
164 check_factor_exists() {
165 if [[ -d "factor" ]] ; then
166 $ECHO "A directory called 'factor' already exists."
167 $ECHO "Rename or delete it and try again."
173 if [[ -n $OS ]] ; then return; fi
174 $ECHO "Finding OS..."
178 CYGWIN_NT-5.2-WOW64) OS=windows;;
179 *CYGWIN_NT*) OS=windows;;
180 *CYGWIN*) OS=windows;;
181 MINGW32*) OS=windows;;
182 *darwin*) OS=macosx;;
183 *Darwin*) OS=macosx;;
187 echo "Here's a nickel, kid:"
188 echo " ..;;iiiittttjjttttii;;........ "
189 echo " ..ttLLGGGGffttjjjjttttttjjjjtt;;.... "
190 echo " ..iiLLLLjjffffiiiiffttLLjjiiiiiiiiffjjii.... "
191 echo " ;;LLttii;;iiiittttiiiittttffLLGGiiii;;iiLLLL;;.. "
192 echo " ..iiGGii..ii;;iiiittiittiiiiiittffffGGtt;;;;;;ffDDii.. "
193 echo " iiDD;;;;..;;ttttiittiittttiiiittttffDDEE;;,,;;;;ffKKtt.. "
194 echo " iiKKii..,,..iiii;;ii;;iittttttttttjjjjffGGLL::....;;LLWWtt.. "
195 echo " ..DDff..;;ii;;ii::,,;;;;iiiittttttjjffttjjLLDDtt..iiii;;KKWWii.. "
196 echo " LLLL;;;;ii;;;;;;,,;;;;;;ii;;ttttffffttttttLLGGKK..iiiiiiiiWWDD;; "
197 echo " ;;DD;;;;ii;;;;;;;;,,;;;;iiiiiiiijjffffffttttLLGGWWii..iiiiiiGG##jj.. "
198 echo " LLtt::ii;;....ii::;;,,;;;;iiiittttLLLLLLttttttGGKKGG;;;;iiiiii##KK;; "
199 echo " ..LL..iiii;;::::;;;;,,,,;;;;ii;;ttiiDDLLtttt;;iittLL##ii;;iiii;;WW##tt.. "
200 echo " ii;;;;iiff ..;;..ii..;;;;;;ii;;iiiiDDLLiiii;;ttLLEE##tt;;;;ii;;DD##GG.. "
201 echo " tt..iiGG::....ii..;;;;;;;;;;;;;;iiiiDDLLiiiiiiffGGWWKKiiii;;ii..tt##KK;; "
202 echo " ff;;GGtt..,, tt..;;;;,,;;iiii;;iittGGLLttffLLGGKKDDjjLLii;;;;,,ii##WWii "
203 echo " GGttii..;;.. ff::;;..;;iiiitt..iiiittGGffLLEEffEE;;;;EEtt;;::..;;WW##tt "
204 echo " GGjjii..ii..,,ff..::;;iiiiiitt..;;iiffttttffGGWWKKiiiiLLDD..;;....WW##tt "
205 echo " GGff,,..ii..iiii,,..::iiiiii;;..;;jjjjiiiiffGG##DDttiiffKK;;.. ..WW##jj "
206 echo " GGff..;;;;..LL..;;;;..;;iiii..;;ttLLiiiiiiffGGKKEE..jjLLKKjj.. ..WW##tt "
207 echo " LLff..ii..iiGG..::......;;;;;;;;LL;;iittttttLLKKLLffKKLLKKff.. ;;####ii "
208 echo " LLjj..;; LLii;;..;;......;;;;iitt;;ttLLttiiGGGGGGffDDKKii::.. tt##WW;; "
209 echo " jjtt....;;GGttjj ......;;ii;;iitt;;ttffttttLLDDGGttDDKK;;.. LL##KK.. "
210 echo " ;;ii;;..LLtt;;;; ....;;ii....iiGG;;iijjffLLGGKKjjGGKKGG.... KK##LL "
211 echo " ..ffiittttiiii;; ....;;ii,,;;ttLLttiittjjLLGGttjjGGKKtt iiWW##ii "
212 echo " ttLLii;;iiii;; ....,,;; ..;;ttDDiiiiffffffffGGGGGG.. GG##KK.. "
213 echo " ..LLjjii;;;;....::;;,,;;;;..;;ttDDttttjjttffLLLLDDff ;;WW##tt "
214 echo " iiGGii,,....,,iiiiii,,ii ::ttEEttffDDttLLttLLKKii GG##KK.. "
215 echo " LLtt......,,;;;;;;iiiiii;;;;KKffLLKK;;;;tttttt tt##WWii "
216 echo " ..ii;;;;..;;iiii;;tt,,jj iiGGffLLKK....;;.... ;;WW##ff.. "
217 echo " ..;;..::;;iiiiii;;..jj;;..GGttffEE........ iiKK##LL.. "
218 echo " ..,,..;;;;;;;;..;;iitt,,ttttjjLL iiKK##LL.. "
219 echo " ............ ,,;;;;..;;;;LLii ..ttKKKKtt.. "
220 echo " ..::........;;......;;;;;; ..iiDDWWLL,, "
221 echo " ....;;................iittGGDDff;; "
222 echo " ....;;;;;;;;;;iiiiii::.. "
223 echo "Get yourself a real OS."
224 echo "http://www.microsoft.com/"
229 find_architecture() {
230 if [[ -n $ARCH ]] ; then return; fi
231 $ECHO "Finding ARCH..."
242 "Power Macintosh") ARCH=ppc;;
246 write_test_program() {
248 echo "#include <stdio.h>" > $C_WORD.c
249 echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c
253 $ECHO "Finding WORD..."
254 C_WORD=factor-word-size
256 gcc -o $C_WORD $C_WORD.c
262 intel_macosx_word_size() {
263 ensure_program_installed sysctl
264 $ECHO -n "Testing if your Intel Mac supports 64bit binaries..."
265 sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null
266 if [[ $? -eq 0 ]] ; then
276 if [[ -n $WORD ]] ; then return; fi
277 if [[ $OS == macosx && $ARCH == x86 ]] ; then
278 intel_macosx_word_size
284 set_factor_binary() {
286 windows) FACTOR_BINARY=factor.com;;
287 *) FACTOR_BINARY=factor;;
291 set_factor_library() {
293 windows) FACTOR_LIBRARY=factor.dll;;
294 macosx) FACTOR_LIBRARY=libfactor.dylib;;
295 *) FACTOR_LIBRARY=libfactor.a;;
300 FACTOR_IMAGE=factor.image
301 FACTOR_IMAGE_FRESH=factor.image.fresh
308 $ECHO FACTOR_BINARY=$FACTOR_BINARY
309 $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY
310 $ECHO FACTOR_IMAGE=$FACTOR_IMAGE
311 $ECHO MAKE_TARGET=$MAKE_TARGET
312 $ECHO BOOT_IMAGE=$BOOT_IMAGE
313 $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET
314 $ECHO GIT_PROTOCOL=$GIT_PROTOCOL
315 $ECHO GIT_URL=$GIT_URL
316 $ECHO DOWNLOADER=$DOWNLOADER
323 check_os_arch_word() {
324 if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then
328 $ECHO "OS, ARCH, or WORD is empty. Please report this."
337 if [[ $OS == macosx && $ARCH == ppc ]] ; then
338 MAKE_IMAGE_TARGET=macosx-ppc
339 MAKE_TARGET=macosx-ppc
340 elif [[ $OS == linux && $ARCH == ppc ]] ; then
341 MAKE_IMAGE_TARGET=linux-ppc.32
342 MAKE_TARGET=linux-ppc-32
343 elif [[ $OS == windows && $ARCH == x86 && $WORD == 64 ]] ; then
344 MAKE_IMAGE_TARGET=windows-x86.64
345 MAKE_TARGET=windows-x86-64
346 elif [[ $OS == windows && $ARCH == x86 && $WORD == 32 ]] ; then
347 MAKE_IMAGE_TARGET=windows-x86.32
348 MAKE_TARGET=windows-x86-32
349 elif [[ $ARCH == x86 && $WORD == 64 ]] ; then
350 MAKE_IMAGE_TARGET=unix-x86.64
351 MAKE_TARGET=$OS-x86-64
352 elif [[ $ARCH == x86 && $WORD == 32 ]] ; then
353 MAKE_IMAGE_TARGET=unix-x86.32
354 MAKE_TARGET=$OS-x86-32
356 MAKE_IMAGE_TARGET=$ARCH.$WORD
357 MAKE_TARGET=$OS-$ARCH-$WORD
359 BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image
363 ensure_program_installed cut
364 $ECHO "Parsing make target from command line: $1"
365 OS=`echo $1 | cut -d '-' -f 1`
366 ARCH=`echo $1 | cut -d '-' -f 2`
367 WORD=`echo $1 | cut -d '-' -f 3`
369 if [[ $OS == linux && $ARCH == ppc ]] ; then WORD=32; fi
370 if [[ $OS == linux && $ARCH == arm ]] ; then WORD=32; fi
371 if [[ $OS == macosx && $ARCH == ppc ]] ; then WORD=32; fi
398 $ECHO "Downloading the git repository from factorcode.org..."
399 invoke_git clone $GIT_URL
402 update_script_name() {
403 $ECHO `dirname $0`/_update.sh
407 update_script=`update_script_name`
408 bash_path=`which bash`
409 $ECHO "#!$bash_path" >"$update_script"
410 $ECHO "git pull \"$GIT_URL\" master" >>"$update_script"
411 $ECHO "if [[ \$? -eq 0 ]]; then exec \"$0\" $SCRIPT_ARGS; else echo \"git pull failed\"; exit 2; fi" \
413 $ECHO "exit 0" >>"$update_script"
415 chmod 755 "$update_script"
416 exec "$update_script"
419 update_script_changed() {
420 invoke_git diff --stat `invoke_git merge-base HEAD FETCH_HEAD` FETCH_HEAD | grep 'build-support.factor\.sh' >/dev/null
423 git_fetch_factorcode() {
424 $ECHO "Fetching the git repository from factorcode.org..."
426 rm -f `update_script_name`
427 invoke_git fetch "$GIT_URL" master
429 if update_script_changed; then
430 $ECHO "Updating and restarting the factor.sh script..."
433 $ECHO "Updating the working tree..."
434 invoke_git pull "$GIT_URL" master
458 $ECHO "Backing up factor..."
459 $COPY $FACTOR_BINARY $FACTOR_BINARY.bak
460 $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak
461 $COPY $BOOT_IMAGE $BOOT_IMAGE.bak
462 $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak
463 $ECHO "Done with backup."
466 check_makefile_exists() {
467 if [[ ! -e "GNUmakefile" ]] ; then
469 $ECHO "***GNUmakefile not found***"
470 $ECHO "You are likely in the wrong directory."
471 $ECHO "Run this script from your factor directory:"
472 $ECHO " ./build-support/factor.sh"
478 check_makefile_exists
488 invoke_make NO_UI=$NO_UI $MAKE_TARGET -j5
491 make_clean_factor() {
496 update_boot_images() {
497 $ECHO "Deleting old images..."
498 $DELETE checksums.txt* > /dev/null 2>&1
499 # delete boot images with one or two characters after the dot
500 $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1
501 $DELETE temp/staging.*.image > /dev/null 2>&1
502 if [[ -f $BOOT_IMAGE ]] ; then
503 get_url http://downloads.factorcode.org/images/latest/checksums.txt
504 factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '`;
506 disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '` ;;
507 $ECHO "Factorcode md5: $factorcode_md5";
508 $ECHO "Disk md5: $disk_md5";
509 if [[ "$factorcode_md5" == "$disk_md5" ]] ; then
510 $ECHO "Your disk boot image matches the one on factorcode.org."
512 $DELETE $BOOT_IMAGE > /dev/null 2>&1
521 $ECHO "Downloading boot image $BOOT_IMAGE."
522 get_url http://downloads.factorcode.org/images/latest/$BOOT_IMAGE
526 if [[ -z $DOWNLOADER ]] ; then
529 $ECHO $DOWNLOADER $1 ;
531 check_ret $DOWNLOADER
536 check_installed_programs
541 $ECHO "Copying $FACTOR_IMAGE to $FACTOR_IMAGE_FRESH..."
542 $COPY $FACTOR_IMAGE $FACTOR_IMAGE_FRESH
546 ./$FACTOR_BINARY -i=$BOOT_IMAGE
572 net_bootstrap_no_pull() {
579 ./$FACTOR_BINARY -script -e="USING: vocabs.loader vocabs.refresh system memory ; refresh-all save 0 exit"
584 ./$FACTOR_BINARY -script -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit"
588 install_deps_linux() {
589 sudo apt-get --yes install libc6-dev libpango1.0-dev libx11-dev xorg-dev libgtk2.0-dev gtk2-engines-pixbuf libgtkglext1-dev wget git-core git-doc rlwrap gcc make
593 install_deps_macosx() {
594 test_program_installed git
595 if [[ $? -ne 1 ]] ; then
596 ensure_program_installed yes
597 $ECHO "git not found."
598 $ECHO "This script requires either git-core or port."
599 $ECHO "If it fails, install git-core or port and try again."
600 ensure_program_installed port
601 $ECHO "Installing git-core with port...this will take awhile."
602 yes | sudo port install git-core
607 $ECHO "usage: $0 install|deps-linux|deps-macosx|self-update|quick-update|update|bootstrap|net-bootstrap|make-target|report [optional-target]"
608 $ECHO "If you are behind a firewall, invoke as:"
609 $ECHO "env GIT_PROTOCOL=http $0 <command>"
611 $ECHO "Example for overriding the default target:"
612 $ECHO " $0 update macosx-x86-32"
617 # -n is nonzero length, -z is zero length
618 if [[ -n "$2" ]] ; then
627 deps-linux) install_deps_linux ;;
628 deps-macosx) install_deps_macosx ;;
629 self-update) update; make_boot_image; bootstrap;;
630 quick-update) update; refresh_image ;;
631 update) update; update_bootstrap ;;
632 bootstrap) get_config_info; bootstrap ;;
633 net-bootstrap) net_bootstrap_no_pull ;;
634 make-target) FIND_MAKE_TARGET=true; ECHO=false; find_build_info; exit_script ;;
635 report) find_build_info ;;