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"}
18 test_program_installed() {
19 if ! [[ -n `type -p $1` ]] ; then
25 ensure_program_installed() {
29 $ECHO -n "Checking for $i..."
30 test_program_installed $i
31 if [[ $? -eq 0 ]]; then
34 installed=$(( $installed + 1 ))
38 if [[ $installed -eq 0 ]] ; then
40 if [[ $# -eq 1 ]] ; then
43 $ECHO -n "any of [ $* ]"
45 $ECHO " and try again."
52 if [[ $RET -ne 0 ]] ; then
59 $ECHO -n "Checking gcc version..."
60 GCC_VERSION=`$CC --version`
62 if [[ $GCC_VERSION == *3.3.* ]] ; then
63 $ECHO "You have a known buggy version of gcc (3.3)"
64 $ECHO "Install gcc 3.4 or higher and try again."
66 elif [[ $GCC_VERSION == *4.3.* ]] ; then
67 MAKE_OPTS="$MAKE_OPTS SITE_CFLAGS=-fno-forward-propagate"
73 test_program_installed wget curl
74 if [[ $? -ne 0 ]] ; then
82 test_program_installed md5sum
83 if [[ $? -ne 0 ]] ; then
92 openbsd) ensure_program_installed egcc; CC=egcc;;
99 netbsd) MAKE='gmake';;
100 freebsd) MAKE='gmake';;
101 openbsd) MAKE='gmake';;
102 dragonflybsd) MAKE='gmake';;
105 if ! [[ $MAKE -eq 'gmake' ]] ; then
106 ensure_program_installed gmake
110 check_installed_programs() {
111 ensure_program_installed chmod
112 ensure_program_installed uname
113 ensure_program_installed git
114 ensure_program_installed wget curl
115 ensure_program_installed gcc
116 ensure_program_installed make gmake
117 ensure_program_installed md5sum md5
118 ensure_program_installed cut
122 check_library_exists() {
123 GCC_TEST=factor-library-test.c
124 GCC_OUT=factor-library-test.out
125 $ECHO -n "Checking for library $1..."
126 $ECHO "int main(){return 0;}" > $GCC_TEST
127 $CC $GCC_TEST -o $GCC_OUT -l $1
128 if [[ $? -ne 0 ]] ; then
130 $ECHO "Warning: library $1 not found."
131 $ECHO "***Factor will compile NO_UI=1"
141 check_X11_libraries() {
142 check_library_exists freetype
143 check_library_exists GLU
144 check_library_exists GL
145 check_library_exists X11
150 linux) check_X11_libraries;;
154 check_factor_exists() {
155 if [[ -d "factor" ]] ; then
156 $ECHO "A directory called 'factor' already exists."
157 $ECHO "Rename or delete it and try again."
163 if [[ -n $OS ]] ; then return; fi
164 $ECHO "Finding OS..."
168 CYGWIN_NT-5.2-WOW64) OS=winnt;;
169 *CYGWIN_NT*) OS=winnt;;
171 *darwin*) OS=macosx;;
172 *Darwin*) OS=macosx;;
175 *NetBSD*) OS=netbsd;;
176 *FreeBSD*) OS=freebsd;;
177 *OpenBSD*) OS=openbsd;;
178 *DragonFly*) OS=dragonflybsd;;
183 find_architecture() {
184 if [[ -n $ARCH ]] ; then return; fi
185 $ECHO "Finding ARCH..."
196 "Power Macintosh") ARCH=ppc;;
200 write_test_program() {
201 echo "#include <stdio.h>" > $C_WORD.c
202 echo "int main(){printf(\"%d\", 8*sizeof(void*)); return 0; }" >> $C_WORD.c
206 $ECHO "Finding WORD..."
207 C_WORD=factor-word-size
209 gcc -o $C_WORD $C_WORD.c
215 intel_macosx_word_size() {
216 ensure_program_installed sysctl
217 $ECHO -n "Testing if your Intel Mac supports 64bit binaries..."
218 sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null
219 if [[ $? -eq 0 ]] ; then
229 if [[ -n $WORD ]] ; then return; fi
230 if [[ $OS == macosx && $ARCH == x86 ]] ; then
231 intel_macosx_word_size
237 set_factor_binary() {
239 winnt) FACTOR_BINARY=factor-console.exe;;
240 *) FACTOR_BINARY=factor;;
244 set_factor_library() {
246 winnt) FACTOR_LIBRARY=factor.dll;;
247 macosx) FACTOR_LIBRARY=libfactor.dylib;;
248 *) FACTOR_LIBRARY=libfactor.a;;
253 FACTOR_IMAGE=factor.image
260 $ECHO FACTOR_BINARY=$FACTOR_BINARY
261 $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY
262 $ECHO FACTOR_IMAGE=$FACTOR_IMAGE
263 $ECHO MAKE_TARGET=$MAKE_TARGET
264 $ECHO BOOT_IMAGE=$BOOT_IMAGE
265 $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET
266 $ECHO GIT_PROTOCOL=$GIT_PROTOCOL
267 $ECHO GIT_URL=$GIT_URL
268 $ECHO DOWNLOADER=$DOWNLOADER
275 check_os_arch_word() {
276 if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then
280 $ECHO "OS, ARCH, or WORD is empty. Please report this."
289 if [[ $OS == macosx && $ARCH == ppc ]] ; then
290 MAKE_IMAGE_TARGET=macosx-ppc
291 MAKE_TARGET=macosx-ppc
292 elif [[ $OS == linux && $ARCH == ppc ]] ; then
293 MAKE_IMAGE_TARGET=linux-ppc
294 MAKE_TARGET=linux-ppc
295 elif [[ $OS == winnt && $ARCH == x86 && $WORD == 64 ]] ; then
296 MAKE_IMAGE_TARGET=winnt-x86.64
297 MAKE_TARGET=winnt-x86-64
298 elif [[ $ARCH == x86 && $WORD == 64 ]] ; then
299 MAKE_IMAGE_TARGET=unix-x86.64
300 MAKE_TARGET=$OS-x86-64
302 MAKE_IMAGE_TARGET=$ARCH.$WORD
303 MAKE_TARGET=$OS-$ARCH-$WORD
305 BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image
309 ensure_program_installed cut
310 $ECHO "Parsing make target from command line: $1"
311 OS=`echo $1 | cut -d '-' -f 1`
312 ARCH=`echo $1 | cut -d '-' -f 2`
313 WORD=`echo $1 | cut -d '-' -f 3`
315 if [[ $OS == linux && $ARCH == ppc ]] ; then WORD=32; fi
316 if [[ $OS == linux && $ARCH == arm ]] ; then WORD=32; fi
317 if [[ $OS == macosx && $ARCH == ppc ]] ; then WORD=32; fi
318 if [[ $OS == wince && $ARCH == arm ]] ; then WORD=32; fi
345 echo "Downloading the git repository from factorcode.org..."
346 invoke_git clone $GIT_URL
349 git_pull_factorcode() {
350 echo "Updating the git repository from factorcode.org..."
351 invoke_git pull $GIT_URL master
374 $ECHO "Backing up factor..."
375 $COPY $FACTOR_BINARY $FACTOR_BINARY.bak
376 $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak
377 $COPY $BOOT_IMAGE $BOOT_IMAGE.bak
378 $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak
379 $ECHO "Done with backup."
382 check_makefile_exists() {
383 if [[ ! -e "Makefile" ]] ; then
385 echo "***Makefile not found***"
386 echo "You are likely in the wrong directory."
387 echo "Run this script from your factor directory:"
388 echo " ./build-support/factor.sh"
394 check_makefile_exists
404 invoke_make NO_UI=$NO_UI $MAKE_TARGET -j5
407 update_boot_images() {
408 echo "Deleting old images..."
409 $DELETE checksums.txt* > /dev/null 2>&1
410 # delete boot images with one or two characters after the dot
411 $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1
412 $DELETE temp/staging.*.image > /dev/null 2>&1
413 if [[ -f $BOOT_IMAGE ]] ; then
414 get_url http://factorcode.org/images/latest/checksums.txt
415 factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '`;
418 netbsd) disk_md5=`md5 $BOOT_IMAGE | cut -f4 -d' '`;;
419 *) disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '` ;;
421 echo "Factorcode md5: $factorcode_md5";
422 echo "Disk md5: $disk_md5";
423 if [[ "$factorcode_md5" == "$disk_md5" ]] ; then
424 echo "Your disk boot image matches the one on factorcode.org."
426 $DELETE $BOOT_IMAGE > /dev/null 2>&1
435 echo "Downloading boot image $BOOT_IMAGE."
436 get_url http://factorcode.org/images/latest/$BOOT_IMAGE
440 if [[ $DOWNLOADER -eq "" ]] ; then
443 echo $DOWNLOADER $1 ;
445 check_ret $DOWNLOADER
448 maybe_download_dlls() {
449 if [[ $OS == winnt ]] ; then
450 get_url http://factorcode.org/dlls/freetype6.dll
451 get_url http://factorcode.org/dlls/zlib1.dll
452 get_url http://factorcode.org/dlls/OpenAL32.dll
453 get_url http://factorcode.org/dlls/alut.dll
454 get_url http://factorcode.org/dlls/comerr32.dll
455 get_url http://factorcode.org/dlls/gssapi32.dll
456 get_url http://factorcode.org/dlls/iconv.dll
457 get_url http://factorcode.org/dlls/k5sprt32.dll
458 get_url http://factorcode.org/dlls/krb5_32.dll
459 get_url http://factorcode.org/dlls/libcairo-2.dll
460 get_url http://factorcode.org/dlls/libeay32.dll
461 get_url http://factorcode.org/dlls/libiconv2.dll
462 get_url http://factorcode.org/dlls/libintl3.dll
463 get_url http://factorcode.org/dlls/libpq.dll
464 get_url http://factorcode.org/dlls/libxml2.dll
465 get_url http://factorcode.org/dlls/libxslt.dll
466 get_url http://factorcode.org/dlls/msvcr71.dll
467 get_url http://factorcode.org/dlls/ogg.dll
468 get_url http://factorcode.org/dlls/pgaevent.dll
469 get_url http://factorcode.org/dlls/sqlite3.dll
470 get_url http://factorcode.org/dlls/ssleay32.dll
471 get_url http://factorcode.org/dlls/theora.dll
472 get_url http://factorcode.org/dlls/vorbis.dll
480 check_installed_programs
485 ./$FACTOR_BINARY -i=$BOOT_IMAGE
514 ./$FACTOR_BINARY -script -e="USE: vocabs.loader USE: system refresh-all USE: memory save 0 exit"
519 ./$FACTOR_BINARY -script -e="\"$MAKE_IMAGE_TARGET\" USE: system USE: bootstrap.image make-image save 0 exit"
524 install_build_system_apt() {
525 sudo apt-get --yes install libc6-dev libfreetype6-dev libx11-dev xorg-dev glutg3-dev wget git-core git-doc rlwrap gcc make
529 install_build_system_port() {
530 test_program_installed git
531 if [[ $? -ne 1 ]] ; then
532 ensure_program_installed yes
533 echo "git not found."
534 echo "This script requires either git-core or port."
535 echo "If it fails, install git-core or port and try again."
536 ensure_program_installed port
537 echo "Installing git-core with port...this will take awhile."
538 yes | sudo port install git-core
543 echo "usage: $0 install|install-x11|install-macosx|self-update|quick-update|update|bootstrap|dlls|net-bootstrap|make-target|report [optional-target]"
544 echo "If you are behind a firewall, invoke as:"
545 echo "env GIT_PROTOCOL=http $0 <command>"
547 echo "Example for overriding the default target:"
548 echo " $0 update macosx-x86-32"
553 # -n is nonzero length, -z is zero length
554 if [[ -n "$2" ]] ; then
563 install-x11) install_build_system_apt; install ;;
564 install-macosx) install_build_system_port; install ;;
565 self-update) update; make_boot_image; bootstrap;;
566 quick-update) update; refresh_image ;;
567 update) update; update_bootstrap ;;
568 bootstrap) get_config_info; bootstrap ;;
569 report) find_build_info ;;
570 dlls) get_config_info; maybe_download_dlls;;
571 net-bootstrap) get_config_info; update_boot_images; bootstrap ;;
572 make-target) ECHO=false; find_build_info; echo $MAKE_TARGET ;;