From: John Benediktsson Date: Tue, 15 Mar 2016 10:16:33 +0000 (-0700) Subject: moving build-support/factor.(sh|cmd) to ./build.(sh|cmd). X-Git-Tag: unmaintained~1520 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=5dd6435511af441cac3af51ce609b818cd017326 moving build-support/factor.(sh|cmd) to ./build.(sh|cmd). --- diff --git a/README.md b/README.md index 06d0491c9d..6c042a9004 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ To check out Factor: To build the latest complete Factor system from git: -* Windows: `build-support\factor.cmd` -* Unix: `./build-support/factor.sh update` +* Windows: `build.cmd` +* Unix: `./build.sh update` Now you should have a complete Factor system ready to run. @@ -112,7 +112,6 @@ You can also write scripts that can be run from the terminal, by putting The Factor source tree is organized as follows: -* `build-support/` - scripts used for compiling Factor (not present in binary packages) * `vm/` - Factor VM source code (not present in binary packages) * `core/` - Factor core library * `basis/` - Factor basis library, compiler, tools diff --git a/build-support/factor.cmd b/build-support/factor.cmd deleted file mode 100644 index b14f4dbe1e..0000000000 --- a/build-support/factor.cmd +++ /dev/null @@ -1,96 +0,0 @@ -@echo off -setlocal - -if "%1"=="/?" ( - goto usage -) else if "%1"=="" ( - set _bootimage_version=latest -) else if "%1"=="latest" ( - set _bootimage_version=latest -) else if "%1"=="clean" ( - set _bootimage_version=clean -) else goto usage - -if not exist Nmakefile goto wrongdir - -call cl 2>&1 | find "x86" >nul -if not errorlevel 1 ( - echo x86-32 cl.exe detected. - set _target=x86-32 - set _bootimage=boot.windows-x86.32.image -) else ( - call cl 2>&1 | find "x64" >nul - if not errorlevel 1 ( - echo x86-64 cl.exe detected. - set _target=x86-64 - set _bootimage=boot.windows-x86.64.image - ) else goto nocl -) - -: Fun syntax -for /f %%x in ('git describe --all') do set GIT_DESCRIBE=%%x -for /f %%y in ('git rev-parse HEAD') do set GIT_ID=%%y - -set git_label=%GIT_DESCRIBE%-%GIT_ID% -set version=0.98 - -if %_bootimage_version%==clean ( - set _git_branch=clean-windows-%_target% - set _bootimage_path=clean/windows-%_target% -) else ( - set _git_branch=master - set _bootimage_path=latest -) - -echo Deleting staging images from temp/... -del temp\staging.*.image - -echo Updating working copy from %_git_branch%... -call git pull git://factorcode.org/git/factor.git %_git_branch% -if errorlevel 1 goto fail - -echo Building vm... -nmake /nologo /f Nmakefile clean -if errorlevel 1 goto fail -nmake /nologo /f Nmakefile %_target% -if errorlevel 1 goto fail - -echo Fetching %_bootimage_version% boot image... -cscript /nologo build-support\http-get.vbs http://downloads.factorcode.org/images/%_bootimage_path%/%_bootimage% %_bootimage% -if errorlevel 1 goto fail - -echo Bootstrapping... -.\factor.com -i=%_bootimage% -if errorlevel 1 goto fail - -echo Copying fresh factor.image to factor.image.fresh. -copy factor.image factor.image.fresh -if errorlevel 1 goto fail - -echo Build complete. -goto :EOF - -:fail -echo Build failed. -goto :EOF - -:wrongdir -echo build-support\factor.cmd must be run from the root of the Factor source tree. -goto :EOF - -:nocl -echo Unable to detect cl.exe target platform. -echo Make sure you're running within the Visual Studio or Windows SDK environment. -goto :EOF - -:usage -echo Usage: build-support\factor.cmd [latest/clean] -echo Updates the working copy, cleans and builds the vm using nmake, -echo fetches a boot image, and bootstraps factor. -echo If latest is specified, then the working copy is updated to the -echo upstream "master" branch and the boot image corresponding to the -echo most recent factor build is downloaded. This is the default. -echo If clean is specified, then the working copy is updated to the -echo upstream "clean-windows-*" branch corresponding to the current -echo platform and the corresponding boot image is downloaded. -goto :EOF diff --git a/build-support/factor.sh b/build-support/factor.sh deleted file mode 100755 index 7a64fb52a2..0000000000 --- a/build-support/factor.sh +++ /dev/null @@ -1,722 +0,0 @@ -#!/usr/bin/env bash - -# Programs returning != 0 will not cause script to exit -set +e - -# Case insensitive string comparison -shopt -s nocaseglob -#shopt -s nocasematch - -ECHO=echo -OS= -ARCH= -WORD= -NO_UI=${NO_UI-} -GIT_PROTOCOL=${GIT_PROTOCOL:="git"} -GIT_URL=${GIT_URL:=$GIT_PROTOCOL"://factorcode.org/git/factor.git"} -SCRIPT_ARGS="$*" - -# return 1 on found -test_program_installed() { - if ! [[ -n `type -p $1` ]] ; then - return 0; - fi - return 1; -} - -# return 1 on found -test_programs_installed() { - installed=0; - $ECHO -n "Checking for all($*)..." - for i in $* ; - do - test_program_installed $i - if [[ $? -eq 1 ]]; then - installed=$(( $installed + 1 )) - fi - done - if [[ $installed -eq $# ]] ; then - $ECHO "found!" - return 1 - else - $ECHO "all not found." - return 0 - fi -} - -exit_script() { - if [[ $FIND_MAKE_TARGET = true ]] ; then - # Must be echo not $ECHO - echo $MAKE_TARGET; - fi - exit $1 -} - -ensure_program_installed() { - installed=0; - $ECHO -n "Checking for any($*)..." - for i in $* ; - do - test_program_installed $i - if [[ $? -eq 1 ]]; then - $ECHO "found $i!" - installed=$(( $installed + 1 )) - return - fi - done - $ECHO "none found." - $ECHO -n "Install " - if [[ $# -eq 1 ]] ; then - $ECHO -n $1 - else - $ECHO -n "any of [ $* ]" - fi - $ECHO " and try again." - if [[ $OS == macosx ]] ; then - $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 - exit_script 1; -} - -check_ret() { - RET=$? - if [[ $RET -ne 0 ]] ; then - $ECHO $1 failed - exit_script 2 - fi -} - -set_downloader() { - test_program_installed wget - if [[ $? -ne 0 ]] ; then - DOWNLOADER=wget - return - fi - test_program_installed curl - if [[ $? -ne 0 ]] ; then - DOWNLOADER="curl -f -O" - return - fi - $ECHO "error: wget or curl required" - exit_script 11 -} - -set_md5sum() { - test_program_installed md5sum - if [[ $? -ne 0 ]] ; then - MD5SUM=md5sum - else - MD5SUM="md5 -r" - fi -} - -semver_into() { - RE_SEMVER="^([0-9]*)\.([0-9]*)\.([0-9]*)-?(.*)?$" # 3.3.3-5 - CLANG_RE_OLD="^([0-9]*)\.([0-9]*)-?(.*)?$" # 3.3-5 - if [[ $1 =~ $RE_SEMVER ]] ; then - export "$2=${BASH_REMATCH[1]}" - export "$3=${BASH_REMATCH[2]}" - export "$4=${BASH_REMATCH[3]}" - export "$5=${BASH_REMATCH[4]}" - elif [[ $1 =~ $CLANG_RE_OLD ]] ; then - export "$2=${BASH_REMATCH[1]}" - export "$3=${BASH_REMATCH[2]}" - export "$4=0" - export "$5=${BASH_REMATCH[3]}" - else - echo "unsupported version number, please report a bug: $1" - exit 123 - fi -} - -# issue 1440 -gcc_version_ok() { - GCC_VERSION=`gcc -dumpversion` - local GCC_MAJOR local GCC_MINOR local GCC_PATCH local GCC_SPECIAL - semver_into $GCC_VERSION GCC_MAJOR GCC_MINOR GCC_PATCH GCC_SPECIAL - - if [[ $GCC_MAJOR -lt 4 - || ( $GCC_MAJOR -eq 4 && $GCC_MINOR -lt 7 ) - || ( $GCC_MAJOR -eq 4 && $GCC_MINOR -eq 7 && $GCC_THIRD -lt 3 ) - || ( $GCC_MAJOR -eq 4 && $GCC_MINOR -eq 8 && $GCC_THIRD -eq 0 ) - ]] ; then - echo "gcc version required >= 4.7.3, != 4.8.0, >= 4.8.1, got $GCC_VERSION" - return 1 - fi - return 0 -} - -clang_version_ok() { - CLANG_VERSION=`clang --version | head -n1` - CLANG_VERSION_RE='^[a-zA-Z0-9 ]* version (.*)$' # 3.3-5 - if [[ $CLANG_VERSION =~ $CLANG_VERSION_RE ]] ; then - export "CLANG_VERSION=${BASH_REMATCH[1]}" - local CLANG_MAJOR local CLANG_MINOR local CLANG_PATCH local CLANG_SPECIAL - semver_into "$CLANG_VERSION" CLANG_MAJOR CLANG_MINOR CLANG_PATCH CLANG_SPECIAL - if [[ $CLANG_MAJOR -lt 3 - || ( $CLANG_MAJOR -eq 3 && $CLANG_MINOR -le 1 ) - ]] ; then - echo "clang version required >= 3.1, got $CLANG_VERSION" - return 1 - fi - else - return 1 - fi - return 0 -} - -set_cc() { - test_programs_installed clang clang++ - if [[ $? -ne 0 ]] && clang_version_ok ; then - [ -z "$CC" ] && CC=clang - [ -z "$CXX" ] && CXX=clang++ - return - fi - - test_programs_installed gcc g++ - if [[ $? -ne 0 ]] && gcc_version_ok ; then - [ -z "$CC" ] && CC=gcc - [ -z "$CXX" ] && CXX=g++ - return - fi - - $ECHO "error: high enough version of either (clang/clang++) or (gcc/g++) required!" - exit_script 10 -} - -set_make() { - MAKE='make' -} - -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 -} - -check_installed_programs() { - ensure_program_installed chmod - ensure_program_installed uname - ensure_program_installed git - ensure_program_installed wget curl - ensure_program_installed clang gcc - ensure_program_installed clang++ g++ cl - ensure_program_installed make gmake - ensure_program_installed md5sum md5 - ensure_program_installed cut -} - -check_library_exists() { - GCC_TEST=factor-library-test.c - GCC_OUT=factor-library-test.out - $ECHO -n "Checking for library $1..." - $ECHO "int main(){return 0;}" > $GCC_TEST - $CC $GCC_TEST -o $GCC_OUT -l $1 2>&- - if [[ $? -ne 0 ]] ; then - $ECHO "not found." - $ECHO "***Factor will compile NO_UI=1" - NO_UI=1 - else - $ECHO "found." - fi - $DELETE -f $GCC_TEST - check_ret $DELETE - $DELETE -f $GCC_OUT - check_ret $DELETE -} - -check_X11_libraries() { - if [ -z "$NO_UI" ]; then - check_library_exists GL - check_library_exists X11 - check_library_exists pango-1.0 - fi -} - -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 -} - - -check_libraries() { - case $OS in - linux) check_X11_libraries - check_gtk_libraries;; - unix) check_gtk_libraries;; - esac -} - -check_factor_exists() { - if [[ -d "factor" ]] ; then - $ECHO "A directory called 'factor' already exists." - $ECHO "Rename or delete it and try again." - exit_script 4 - fi -} - -find_os() { - if [[ -n $OS ]] ; then return; fi - $ECHO "Finding OS..." - uname_s=`uname -s` - check_ret uname - case $uname_s in - CYGWIN_NT-5.2-WOW64) OS=windows;; - *CYGWIN_NT*) OS=windows;; - *CYGWIN*) OS=windows;; - MINGW32*) OS=windows;; - *darwin*) OS=macosx;; - *Darwin*) OS=macosx;; - *linux*) OS=linux;; - *Linux*) OS=linux;; - esac -} - -find_architecture() { - if [[ -n $ARCH ]] ; then return; fi - $ECHO "Finding ARCH..." - uname_m=`uname -m` - check_ret uname - case $uname_m in - i386) ARCH=x86;; - i686) ARCH=x86;; - i86pc) ARCH=x86;; - amd64) ARCH=x86;; - ppc64) ARCH=ppc;; - *86) ARCH=x86;; - *86_64) ARCH=x86;; - "Power Macintosh") ARCH=ppc;; - esac -} - -write_test_program() { - #! Must be 'echo' - echo "#include " > $C_WORD.c - echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c -} - -c_find_word_size() { - $ECHO "Finding WORD..." - C_WORD=factor-word-size - write_test_program - $CC -o $C_WORD $C_WORD.c - WORD=$(./$C_WORD) - check_ret $C_WORD - $DELETE -f $C_WORD* -} - -intel_macosx_word_size() { - ensure_program_installed sysctl - $ECHO -n "Testing if your Intel Mac supports 64bit binaries..." - sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null - if [[ $? -eq 0 ]] ; then - WORD=64 - $ECHO "yes!" - else - WORD=32 - $ECHO "no." - fi -} - -find_word_size() { - if [[ -n $WORD ]] ; then return; fi - if [[ $OS == macosx && $ARCH == x86 ]] ; then - intel_macosx_word_size - else - c_find_word_size - fi -} - -set_factor_binary() { - case $OS in - windows) FACTOR_BINARY=factor.com;; - *) FACTOR_BINARY=factor;; - esac -} - -set_factor_library() { - case $OS in - windows) FACTOR_LIBRARY=factor.dll;; - macosx) FACTOR_LIBRARY=libfactor.dylib;; - *) FACTOR_LIBRARY=libfactor.a;; - esac -} - -set_factor_image() { - FACTOR_IMAGE=factor.image - FACTOR_IMAGE_FRESH=factor.image.fresh -} - -echo_build_info() { - $ECHO OS=$OS - $ECHO ARCH=$ARCH - $ECHO WORD=$WORD - $ECHO FACTOR_BINARY=$FACTOR_BINARY - $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY - $ECHO FACTOR_IMAGE=$FACTOR_IMAGE - $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 - $ECHO CXX=$CXX - $ECHO MAKE=$MAKE - $ECHO COPY=$COPY - $ECHO DELETE=$DELETE -} - -check_os_arch_word() { - if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then - $ECHO "OS: $OS" - $ECHO "ARCH: $ARCH" - $ECHO "WORD: $WORD" - $ECHO "OS, ARCH, or WORD is empty. Please report this." - - $ECHO $MAKE_TARGET - exit_script 5 - fi -} - -set_build_info() { - check_os_arch_word - if [[ $OS == linux && $ARCH == ppc ]] ; then - MAKE_IMAGE_TARGET=linux-ppc.32 - MAKE_TARGET=linux-ppc-32 - 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 - elif [[ $ARCH == x86 && $WORD == 64 ]] ; then - MAKE_IMAGE_TARGET=unix-x86.64 - MAKE_TARGET=$OS-x86-64 - elif [[ $ARCH == x86 && $WORD == 32 ]] ; then - MAKE_IMAGE_TARGET=unix-x86.32 - MAKE_TARGET=$OS-x86-32 - else - MAKE_IMAGE_TARGET=$ARCH.$WORD - MAKE_TARGET=$OS-$ARCH-$WORD - fi - BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image -} - -parse_build_info() { - 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` - - 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 - - $ECHO "OS=$OS" - $ECHO "ARCH=$ARCH" - $ECHO "WORD=$WORD" -} - -find_build_info() { - find_os - find_architecture - set_cc - find_word_size - set_factor_binary - set_factor_library - set_factor_image - set_build_info - set_downloader - set_make - echo_build_info -} - -invoke_git() { - git $* - check_ret git -} - -git_clone() { - $ECHO "Downloading the git repository from factorcode.org..." - invoke_git clone $GIT_URL -} - -update_script_name() { - $ECHO `dirname $0`/_update.sh -} - -update_script() { - update_script=`update_script_name` - bash_path=`which bash` - $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" \ - >>"$update_script" - $ECHO "exit 0" >>"$update_script" - - chmod 755 "$update_script" - exec "$update_script" -} - -update_script_changed() { - invoke_git diff --stat `invoke_git merge-base HEAD FETCH_HEAD` FETCH_HEAD | grep 'build-support.factor\.sh' >/dev/null -} - -git_fetch_factorcode() { - $ECHO "Fetching the git repository from factorcode.org..." - - rm -f `update_script_name` - invoke_git fetch "$GIT_URL" master - - if update_script_changed; then - $ECHO "Updating and restarting the factor.sh script..." - update_script - else - $ECHO "Updating the working tree..." - invoke_git pull "$GIT_URL" master - fi -} - -cd_factor() { - cd factor - check_ret cd -} - -set_copy() { - case $OS in - windows) COPY=cp;; - *) COPY=cp;; - esac -} - -set_delete() { - case $OS in - windows) DELETE=rm;; - *) DELETE=rm;; - esac -} - -backup_factor() { - $ECHO "Backing up factor..." - $COPY $FACTOR_BINARY $FACTOR_BINARY.bak - $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak - $COPY $BOOT_IMAGE $BOOT_IMAGE.bak - $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak - $ECHO "Done with backup." -} - -check_makefile_exists() { - if [[ ! -e "GNUmakefile" ]] ; then - $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" - exit_script 6 - fi -} - -invoke_make() { - check_makefile_exists - $MAKE $MAKE_OPTS $* - check_ret $MAKE -} - -make_clean() { - invoke_make clean -} - -make_factor() { - invoke_make CC=$CC CXX=$CXX NO_UI=$NO_UI $MAKE_TARGET -j5 -} - -make_clean_factor() { - make_clean - make_factor -} - -update_boot_images() { - $ECHO "Deleting old images..." - $DELETE checksums.txt* > /dev/null 2>&1 - # delete boot images with one or two characters after the dot - $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1 - $DELETE temp/staging.*.image > /dev/null 2>&1 - if [[ -f $BOOT_IMAGE ]] ; then - get_url http://downloads.factorcode.org/images/latest/checksums.txt - factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '` - set_md5sum - disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '` - $ECHO "Factorcode md5: $factorcode_md5"; - $ECHO "Disk md5: $disk_md5"; - if [[ "$factorcode_md5" == "$disk_md5" ]] ; then - $ECHO "Your disk boot image matches the one on factorcode.org." - else - $DELETE $BOOT_IMAGE > /dev/null 2>&1 - get_boot_image; - fi - else - get_boot_image - fi -} - -get_boot_image() { - $ECHO "Downloading boot image $BOOT_IMAGE." - get_url http://downloads.factorcode.org/images/latest/$BOOT_IMAGE -} - -get_url() { - if [[ -z $DOWNLOADER ]] ; then - set_downloader; - fi - $ECHO $DOWNLOADER $1 ; - $DOWNLOADER $1 - check_ret $DOWNLOADER -} - -get_config_info() { - find_build_info - check_installed_programs - check_libraries -} - -copy_fresh_image() { - $ECHO "Copying $FACTOR_IMAGE to $FACTOR_IMAGE_FRESH..." - $COPY $FACTOR_IMAGE $FACTOR_IMAGE_FRESH -} - -bootstrap() { - ./$FACTOR_BINARY -i=$BOOT_IMAGE - copy_fresh_image -} - -install() { - check_factor_exists - get_config_info - git_clone - cd_factor - make_factor - get_boot_image - bootstrap -} - -update() { - get_config_info - check_git_branch - git_fetch_factorcode - backup_factor - make_clean_factor -} - -download_and_bootstrap() { - update_boot_images - bootstrap -} - -net_bootstrap_no_pull() { - get_config_info - make_clean_factor - download_and_bootstrap -} - -refresh_image() { - ./$FACTOR_BINARY -script -e="USING: vocabs.loader vocabs.refresh system memory ; refresh-all save 0 exit" - check_ret factor -} - -make_boot_image() { - ./$FACTOR_BINARY -script -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit" - check_ret factor -} - -install_deps_apt_get() { - 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 g++ - check_ret sudo -} - -install_deps_pacman() { - sudo pacman --noconfirm -S gcc clang make rlwrap git wget pango glibc gtk2 gtk3 gtkglext gtk-engines gdk-pixbuf2 libx11 screen tmux - check_ret sudo -} - -install_deps_dnf() { - sudo dnf --assumeyes install gcc gcc-c++ glibc-devel binutils libX11-devel pango-devel gtk3-devel gdk-pixbuf2-devel gtkglext-devel tmux rlwrap wget - check_ret sudo -} - - -install_deps_macosx() { - test_program_installed git - if [[ $? -ne 1 ]] ; then - ensure_program_installed yes - $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." - ensure_program_installed port - $ECHO "Installing git-core with port...this will take awhile." - yes | sudo port install git-core - fi -} - -usage() { - $ECHO "usage: $0 command [optional-target]" - $ECHO " install - git clone, compile, bootstrap" - $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" - $ECHO " deps-dnf - install required packages for Factor on Linux using dnf" - $ECHO " deps-macosx - install git on MacOSX using port" - $ECHO " self-update - git pull, recompile, make local boot image, bootstrap" - $ECHO " quick-update - git pull, refresh-all, save" - $ECHO " update - git pull, recompile, download a boot image, bootstrap" - $ECHO " bootstrap - bootstrap with existing boot image" - $ECHO " net-bootstrap - recompile, download a boot image, bootstrap" - $ECHO " make-target - find and print the os-arch-cpu string" - $ECHO " report - print the build variables" - $ECHO "" - $ECHO "If you are behind a firewall, invoke as:" - $ECHO "env GIT_PROTOCOL=http $0 " - $ECHO "" - $ECHO "Example for overriding the default target:" - $ECHO " $0 update macosx-x86-32" -} - -MAKE_TARGET=unknown - -# -n is nonzero length, -z is zero length -if [[ -n "$2" ]] ; then - parse_build_info $2 -fi - -set_copy -set_delete - -case "$1" in - install) install ;; - deps-apt-get) install_deps_apt_get ;; - deps-pacman) install_deps_pacman ;; - deps-macosx) install_deps_macosx ;; - deps-dnf) install_deps_dnf ;; - self-update) update; make_boot_image; bootstrap;; - quick-update) update; refresh_image ;; - update) update; download_and_bootstrap ;; - bootstrap) get_config_info; bootstrap ;; - net-bootstrap) net_bootstrap_no_pull ;; - make-target) FIND_MAKE_TARGET=true; ECHO=false; find_build_info; exit_script ;; - report) find_build_info ;; - full-report) find_build_info; check_installed_programs; check_libraries ;; - *) usage ;; -esac diff --git a/build-support/http-get.vbs b/build-support/http-get.vbs deleted file mode 100644 index 4bb95e2541..0000000000 --- a/build-support/http-get.vbs +++ /dev/null @@ -1,42 +0,0 @@ -on error resume next - -if WScript.Arguments.Count < 2 then - WScript.Echo "usage: http-get.vbs source-url dest-file" - WScript.Quit 1 -else - source_url = WScript.Arguments.Item(0) - dest_filename = WScript.Arguments.Item(1) - - dim http, source_data - set http = CreateObject("WinHttp.WinHttpRequest.5.1") - - Err.Clear - http.Open "GET", source_url, false - http.Send - - if Err.Number = 0 then - if http.Status = 200 then - dim dest_stream - odd = "DOD" - set dest_stream = CreateObject("A"+odd+"B"+".Stream") - - Err.Clear - dest_stream.Type = 1 ' adTypeBinary - dest_stream.Open - dest_stream.Write http.ResponseBody - dest_stream.SaveToFile dest_filename, 2 ' adSaveCreateOverWrite - if Err.Number <> 0 then - WScript.Echo "Error " + CStr(Err.Number) + " when writing " + dest_filename + ":" - WScript.Echo Err.Description - WScript.Quit 1 - end if - else - WScript.Echo CStr(http.Status) + " " + http.StatusText + " when fetching " + source_url - WScript.Quit 1 - end if - else - WScript.Echo "Error " + CStr(Err.Number) + " when fetching " + source_url + ":" - WScript.Echo Err.Description - WScript.Quit 1 - end if -end if diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000000..b0430bbfb7 --- /dev/null +++ b/build.cmd @@ -0,0 +1,96 @@ +@echo off +setlocal + +if "%1"=="/?" ( + goto usage +) else if "%1"=="" ( + set _bootimage_version=latest +) else if "%1"=="latest" ( + set _bootimage_version=latest +) else if "%1"=="clean" ( + set _bootimage_version=clean +) else goto usage + +if not exist Nmakefile goto wrongdir + +call cl 2>&1 | find "x86" >nul +if not errorlevel 1 ( + echo x86-32 cl.exe detected. + set _target=x86-32 + set _bootimage=boot.windows-x86.32.image +) else ( + call cl 2>&1 | find "x64" >nul + if not errorlevel 1 ( + echo x86-64 cl.exe detected. + set _target=x86-64 + set _bootimage=boot.windows-x86.64.image + ) else goto nocl +) + +: Fun syntax +for /f %%x in ('git describe --all') do set GIT_DESCRIBE=%%x +for /f %%y in ('git rev-parse HEAD') do set GIT_ID=%%y + +set git_label=%GIT_DESCRIBE%-%GIT_ID% +set version=0.98 + +if %_bootimage_version%==clean ( + set _git_branch=clean-windows-%_target% + set _bootimage_path=clean/windows-%_target% +) else ( + set _git_branch=master + set _bootimage_path=latest +) + +echo Deleting staging images from temp/... +del temp\staging.*.image + +echo Updating working copy from %_git_branch%... +call git pull git://factorcode.org/git/factor.git %_git_branch% +if errorlevel 1 goto fail + +echo Building vm... +nmake /nologo /f Nmakefile clean +if errorlevel 1 goto fail +nmake /nologo /f Nmakefile %_target% +if errorlevel 1 goto fail + +echo Fetching %_bootimage_version% boot image... +cscript /nologo misc\http-get.vbs http://downloads.factorcode.org/images/%_bootimage_path%/%_bootimage% %_bootimage% +if errorlevel 1 goto fail + +echo Bootstrapping... +.\factor.com -i=%_bootimage% +if errorlevel 1 goto fail + +echo Copying fresh factor.image to factor.image.fresh. +copy factor.image factor.image.fresh +if errorlevel 1 goto fail + +echo Build complete. +goto :EOF + +:fail +echo Build failed. +goto :EOF + +:wrongdir +echo build.cmd must be run from the root of the Factor source tree. +goto :EOF + +:nocl +echo Unable to detect cl.exe target platform. +echo Make sure you're running within the Visual Studio or Windows SDK environment. +goto :EOF + +:usage +echo Usage: build.cmd [latest/clean] +echo Updates the working copy, cleans and builds the vm using nmake, +echo fetches a boot image, and bootstraps factor. +echo If latest is specified, then the working copy is updated to the +echo upstream "master" branch and the boot image corresponding to the +echo most recent factor build is downloaded. This is the default. +echo If clean is specified, then the working copy is updated to the +echo upstream "clean-windows-*" branch corresponding to the current +echo platform and the corresponding boot image is downloaded. +goto :EOF diff --git a/build.sh b/build.sh new file mode 100755 index 0000000000..da76c3cc18 --- /dev/null +++ b/build.sh @@ -0,0 +1,722 @@ +#!/usr/bin/env bash + +# Programs returning != 0 will not cause script to exit +set +e + +# Case insensitive string comparison +shopt -s nocaseglob +#shopt -s nocasematch + +ECHO=echo +OS= +ARCH= +WORD= +NO_UI=${NO_UI-} +GIT_PROTOCOL=${GIT_PROTOCOL:="git"} +GIT_URL=${GIT_URL:=$GIT_PROTOCOL"://factorcode.org/git/factor.git"} +SCRIPT_ARGS="$*" + +# return 1 on found +test_program_installed() { + if ! [[ -n `type -p $1` ]] ; then + return 0; + fi + return 1; +} + +# return 1 on found +test_programs_installed() { + installed=0; + $ECHO -n "Checking for all($*)..." + for i in $* ; + do + test_program_installed $i + if [[ $? -eq 1 ]]; then + installed=$(( $installed + 1 )) + fi + done + if [[ $installed -eq $# ]] ; then + $ECHO "found!" + return 1 + else + $ECHO "all not found." + return 0 + fi +} + +exit_script() { + if [[ $FIND_MAKE_TARGET = true ]] ; then + # Must be echo not $ECHO + echo $MAKE_TARGET; + fi + exit $1 +} + +ensure_program_installed() { + installed=0; + $ECHO -n "Checking for any($*)..." + for i in $* ; + do + test_program_installed $i + if [[ $? -eq 1 ]]; then + $ECHO "found $i!" + installed=$(( $installed + 1 )) + return + fi + done + $ECHO "none found." + $ECHO -n "Install " + if [[ $# -eq 1 ]] ; then + $ECHO -n $1 + else + $ECHO -n "any of [ $* ]" + fi + $ECHO " and try again." + if [[ $OS == macosx ]] ; then + $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 + exit_script 1; +} + +check_ret() { + RET=$? + if [[ $RET -ne 0 ]] ; then + $ECHO $1 failed + exit_script 2 + fi +} + +set_downloader() { + test_program_installed wget + if [[ $? -ne 0 ]] ; then + DOWNLOADER=wget + return + fi + test_program_installed curl + if [[ $? -ne 0 ]] ; then + DOWNLOADER="curl -f -O" + return + fi + $ECHO "error: wget or curl required" + exit_script 11 +} + +set_md5sum() { + test_program_installed md5sum + if [[ $? -ne 0 ]] ; then + MD5SUM=md5sum + else + MD5SUM="md5 -r" + fi +} + +semver_into() { + RE_SEMVER="^([0-9]*)\.([0-9]*)\.([0-9]*)-?(.*)?$" # 3.3.3-5 + CLANG_RE_OLD="^([0-9]*)\.([0-9]*)-?(.*)?$" # 3.3-5 + if [[ $1 =~ $RE_SEMVER ]] ; then + export "$2=${BASH_REMATCH[1]}" + export "$3=${BASH_REMATCH[2]}" + export "$4=${BASH_REMATCH[3]}" + export "$5=${BASH_REMATCH[4]}" + elif [[ $1 =~ $CLANG_RE_OLD ]] ; then + export "$2=${BASH_REMATCH[1]}" + export "$3=${BASH_REMATCH[2]}" + export "$4=0" + export "$5=${BASH_REMATCH[3]}" + else + echo "unsupported version number, please report a bug: $1" + exit 123 + fi +} + +# issue 1440 +gcc_version_ok() { + GCC_VERSION=`gcc -dumpversion` + local GCC_MAJOR local GCC_MINOR local GCC_PATCH local GCC_SPECIAL + semver_into $GCC_VERSION GCC_MAJOR GCC_MINOR GCC_PATCH GCC_SPECIAL + + if [[ $GCC_MAJOR -lt 4 + || ( $GCC_MAJOR -eq 4 && $GCC_MINOR -lt 7 ) + || ( $GCC_MAJOR -eq 4 && $GCC_MINOR -eq 7 && $GCC_THIRD -lt 3 ) + || ( $GCC_MAJOR -eq 4 && $GCC_MINOR -eq 8 && $GCC_THIRD -eq 0 ) + ]] ; then + echo "gcc version required >= 4.7.3, != 4.8.0, >= 4.8.1, got $GCC_VERSION" + return 1 + fi + return 0 +} + +clang_version_ok() { + CLANG_VERSION=`clang --version | head -n1` + CLANG_VERSION_RE='^[a-zA-Z0-9 ]* version (.*)$' # 3.3-5 + if [[ $CLANG_VERSION =~ $CLANG_VERSION_RE ]] ; then + export "CLANG_VERSION=${BASH_REMATCH[1]}" + local CLANG_MAJOR local CLANG_MINOR local CLANG_PATCH local CLANG_SPECIAL + semver_into "$CLANG_VERSION" CLANG_MAJOR CLANG_MINOR CLANG_PATCH CLANG_SPECIAL + if [[ $CLANG_MAJOR -lt 3 + || ( $CLANG_MAJOR -eq 3 && $CLANG_MINOR -le 1 ) + ]] ; then + echo "clang version required >= 3.1, got $CLANG_VERSION" + return 1 + fi + else + return 1 + fi + return 0 +} + +set_cc() { + test_programs_installed clang clang++ + if [[ $? -ne 0 ]] && clang_version_ok ; then + [ -z "$CC" ] && CC=clang + [ -z "$CXX" ] && CXX=clang++ + return + fi + + test_programs_installed gcc g++ + if [[ $? -ne 0 ]] && gcc_version_ok ; then + [ -z "$CC" ] && CC=gcc + [ -z "$CXX" ] && CXX=g++ + return + fi + + $ECHO "error: high enough version of either (clang/clang++) or (gcc/g++) required!" + exit_script 10 +} + +set_make() { + MAKE='make' +} + +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 +} + +check_installed_programs() { + ensure_program_installed chmod + ensure_program_installed uname + ensure_program_installed git + ensure_program_installed wget curl + ensure_program_installed clang gcc + ensure_program_installed clang++ g++ cl + ensure_program_installed make gmake + ensure_program_installed md5sum md5 + ensure_program_installed cut +} + +check_library_exists() { + GCC_TEST=factor-library-test.c + GCC_OUT=factor-library-test.out + $ECHO -n "Checking for library $1..." + $ECHO "int main(){return 0;}" > $GCC_TEST + $CC $GCC_TEST -o $GCC_OUT -l $1 2>&- + if [[ $? -ne 0 ]] ; then + $ECHO "not found." + $ECHO "***Factor will compile NO_UI=1" + NO_UI=1 + else + $ECHO "found." + fi + $DELETE -f $GCC_TEST + check_ret $DELETE + $DELETE -f $GCC_OUT + check_ret $DELETE +} + +check_X11_libraries() { + if [ -z "$NO_UI" ]; then + check_library_exists GL + check_library_exists X11 + check_library_exists pango-1.0 + fi +} + +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 +} + + +check_libraries() { + case $OS in + linux) check_X11_libraries + check_gtk_libraries;; + unix) check_gtk_libraries;; + esac +} + +check_factor_exists() { + if [[ -d "factor" ]] ; then + $ECHO "A directory called 'factor' already exists." + $ECHO "Rename or delete it and try again." + exit_script 4 + fi +} + +find_os() { + if [[ -n $OS ]] ; then return; fi + $ECHO "Finding OS..." + uname_s=`uname -s` + check_ret uname + case $uname_s in + CYGWIN_NT-5.2-WOW64) OS=windows;; + *CYGWIN_NT*) OS=windows;; + *CYGWIN*) OS=windows;; + MINGW32*) OS=windows;; + *darwin*) OS=macosx;; + *Darwin*) OS=macosx;; + *linux*) OS=linux;; + *Linux*) OS=linux;; + esac +} + +find_architecture() { + if [[ -n $ARCH ]] ; then return; fi + $ECHO "Finding ARCH..." + uname_m=`uname -m` + check_ret uname + case $uname_m in + i386) ARCH=x86;; + i686) ARCH=x86;; + i86pc) ARCH=x86;; + amd64) ARCH=x86;; + ppc64) ARCH=ppc;; + *86) ARCH=x86;; + *86_64) ARCH=x86;; + "Power Macintosh") ARCH=ppc;; + esac +} + +write_test_program() { + #! Must be 'echo' + echo "#include " > $C_WORD.c + echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c +} + +c_find_word_size() { + $ECHO "Finding WORD..." + C_WORD=factor-word-size + write_test_program + $CC -o $C_WORD $C_WORD.c + WORD=$(./$C_WORD) + check_ret $C_WORD + $DELETE -f $C_WORD* +} + +intel_macosx_word_size() { + ensure_program_installed sysctl + $ECHO -n "Testing if your Intel Mac supports 64bit binaries..." + sysctl machdep.cpu.extfeatures | grep EM64T >/dev/null + if [[ $? -eq 0 ]] ; then + WORD=64 + $ECHO "yes!" + else + WORD=32 + $ECHO "no." + fi +} + +find_word_size() { + if [[ -n $WORD ]] ; then return; fi + if [[ $OS == macosx && $ARCH == x86 ]] ; then + intel_macosx_word_size + else + c_find_word_size + fi +} + +set_factor_binary() { + case $OS in + windows) FACTOR_BINARY=factor.com;; + *) FACTOR_BINARY=factor;; + esac +} + +set_factor_library() { + case $OS in + windows) FACTOR_LIBRARY=factor.dll;; + macosx) FACTOR_LIBRARY=libfactor.dylib;; + *) FACTOR_LIBRARY=libfactor.a;; + esac +} + +set_factor_image() { + FACTOR_IMAGE=factor.image + FACTOR_IMAGE_FRESH=factor.image.fresh +} + +echo_build_info() { + $ECHO OS=$OS + $ECHO ARCH=$ARCH + $ECHO WORD=$WORD + $ECHO FACTOR_BINARY=$FACTOR_BINARY + $ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY + $ECHO FACTOR_IMAGE=$FACTOR_IMAGE + $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 + $ECHO CXX=$CXX + $ECHO MAKE=$MAKE + $ECHO COPY=$COPY + $ECHO DELETE=$DELETE +} + +check_os_arch_word() { + if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then + $ECHO "OS: $OS" + $ECHO "ARCH: $ARCH" + $ECHO "WORD: $WORD" + $ECHO "OS, ARCH, or WORD is empty. Please report this." + + $ECHO $MAKE_TARGET + exit_script 5 + fi +} + +set_build_info() { + check_os_arch_word + if [[ $OS == linux && $ARCH == ppc ]] ; then + MAKE_IMAGE_TARGET=linux-ppc.32 + MAKE_TARGET=linux-ppc-32 + 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 + elif [[ $ARCH == x86 && $WORD == 64 ]] ; then + MAKE_IMAGE_TARGET=unix-x86.64 + MAKE_TARGET=$OS-x86-64 + elif [[ $ARCH == x86 && $WORD == 32 ]] ; then + MAKE_IMAGE_TARGET=unix-x86.32 + MAKE_TARGET=$OS-x86-32 + else + MAKE_IMAGE_TARGET=$ARCH.$WORD + MAKE_TARGET=$OS-$ARCH-$WORD + fi + BOOT_IMAGE=boot.$MAKE_IMAGE_TARGET.image +} + +parse_build_info() { + 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` + + 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 + + $ECHO "OS=$OS" + $ECHO "ARCH=$ARCH" + $ECHO "WORD=$WORD" +} + +find_build_info() { + find_os + find_architecture + set_cc + find_word_size + set_factor_binary + set_factor_library + set_factor_image + set_build_info + set_downloader + set_make + echo_build_info +} + +invoke_git() { + git $* + check_ret git +} + +git_clone() { + $ECHO "Downloading the git repository from factorcode.org..." + invoke_git clone $GIT_URL +} + +update_script_name() { + $ECHO `dirname $0`/_update.sh +} + +update_script() { + update_script=`update_script_name` + bash_path=`which bash` + $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" \ + >>"$update_script" + $ECHO "exit 0" >>"$update_script" + + chmod 755 "$update_script" + exec "$update_script" +} + +update_script_changed() { + invoke_git diff --stat `invoke_git merge-base HEAD FETCH_HEAD` FETCH_HEAD | grep 'build\.sh' >/dev/null +} + +git_fetch_factorcode() { + $ECHO "Fetching the git repository from factorcode.org..." + + rm -f `update_script_name` + invoke_git fetch "$GIT_URL" master + + if update_script_changed; then + $ECHO "Updating and restarting the factor.sh script..." + update_script + else + $ECHO "Updating the working tree..." + invoke_git pull "$GIT_URL" master + fi +} + +cd_factor() { + cd factor + check_ret cd +} + +set_copy() { + case $OS in + windows) COPY=cp;; + *) COPY=cp;; + esac +} + +set_delete() { + case $OS in + windows) DELETE=rm;; + *) DELETE=rm;; + esac +} + +backup_factor() { + $ECHO "Backing up factor..." + $COPY $FACTOR_BINARY $FACTOR_BINARY.bak + $COPY $FACTOR_LIBRARY $FACTOR_LIBRARY.bak + $COPY $BOOT_IMAGE $BOOT_IMAGE.bak + $COPY $FACTOR_IMAGE $FACTOR_IMAGE.bak + $ECHO "Done with backup." +} + +check_makefile_exists() { + if [[ ! -e "GNUmakefile" ]] ; then + $ECHO "" + $ECHO "***GNUmakefile not found***" + $ECHO "You are likely in the wrong directory." + $ECHO "Run this script from your factor directory:" + $ECHO " ./build.sh" + exit_script 6 + fi +} + +invoke_make() { + check_makefile_exists + $MAKE $MAKE_OPTS $* + check_ret $MAKE +} + +make_clean() { + invoke_make clean +} + +make_factor() { + invoke_make CC=$CC CXX=$CXX NO_UI=$NO_UI $MAKE_TARGET -j5 +} + +make_clean_factor() { + make_clean + make_factor +} + +update_boot_images() { + $ECHO "Deleting old images..." + $DELETE checksums.txt* > /dev/null 2>&1 + # delete boot images with one or two characters after the dot + $DELETE $BOOT_IMAGE.{?,??} > /dev/null 2>&1 + $DELETE temp/staging.*.image > /dev/null 2>&1 + if [[ -f $BOOT_IMAGE ]] ; then + get_url http://downloads.factorcode.org/images/latest/checksums.txt + factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '` + set_md5sum + disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '` + $ECHO "Factorcode md5: $factorcode_md5"; + $ECHO "Disk md5: $disk_md5"; + if [[ "$factorcode_md5" == "$disk_md5" ]] ; then + $ECHO "Your disk boot image matches the one on factorcode.org." + else + $DELETE $BOOT_IMAGE > /dev/null 2>&1 + get_boot_image; + fi + else + get_boot_image + fi +} + +get_boot_image() { + $ECHO "Downloading boot image $BOOT_IMAGE." + get_url http://downloads.factorcode.org/images/latest/$BOOT_IMAGE +} + +get_url() { + if [[ -z $DOWNLOADER ]] ; then + set_downloader; + fi + $ECHO $DOWNLOADER $1 ; + $DOWNLOADER $1 + check_ret $DOWNLOADER +} + +get_config_info() { + find_build_info + check_installed_programs + check_libraries +} + +copy_fresh_image() { + $ECHO "Copying $FACTOR_IMAGE to $FACTOR_IMAGE_FRESH..." + $COPY $FACTOR_IMAGE $FACTOR_IMAGE_FRESH +} + +bootstrap() { + ./$FACTOR_BINARY -i=$BOOT_IMAGE + copy_fresh_image +} + +install() { + check_factor_exists + get_config_info + git_clone + cd_factor + make_factor + get_boot_image + bootstrap +} + +update() { + get_config_info + check_git_branch + git_fetch_factorcode + backup_factor + make_clean_factor +} + +download_and_bootstrap() { + update_boot_images + bootstrap +} + +net_bootstrap_no_pull() { + get_config_info + make_clean_factor + download_and_bootstrap +} + +refresh_image() { + ./$FACTOR_BINARY -script -e="USING: vocabs.loader vocabs.refresh system memory ; refresh-all save 0 exit" + check_ret factor +} + +make_boot_image() { + ./$FACTOR_BINARY -script -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit" + check_ret factor +} + +install_deps_apt_get() { + 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 g++ + check_ret sudo +} + +install_deps_pacman() { + sudo pacman --noconfirm -S gcc clang make rlwrap git wget pango glibc gtk2 gtk3 gtkglext gtk-engines gdk-pixbuf2 libx11 screen tmux + check_ret sudo +} + +install_deps_dnf() { + sudo dnf --assumeyes install gcc gcc-c++ glibc-devel binutils libX11-devel pango-devel gtk3-devel gdk-pixbuf2-devel gtkglext-devel tmux rlwrap wget + check_ret sudo +} + + +install_deps_macosx() { + test_program_installed git + if [[ $? -ne 1 ]] ; then + ensure_program_installed yes + $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." + ensure_program_installed port + $ECHO "Installing git-core with port...this will take awhile." + yes | sudo port install git-core + fi +} + +usage() { + $ECHO "usage: $0 command [optional-target]" + $ECHO " install - git clone, compile, bootstrap" + $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" + $ECHO " deps-dnf - install required packages for Factor on Linux using dnf" + $ECHO " deps-macosx - install git on MacOSX using port" + $ECHO " self-update - git pull, recompile, make local boot image, bootstrap" + $ECHO " quick-update - git pull, refresh-all, save" + $ECHO " update - git pull, recompile, download a boot image, bootstrap" + $ECHO " bootstrap - bootstrap with existing boot image" + $ECHO " net-bootstrap - recompile, download a boot image, bootstrap" + $ECHO " make-target - find and print the os-arch-cpu string" + $ECHO " report - print the build variables" + $ECHO "" + $ECHO "If you are behind a firewall, invoke as:" + $ECHO "env GIT_PROTOCOL=http $0 " + $ECHO "" + $ECHO "Example for overriding the default target:" + $ECHO " $0 update macosx-x86-32" +} + +MAKE_TARGET=unknown + +# -n is nonzero length, -z is zero length +if [[ -n "$2" ]] ; then + parse_build_info $2 +fi + +set_copy +set_delete + +case "$1" in + install) install ;; + deps-apt-get) install_deps_apt_get ;; + deps-pacman) install_deps_pacman ;; + deps-macosx) install_deps_macosx ;; + deps-dnf) install_deps_dnf ;; + self-update) update; make_boot_image; bootstrap;; + quick-update) update; refresh_image ;; + update) update; download_and_bootstrap ;; + bootstrap) get_config_info; bootstrap ;; + net-bootstrap) net_bootstrap_no_pull ;; + make-target) FIND_MAKE_TARGET=true; ECHO=false; find_build_info; exit_script ;; + report) find_build_info ;; + full-report) find_build_info; check_installed_programs; check_libraries ;; + *) usage ;; +esac diff --git a/extra/build-support/build-support-tests.factor b/extra/build-support/build-support-tests.factor index c635418ab2..e1561502bd 100644 --- a/extra/build-support/build-support-tests.factor +++ b/extra/build-support/build-support-tests.factor @@ -3,4 +3,4 @@ USING: build-support sequences tools.test ; IN: build-support.tests -{ f } [ factor.sh-make-target empty? ] unit-test +{ f } [ build-make-target empty? ] unit-test diff --git a/extra/build-support/build-support.factor b/extra/build-support/build-support.factor index 7d32b2da53..15ab8c7ab5 100644 --- a/extra/build-support/build-support.factor +++ b/extra/build-support/build-support.factor @@ -4,10 +4,8 @@ USING: accessors arrays calendar io io.backend io.encodings.utf8 io.launcher ; IN: build-support -CONSTANT: factor.sh-path "resource:build-support/factor.sh" - -: factor.sh-make-target ( -- string ) +: build-make-target ( -- string ) - factor.sh-path normalize-path "make-target" 2array >>command + "resource:build.sh" normalize-path "make-target" 2array >>command 10 seconds >>timeout utf8 [ readln ] with-process-reader ; diff --git a/extra/mason/child/child.factor b/extra/mason/child/child.factor index 08dd65fd4b..b97a2e5124 100644 --- a/extra/mason/child/child.factor +++ b/extra/mason/child/child.factor @@ -9,7 +9,7 @@ IN: mason.child ! Make sure we call the build directory's factor.cmd : nmake-cmd ( -- args ) - "./build-support/factor.cmd" absolute-path + "./build.cmd" absolute-path "latest" target-cpu get name>> "." split "-" join 3array ; diff --git a/misc/http-get.vbs b/misc/http-get.vbs new file mode 100644 index 0000000000..4bb95e2541 --- /dev/null +++ b/misc/http-get.vbs @@ -0,0 +1,42 @@ +on error resume next + +if WScript.Arguments.Count < 2 then + WScript.Echo "usage: http-get.vbs source-url dest-file" + WScript.Quit 1 +else + source_url = WScript.Arguments.Item(0) + dest_filename = WScript.Arguments.Item(1) + + dim http, source_data + set http = CreateObject("WinHttp.WinHttpRequest.5.1") + + Err.Clear + http.Open "GET", source_url, false + http.Send + + if Err.Number = 0 then + if http.Status = 200 then + dim dest_stream + odd = "DOD" + set dest_stream = CreateObject("A"+odd+"B"+".Stream") + + Err.Clear + dest_stream.Type = 1 ' adTypeBinary + dest_stream.Open + dest_stream.Write http.ResponseBody + dest_stream.SaveToFile dest_filename, 2 ' adSaveCreateOverWrite + if Err.Number <> 0 then + WScript.Echo "Error " + CStr(Err.Number) + " when writing " + dest_filename + ":" + WScript.Echo Err.Description + WScript.Quit 1 + end if + else + WScript.Echo CStr(http.Status) + " " + http.StatusText + " when fetching " + source_url + WScript.Quit 1 + end if + else + WScript.Echo "Error " + CStr(Err.Number) + " when fetching " + source_url + ":" + WScript.Echo Err.Description + WScript.Quit 1 + end if +end if