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
87 openbsd) ensure_program_installed egcc; CC=egcc;;
94 netbsd) MAKE='gmake';;
95 freebsd) MAKE='gmake';;
96 openbsd) MAKE='gmake';;
97 dragonflybsd) MAKE='gmake';;
100 if [[ $MAKE = 'gmake' ]] ; then
101 ensure_program_installed gmake
105 check_installed_programs() {
106 ensure_program_installed chmod
107 ensure_program_installed uname
108 ensure_program_installed git
109 ensure_program_installed wget curl
110 ensure_program_installed gcc
111 ensure_program_installed g++ cl
112 ensure_program_installed make gmake
113 ensure_program_installed md5sum md5
114 ensure_program_installed cut
117 check_library_exists() {
118 GCC_TEST=factor-library-test.c
119 GCC_OUT=factor-library-test.out
120 $ECHO -n "Checking for library $1..."
121 $ECHO "int main(){return 0;}" > $GCC_TEST
122 $CC $GCC_TEST -o $GCC_OUT -l $1 2>&-
123 if [[ $? -ne 0 ]] ; then
125 $ECHO "***Factor will compile NO_UI=1"
136 check_X11_libraries() {
137 if [ -z "$NO_UI" ]; then
138 check_library_exists GL
139 check_library_exists X11
140 check_library_exists pango-1.0
144 check_gtk_libraries() {
145 if [ -z "$NO_UI" ]; then
146 check_library_exists gobject-2.0
147 check_library_exists gtk-x11-2.0
148 check_library_exists gdk-x11-2.0
149 check_library_exists gdk_pixbuf-2.0
150 check_library_exists gtkglext-x11-1.0
151 check_library_exists atk-1.0
152 check_library_exists gio-2.0
153 check_library_exists gdkglext-x11-1.0
154 check_library_exists pango-1.0
161 linux) check_X11_libraries
162 check_gtk_libraries;;
163 unix) check_gtk_libraries;;
167 check_factor_exists() {
168 if [[ -d "factor" ]] ; then
169 $ECHO "A directory called 'factor' already exists."
170 $ECHO "Rename or delete it and try again."
176 if [[ -n $OS ]] ; then return; fi
177 $ECHO "Finding OS..."
181 CYGWIN_NT-5.2-WOW64) OS=windows;;
182 *CYGWIN_NT*) OS=windows;;
183 *CYGWIN*) OS=windows;;
184 MINGW32*) OS=windows;;
185 *darwin*) OS=macosx;;
186 *Darwin*) OS=macosx;;
189 *NetBSD*) OS=netbsd;;
190 *FreeBSD*) OS=freebsd;;
191 *OpenBSD*) OS=openbsd;;
192 *DragonFly*) OS=dragonflybsd;;
197 find_architecture() {
198 if [[ -n $ARCH ]] ; then return; fi
199 $ECHO "Finding ARCH..."
210 "Power Macintosh") ARCH=ppc;;
214 write_test_program() {
216 echo "#include <stdio.h>" > $C_WORD.c
217 echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c
221 $ECHO "Finding WORD..."
222 C_WORD=factor-word-size
224 gcc -o $C_WORD $C_WORD.c
230 intel_macosx_word_size() {
231 ensure_program_installed sysctl
232 $ECHO -n "Testing if your Intel Mac supports 64bit binaries..."
233 sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null
234 if [[ $? -eq 0 ]] ; then
244 if [[ -n $WORD ]] ; then return; fi
245 if [[ $OS == macosx && $ARCH == x86 ]] ; then
246 intel_macosx_word_size
252 set_factor_binary() {
254 windows) FACTOR_BINARY=factor.com;;
255 *) FACTOR_BINARY=factor;;
259 set_factor_library() {
261 windows) FACTOR_LIBRARY=factor.dll;;
262 macosx) FACTOR_LIBRARY=libfactor.dylib;;
263 *) FACTOR_LIBRARY=libfactor.a;;
268 FACTOR_IMAGE=factor.image
269 FACTOR_IMAGE_FRESH=factor.image.fresh
276 $ECHO FACTOR_BINARY=$FACTOR_BINARY
277 $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY
278 $ECHO FACTOR_IMAGE=$FACTOR_IMAGE
279 $ECHO MAKE_TARGET=$MAKE_TARGET
280 $ECHO BOOT_IMAGE=$BOOT_IMAGE
281 $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET
282 $ECHO GIT_PROTOCOL=$GIT_PROTOCOL
283 $ECHO GIT_URL=$GIT_URL
284 $ECHO DOWNLOADER=$DOWNLOADER
291 check_os_arch_word() {
292 if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then
296 $ECHO "OS, ARCH, or WORD is empty. Please report this."
305 if [[ $OS == macosx && $ARCH == ppc ]] ; then
306 MAKE_IMAGE_TARGET=macosx-ppc
307 MAKE_TARGET=macosx-ppc
308 elif [[ $OS == linux && $ARCH == ppc ]] ; then
309 MAKE_IMAGE_TARGET=linux-ppc.32
310 MAKE_TARGET=linux-ppc-32
311 elif [[ $OS == windows && $ARCH == x86 && $WORD == 64 ]] ; then
312 MAKE_IMAGE_TARGET=windows-x86.64
313 MAKE_TARGET=windows-x86-64
314 elif [[ $OS == windows && $ARCH == x86 && $WORD == 32 ]] ; then
315 MAKE_IMAGE_TARGET=windows-x86.32
316 MAKE_TARGET=windows-x86-32
317 elif [[ $ARCH == x86 && $WORD == 64 ]] ; then
318 MAKE_IMAGE_TARGET=unix-x86.64
319 MAKE_TARGET=$OS-x86-64
320 elif [[ $ARCH == x86 && $WORD == 32 ]] ; then
321 MAKE_IMAGE_TARGET=unix-x86.32
322 MAKE_TARGET=$OS-x86-32
324 MAKE_IMAGE_TARGET=$ARCH.$WORD
325 MAKE_TARGET=$OS-$ARCH-$WORD
327 BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image
331 ensure_program_installed cut
332 $ECHO "Parsing make target from command line: $1"
333 OS=`echo $1 | cut -d '-' -f 1`
334 ARCH=`echo $1 | cut -d '-' -f 2`
335 WORD=`echo $1 | cut -d '-' -f 3`
337 if [[ $OS == linux && $ARCH == ppc ]] ; then WORD=32; fi
338 if [[ $OS == linux && $ARCH == arm ]] ; then WORD=32; fi
339 if [[ $OS == macosx && $ARCH == ppc ]] ; then WORD=32; fi
366 $ECHO "Downloading the git repository from factorcode.org..."
367 invoke_git clone $GIT_URL
370 update_script_name() {
371 $ECHO `dirname $0`/_update.sh
375 update_script=`update_script_name`
376 bash_path=`which bash`
377 $ECHO "#!$bash_path" >"$update_script"
378 $ECHO "git pull \"$GIT_URL\" master" >>"$update_script"
379 $ECHO "if [[ \$? -eq 0 ]]; then exec \"$0\" $SCRIPT_ARGS; else echo \"git pull failed\"; exit 2; fi" \
381 $ECHO "exit 0" >>"$update_script"
383 chmod 755 "$update_script"
384 exec "$update_script"
387 update_script_changed() {
388 invoke_git diff --stat `invoke_git merge-base HEAD FETCH_HEAD` FETCH_HEAD | grep 'build-support.factor\.sh' >/dev/null
391 git_fetch_factorcode() {
392 $ECHO "Fetching the git repository from factorcode.org..."
394 rm -f `update_script_name`
395 invoke_git fetch "$GIT_URL" master
397 if update_script_changed; then
398 $ECHO "Updating and restarting the factor.sh script..."
401 $ECHO "Updating the working tree..."
402 invoke_git pull "$GIT_URL" master
426 $ECHO "Backing up factor..."
427 $COPY $FACTOR_BINARY $FACTOR_BINARY.bak
428 $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak
429 $COPY $BOOT_IMAGE $BOOT_IMAGE.bak
430 $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak
431 $ECHO "Done with backup."
434 check_makefile_exists() {
435 if [[ ! -e "GNUmakefile" ]] ; then
437 $ECHO "***GNUmakefile not found***"
438 $ECHO "You are likely in the wrong directory."
439 $ECHO "Run this script from your factor directory:"
440 $ECHO " ./build-support/factor.sh"
446 check_makefile_exists
456 invoke_make NO_UI=$NO_UI $MAKE_TARGET -j5
459 make_clean_factor() {
464 update_boot_images() {
465 $ECHO "Deleting old images..."
466 $DELETE checksums.txt* > /dev/null 2>&1
467 # delete boot images with one or two characters after the dot
468 $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1
469 $DELETE temp/staging.*.image > /dev/null 2>&1
470 if [[ -f $BOOT_IMAGE ]] ; then
471 get_url http://downloads.factorcode.org/images/latest/checksums.txt
472 factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '`;
475 netbsd) disk_md5=`md5 $BOOT_IMAGE | cut -f4 -d' '`;;
476 *) disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '` ;;
478 $ECHO "Factorcode md5: $factorcode_md5";
479 $ECHO "Disk md5: $disk_md5";
480 if [[ "$factorcode_md5" == "$disk_md5" ]] ; then
481 $ECHO "Your disk boot image matches the one on factorcode.org."
483 $DELETE $BOOT_IMAGE > /dev/null 2>&1
492 $ECHO "Downloading boot image $BOOT_IMAGE."
493 get_url http://downloads.factorcode.org/images/latest/$BOOT_IMAGE
497 if [[ -z $DOWNLOADER ]] ; then
500 $ECHO $DOWNLOADER $1 ;
502 check_ret $DOWNLOADER
507 check_installed_programs
512 $ECHO "Copying $FACTOR_IMAGE to $FACTOR_IMAGE_FRESH..."
513 $COPY $FACTOR_IMAGE $FACTOR_IMAGE_FRESH
517 ./$FACTOR_BINARY -i=$BOOT_IMAGE
543 net_bootstrap_no_pull() {
550 ./$FACTOR_BINARY -script -e="USING: vocabs.loader vocabs.refresh system memory ; refresh-all save 0 exit"
555 ./$FACTOR_BINARY -script -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit"
559 install_deps_linux() {
560 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
564 install_deps_macosx() {
565 test_program_installed git
566 if [[ $? -ne 1 ]] ; then
567 ensure_program_installed yes
568 $ECHO "git not found."
569 $ECHO "This script requires either git-core or port."
570 $ECHO "If it fails, install git-core or port and try again."
571 ensure_program_installed port
572 $ECHO "Installing git-core with port...this will take awhile."
573 yes | sudo port install git-core
578 $ECHO "usage: $0 install|deps-linux|deps-macosx|self-update|quick-update|update|bootstrap|net-bootstrap|make-target|report [optional-target]"
579 $ECHO "If you are behind a firewall, invoke as:"
580 $ECHO "env GIT_PROTOCOL=http $0 <command>"
582 $ECHO "Example for overriding the default target:"
583 $ECHO " $0 update macosx-x86-32"
588 # -n is nonzero length, -z is zero length
589 if [[ -n "$2" ]] ; then
598 deps-linux) install_deps_linux ;;
599 deps-macosx) install_deps_macosx ;;
600 self-update) update; make_boot_image; bootstrap;;
601 quick-update) update; refresh_image ;;
602 update) update; update_bootstrap ;;
603 bootstrap) get_config_info; bootstrap ;;
604 net-bootstrap) net_bootstrap_no_pull ;;
605 make-target) FIND_MAKE_TARGET=true; ECHO=false; find_build_info; exit_script ;;
606 report) find_build_info ;;