GIT_URL=${GIT_URL:=$GIT_PROTOCOL"://factorcode.org/git/factor.git"}
SCRIPT_ARGS="$*"
+REQUIRE_CLANG_VERSION=3.1
+
# return 1 on found
test_program_installed() {
- if ! [[ -n `type -p $1` ]] ; then
+ if ! [[ -n $(type -p $1) ]] ; then
return 0;
fi
return 1;
# return 1 on found
test_programs_installed() {
- installed=0;
+ local installed=0;
$ECHO -n "Checking for all($*)..."
- for i in $* ;
+ for i in "$@" ;
do
test_program_installed $i
if [[ $? -eq 1 ]]; then
}
ensure_program_installed() {
- installed=0;
+ local installed=0;
$ECHO -n "Checking for any($*)..."
- for i in $* ;
+ for i in "$@" ;
do
test_program_installed $i
if [[ $? -eq 1 ]]; then
fi
test_program_installed curl
if [[ $? -ne 0 ]] ; then
- DOWNLOADER="curl -f -O"
+ DOWNLOADER="curl -L -f -O"
DOWNLOADER_NAME=curl
return
fi
}
clang_version_ok() {
- CLANG_VERSION=`clang --version | head -n1`
+ 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
+ local CLANG_MAJOR CLANG_MINOR CLANG_PATCH 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"
+ echo "clang version required >= $REQUIRE_CLANG_VERSION, got $CLANG_VERSION"
return 1
fi
else
}
set_make() {
- MAKE='make'
+ case $OS in
+ freebsd) MAKE=gmake ;;
+ *) MAKE=make ;;
+ esac
+ if [[ $MAKE = 'gmake' ]] ; then
+ ensure_program_installed gmake
+ fi
}
check_installed_programs() {
find_os() {
if [[ -n $OS ]] ; then return; fi
$ECHO "Finding OS..."
- uname_s=`uname -s`
+ local 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;;
+ MSYS_NT*) OS=windows;;
*darwin*) OS=macosx;;
*Darwin*) OS=macosx;;
*linux*) OS=linux;;
*Linux*) OS=linux;;
+ FreeBSD) OS=freebsd;;
esac
}
find_architecture() {
if [[ -n $ARCH ]] ; then return; fi
$ECHO "Finding ARCH..."
- uname_m=`uname -m`
+ uname_m=$(uname -m)
check_ret uname
case $uname_m in
i386) ARCH=x86;;
find_num_cores() {
$ECHO "Finding num cores..."
- NUM_CORES=7ZZ
- uname_s=`uname -s`
+ NUM_CORES=1
+ uname_s=$(uname -s)
check_ret uname
case $uname_s in
CYGWIN_NT-5.2-WOW64 | *CYGWIN_NT* | *CYGWIN* | MINGW32*) NUM_CORES=$NUMBER_OF_PROCESSORS;;
*darwin* | *Darwin* | *linux* | *Linux*) NUM_CORES=$(getconf _NPROCESSORS_ONLN);;
+ freebsd) NUM_CORES=$(sysctl -n hw.ncpu);;
esac
}
-write_test_program() {
+echo_test_program() {
#! Must be 'echo'
- echo "#include <stdio.h>" > $C_WORD.c
- echo "int main(){printf(\"%ld\", (long)(8*sizeof(void*))); return 0; }" >> $C_WORD.c
+ echo -e "int main(){ return (long)(8*sizeof(void*)); }"
}
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*
+ C_WORD="factor-word-size"
+ echo_test_program | $CC -o $C_WORD -xc -
+ check_ret $CC
+ ./$C_WORD
+ WORD=$?
+ $DELETE -f $C_WORD
}
intel_macosx_word_size() {
$ECHO NUM_CORES=$NUM_CORES
$ECHO WORD=$WORD
$ECHO DEBUG=$DEBUG
+ $ECHO REPRODUCIBLE=$REPRODUCIBLE
$ECHO CURRENT_BRANCH=$CURRENT_BRANCH
$ECHO FACTOR_BINARY=$FACTOR_BINARY
$ECHO FACTOR_LIBRARY=$FACTOR_LIBRARY
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`
+ 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
}
invoke_git() {
- git $*
+ git "$@"
check_ret git
}
}
update_script_name() {
- $ECHO `dirname $0`/_update.sh
+ $ECHO "$(dirname $0)/_update.sh"
}
update_script() {
- update_script=`update_script_name`
- bash_path=`which bash`
+ local -r update_script=$(update_script_name)
+ local -r 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_changed() {
- invoke_git diff --stat `invoke_git merge-base HEAD FETCH_HEAD` FETCH_HEAD | grep 'build\.sh' >/dev/null
+ 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`
+ rm -f "$(update_script_name)"
invoke_git fetch "$GIT_URL" master
if update_script_changed; then
}
cd_factor() {
- cd factor
+ cd "factor"
check_ret cd
}
invoke_make() {
check_makefile_exists
- $MAKE $MAKE_OPTS $*
+ $MAKE $MAKE_OPTS "$@"
check_ret $MAKE
}
check_url() {
if [[ $DOWNLOADER_NAME == 'wget' ]]; then
- if [[ `wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then
+ if [[ $(wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then
return 0
else
return 1
fi
elif [[ $DOWNLOADER_NAME == 'curl' ]]; then
- code=`curl -sL -w "%{http_code}\\n" "$1" -o /dev/null`
+ local code=$(curl -sL -w "%{http_code}\\n" "$1" -o /dev/null)
if [[ $code -eq 200 ]]; then return 0; else return 1; fi
else
$ECHO "error: wget or curl required in check_url"
# Otherwise, just use `master`
set_boot_image_vars() {
set_current_branch
- url="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/checksums.txt"
+ local url="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/checksums.txt"
check_url $url
if [[ $? -eq 0 ]]; then
- CHECKSUM_URL="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/checksums.txt"
+ CHECKSUM_URL="$url"
BOOT_IMAGE_URL="http://downloads.factorcode.org/images/${CURRENT_BRANCH}/${BOOT_IMAGE}"
else
CHECKSUM_URL="http://downloads.factorcode.org/images/master/checksums.txt"
$DELETE temp/staging.*.image > /dev/null 2>&1
if [[ -f $BOOT_IMAGE ]] ; then
get_url $CHECKSUM_URL
- factorcode_md5=`cat checksums.txt|grep $BOOT_IMAGE|cut -f2 -d' '`
+ local factorcode_md5=$(cat checksums.txt | grep $BOOT_IMAGE | cut -f2 -d' ')
set_md5sum
- disk_md5=`$MD5SUM $BOOT_IMAGE|cut -f1 -d' '`
+ local disk_md5=$($MD5SUM $BOOT_IMAGE | cut -f1 -d' ')
$ECHO "Factorcode md5: $factorcode_md5";
$ECHO "Disk md5: $disk_md5";
if [[ "$factorcode_md5" == "$disk_md5" ]] ; then
}
refresh_image() {
- ./$FACTOR_BINARY -script -e="USING: vocabs.loader vocabs.refresh system memory ; refresh-all save 0 exit"
+ ./$FACTOR_BINARY -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"
+ ./$FACTOR_BINARY -e="\"$MAKE_IMAGE_TARGET\" USING: system bootstrap.image memory ; make-image save 0 exit"
check_ret factor
}
install_deps_apt() {
- sudo apt install --yes 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++
+ sudo apt install --yes libc6-dev libpango1.0-dev libx11-dev xorg-dev libgtk2.0-dev gtk2-engines-pixbuf libgtkglext1-dev wget git git-doc rlwrap clang make screen tmux libssl-dev
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
+ sudo pacman --noconfirm -Syu gcc clang make rlwrap git wget pango glibc gtk2 gtk3 gtkglext gtk-engines gdk-pixbuf2 libx11 screen tmux
check_ret sudo
}
check_ret sudo
}
+install_deps_pkg() {
+ sudo pkg install --yes git gmake gcc rlwrap ripgrep curl gmake x11-toolkits/gtk30 x11-toolkits/gtkglext pango cairo vim
+}
+
install_deps_macosx() {
test_program_installed git
$ECHO " deps-apt - install required packages for Factor on Linux using apt"
$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-pkg - install required packages for Factor on FreeBSD using pkg"
$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|latest - git pull, recompile, download a boot image, bootstrap"
+ $ECHO " compile - compile the binary"
+ $ECHO " recompile - recompile the binary"
$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 " report|info - print the build variables"
$ECHO " update-boot-image - get the boot image for the current branch of for master"
$ECHO ""
$ECHO "If you are behind a firewall, invoke as:"
parse_build_info $2
fi
+if [ "$#" -gt 3 ]; then
+ usage
+ $ECHO "error: too many arguments"
+ exit 1
+fi
+
+
set_copy
set_delete
deps-pacman) install_deps_pacman ;;
deps-macosx) install_deps_macosx ;;
deps-dnf) install_deps_dnf ;;
+ deps-pkg) install_deps_pkg ;;
self-update) update; make_boot_image; bootstrap;;
quick-update) update; refresh_image ;;
- update) update; download_and_bootstrap ;;
- latest) update; download_and_bootstrap ;;
+ update|latest) update; download_and_bootstrap ;;
+ compile) find_build_info; make_factor ;;
+ recompile) find_build_info; make_clean; make_factor ;;
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 ;;
+ report|info) find_build_info ;;
full-report) find_build_info; check_installed_programs; check_libraries ;;
update-boot-image) find_build_info; check_installed_programs; update_boot_image;;
*) usage ;;