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 -eq true ]] ; then
33 ensure_program_installed() {
37 $ECHO -n "Checking for $i..."
38 test_program_installed $i
39 if [[ $? -eq 0 ]]; then
42 installed=$(( $installed + 1 ))
46 if [[ $installed -eq 0 ]] ; then
48 if [[ $# -eq 1 ]] ; then
51 $ECHO -n "any of [ $* ]"
53 $ECHO " and try again."
60 if [[ $RET -ne 0 ]] ; then
67 test_program_installed wget curl
68 if [[ $? -ne 0 ]] ; then
76 test_program_installed md5sum
77 if [[ $? -ne 0 ]] ; then
86 openbsd) ensure_program_installed egcc; CC=egcc;;
93 netbsd) MAKE='gmake';;
94 freebsd) MAKE='gmake';;
95 openbsd) MAKE='gmake';;
96 dragonflybsd) MAKE='gmake';;
99 if ! [[ $MAKE -eq 'gmake' ]] ; then
100 ensure_program_installed gmake
104 check_installed_programs() {
105 ensure_program_installed chmod
106 ensure_program_installed uname
107 ensure_program_installed git
108 ensure_program_installed wget curl
109 ensure_program_installed gcc
110 ensure_program_installed make gmake
111 ensure_program_installed md5sum md5
112 ensure_program_installed cut
115 check_library_exists() {
116 GCC_TEST=factor-library-test.c
117 GCC_OUT=factor-library-test.out
118 $ECHO -n "Checking for library $1..."
119 $ECHO "int main(){return 0;}" > $GCC_TEST
120 $CC $GCC_TEST -o $GCC_OUT -l $1
121 if [[ $? -ne 0 ]] ; then
123 $ECHO "Warning: library $1 not found."
124 $ECHO "***Factor will compile NO_UI=1"
134 check_X11_libraries() {
135 if [ -z "$NO_UI" ]; then
136 check_library_exists GL
137 check_library_exists X11
138 check_library_exists pango-1.0
144 linux) check_X11_libraries;;
148 check_factor_exists() {
149 if [[ -d "factor" ]] ; then
150 $ECHO "A directory called 'factor' already exists."
151 $ECHO "Rename or delete it and try again."
157 if [[ -n $OS ]] ; then return; fi
158 $ECHO "Finding OS..."
162 CYGWIN_NT-5.2-WOW64) OS=winnt;;
163 *CYGWIN_NT*) OS=winnt;;
166 *darwin*) OS=macosx;;
167 *Darwin*) OS=macosx;;
170 *NetBSD*) OS=netbsd;;
171 *FreeBSD*) OS=freebsd;;
172 *OpenBSD*) OS=openbsd;;
173 *DragonFly*) OS=dragonflybsd;;
178 find_architecture() {
179 if [[ -n $ARCH ]] ; then return; fi
180 $ECHO "Finding ARCH..."
191 "Power Macintosh") ARCH=ppc;;
195 write_test_program() {
196 echo "#include <stdio.h>" > $C_WORD.c
197 echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c
201 $ECHO "Finding WORD..."
202 C_WORD=factor-word-size
204 gcc -o $C_WORD $C_WORD.c
210 intel_macosx_word_size() {
211 ensure_program_installed sysctl
212 $ECHO -n "Testing if your Intel Mac supports 64bit binaries..."
213 sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null
214 if [[ $? -eq 0 ]] ; then
224 if [[ -n $WORD ]] ; then return; fi
225 if [[ $OS == macosx && $ARCH == x86 ]] ; then
226 intel_macosx_word_size
232 set_factor_binary() {
234 winnt) FACTOR_BINARY=factor.com;;
235 *) FACTOR_BINARY=factor;;
239 set_factor_library() {
241 winnt) FACTOR_LIBRARY=factor.dll;;
242 macosx) FACTOR_LIBRARY=libfactor.dylib;;
243 *) FACTOR_LIBRARY=libfactor.a;;
248 FACTOR_IMAGE=factor.image
255 $ECHO FACTOR_BINARY=$FACTOR_BINARY
256 $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY
257 $ECHO FACTOR_IMAGE=$FACTOR_IMAGE
258 $ECHO MAKE_TARGET=$MAKE_TARGET
259 $ECHO BOOT_IMAGE=$BOOT_IMAGE
260 $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET
261 $ECHO GIT_PROTOCOL=$GIT_PROTOCOL
262 $ECHO GIT_URL=$GIT_URL
263 $ECHO DOWNLOADER=$DOWNLOADER
270 check_os_arch_word() {
271 if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then
275 $ECHO "OS, ARCH, or WORD is empty. Please report this."
284 if [[ $OS == macosx && $ARCH == ppc ]] ; then
285 MAKE_IMAGE_TARGET=macosx-ppc
286 MAKE_TARGET=macosx-ppc
287 elif [[ $OS == linux && $ARCH == ppc ]] ; then
288 MAKE_IMAGE_TARGET=linux-ppc
289 MAKE_TARGET=linux-ppc
290 elif [[ $OS == winnt && $ARCH == x86 && $WORD == 64 ]] ; then
291 MAKE_IMAGE_TARGET=winnt-x86.64
292 MAKE_TARGET=winnt-x86-64
293 elif [[ $ARCH == x86 && $WORD == 64 ]] ; then
294 MAKE_IMAGE_TARGET=unix-x86.64
295 MAKE_TARGET=$OS-x86-64
297 MAKE_IMAGE_TARGET=$ARCH.$WORD
298 MAKE_TARGET=$OS-$ARCH-$WORD
300 BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image
304 ensure_program_installed cut
305 $ECHO "Parsing make target from command line: $1"
306 OS=`echo $1 | cut -d '-' -f 1`
307 ARCH=`echo $1 | cut -d '-' -f 2`
308 WORD=`echo $1 | cut -d '-' -f 3`
310 if [[ $OS == linux && $ARCH == ppc ]] ; then WORD=32; fi
311 if [[ $OS == linux && $ARCH == arm ]] ; then WORD=32; fi
312 if [[ $OS == macosx && $ARCH == ppc ]] ; then WORD=32; fi
313 if [[ $OS == wince && $ARCH == arm ]] ; then WORD=32; fi
340 echo "Downloading the git repository from factorcode.org..."
341 invoke_git clone $GIT_URL
344 update_script_name() {
345 echo `dirname $0`/_update.sh
349 update_script=`update_script_name`
350 bash_path=`which bash`
351 echo "#!$bash_path" >"$update_script"
352 echo "git pull \"$GIT_URL\" master" >>"$update_script"
353 echo "if [[ \$? -eq 0 ]]; then exec \"$0\" $SCRIPT_ARGS; else echo \"git pull failed\"; exit 2; fi" \
355 echo "exit 0" >>"$update_script"
357 chmod 755 "$update_script"
358 exec "$update_script"
361 update_script_changed() {
362 invoke_git diff --stat `invoke_git merge-base HEAD FETCH_HEAD` FETCH_HEAD | grep 'build-support.factor\.sh' >/dev/null
365 git_fetch_factorcode() {
366 echo "Fetching the git repository from factorcode.org..."
368 rm -f `update_script_name`
369 invoke_git fetch "$GIT_URL" master
371 if update_script_changed; then
372 echo "Updating and restarting the factor.sh script..."
375 echo "Updating the working tree..."
376 invoke_git pull "$GIT_URL" master
400 $ECHO "Backing up factor..."
401 $COPY $FACTOR_BINARY $FACTOR_BINARY.bak
402 $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak
403 $COPY $BOOT_IMAGE $BOOT_IMAGE.bak
404 $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak
405 $ECHO "Done with backup."
408 check_makefile_exists() {
409 if [[ ! -e "GNUmakefile" ]] ; then
411 echo "***GNUmakefile not found***"
412 echo "You are likely in the wrong directory."
413 echo "Run this script from your factor directory:"
414 echo " ./build-support/factor.sh"
420 check_makefile_exists
430 invoke_make NO_UI=$NO_UI $MAKE_TARGET -j5
433 update_boot_images() {
434 echo "Deleting old images..."
435 $DELETE checksums.txt* > /dev/null 2>&1
436 # delete boot images with one or two characters after the dot
437 $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1
438 $DELETE temp/staging.*.image > /dev/null 2>&1
439 if [[ -f $BOOT_IMAGE ]] ; then
440 get_url http://factorcode.org/images/latest/checksums.txt
441 factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '`;
444 netbsd) disk_md5=`md5 $BOOT_IMAGE | cut -f4 -d' '`;;
445 *) disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '` ;;
447 echo "Factorcode md5: $factorcode_md5";
448 echo "Disk md5: $disk_md5";
449 if [[ "$factorcode_md5" == "$disk_md5" ]] ; then
450 echo "Your disk boot image matches the one on factorcode.org."
452 $DELETE $BOOT_IMAGE > /dev/null 2>&1
461 echo "Downloading boot image $BOOT_IMAGE."
462 get_url http://factorcode.org/images/latest/$BOOT_IMAGE
466 if [[ $DOWNLOADER -eq "" ]] ; then
469 echo $DOWNLOADER $1 ;
471 check_ret $DOWNLOADER
476 check_installed_programs
481 ./$FACTOR_BINARY -i=$BOOT_IMAGE
509 ./$FACTOR_BINARY -script -e="USING: vocabs.loader system memory ; refresh-all USE: memory save 0 exit"
514 ./$FACTOR_BINARY -script -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit"
519 install_build_system_apt() {
520 sudo apt-get --yes install libc6-dev libpango1.0-dev libx11-dev xorg-dev wget git-core git-doc rlwrap gcc make
524 install_build_system_port() {
525 test_program_installed git
526 if [[ $? -ne 1 ]] ; then
527 ensure_program_installed yes
528 echo "git not found."
529 echo "This script requires either git-core or port."
530 echo "If it fails, install git-core or port and try again."
531 ensure_program_installed port
532 echo "Installing git-core with port...this will take awhile."
533 yes | sudo port install git-core
538 echo "usage: $0 install|install-x11|install-macosx|self-update|quick-update|update|bootstrap|dlls|net-bootstrap|make-target|report [optional-target]"
539 echo "If you are behind a firewall, invoke as:"
540 echo "env GIT_PROTOCOL=http $0 <command>"
542 echo "Example for overriding the default target:"
543 echo " $0 update macosx-x86-32"
548 # -n is nonzero length, -z is zero length
549 if [[ -n "$2" ]] ; then
558 install-x11) install_build_system_apt; install ;;
559 install-macosx) install_build_system_port; install ;;
560 self-update) update; make_boot_image; bootstrap;;
561 quick-update) update; refresh_image ;;
562 update) update; update_bootstrap ;;
563 bootstrap) get_config_info; bootstrap ;;
564 report) find_build_info ;;
565 net-bootstrap) get_config_info; update_boot_images; bootstrap ;;
566 make-target) FIND_MAKE_TARGET=true; ECHO=false; find_build_info; exit_script ;;