parent
e9e26039b2
commit
f26a656937
246
misc/factor.sh
246
misc/factor.sh
|
@ -12,41 +12,41 @@ ARCH=
|
||||||
WORD=
|
WORD=
|
||||||
|
|
||||||
ensure_program_installed() {
|
ensure_program_installed() {
|
||||||
echo -n "Checking for $1..."
|
echo -n "Checking for $1..."
|
||||||
result=`type -p $1`
|
result=`type -p $1`
|
||||||
if ! [[ -n $result ]] ; then
|
if ! [[ -n $result ]] ; then
|
||||||
echo "not found!"
|
echo "not found!"
|
||||||
echo "Install $1 and try again."
|
echo "Install $1 and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "found!"
|
echo "found!"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_ret() {
|
check_ret() {
|
||||||
RET=$?
|
RET=$?
|
||||||
if [[ $RET -ne 0 ]] ; then
|
if [[ $RET -ne 0 ]] ; then
|
||||||
echo $1 failed
|
echo $1 failed
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_gcc_version() {
|
check_gcc_version() {
|
||||||
GCC_VERSION=`gcc --version`
|
GCC_VERSION=`gcc --version`
|
||||||
if [[ $GCC_VERSION == *3.3.* ]] ; then
|
if [[ $GCC_VERSION == *3.3.* ]] ; then
|
||||||
echo "You have a known buggy version of gcc (3.3)"
|
echo "You have a known buggy version of gcc (3.3)"
|
||||||
echo "Install gcc 3.4 or higher and try again."
|
echo "Install gcc 3.4 or higher and try again."
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_installed_programs() {
|
check_installed_programs() {
|
||||||
ensure_program_installed chmod
|
ensure_program_installed chmod
|
||||||
ensure_program_installed uname
|
ensure_program_installed uname
|
||||||
ensure_program_installed git
|
ensure_program_installed git
|
||||||
ensure_program_installed wget
|
ensure_program_installed wget
|
||||||
ensure_program_installed gcc
|
ensure_program_installed gcc
|
||||||
ensure_program_installed make
|
ensure_program_installed make
|
||||||
check_gcc_version
|
check_gcc_version
|
||||||
}
|
}
|
||||||
|
|
||||||
check_factor_exists() {
|
check_factor_exists() {
|
||||||
|
@ -58,152 +58,158 @@ check_factor_exists() {
|
||||||
}
|
}
|
||||||
|
|
||||||
find_os() {
|
find_os() {
|
||||||
uname_s=`uname -s`
|
uname_s=`uname -s`
|
||||||
case $uname_s in
|
case $uname_s in
|
||||||
CYGWIN_NT-5.2-WOW64) OS=windows-nt;;
|
CYGWIN_NT-5.2-WOW64) OS=windows-nt;;
|
||||||
*CYGWIN_NT*) OS=windows-nt;;
|
*CYGWIN_NT*) OS=windows-nt;;
|
||||||
*CYGWIN*) OS=windows-nt;;
|
*CYGWIN*) OS=windows-nt;;
|
||||||
*darwin*) OS=macosx;;
|
*darwin*) OS=macosx;;
|
||||||
*Darwin*) OS=macosx;;
|
*Darwin*) OS=macosx;;
|
||||||
*linux*) OS=linux;;
|
*linux*) OS=linux;;
|
||||||
*Linux*) OS=linux;;
|
*Linux*) OS=linux;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
find_architecture() {
|
find_architecture() {
|
||||||
uname_m=`uname -m`
|
uname_m=`uname -m`
|
||||||
case $uname_m in
|
case $uname_m in
|
||||||
i386) ARCH=x86;;
|
i386) ARCH=x86;;
|
||||||
i686) ARCH=x86;;
|
i686) ARCH=x86;;
|
||||||
*86) ARCH=x86;;
|
*86) ARCH=x86;;
|
||||||
"Power Macintosh") ARCH=ppc;;
|
"Power Macintosh") ARCH=ppc;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
write_test_program() {
|
write_test_program() {
|
||||||
echo "#include <stdio.h>" > $C_WORD.c
|
echo "#include <stdio.h>" > $C_WORD.c
|
||||||
echo "int main(){printf(\"%d\", 8*sizeof(void*)); return 0; }" >> $C_WORD.c
|
echo "int main(){printf(\"%d\", 8*sizeof(void*)); return 0; }" >> $C_WORD.c
|
||||||
}
|
}
|
||||||
|
|
||||||
find_word_size() {
|
find_word_size() {
|
||||||
C_WORD=factor-word-size
|
C_WORD=factor-word-size
|
||||||
write_test_program
|
write_test_program
|
||||||
gcc -o $C_WORD $C_WORD.c
|
gcc -o $C_WORD $C_WORD.c
|
||||||
WORD=$(./$C_WORD)
|
WORD=$(./$C_WORD)
|
||||||
check_ret $C_WORD
|
check_ret $C_WORD
|
||||||
rm -f $C_WORD*
|
rm -f $C_WORD*
|
||||||
}
|
}
|
||||||
|
|
||||||
set_factor_binary() {
|
set_factor_binary() {
|
||||||
case $OS in
|
case $OS in
|
||||||
windows-nt) FACTOR_BINARY=factor-nt;;
|
windows-nt) FACTOR_BINARY=factor-nt;;
|
||||||
macosx) FACTOR_BINARY=./Factor.app/Contents/MacOS/factor;;
|
macosx) FACTOR_BINARY=./Factor.app/Contents/MacOS/factor;;
|
||||||
*) FACTOR_BINARY=factor;;
|
*) FACTOR_BINARY=factor;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_build_info() {
|
echo_build_info() {
|
||||||
echo OS=$OS
|
echo OS=$OS
|
||||||
echo ARCH=$ARCH
|
echo ARCH=$ARCH
|
||||||
echo WORD=$WORD
|
echo WORD=$WORD
|
||||||
echo FACTOR_BINARY=$FACTOR_BINARY
|
echo FACTOR_BINARY=$FACTOR_BINARY
|
||||||
echo MAKE_TARGET=$MAKE_TARGET
|
echo MAKE_TARGET=$MAKE_TARGET
|
||||||
echo BOOT_IMAGE=$BOOT_IMAGE
|
echo BOOT_IMAGE=$BOOT_IMAGE
|
||||||
}
|
}
|
||||||
|
|
||||||
set_build_info() {
|
set_build_info() {
|
||||||
if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then
|
if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then
|
||||||
echo "OS, ARCH, or WORD is empty. Please report this"
|
echo "OS, ARCH, or WORD is empty. Please report this"
|
||||||
exit 5
|
exit 5
|
||||||
fi
|
fi
|
||||||
MAKE_TARGET=$OS-$ARCH-$WORD
|
MAKE_TARGET=$OS-$ARCH-$WORD
|
||||||
BOOT_IMAGE=boot.$ARCH.$WORD.image
|
BOOT_IMAGE=boot.$ARCH.$WORD.image
|
||||||
}
|
}
|
||||||
|
|
||||||
find_build_info() {
|
find_build_info() {
|
||||||
find_os
|
find_os
|
||||||
find_architecture
|
find_architecture
|
||||||
find_word_size
|
find_word_size
|
||||||
set_factor_binary
|
set_factor_binary
|
||||||
set_build_info
|
set_build_info
|
||||||
echo_build_info
|
echo_build_info
|
||||||
}
|
}
|
||||||
|
|
||||||
git_clone() {
|
git_clone() {
|
||||||
echo "Downloading the git repository from factorcode.org..."
|
echo "Downloading the git repository from factorcode.org..."
|
||||||
git clone git://factorcode.org/git/factor.git
|
git clone git://factorcode.org/git/factor.git
|
||||||
check_ret git
|
check_ret git
|
||||||
}
|
}
|
||||||
|
|
||||||
git_pull_factorcode() {
|
git_pull_factorcode() {
|
||||||
git pull git://factorcode.org/git/factor.git
|
git pull git://factorcode.org/git/factor.git
|
||||||
check_ret git
|
check_ret git
|
||||||
}
|
}
|
||||||
|
|
||||||
cd_factor() {
|
cd_factor() {
|
||||||
cd factor
|
cd factor
|
||||||
check_ret cd
|
check_ret cd
|
||||||
|
}
|
||||||
|
|
||||||
|
make_clean() {
|
||||||
|
make clean
|
||||||
|
check_ret make
|
||||||
}
|
}
|
||||||
|
|
||||||
make_factor() {
|
make_factor() {
|
||||||
make $MAKE_TARGET
|
make $MAKE_TARGET -j5
|
||||||
check_ret make
|
check_ret make
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_boot_images() {
|
delete_boot_images() {
|
||||||
echo "Deleting old images..."
|
echo "Deleting old images..."
|
||||||
rm $BOOT_IMAGE > /dev/null 2>&1
|
rm $BOOT_IMAGE > /dev/null 2>&1
|
||||||
rm $BOOT_IMAGE.* > /dev/null 2>&1
|
rm $BOOT_IMAGE.* > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
get_boot_image() {
|
get_boot_image() {
|
||||||
wget http://factorcode.org/images/latest/$BOOT_IMAGE
|
wget http://factorcode.org/images/latest/$BOOT_IMAGE
|
||||||
check_ret wget
|
check_ret wget
|
||||||
}
|
}
|
||||||
|
|
||||||
maybe_download_dlls() {
|
maybe_download_dlls() {
|
||||||
if [[ $OS == windows-nt ]] ; then
|
if [[ $OS == windows-nt ]] ; then
|
||||||
wget http://factorcode.org/dlls/freetype6.dll
|
wget http://factorcode.org/dlls/freetype6.dll
|
||||||
check_ret
|
check_ret
|
||||||
wget http://factorcode.org/dlls/zlib1.dll
|
wget http://factorcode.org/dlls/zlib1.dll
|
||||||
check_ret
|
check_ret
|
||||||
chmod 777 *.dll
|
chmod 777 *.dll
|
||||||
check_ret
|
check_ret
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap() {
|
bootstrap() {
|
||||||
./$FACTOR_BINARY -i=$BOOT_IMAGE
|
./$FACTOR_BINARY -i=$BOOT_IMAGE
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: $0 install|update"
|
echo "usage: $0 install|update"
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
install)
|
install)
|
||||||
check_factor_exists
|
check_factor_exists
|
||||||
check_installed_programs
|
check_installed_programs
|
||||||
find_build_info
|
find_build_info
|
||||||
git_clone
|
git_clone
|
||||||
cd_factor
|
cd_factor
|
||||||
make_factor
|
make_factor
|
||||||
get_boot_image
|
get_boot_image
|
||||||
maybe_download_dlls
|
maybe_download_dlls
|
||||||
bootstrap
|
bootstrap
|
||||||
;;
|
;;
|
||||||
|
|
||||||
update)
|
update)
|
||||||
check_installed_programs
|
check_installed_programs
|
||||||
find_build_info
|
find_build_info
|
||||||
git_pull_factorcode
|
git_pull_factorcode
|
||||||
make_factor
|
make_clean
|
||||||
delete_boot_images
|
make_factor
|
||||||
get_boot_image
|
delete_boot_images
|
||||||
bootstrap
|
get_boot_image
|
||||||
;;
|
bootstrap
|
||||||
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue