| 
									
										
										
										
											2008-02-11 17:19:10 -05:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Programs returning != 0 will not cause script to exit | 
					
						
							|  |  |  | set +e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Case insensitive string comparison | 
					
						
							|  |  |  | shopt -s nocaseglob | 
					
						
							|  |  |  | #shopt -s nocasematch | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  | ECHO=echo | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | OS= | 
					
						
							|  |  |  | ARCH= | 
					
						
							|  |  |  | WORD= | 
					
						
							| 
									
										
										
										
											2009-12-02 11:34:37 -05:00
										 |  |  | NO_UI=${NO_UI-} | 
					
						
							| 
									
										
										
										
											2008-02-11 17:19:10 -05:00
										 |  |  | GIT_PROTOCOL=${GIT_PROTOCOL:="git"} | 
					
						
							|  |  |  | GIT_URL=${GIT_URL:=$GIT_PROTOCOL"://factorcode.org/git/factor.git"} | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  | SCRIPT_ARGS="$*" | 
					
						
							| 
									
										
										
										
											2008-02-11 17:19:10 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-13 14:38:41 -05:00
										 |  |  | test_program_installed() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     if ! [[ -n `type -p $1` ]] ; then | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     return 1; | 
					
						
							| 
									
										
										
										
											2008-02-13 14:38:41 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 00:23:16 -04:00
										 |  |  | exit_script() { | 
					
						
							| 
									
										
										
										
											2011-01-24 06:20:59 -05:00
										 |  |  |     if [[ $FIND_MAKE_TARGET = true ]] ; then | 
					
						
							|  |  |  |         # Must be echo not $ECHO | 
					
						
							| 
									
										
										
										
											2010-04-25 15:59:07 -04:00
										 |  |  |         echo $MAKE_TARGET; | 
					
						
							| 
									
										
										
										
											2009-12-22 12:09:42 -05:00
										 |  |  |     fi | 
					
						
							|  |  |  |     exit $1 | 
					
						
							| 
									
										
										
										
											2009-04-21 00:23:16 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | ensure_program_installed() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     installed=0; | 
					
						
							|  |  |  |     for i in $* ; | 
					
						
							|  |  |  |     do | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |         $ECHO -n "Checking for $i..." | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |         test_program_installed $i | 
					
						
							|  |  |  |         if [[ $? -eq 0 ]]; then | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |             $ECHO -n "not " | 
					
						
							| 
									
										
										
										
											2011-01-24 06:20:59 -05:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |             installed=$(( $installed + 1 )) | 
					
						
							|  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |         $ECHO "found!" | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     done | 
					
						
							|  |  |  |     if [[ $installed -eq 0 ]] ; then | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |         $ECHO -n "Install " | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |         if [[ $# -eq 1 ]] ; then | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |             $ECHO -n $1 | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |             $ECHO -n "any of [ $* ]" | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |         fi | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |         $ECHO " and try again." | 
					
						
							| 
									
										
										
										
											2013-03-24 20:06:29 -04:00
										 |  |  |         if [[ $OS == macosx ]] ; then | 
					
						
							| 
									
										
										
										
											2012-02-19 02:23:47 -05:00
										 |  |  |             $ECHO "If you have Xcode 4.3 or higher installed, you must install the" | 
					
						
							|  |  |  |             $ECHO "Command Line Tools from Xcode Preferences > Downloads in order" | 
					
						
							|  |  |  |             $ECHO "to build Factor." | 
					
						
							|  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2009-04-21 00:23:16 -04:00
										 |  |  |         exit_script 1; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | check_ret() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     RET=$? | 
					
						
							|  |  |  |     if [[ $RET -ne 0 ]] ; then | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |        $ECHO $1 failed | 
					
						
							| 
									
										
										
										
											2009-04-21 00:23:16 -04:00
										 |  |  |        exit_script 2 | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-13 14:38:41 -05:00
										 |  |  | set_downloader() { | 
					
						
							| 
									
										
										
										
											2008-03-08 13:00:40 -05:00
										 |  |  |     test_program_installed wget curl | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     if [[ $? -ne 0 ]] ; then | 
					
						
							| 
									
										
										
										
											2008-03-08 13:00:40 -05:00
										 |  |  |         DOWNLOADER=wget | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2010-04-04 15:30:29 -04:00
										 |  |  |         DOWNLOADER="curl -f -O" | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-02-13 14:38:41 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-13 15:32:43 -05:00
										 |  |  | set_md5sum() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     test_program_installed md5sum | 
					
						
							|  |  |  |     if [[ $? -ne 0 ]] ; then | 
					
						
							|  |  |  |         MD5SUM=md5sum | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         MD5SUM="md5 -r" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-02-13 15:32:43 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-11 16:44:50 -04:00
										 |  |  | set_gcc() { | 
					
						
							|  |  |  |     case $OS in | 
					
						
							| 
									
										
										
										
											2011-11-02 20:13:31 -04:00
										 |  |  |         macosx) | 
					
						
							| 
									
										
										
										
											2011-11-02 21:40:27 -04:00
										 |  |  |             xcode_major=`xcodebuild -version | sed -E -ne 's/^Xcode ([0-9]+).*$/\1/p'` | 
					
						
							|  |  |  |             if [[ $xcode_major -ge 4 ]]; then | 
					
						
							| 
									
										
										
										
											2014-06-06 18:06:48 -04:00
										 |  |  |                 [ -z "$CC" ] && CC=clang | 
					
						
							|  |  |  |                 [ -z "$CXX" ] && CXX=clang++ | 
					
						
							| 
									
										
										
										
											2011-11-02 20:13:31 -04:00
										 |  |  |             else | 
					
						
							| 
									
										
										
										
											2014-06-06 18:06:48 -04:00
										 |  |  |                 [ -z "$CC" ] && CC=gcc | 
					
						
							|  |  |  |                 [ -z "$CXX" ] && CXX=g++ | 
					
						
							| 
									
										
										
										
											2011-11-02 20:13:31 -04:00
										 |  |  |             fi | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2011-11-02 21:40:27 -04:00
										 |  |  |         *) | 
					
						
							| 
									
										
										
										
											2014-06-06 18:06:48 -04:00
										 |  |  |             [ -z "$CC" ] && CC=gcc | 
					
						
							|  |  |  |             [ -z "$CXX" ] && CXX=g++ | 
					
						
							| 
									
										
										
										
											2011-11-02 21:40:27 -04:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2008-03-11 16:44:50 -04:00
										 |  |  |     esac | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set_make() { | 
					
						
							| 
									
										
										
										
											2011-11-02 20:13:31 -04:00
										 |  |  |     MAKE='make' | 
					
						
							| 
									
										
										
										
											2008-03-11 16:44:50 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-11 15:08:29 -04:00
										 |  |  | check_git_branch() { | 
					
						
							|  |  |  |     BRANCH=`git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,'` | 
					
						
							|  |  |  |     if [ "$BRANCH" != "master" ] ; then | 
					
						
							|  |  |  |         $ECHO "git branch is $BRANCH, not master" | 
					
						
							|  |  |  |         exit_script 3 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | check_installed_programs() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     ensure_program_installed chmod | 
					
						
							|  |  |  |     ensure_program_installed uname | 
					
						
							|  |  |  |     ensure_program_installed git | 
					
						
							|  |  |  |     ensure_program_installed wget curl | 
					
						
							| 
									
										
										
										
											2012-02-19 02:23:47 -05:00
										 |  |  |     ensure_program_installed clang gcc | 
					
						
							|  |  |  |     ensure_program_installed clang++ g++ cl | 
					
						
							| 
									
										
										
										
											2008-03-11 16:44:50 -04:00
										 |  |  |     ensure_program_installed make gmake | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     ensure_program_installed md5sum md5 | 
					
						
							|  |  |  |     ensure_program_installed cut | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 22:03:32 -05:00
										 |  |  | check_library_exists() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     GCC_TEST=factor-library-test.c | 
					
						
							|  |  |  |     GCC_OUT=factor-library-test.out | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |     $ECHO -n "Checking for library $1..." | 
					
						
							|  |  |  |     $ECHO "int main(){return 0;}" > $GCC_TEST | 
					
						
							| 
									
										
										
										
											2011-04-06 18:49:15 -04:00
										 |  |  |     $CC $GCC_TEST -o $GCC_OUT -l $1 2>&- | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     if [[ $? -ne 0 ]] ; then | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |         $ECHO "not found!" | 
					
						
							|  |  |  |         $ECHO "***Factor will compile NO_UI=1" | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |         NO_UI=1 | 
					
						
							| 
									
										
										
										
											2011-04-06 18:49:15 -04:00
										 |  |  |     else | 
					
						
							|  |  |  |         $ECHO "found." | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     $DELETE -f $GCC_TEST | 
					
						
							|  |  |  |     check_ret $DELETE | 
					
						
							|  |  |  |     $DELETE -f $GCC_OUT | 
					
						
							|  |  |  |     check_ret $DELETE | 
					
						
							| 
									
										
										
										
											2007-11-24 22:03:32 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | check_X11_libraries() { | 
					
						
							| 
									
										
										
										
											2009-12-02 11:34:37 -05:00
										 |  |  |     if [ -z "$NO_UI" ]; then | 
					
						
							|  |  |  |         check_library_exists GL | 
					
						
							|  |  |  |         check_library_exists X11 | 
					
						
							|  |  |  |         check_library_exists pango-1.0 | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2007-11-24 22:03:32 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-06 18:49:15 -04:00
										 |  |  | check_gtk_libraries() { | 
					
						
							|  |  |  |     if [ -z "$NO_UI" ]; then | 
					
						
							|  |  |  |         check_library_exists gobject-2.0 | 
					
						
							|  |  |  |         check_library_exists gtk-x11-2.0 | 
					
						
							|  |  |  |         check_library_exists gdk-x11-2.0 | 
					
						
							|  |  |  |         check_library_exists gdk_pixbuf-2.0 | 
					
						
							|  |  |  |         check_library_exists gtkglext-x11-1.0 | 
					
						
							|  |  |  |         check_library_exists atk-1.0 | 
					
						
							|  |  |  |         check_library_exists gio-2.0 | 
					
						
							|  |  |  |         check_library_exists gdkglext-x11-1.0 | 
					
						
							|  |  |  |         check_library_exists pango-1.0 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 22:03:32 -05:00
										 |  |  | check_libraries() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     case $OS in | 
					
						
							| 
									
										
										
										
											2011-04-06 18:49:15 -04:00
										 |  |  |             linux) check_X11_libraries | 
					
						
							|  |  |  |                    check_gtk_libraries;; | 
					
						
							|  |  |  |             unix) check_gtk_libraries;; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     esac | 
					
						
							| 
									
										
										
										
											2007-11-24 22:03:32 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:03:01 -05:00
										 |  |  | check_factor_exists() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     if [[ -d "factor" ]] ; then | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |         $ECHO "A directory called 'factor' already exists." | 
					
						
							|  |  |  |         $ECHO "Rename or delete it and try again." | 
					
						
							| 
									
										
										
										
											2009-04-21 00:23:16 -04:00
										 |  |  |         exit_script 4 | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2007-11-24 19:03:01 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | find_os() { | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     if [[ -n $OS ]] ; then return; fi | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |     $ECHO "Finding OS..." | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     uname_s=`uname -s` | 
					
						
							|  |  |  |     check_ret uname | 
					
						
							|  |  |  |     case $uname_s in | 
					
						
							| 
									
										
										
										
											2011-09-18 21:25:06 -04:00
										 |  |  |         CYGWIN_NT-5.2-WOW64) OS=windows;; | 
					
						
							|  |  |  |         *CYGWIN_NT*) OS=windows;; | 
					
						
							|  |  |  |         *CYGWIN*) OS=windows;; | 
					
						
							|  |  |  |         MINGW32*) OS=windows;; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |         *darwin*) OS=macosx;; | 
					
						
							|  |  |  |         *Darwin*) OS=macosx;; | 
					
						
							|  |  |  |         *linux*) OS=linux;; | 
					
						
							|  |  |  |         *Linux*) OS=linux;; | 
					
						
							|  |  |  |     esac | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | find_architecture() { | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     if [[ -n $ARCH ]] ; then return; fi | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |     $ECHO "Finding ARCH..." | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     uname_m=`uname -m` | 
					
						
							|  |  |  |     check_ret uname | 
					
						
							|  |  |  |     case $uname_m in | 
					
						
							|  |  |  |        i386) ARCH=x86;; | 
					
						
							|  |  |  |        i686) ARCH=x86;; | 
					
						
							| 
									
										
										
										
											2008-09-16 16:59:07 -04:00
										 |  |  |        i86pc) ARCH=x86;; | 
					
						
							| 
									
										
										
										
											2008-03-07 08:51:00 -05:00
										 |  |  |        amd64) ARCH=x86;; | 
					
						
							| 
									
										
										
										
											2008-04-09 15:01:04 -04:00
										 |  |  |        ppc64) ARCH=ppc;; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |        *86) ARCH=x86;; | 
					
						
							|  |  |  |        *86_64) ARCH=x86;; | 
					
						
							|  |  |  |        "Power Macintosh") ARCH=ppc;; | 
					
						
							|  |  |  |     esac | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | write_test_program() { | 
					
						
							| 
									
										
										
										
											2010-04-29 01:23:03 -04:00
										 |  |  |     #! Must be 'echo' | 
					
						
							|  |  |  |     echo "#include <stdio.h>" > $C_WORD.c | 
					
						
							|  |  |  |     echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-13 22:24:36 -04:00
										 |  |  | c_find_word_size() { | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |     $ECHO "Finding WORD..." | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     C_WORD=factor-word-size | 
					
						
							|  |  |  |     write_test_program | 
					
						
							| 
									
										
										
										
											2014-06-06 18:06:48 -04:00
										 |  |  |     $CC -o $C_WORD $C_WORD.c | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     WORD=$(./$C_WORD) | 
					
						
							|  |  |  |     check_ret $C_WORD | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     $DELETE -f $C_WORD* | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  | intel_macosx_word_size() { | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     ensure_program_installed sysctl | 
					
						
							|  |  |  |     $ECHO -n "Testing if your Intel Mac supports 64bit binaries..." | 
					
						
							|  |  |  |     sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null | 
					
						
							| 
									
										
										
										
											2008-09-13 22:24:36 -04:00
										 |  |  |     if [[ $? -eq 0 ]] ; then | 
					
						
							| 
									
										
										
										
											2008-09-20 16:53:18 -04:00
										 |  |  |         WORD=64 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |         $ECHO "yes!" | 
					
						
							| 
									
										
										
										
											2008-09-13 22:24:36 -04:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |         WORD=32 | 
					
						
							|  |  |  |         $ECHO "no." | 
					
						
							| 
									
										
										
										
											2008-09-13 22:24:36 -04:00
										 |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | find_word_size() { | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     if [[ -n $WORD ]] ; then return; fi | 
					
						
							|  |  |  |     if [[ $OS == macosx && $ARCH == x86 ]] ; then | 
					
						
							|  |  |  |         intel_macosx_word_size | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         c_find_word_size | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-09-13 22:24:36 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | set_factor_binary() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     case $OS in | 
					
						
							| 
									
										
										
										
											2011-09-18 21:25:06 -04:00
										 |  |  |         windows) FACTOR_BINARY=factor.com;; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |         *) FACTOR_BINARY=factor;; | 
					
						
							|  |  |  |     esac | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  | set_factor_library() { | 
					
						
							|  |  |  |     case $OS in | 
					
						
							| 
									
										
										
										
											2011-09-18 21:25:06 -04:00
										 |  |  |         windows) FACTOR_LIBRARY=factor.dll;; | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |         macosx) FACTOR_LIBRARY=libfactor.dylib;; | 
					
						
							|  |  |  |         *) FACTOR_LIBRARY=libfactor.a;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set_factor_image() { | 
					
						
							|  |  |  |     FACTOR_IMAGE=factor.image | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     FACTOR_IMAGE_FRESH=factor.image.fresh | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | echo_build_info() { | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |     $ECHO OS=$OS | 
					
						
							|  |  |  |     $ECHO ARCH=$ARCH | 
					
						
							|  |  |  |     $ECHO WORD=$WORD | 
					
						
							|  |  |  |     $ECHO FACTOR_BINARY=$FACTOR_BINARY | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY | 
					
						
							|  |  |  |     $ECHO FACTOR_IMAGE=$FACTOR_IMAGE | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |     $ECHO MAKE_TARGET=$MAKE_TARGET | 
					
						
							|  |  |  |     $ECHO BOOT_IMAGE=$BOOT_IMAGE | 
					
						
							|  |  |  |     $ECHO MAKE_IMAGE_TARGET=$MAKE_IMAGE_TARGET | 
					
						
							|  |  |  |     $ECHO GIT_PROTOCOL=$GIT_PROTOCOL | 
					
						
							|  |  |  |     $ECHO GIT_URL=$GIT_URL | 
					
						
							|  |  |  |     $ECHO DOWNLOADER=$DOWNLOADER | 
					
						
							|  |  |  |     $ECHO CC=$CC | 
					
						
							| 
									
										
										
										
											2014-06-06 18:06:48 -04:00
										 |  |  |     $ECHO CXX=$CXX | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |     $ECHO MAKE=$MAKE | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     $ECHO COPY=$COPY | 
					
						
							|  |  |  |     $ECHO DELETE=$DELETE | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  | check_os_arch_word() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then | 
					
						
							| 
									
										
										
										
											2008-03-28 22:40:02 -04:00
										 |  |  |         $ECHO "OS: $OS" | 
					
						
							|  |  |  |         $ECHO "ARCH: $ARCH" | 
					
						
							|  |  |  |         $ECHO "WORD: $WORD" | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  |         $ECHO "OS, ARCH, or WORD is empty.  Please report this." | 
					
						
							| 
									
										
										
										
											2008-09-17 01:56:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |         $ECHO $MAKE_TARGET | 
					
						
							| 
									
										
										
										
											2009-04-21 00:23:16 -04:00
										 |  |  |         exit_script 5 | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  | set_build_info() { | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     check_os_arch_word | 
					
						
							| 
									
										
										
										
											2011-11-02 21:40:27 -04:00
										 |  |  |     if [[ $OS == linux && $ARCH == ppc ]] ; then | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  |         MAKE_IMAGE_TARGET=linux-ppc.32 | 
					
						
							|  |  |  |         MAKE_TARGET=linux-ppc-32 | 
					
						
							| 
									
										
										
										
											2011-09-18 21:25:06 -04:00
										 |  |  |     elif [[ $OS == windows && $ARCH == x86 && $WORD == 64 ]] ; then | 
					
						
							|  |  |  |         MAKE_IMAGE_TARGET=windows-x86.64 | 
					
						
							|  |  |  |         MAKE_TARGET=windows-x86-64 | 
					
						
							|  |  |  |     elif [[ $OS == windows && $ARCH == x86 && $WORD == 32 ]] ; then | 
					
						
							|  |  |  |         MAKE_IMAGE_TARGET=windows-x86.32 | 
					
						
							|  |  |  |         MAKE_TARGET=windows-x86-32 | 
					
						
							| 
									
										
										
										
											2008-11-07 22:09:42 -05:00
										 |  |  |     elif [[ $ARCH == x86 && $WORD == 64 ]] ; then | 
					
						
							|  |  |  |         MAKE_IMAGE_TARGET=unix-x86.64 | 
					
						
							| 
									
										
										
										
											2008-11-08 21:36:05 -05:00
										 |  |  |         MAKE_TARGET=$OS-x86-64 | 
					
						
							| 
									
										
										
										
											2010-04-04 15:39:59 -04:00
										 |  |  |     elif [[ $ARCH == x86 && $WORD == 32 ]] ; then | 
					
						
							|  |  |  |         MAKE_IMAGE_TARGET=unix-x86.32 | 
					
						
							|  |  |  |         MAKE_TARGET=$OS-x86-32 | 
					
						
							| 
									
										
										
										
											2008-11-08 21:36:05 -05:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2008-11-07 22:09:42 -05:00
										 |  |  |         MAKE_IMAGE_TARGET=$ARCH.$WORD | 
					
						
							| 
									
										
										
										
											2008-11-08 21:36:05 -05:00
										 |  |  |         MAKE_TARGET=$OS-$ARCH-$WORD | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-11-07 22:56:57 -05:00
										 |  |  |     BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  | parse_build_info() { | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     ensure_program_installed cut | 
					
						
							|  |  |  |     $ECHO "Parsing make target from command line: $1" | 
					
						
							|  |  |  |     OS=`echo $1 | cut -d '-' -f 1` | 
					
						
							|  |  |  |     ARCH=`echo $1 | cut -d '-' -f 2` | 
					
						
							|  |  |  |     WORD=`echo $1 | cut -d '-' -f 3` | 
					
						
							| 
									
										
										
										
											2013-08-19 11:34:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:18:56 -04:00
										 |  |  |     if [[ $OS == linux && $ARCH == ppc ]] ; then WORD=32; fi | 
					
						
							|  |  |  |     if [[ $OS == linux && $ARCH == arm ]] ; then WORD=32; fi | 
					
						
							|  |  |  |     if [[ $OS == macosx && $ARCH == ppc ]] ; then WORD=32; fi | 
					
						
							| 
									
										
										
										
											2014-06-06 18:06:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     $ECHO "OS=$OS" | 
					
						
							|  |  |  |     $ECHO "ARCH=$ARCH" | 
					
						
							|  |  |  |     $ECHO "WORD=$WORD" | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | find_build_info() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     find_os | 
					
						
							|  |  |  |     find_architecture | 
					
						
							| 
									
										
										
										
											2014-06-06 18:06:48 -04:00
										 |  |  |     set_gcc | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     find_word_size | 
					
						
							|  |  |  |     set_factor_binary | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     set_factor_library | 
					
						
							|  |  |  |     set_factor_image | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     set_build_info | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     set_downloader | 
					
						
							|  |  |  |     set_make | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     echo_build_info | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-11 17:19:10 -05:00
										 |  |  | invoke_git() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     git $* | 
					
						
							|  |  |  |     check_ret git | 
					
						
							| 
									
										
										
										
											2008-02-11 17:19:10 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | git_clone() { | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO "Downloading the git repository from factorcode.org..." | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     invoke_git clone $GIT_URL | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  | update_script_name() { | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO `dirname $0`/_update.sh | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | update_script() { | 
					
						
							|  |  |  |     update_script=`update_script_name` | 
					
						
							| 
									
										
										
										
											2009-12-22 12:09:42 -05:00
										 |  |  |     bash_path=`which bash` | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO "#!$bash_path" >"$update_script" | 
					
						
							|  |  |  |     $ECHO "git pull \"$GIT_URL\" master" >>"$update_script" | 
					
						
							|  |  |  |     $ECHO "if [[ \$? -eq 0 ]]; then exec \"$0\" $SCRIPT_ARGS; else echo \"git pull failed\"; exit 2; fi" \
 | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  |         >>"$update_script" | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO "exit 0" >>"$update_script" | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     chmod 755 "$update_script" | 
					
						
							|  |  |  |     exec "$update_script" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | update_script_changed() { | 
					
						
							| 
									
										
										
										
											2013-08-19 11:34:29 -04:00
										 |  |  |     invoke_git diff --stat `invoke_git merge-base HEAD FETCH_HEAD` FETCH_HEAD | grep 'build-support.factor\.sh' >/dev/null | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | git_fetch_factorcode() { | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO "Fetching the git repository from factorcode.org..." | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     rm -f `update_script_name` | 
					
						
							|  |  |  |     invoke_git fetch "$GIT_URL" master | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if update_script_changed; then | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |         $ECHO "Updating and restarting the factor.sh script..." | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  |         update_script | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |         $ECHO "Updating the working tree..." | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  |         invoke_git pull "$GIT_URL" master | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-02-06 20:49:07 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | cd_factor() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     cd factor | 
					
						
							|  |  |  |     check_ret cd | 
					
						
							| 
									
										
										
										
											2007-11-24 19:51:24 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  | set_copy() { | 
					
						
							|  |  |  |     case $OS in | 
					
						
							| 
									
										
										
										
											2011-09-18 21:25:06 -04:00
										 |  |  |         windows) COPY=cp;; | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |         *) COPY=cp;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set_delete() { | 
					
						
							|  |  |  |     case $OS in | 
					
						
							| 
									
										
										
										
											2011-09-18 21:25:06 -04:00
										 |  |  |         windows) DELETE=rm;; | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |         *) DELETE=rm;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | backup_factor() { | 
					
						
							|  |  |  |     $ECHO "Backing up factor..." | 
					
						
							|  |  |  |     $COPY $FACTOR_BINARY $FACTOR_BINARY.bak | 
					
						
							|  |  |  |     $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak | 
					
						
							| 
									
										
										
										
											2008-11-19 18:00:35 -05:00
										 |  |  |     $COPY $BOOT_IMAGE $BOOT_IMAGE.bak | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak | 
					
						
							|  |  |  |     $ECHO "Done with backup." | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-11 11:19:42 -05:00
										 |  |  | check_makefile_exists() { | 
					
						
							| 
									
										
										
										
											2010-01-16 09:43:22 -05:00
										 |  |  |     if [[ ! -e "GNUmakefile" ]] ; then | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |         $ECHO "" | 
					
						
							|  |  |  |         $ECHO "***GNUmakefile not found***" | 
					
						
							|  |  |  |         $ECHO "You are likely in the wrong directory." | 
					
						
							|  |  |  |         $ECHO "Run this script from your factor directory:" | 
					
						
							|  |  |  |         $ECHO "     ./build-support/factor.sh" | 
					
						
							| 
									
										
										
										
											2009-04-21 00:23:16 -04:00
										 |  |  |         exit_script 6 | 
					
						
							| 
									
										
										
										
											2008-11-11 11:19:42 -05:00
										 |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-11 17:19:10 -05:00
										 |  |  | invoke_make() { | 
					
						
							| 
									
										
										
										
											2008-11-11 11:19:42 -05:00
										 |  |  |     check_makefile_exists | 
					
						
							|  |  |  |     $MAKE $MAKE_OPTS $* | 
					
						
							|  |  |  |     check_ret $MAKE | 
					
						
							| 
									
										
										
										
											2008-02-11 17:19:10 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 19:51:24 -05:00
										 |  |  | make_clean() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     invoke_make clean | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | make_factor() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     invoke_make NO_UI=$NO_UI $MAKE_TARGET -j5 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-29 01:48:55 -04:00
										 |  |  | make_clean_factor() { | 
					
						
							|  |  |  |     make_clean | 
					
						
							|  |  |  |     make_factor | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-13 15:20:37 -05:00
										 |  |  | update_boot_images() { | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO "Deleting old images..." | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     $DELETE checksums.txt* > /dev/null 2>&1 | 
					
						
							| 
									
										
										
										
											2009-12-22 12:09:42 -05:00
										 |  |  |     # delete boot images with one or two characters after the dot | 
					
						
							| 
									
										
										
										
											2008-11-19 18:00:35 -05:00
										 |  |  |     $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1 | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     $DELETE temp/staging.*.image > /dev/null 2>&1 | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     if [[ -f $BOOT_IMAGE ]] ; then | 
					
						
							| 
									
										
										
										
											2010-09-27 23:29:09 -04:00
										 |  |  |         get_url http://downloads.factorcode.org/images/latest/checksums.txt | 
					
						
							| 
									
										
										
										
											2011-11-02 20:18:26 -04:00
										 |  |  |         factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '` | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |         set_md5sum | 
					
						
							| 
									
										
										
										
											2011-11-02 20:18:26 -04:00
										 |  |  |         disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '` | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |         $ECHO "Factorcode md5: $factorcode_md5"; | 
					
						
							|  |  |  |         $ECHO "Disk md5: $disk_md5"; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |         if [[ "$factorcode_md5" == "$disk_md5" ]] ; then | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |             $ECHO "Your disk boot image matches the one on factorcode.org." | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |             $DELETE $BOOT_IMAGE > /dev/null 2>&1 | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |             get_boot_image; | 
					
						
							|  |  |  |         fi | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         get_boot_image | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | get_boot_image() { | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO "Downloading boot image $BOOT_IMAGE." | 
					
						
							| 
									
										
										
										
											2010-09-27 23:29:09 -04:00
										 |  |  |     get_url http://downloads.factorcode.org/images/latest/$BOOT_IMAGE | 
					
						
							| 
									
										
										
										
											2008-02-13 14:38:41 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | get_url() { | 
					
						
							| 
									
										
										
										
											2011-01-24 06:20:59 -05:00
										 |  |  |     if [[ -z $DOWNLOADER ]] ; then | 
					
						
							| 
									
										
										
										
											2008-03-04 16:19:00 -05:00
										 |  |  |         set_downloader; | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO $DOWNLOADER $1 ; | 
					
						
							| 
									
										
										
										
											2008-03-08 13:00:40 -05:00
										 |  |  |     $DOWNLOADER $1 | 
					
						
							|  |  |  |     check_ret $DOWNLOADER | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-19 15:18:35 -05:00
										 |  |  | get_config_info() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     find_build_info | 
					
						
							|  |  |  |     check_installed_programs | 
					
						
							|  |  |  |     check_libraries | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  | copy_fresh_image() { | 
					
						
							|  |  |  |     $ECHO "Copying $FACTOR_IMAGE to $FACTOR_IMAGE_FRESH..." | 
					
						
							|  |  |  |     $COPY $FACTOR_IMAGE $FACTOR_IMAGE_FRESH | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-19 15:18:35 -05:00
										 |  |  | bootstrap() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     ./$FACTOR_BINARY -i=$BOOT_IMAGE | 
					
						
							| 
									
										
										
										
											2011-10-29 01:48:55 -04:00
										 |  |  |     copy_fresh_image | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 22:03:32 -05:00
										 |  |  | install() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     check_factor_exists | 
					
						
							|  |  |  |     get_config_info | 
					
						
							|  |  |  |     git_clone | 
					
						
							|  |  |  |     cd_factor | 
					
						
							|  |  |  |     make_factor | 
					
						
							|  |  |  |     get_boot_image | 
					
						
							|  |  |  |     bootstrap | 
					
						
							| 
									
										
										
										
											2007-11-24 22:03:32 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | update() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     get_config_info | 
					
						
							| 
									
										
										
										
											2013-01-21 16:17:01 -05:00
										 |  |  |     check_git_branch | 
					
						
							| 
									
										
										
										
											2009-08-27 13:05:56 -04:00
										 |  |  |     git_fetch_factorcode | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  |     backup_factor | 
					
						
							| 
									
										
										
										
											2011-10-29 01:48:55 -04:00
										 |  |  |     make_clean_factor | 
					
						
							| 
									
										
										
										
											2007-12-04 14:44:46 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-21 16:17:01 -05:00
										 |  |  | download_and_bootstrap() { | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     update_boot_images | 
					
						
							|  |  |  |     bootstrap | 
					
						
							| 
									
										
										
										
											2007-11-24 22:03:32 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-29 01:48:55 -04:00
										 |  |  | net_bootstrap_no_pull() { | 
					
						
							|  |  |  |     get_config_info | 
					
						
							|  |  |  |     make_clean_factor | 
					
						
							| 
									
										
										
										
											2013-01-21 16:17:01 -05:00
										 |  |  |     download_and_bootstrap | 
					
						
							| 
									
										
										
										
											2011-10-29 01:48:55 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-04 14:44:46 -05:00
										 |  |  | refresh_image() { | 
					
						
							| 
									
										
										
										
											2011-07-30 00:05:21 -04:00
										 |  |  |     ./$FACTOR_BINARY -script -e="USING: vocabs.loader vocabs.refresh system memory ; refresh-all save 0 exit" | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     check_ret factor | 
					
						
							| 
									
										
										
										
											2007-12-18 18:07:24 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | make_boot_image() { | 
					
						
							| 
									
										
										
										
											2009-08-15 15:25:16 -04:00
										 |  |  |     ./$FACTOR_BINARY -script -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit" | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     check_ret factor | 
					
						
							| 
									
										
										
										
											2007-12-04 14:44:46 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-03 20:04:18 -04:00
										 |  |  | install_deps_apt_get() { | 
					
						
							| 
									
										
										
										
											2013-11-16 17:43:32 -05:00
										 |  |  |     sudo apt-get --yes install 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 | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     check_ret sudo | 
					
						
							| 
									
										
										
										
											2007-12-03 22:17:23 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-03 20:04:18 -04:00
										 |  |  | install_deps_pacman() { | 
					
						
							| 
									
										
										
										
											2013-11-16 17:40:18 -05:00
										 |  |  |     sudo pacman --noconfirm -S gcc clang make rlwrap git wget pango glibc gtk2 gtk3 gtkglext gtk-engines gdk-pixbuf2 libx11 screen tmux | 
					
						
							| 
									
										
										
										
											2013-06-03 20:04:18 -04:00
										 |  |  |     check_ret sudo | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-07 18:14:26 -04:00
										 |  |  | install_deps_macosx() { | 
					
						
							| 
									
										
										
										
											2008-03-08 13:00:40 -05:00
										 |  |  |     test_program_installed git | 
					
						
							|  |  |  |     if [[ $? -ne 1 ]] ; then | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |         ensure_program_installed yes | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |         $ECHO "git not found." | 
					
						
							|  |  |  |         $ECHO "This script requires either git-core or port." | 
					
						
							|  |  |  |         $ECHO "If it fails, install git-core or port and try again." | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |         ensure_program_installed port | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |         $ECHO "Installing git-core with port...this will take awhile." | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |         yes | sudo port install git-core | 
					
						
							| 
									
										
										
										
											2008-03-08 13:00:40 -05:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2008-03-04 16:11:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-19 15:18:35 -05:00
										 |  |  | usage() { | 
					
						
							| 
									
										
										
										
											2011-11-12 17:05:21 -05:00
										 |  |  |     $ECHO "usage: $0 command [optional-target]" | 
					
						
							| 
									
										
										
										
											2011-11-10 01:56:59 -05:00
										 |  |  |     $ECHO "  install - git clone, compile, bootstrap" | 
					
						
							| 
									
										
										
										
											2013-06-03 20:04:18 -04:00
										 |  |  |     $ECHO "  deps-apt-get - install required packages for Factor on Linux using apt-get" | 
					
						
							|  |  |  |     $ECHO "  deps-pacman - install required packages for Factor on Linux using pacman" | 
					
						
							| 
									
										
										
										
											2011-11-10 01:56:59 -05:00
										 |  |  |     $ECHO "  deps-macosx - install git on MacOSX using port" | 
					
						
							| 
									
										
										
										
											2015-06-08 21:02:00 -04:00
										 |  |  |     $ECHO "  self-update - git pull, recompile, make local boot image, bootstrap" | 
					
						
							| 
									
										
										
										
											2011-11-10 01:56:59 -05:00
										 |  |  |     $ECHO "  quick-update - git pull, refresh-all, save" | 
					
						
							| 
									
										
										
										
											2015-06-08 21:02:00 -04:00
										 |  |  |     $ECHO "  update - git pull, recompile, download a boot image, bootstrap" | 
					
						
							| 
									
										
										
										
											2015-06-16 21:35:59 -04:00
										 |  |  |     $ECHO "  bootstrap - bootstrap with existing boot image" | 
					
						
							| 
									
										
										
										
											2015-06-08 21:02:00 -04:00
										 |  |  |     $ECHO "  net-bootstrap - recompile, download a boot image, bootstrap" | 
					
						
							| 
									
										
										
										
											2011-11-10 01:56:59 -05:00
										 |  |  |     $ECHO "  make-target - find and print the os-arch-cpu string" | 
					
						
							|  |  |  |     $ECHO "  report - print the build variables" | 
					
						
							|  |  |  |     $ECHO "" | 
					
						
							| 
									
										
										
										
											2010-04-24 00:14:53 -04:00
										 |  |  |     $ECHO "If you are behind a firewall, invoke as:" | 
					
						
							|  |  |  |     $ECHO "env GIT_PROTOCOL=http $0 <command>" | 
					
						
							|  |  |  |     $ECHO "" | 
					
						
							|  |  |  |     $ECHO "Example for overriding the default target:" | 
					
						
							|  |  |  |     $ECHO "    $0 update macosx-x86-32" | 
					
						
							| 
									
										
										
										
											2008-01-19 15:18:35 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-16 16:56:17 -04:00
										 |  |  | MAKE_TARGET=unknown | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  | # -n is nonzero length, -z is zero length | 
					
						
							|  |  |  | if [[ -n "$2" ]] ; then | 
					
						
							| 
									
										
										
										
											2008-09-13 23:24:45 -04:00
										 |  |  |     parse_build_info $2 | 
					
						
							| 
									
										
										
										
											2008-09-13 23:00:54 -04:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-19 17:27:12 -05:00
										 |  |  | set_copy | 
					
						
							|  |  |  | set_delete | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | case "$1" in | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     install) install ;; | 
					
						
							| 
									
										
										
										
											2013-06-03 20:04:18 -04:00
										 |  |  |     deps-apt-get) install_deps_apt_get ;; | 
					
						
							|  |  |  |     deps-pacman) install_deps_pacman ;; | 
					
						
							| 
									
										
										
										
											2011-04-07 18:14:26 -04:00
										 |  |  |     deps-macosx) install_deps_macosx ;; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     self-update) update; make_boot_image; bootstrap;; | 
					
						
							|  |  |  |     quick-update) update; refresh_image ;; | 
					
						
							| 
									
										
										
										
											2013-01-21 16:17:01 -05:00
										 |  |  |     update) update; download_and_bootstrap ;; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     bootstrap) get_config_info; bootstrap ;; | 
					
						
							| 
									
										
										
										
											2011-10-29 01:48:55 -04:00
										 |  |  |     net-bootstrap) net_bootstrap_no_pull ;; | 
					
						
							| 
									
										
										
										
											2009-04-21 00:23:16 -04:00
										 |  |  |     make-target) FIND_MAKE_TARGET=true; ECHO=false; find_build_info; exit_script ;; | 
					
						
							| 
									
										
										
										
											2011-10-19 13:31:40 -04:00
										 |  |  |     report) find_build_info ;; | 
					
						
							| 
									
										
										
										
											2008-03-04 16:25:36 -05:00
										 |  |  |     *) usage ;; | 
					
						
							| 
									
										
										
										
											2007-11-24 18:59:11 -05:00
										 |  |  | esac |