#!/bin/bash function program_exists() { $1 $2 1>/dev/null 2>&1 if [ $? -eq 127 ]; then return 0 fi upname=$(echo $1 | tr '[a-z]' '[A-Z]' | tr '-' '_') eval "$upname=$1" return 1 } function print_make_file_list() { FOO=GL_SRC FOOO=GL_OBJ ( grep -l "^namespace OpenGL" *.cpp ;echo "gl_frustum.cpp";echo "math/obox.cpp coldet/math3d.cpp util/physfsrwops.c" ) | sort | xargs echo "$FOO =" echo "$FOOO = \${$FOO:.cpp=.o}" FOO=OGTA_SRC FOOO=OGTA_OBJ ( grep -l "^namespace OpenGTA" *.cpp ; echo "slope_height_func.cpp" )|grep -v viewer.cpp |grep -v sprite_anim_player.cpp| sort | xargs echo "$FOO =" echo "$FOOO = \${$FOO:.cpp=.o}" UTIL_SRC=$(ls util/*.cpp | grep -v color.cpp | grep -v sound | xargs echo) SOUND_SRC=$(ls util/*.cpp | grep sound.* | xargs echo) LUA_SRC=$(ls lua_addon/*.cpp | xargs echo) cat < src_list.make #print_target_list >> src_list.make function pkg_config_haslib () { $PKG_CONFIG $1 1>/dev/null 2>&1 if [ $? -eq 0 ]; then return 1 fi return 0 } function check_sdl () { program_exists sdl-config if [ $? -eq 1 ]; then SDL_INC=$($SDL_CONFIG --cflags) SDL_LIB=$($SDL_CONFIG --libs) else program_exists pkg-config if [ $? -eq 1 ]; then pkg_config_try_multiple SDL SDL sdl fi fi cat <_out_$$.cpp #include int main(int argc, char* argv[]) { SDL_GL_SWAP_CONTROL; } EOF g++ $SDL_INC _out_$$.cpp 2>/dev/null if [ $? -eq 0 ]; then SDL_GL_SWAP_CONTROL='#define HAVE_SDL_VSYNC' else SDL_GL_SWAP_CONTROL='#undef HAVE_SDL_VSYNC' fi rm -f _out_$$.cpp a.out } function pkg_config_try_multiple () { local _prefixName=$1 shift while [ $# -gt 0 ]; do pkg_config_haslib $1 if [ $? -eq 1 ]; then eval "${_prefixName}_INC=\$($PKG_CONFIG --cflags $1)" eval "${_prefixName}_LIB=\$($PKG_CONFIG --libs $1)" return fi shift done } function check_lua () { program_exists pkg-config if [ $? -eq 1 ]; then pkg_config_try_multiple LUA lua5.1 lua51 lua5 lua else program_exists lua-config if [ $? -eq 1 ]; then LUA_INC=$($LUA_CONFIG --include) LUA_LIB=$($LUA_CONFIG --libs) fi fi } function check_sdl_audio () { local good=0 cat <_out_$$.cpp #include int main(int argc, char* argv[]) { } EOF g++ $SDL_INC _out_$$.cpp 2>/dev/null if [ $? -eq 0 ]; then let good=$good+1 fi rm -f _out_$$.cpp cat <_out_$$.cpp #include int main(int argc, char* argv[]) { } EOF g++ $SDL_INC _out_$$.cpp 2>/dev/null if [ $? -eq 0 ]; then let good=$good+1 fi rm -f _out_$$.cpp a.out if [ $good -eq 2 ]; then AUDIO_LD="-lSDL_mixer -lSDL_sound" SDL_SOUND_MIXER='#define WITH_SOUND' else SDL_SOUND_MIXER='#undef WITH_SOUND' fi } function check_physfs () { program_exists pkg-config if [ $? -eq 1 ]; then pkg_config_try_multiple PHYSFS physfs fi } function check_compiler () { if [ "$OGTA_PLATFORM" == "WIN32" ]; then _CXX=i586-mingw32msvc-g++ _CC=i586-mingw32msvc-gcc else _CXX=g++ _CC=gcc fi $_CXX 1>/dev/null 2>&1 if [ $? -eq 1 ]; then CXX=$_CXX else CXX= fi $_CC 1>/dev/null 2>&1 if [ $? -eq 1 ]; then CC=$_CC else CC= fi GCC_VERSION=$($CXX --version | head -n 1) } # defaults DEBUG=-ggdb WARN=-Wall OPT=-O2 PHYSFS_LIB=-lphysfs SDL_LIB=-lSDL LUA_LIB=-llua51 function print_detected() { cat <= 5.1 (but not 5.0); not detected LUA_INC = $LUA_INC LUA_LIB = $LUA_LIB AUDIO_INC = AUDIO_LIB = $AUDIO_LD LINK_LAZY = -Xlinker --unresolved-symbols -Xlinker ignore-all EOF } function print_w32settings() { cat <= 5.1 (but not 5.0); not detected LUA_INC = $LUA_INC LUA_LIB = $LUA_LIB # good idea here? LINK_LAZY = -Xlinker --unresolved-symbols -Xlinker ignore-all EOF } function print_all() { check_sdl check_lua check_physfs check_sdl_audio print_detected print_make_file_list print_target_list cat < ogta_version fi cat < src_list.make print_make_file_list >> src_list.make print_target_list >> src_list.make else OGTA_PLATFORM="LINUX" echo "*** LINUX ***" check_compiler DEFS="-include config.h" print_all > src_list.make fi print_config_h > config.h