Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 1135b27c44
Fetching contributors…

Cannot retrieve contributors at this time

executable file 487 lines (441 sloc) 11.438 kB
#! /bin/sh
#set -e
#set -x
CONFIG_H=config.h
MAKEFILE_LOCAL=Makefile.local
DEBUG=1
UNIVERSAL=
HARD_LINKED_GAME=
HARD_LINKED_CGAME=1
PARANOID=
PROFILING=
PREFIX=/usr/local
PKGDATADIR=
PKGBINDIR=
PKGLIBDIR=
LOCALEDIR=
USE_SIGNALS=1
MODE=
CROSS=
USE_CCACHE=
STATIC=
W2K=
SSE=
DISABLE_DEPENDENCY_TRACKING=
HOST_OS=`uname | sed -e s/_.*// | tr '[:upper:]' '[:lower:]'`
TARGET_OS=${HOST_OS}
if [ "${HOST_OS}" = "sunos" ] || [ "${HOST_OS}" = "darwin" ]; then
TARGET_ARCH=`uname -p | sed -e s/i.86/i386/`
else
TARGET_ARCH=`uname -m | sed -e s/i.86/i386/`
fi
add_line_to_makefile_local() {
makefile_local_data="${makefile_local_data}"'
'"$1"
}
error() {
echo $@
exit 1
}
add_to_makefile_local_quote() {
VALUE=`get_var $1`
if [ -n "$VALUE" ]; then
add_line_to_makefile_local "$1 ?= \"$VALUE\""
[ -n "$2" ] && echo $2
else
add_line_to_makefile_local "# $1 ?= \"$VALUE\""
[ -n "$3" ] && echo $3
[ "$4" = "yes" ] && exit 1
fi
}
add_to_makefile_local() {
VALUE=`get_var $1`
if [ -n "$VALUE" ]; then
add_line_to_makefile_local "$1 ?= $VALUE"
[ -n "$2" ] && echo $2
else
add_line_to_makefile_local "# $1 ?= $VALUE"
[ -n "$3" ] && echo $3
[ "$4" = "yes" ] && exit 1
fi
}
add_line_to_config_h() {
config_h_data="${config_h_data}"'
'"$1"
}
add_to_config_h_quote() {
VALUE=`get_var $1`
if [ -n "$VALUE" ] && [ "$VALUE" != "no" ]; then
add_line_to_config_h "#define $1 \"$VALUE\""
[ -n "$2" ] && echo $2
else
add_line_to_config_h "/* #define $1 \"$VALUE\" */"
[ -n "$3" ] && echo $3
[ "$4" = "yes" ] && exit 1
fi
}
add_to_config_h() {
VALUE=`get_var $1`
if [ -n "$VALUE" ] && [ "$VALUE" != "no" ]; then
add_line_to_config_h "#define $1 $VALUE"
[ -n "$2" ] && echo $2
else
add_line_to_config_h "/* #define $1 $VALUE */"
[ -n "$3" ] && echo $3
[ "$4" = "yes" ] && exit 1
fi
}
config_h() {
add_to_config_h PARANOID "Enable paranoid build"
add_to_config_h HARD_LINKED_GAME "Enable hard linked game"
add_to_config_h HARD_LINKED_CGAME "Enable hard linked cgame"
add_to_config_h USE_SIGNALS "Use signal handler"
add_to_config_h_quote PKGDATADIR "Setting custom data directory"
add_to_config_h_quote PKGLIBDIR "Setting custom library directory"
add_to_config_h_quote LOCALEDIR "Setting custom locale directory"
}
makefile_local() {
add_to_makefile_local DEBUG "Debug build"
add_to_makefile_local PROFILING "Enable profiling"
add_to_makefile_local STATIC "Enable static linking"
add_to_makefile_local W2K "Enable Windows 2000 compatibility"
add_to_makefile_local SSE "Enable Streaming SIMD Extensions"
add_to_makefile_local HARD_LINKED_GAME
add_to_makefile_local HARD_LINKED_CGAME
add_to_makefile_local DISABLE_DEPENDENCY_TRACKING "Disable dependency tracking"
add_to_makefile_local UNIVERSAL "Build a universal binary"
add_to_makefile_local TARGET_OS "Compile for ${TARGET_OS}"
add_to_makefile_local TARGET_ARCH "Compile for ${TARGET_ARCH}"
add_to_makefile_local MODE "Compile in ${MODE} mode"
add_to_makefile_local_quote CC "Found cc ${CC}"
add_to_makefile_local_quote CXX "Found cxx ${CXX}"
add_to_makefile_local_quote CROSS "Using tools prefix ${CROSS}"
add_to_makefile_local_quote PKGBINDIR "Using bindir ${PKGBINDIR}"
add_to_makefile_local_quote PKGDATADIR "Using datadir ${PKGDATADIR}"
add_to_makefile_local_quote PKGLIBDIR "Using libdir ${PKGLIBDIR}"
add_to_makefile_local_quote LOCALEDIR "Using localedir ${LOCALEDIR}"
add_to_makefile_local_quote PREFIX "Using prefix ${PREFIX}"
echo "Build modules:"
for i in `get_modules`; do
add_to_makefile_local ${i}_DISABLE
if [ "`get_var ${i}_DISABLE`" = "yes" ]; then
echo "Disable $i"
else
echo "Build $i"
fi
done
}
check_header_cc() {
if [ -n "${2}" ]; then
( echo "#include <${1}>" | ${CROSS}${CC} ${CFLAGS} $(pkg-config --cflags ${2}) -o /dev/null -xc -c - 2> /dev/null ) && echo "1" || echo ""
else
( echo "#include <${1}>" | ${CROSS}${CC} ${CFLAGS} -o /dev/null -xc -c - 2> /dev/null ) && echo "1" || echo ""
fi
}
check_header() {
HEADER=$1
HAVE=HAVE_`echo ${HEADER%.*} | sed 's,/,_,g' | tr '[a-z]' '[A-Z]'`_H
VALUE=`get_var $HAVE`
if [ "$VALUE" != "no" ]; then
set_var $HAVE `check_header_cc $1 $2`
add_to_config_h $HAVE "Found $1" "Could not find $1" $2
add_to_makefile_local $HAVE
else
add_to_config_h $HAVE "Found $1" "Disable $1"
fi
}
check_headers() {
check_header "xvid.h"
check_header "theora/theora.h"
check_header "execinfo.h"
check_header "bfd.h"
check_header "sys/utsname.h"
check_header "link.h"
check_header "CUnit/Basic.h"
check_header "mxml.h"
if [ "$HAVE_CUNIT_BASIC_H" != "1" ]; then
set_var "testall_DISABLE" "yes"
fi
}
check_compiler() {
# TODO Implement compiler check
CC=${CC:-cc}
CXX=${CXX:-c++}
if [ "${TARGET_OS}" = "android" ]; then
CROSS="arm-linux-androideabi-"
fi
if [ "${TARGET_OS}" = "mingw32" ] && [ "${HOST_OS}" != "mingw32" ]; then
CROSS="i686-pc-mingw32-"
fi
if [ -n "${CROSS}" ]; then
# TODO Add a check for this
echo "Cross compiling, make sure that ${CROSS}${CC} is in your path"
fi
}
usage() {
echo "Usage: $0"
echo " --help show this help message"
echo " --enable-ccache use ccache for building"
echo " --enable-hardlinkedgame hard link the server game code"
echo " --enable-paranoid compile in paranoid mode with extra checks"
echo " --enable-profiling activates profiling"
echo " --enable-release build with optimizations"
echo " --enable-static enable static linking"
echo " --enable-universal enable universal build"
echo " --enable-w2k enable Windows 2000 compatibility"
if [ -n "$(echo ${TARGET_ARCH} | grep -e '^i.86$' -e '^x86_64$')" ]; then
echo " --enable-sse enable Streaming SIMD Extensions"
fi
echo " --disable-execinfo disable backtraces for crashes"
echo " --disable-signals disable the use of a signal handler"
echo
echo " --target-os= specify the target os"
(cd build/platforms; for i in *.mk; do echo " * ${i%.mk}"; done)
echo
echo " --bindir= path for the ufoai binaries"
echo " --datadir= path for the ufoai game data"
echo " --libdir= path for the ufoai shared objects"
echo " --localedir= path for the ufoai translations"
echo " --prefix= prefix for directories"
echo
echo " --disable-* specify which target should not get built"
echo " --enable-* specify which target should get built"
echo " --enable-only-* disable all other targets"
(cd build/modules; for i in *.mk; do echo " * ${i%.mk}"; done)
echo
echo " --disable-dependency-tracking"
exit 1
}
make_var() {
echo "$1" | sed 's/-/_/g'
}
set_var() {
eval $(make_var "$1")=\""$2"\"
}
get_var() {
eval echo \${$(make_var "$1")}
}
get_modules() {
(cd build/modules; for i in *.mk; do echo "${i%.mk}"; done)
}
check_path_characters() {
# Find out where configure is (in what dir)
ROOT_DIR="`dirname $0`"
# For MSYS/MinGW we want to know the FULL path. This as that path is generated
# once you call an outside binary. Having the same path for the rest is needed
# for dependency checking.
# pwd -W returns said FULL path, but doesn't exist on others so fall back.
ROOT_DIR="`cd $ROOT_DIR && (pwd -W 2>/dev/null || pwd 2>/dev/null)`"
if [ -n "`echo \"$ROOT_DIR\" | grep '[^-\w\/\\\.:]~?'`" ]; then
echo "WARNING: The path contains a non-alphanumeric character that might cause"
echo " failures in subsequent build stages. Any failures with the build"
echo " will most likely be caused by this."
echo " $ROOT_DIR"
fi
if [ -n "`echo \"$ROOT_DIR\" | grep '[\(\)]'`" ]; then
echo "ERROR: The path contains a square character that cause"
echo " failures in subsequent build stages!!!"
echo " $ROOT_DIR"
exit 1
fi
}
check_ccache() {
if [ "$USE_CCACHE" = "yes" ]; then
ccache --help > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Use ccache"
CC="ccache $CC"
CXX="ccache $CXX"
else
echo "Could not find ccache in your path"
fi
fi
}
check_target_os() {
local FOUND=0
for i in build/platforms/*.mk; do
if [ `basename $i .mk` = $1 ]; then
FOUND=1
fi
done
[ $FOUND -eq 0 ] && echo "invalid target-os given: $1" && exit 1
}
check_module() {
local FOUND=0
for i in `get_modules`; do
if [ $i = $1 ]; then
FOUND=1
fi
done
[ $FOUND -eq 0 ] && error "invalid module given: $1"
}
enable_only() {
for i in `get_modules`; do
if [ "$i" = "$1" ]; then
set_var "${i}_DISABLE" ""
else
set_var "${i}_DISABLE" "yes"
fi
done
}
check_path_characters
# uforadiant is disabled by default
set_var "uforadiant_DISABLE" "yes"
while [ $# -gt 0 ]; do
case "$1" in
--help|-h)
usage
;;
--enable-ccache)
USE_CCACHE="yes"
;;
--disable-ccache)
USE_CCACHE="no"
;;
--enable-release)
MODE=release
DEBUG=
;;
--disable-release)
MODE=debug
DEBUG=1
;;
--enable-static)
STATIC=1
;;
--disable-static)
STATIC=
;;
--enable-universal)
UNIVERSAL=1
DISABLE_DEPENDENCY_TRACKING=1
;;
--disable-universal)
UNIVERSAL=
;;
--enable-hardlinkedgame)
HARD_LINKED_GAME=1
;;
--disable-hardlinkedgame)
HARD_LINKED_GAME=
;;
--enable-hardlinkedcgame)
HARD_LINKED_CGAME=1
;;
--disable-hardlinkedcgame)
HARD_LINKED_CGAME=
;;
--enable-paranoid)
PARANOID=1
;;
--disable-paranoid)
PARANOID=
;;
--enable-profiling)
PROFILING=1
;;
--disable-profiling)
PROFILING=
;;
--enable-w2k)
W2K=1
;;
--disable-w2k)
W2K=
;;
--enable-sse)
if [ -z "$(echo ${TARGET_ARCH} | grep -e '^i.86$' -e '^x86_64$')" ] ;then
echo "invalid $1 option for your CPU"
exit 1
fi
SSE=1
;;
--disable-sse)
SSE=0
;;
--enable-signals)
USE_SIGNALS=1
;;
--disable-signals)
USE_SIGNALS=
;;
--enable-execinfo)
HAVE_EXECINFO_H=yes
;;
--disable-execinfo)
HAVE_EXECINFO_H=no
;;
--disable-dependency-tracking)
DISABLE_DEPENDENCY_TRACKING=1
;;
--prefix=*)
PREFIX="${1#*=}"
;;
--datadir=*)
PKGDATADIR="${1#*=}"
;;
--libdir=*)
PKGLIBDIR="${1#*=}"
;;
--localedir=*)
LOCALEDIR="${1#*=}"
;;
--bindir=*)
PKGBINDIR="${1#*=}"
;;
--target-os=*)
TARGET_OS="${1#*=}"
check_target_os $TARGET_OS
;;
--disable-*)
OPTION="${1#--disable-}"
check_module $OPTION
set_var "${OPTION}_DISABLE" "yes"
;;
--enable-only-*)
OPTION="${1#--enable-only-}"
HARD_LINKED_GAME=1
HARD_LINKED_CGAME=1
check_module $OPTION
enable_only $OPTION
;;
--enable-*)
OPTION="${1#--enable-}"
check_module $OPTION
set_var "${OPTION}_DISABLE" ""
;;
CC=*) CC="${1#CC=}";;
CXX=*) CXX="${1#CXX=}";;
CFLAGS=*) CFLAGS="${1#*=}";;
LDFLAGS=*) LDFLAGS="${1#*=}";;
*)
echo "invalid option $1"
exit 1
;;
esac
shift
done
[ "${TARGET_OS}" = "mingw32" ] && TARGET_ARCH=i386
[ "${TARGET_OS}" = "android" ] && TARGET_ARCH=arm && enable_only ufo
[ "${TARGET_OS}" = "darwin" ] && USE_SIGNALS=
PKGDATADIR=${PKGDATADIR:-${PREFIX}/games/ufoai}
PKGBINDIR=${PKGBINDIR:-${PREFIX}/bin}
PKGLIBDIR=${PKGLIBDIR:-${PREFIX}/lib}
check_compiler
check_ccache
check_headers
makefile_local
config_h
cat > ${MAKEFILE_LOCAL} << EOF
# -------- Automatically generated -----------
$makefile_local_data
# allow to specify your own targets
-include config.mk
EOF
cat > ${CONFIG_H} << EOF
/* This file is automatically generated */
#ifndef CONFIG_H
#define CONFIG_H
$config_h_data
#endif
EOF
Jump to Line
Something went wrong with that request. Please try again.