diff options
Diffstat (limited to 'build/unix')
-rw-r--r-- | build/unix/README | 5 | ||||
-rw-r--r-- | build/unix/README.crossbuild | 49 | ||||
-rw-r--r-- | build/unix/README.packages | 31 | ||||
-rw-r--r-- | build/unix/ansi | 21 | ||||
-rw-r--r-- | build/unix/build.config | 780 | ||||
-rw-r--r-- | build/unix/build.docs | 205 | ||||
-rw-r--r-- | build/unix/build.sh | 143 | ||||
-rw-r--r-- | build/unix/build_clean | 29 | ||||
-rw-r--r-- | build/unix/build_collect | 26 | ||||
-rw-r--r-- | build/unix/build_functions | 311 | ||||
-rw-r--r-- | build/unix/config_functions | 1139 | ||||
-rw-r--r-- | build/unix/config_proginfo_build | 336 | ||||
-rw-r--r-- | build/unix/config_proginfo_host | 356 | ||||
-rw-r--r-- | build/unix/make/buildtools-armv5 | 17 | ||||
-rw-r--r-- | build/unix/make/buildtools-gcce | 8 | ||||
-rw-r--r-- | build/unix/make/buildtools-generic | 36 | ||||
-rw-r--r-- | build/unix/make/buildtools-winscw | 19 | ||||
-rw-r--r-- | build/unix/menu_functions | 662 | ||||
-rwxr-xr-x | build/unix/recurse | 88 | ||||
-rw-r--r-- | build/unix/todo | 15 | ||||
-rwxr-xr-x | build/unix/uqm-wrapper.in | 4 |
21 files changed, 4280 insertions, 0 deletions
diff --git a/build/unix/README b/build/unix/README new file mode 100644 index 0000000..0cad7d9 --- /dev/null +++ b/build/unix/README @@ -0,0 +1,5 @@ +This directory contains files used for building and installing +on unix-like environments. +There's no need to use any of those directly; type './build.sh' from +the top dir to get started. + diff --git a/build/unix/README.crossbuild b/build/unix/README.crossbuild new file mode 100644 index 0000000..3992087 --- /dev/null +++ b/build/unix/README.crossbuild @@ -0,0 +1,49 @@ +-= Instructions for cross-building UQM =- + + +Terminology: + Build system + The system on which the code is being built. + Host system + The system on which the code is supposed to run on. + + +Set the environment variable 'CROSS_ROOT' to the root of your cross building +environment. This is not necessary for the build scripts, but it will +simplify what you type in the following steps. + +Make sure your cross-building tools (gcc, ld, etc) are in the path. + export PATH=$CROSS_ROOT/bin:$PATH +Make sure that it isn't being reset by subshells that are started. + unset ENV BASH_ENV + +Set the environment variable 'BUILD_HOST' to the host system. +This is whatever 'uname -s' returns on such a system (like "MINGW32"). +When building for Windows CE, using the cegcc tools, you should use "cegcc". + +If your host system is big-endian, set the environment variable +'BUILD_HOST_ENDIAN' to "big". For a little-endian system, you don't +have to do anything. + export BUILD_HOST_ENDIAN=little + +If you're using pkg-config (advised), set the environment variable +PKG_CONFIG_PATH' to the pkgconfig directory of the cross environment. +This dir normally resides in the 'lib/' directory. + export PKG_CONFIG_PATH=$CROSS_ROOT/lib/pkgconfig + +For any libraries that can't be detected - which will be a lot if you +don't use pkg-config - set the corresponding include dirs in CFLAGS and +library dirs in LDFLAGS. + export CFLAGS="-I$CROSS_ROOT/include" + export LDFLAGS="-L$CROSS_ROOT/lib" + +Run configure: + ./build.sh uqm config +This will produce the file 'build.vars' and 'config_unix.h' (or config_win.h +on MinGW or Cygwin). If there are any problems during the build, you can +usually easilly solve them by editing these files manually. + +Start the compilation: + ./build.sh uqm + + diff --git a/build/unix/README.packages b/build/unix/README.packages new file mode 100644 index 0000000..68acfaf --- /dev/null +++ b/build/unix/README.packages @@ -0,0 +1,31 @@ +This file describes the easiest way to use this build system from +a packaging system such as rpm. + +If you want an interactive configuration, you can start the build process +like you would do manually: + ./build.sh uqm +to build the game, and + ./build.sh uqm install +to install it. + + +If you want the configuration to be non-interactive, you'll want to do +the following: execute + ./build.sh uqm config +once. This will generate a 'config.vars' file, which you can then +include in your package. Then when you want to build the game, put this +file the directory pointed to by $BUILD_WORK (default is the current +directory), and do + ./build.sh uqm reprocess_config +to generate all the configuration information for the build, and then + ./build.sh uqm +to build the game, and + ./build.sh uqm install +to install it. + +You may wish to set the environment variable BUILD_WORK to a directory +where the files created in the configuration and build process should be +stored. That way, the source tree will remain clean and no write access +to it is required. + + diff --git a/build/unix/ansi b/build/unix/ansi new file mode 100644 index 0000000..ac5b97f --- /dev/null +++ b/build/unix/ansi @@ -0,0 +1,21 @@ +ESC=`printf '\033'` +ANSI_BOLD="${ESC}[1m" +ANSI_NORMAL="${ESC}[0m" + +ANSI_BLK="${ESC}[30m" +ANSI_RED="${ESC}[31m" +ANSI_GRN="${ESC}[32m" +ANSI_YLW="${ESC}[33m" +ANSI_BLU="${ESC}[34m" +ANSI_MGN="${ESC}[35m" +ANSI_CYN="${ESC}[36m" +ANSI_WHT="${ESC}[37m" +ANSI_LBLK="${ESC}[1;30m" +ANSI_LRED="${ESC}[1;31m" +ANSI_LGRN="${ESC}[1;32m" +ANSI_LYLW="${ESC}[1;33m" +ANSI_LBLU="${ESC}[1;34m" +ANSI_LMGN="${ESC}[1;35m" +ANSI_LCYN="${ESC}[1;36m" +ANSI_LWHT="${ESC}[1;37m" + diff --git a/build/unix/build.config b/build/unix/build.config new file mode 100644 index 0000000..4b4ef3c --- /dev/null +++ b/build/unix/build.config @@ -0,0 +1,780 @@ +# This file is sourced by build.sh + +# Include build functions used here +. build/unix/config_functions +. build/unix/menu_functions +. build/unix/ansi + + +uqm_requirements() +{ + # Some requirements: + have_build_tools_language C || exit 1 + have_build_tools_language CXX || exit 1 + have_build_tool LINK || exit 1 + case "$HOST_SYSTEM" in + MINGW32*|cegcc) + have_build_tool WINDRES || exit 1 + ;; + Darwin) + have_build_tools_language OBJC || exit 1 + have_build_tool REZ || exit 1 + ;; + esac + + + # Define WORDS_BIGENDIAN on bigendian machines + check_endianness + + + # Libraries always used + have_library SDL 1.2.8 + have_library SDL2 + have_library SDL 1.2.8 || have_library SDL2 || exit 1 + use_library libpng || exit 1 + + case "$HOST_SYSTEM" in + WINSCW|ARMV5|GCCE) + # Symbian does not use dynamically generated config.h + return + ;; + esac + + # Add defines for HAVE_READDIR_R, HAVE_SETENV, HAVE_STRUPR, + # HAVE_STRCASECMP, and HAVE_STRICMP + define_have_symbol readdir_r + define_have_symbol setenv + define_have_symbol strupr + define_have_symbol strcasecmp + define_have_symbol stricmp + + # Check to see whether math functions are available for free. + define_have_symbol acos + + # Require either strcasecmp or stricmp. + if not have_symbol strcasecmp && not have_symbol stricmp; then + echo "Fatal: Your system defines neither strcasecmp() nor stricmp()." + exit 1 + fi + + # If we don't have math for free, add -lm to LDFLAGS. + if not have_symbol acos; then + LDFLAGS="$LDFLAGS -lm" + fi + + # Add defines for HAVE_ISWGRAPH, HAVE_WCHAR_T, and HAVE_WINT_T + define_have_symbol iswgraph + define_have_type wchar_t + define_have_type wint_t + + # Add defines for HAVE_GETOPT_LONG and HAVE_REGEX_H + define_have_symbol getopt_long + define_have_header regex.h + + # If we have the regex header, see if we need to link it specially + case "$HOST_SYSTEM" in + MINGW32*) + LDFLAGS="$LDFLAGS -lregex" + ;; + esac + + # Add define for HAVE__BOOL + define_have_type _Bool + + # Add an environment variable for MACRO_WIN32 and MACRO___MINGW32__ + define_have_macro WIN32 + define_have_macro __MINGW32__ + + if [ -n "$MACRO___MINGW32__" ]; then + USE_WINSOCK=1 + fi +} + +uqm_prepare_config() +{ + # Describe the menu: + MENU_main_ITEMS="debug graphics sound mikmod ovcodec netplay joystick \ + ioformat accel threadlib" + case "$HOST_SYSTEM" in + Darwin|WINSCW|ARMV5|GCCE) + # Installation directory not modifiable + ;; + MINGW32*|cegcc) + # No install procedure available for MinGW + ;; + *) + MENU_main_ITEMS="$MENU_main_ITEMS install_path" + ;; + esac + MENU_main_TITLE="Main menu" + MENU_main_ITEM_debug_TYPE=CHOICE + MENU_main_ITEM_graphics_TYPE=CHOICE + MENU_main_ITEM_sound_TYPE=CHOICE + MENU_main_ITEM_mikmod_TYPE=CHOICE + MENU_main_ITEM_ovcodec_TYPE=CHOICE + MENU_main_ITEM_netplay_TYPE=CHOICE + MENU_main_ITEM_joystick_TYPE=CHOICE + MENU_main_ITEM_ioformat_TYPE=CHOICE + MENU_main_ITEM_accel_TYPE=CHOICE + MENU_main_ITEM_threadlib_TYPE=CHOICE + MENU_main_ITEM_install_path_TYPE=MENU + + CHOICE_debug_OPTIONS="nodebug debug strictdebug" + CHOICE_debug_TITLE="Type of build" + CHOICE_debug_OPTION_nodebug_TITLE="Optimised release build" + CHOICE_debug_OPTION_nodebug_ACTION='nodebug_action' + nodebug_action() { + case "$HOST_SYSTEM" in + WINSCW) + CCOMMONFLAGS="$CCOMMONFLAGS -O2 -d NDEBUG" + ;; + ARMV5) + CCOMMONFLAGS="$CCOMMONFLAGS -O3 -Otime -DNDEBUG" + ;; + GCCE) + CCOMMONFLAGS="$CCOMMONFLAGS -O3 -DNDEBUG" + ;; + *) + CCOMMONFLAGS="$CCOMMONFLAGS -O3 -DNDEBUG" + ;; + esac + DEBUG=0 + } + CHOICE_debug_OPTION_debug_TITLE="Debugging build" + CHOICE_debug_OPTION_debug_ACTION='debug_action' + debug_action() { + case "$HOST_SYSTEM" in + WINSCW) + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -W all -d DEBUG -d _DEBUG" + ;; + ARMV5|GCCE) + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -DDEBUG -D_DEBUG" + ;; + *) + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -W -Wall -DDEBUG" + LDFLAGS="$LDFLAGS -O0" + ;; + esac + DEBUG=1 + } + CHOICE_debug_OPTION_strictdebug_TITLE="Debug + strict compile checks" + CHOICE_debug_OPTION_strictdebug_ACTION='strictdebug_action' + strictdebug_action() { + case "$HOST_SYSTEM" in + WINSCW) + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -W all -d DEBUG -d _DEBUG" + ;; + ARMV5|GCCE) + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -DDEBUG -D_DEBUG" + ;; + *) + CCOMMONFLAGS="$CCOMMONFLAGS -g -O0 -DDEBUG -W -Wall" +# CCOMMONFLAGS="$CCOMMONFLAGS -O1" + # This is needed for -Wunitialized with gcc 3.4 + CCOMMONFLAGS="$CCOMMONFLAGS -Wcast-qual -Wmissing-declarations \ + -Wwrite-strings -Wimplicit -Wreturn-type -Wformat \ + -Wswitch -Wcomment -Wchar-subscripts \ + -Wparentheses -Wcast-align -Wuninitialized" + CFLAGS="$CFLAGS -Wbad-function-cast -Wmissing-prototypes \ + -Wstrict-prototypes" + # CFLAGS is for flags not valid in C++. + CFLAGS="$CFLAGS -Wdeclaration-after-statement" + # Until we abandon MSVC 6 +# CCOMMONFLAGS="$CCOMMONFLAGS -Waggregate-return" + # It's not unreasonable to return structs at times. +# CCOMMONFLAGS="$CCOMMONFLAGS "-Wpointer-arith" + # Some standard header won't even compile with this on +# CCOMMONFLAGS="$CCOMMONFLAGS -Wshadow" + # This gives absurd conflicts with standard files, + # like from 'y0 and y1' +# CCOMMONFLAGS="$CCOMMONFLAGS -Werror" + # We shouldn't do this until we actually nail them + # all in the original code. Then we can enforce them + # on ourselves. +# CCOMMONFLAGS="$CCOMMONFLAGS -pedantic-errors -ansi -trigraphs" # ANSI +# CCOMMONFLAGS="$CCOMMONFLAGS -Wnested-externs" + # We know they're in the code, and though we'd like to + # get rid of them, they're not bugs. +# CCOMMONFLAGS="$CCOMMONFLAGS -Winline" + # This gives too many warnings which we can do nothing + # about, obscuring legitimate warnings. + CFLAGS=`echo $CFLAGS` + CXXFLAGS=`echo $CXXFLAGS` + CCOMMONFLAGS=`echo $CCOMMONFLAGS` + # Remove all the unnecessary spaces from the flags vars + # for more readable messages. + LDFLAGS="$LDFLAGS -O0" + ;; + esac + DEBUG=1 + } + case "$HOST_SYSTEM" in + ARMV5|WINSCW|GCCE) + CHOICE_debug_DEFAULT=nodebug + ;; + *) + CHOICE_debug_DEFAULT=debug + ;; + esac + + + CHOICE_graphics_OPTIONS="pure opengl sdl2" + CHOICE_graphics_TITLE="Graphics Engine" + CHOICE_graphics_OPTION_pure_TITLE="SDL1 without OpenGL graphics support" + CHOICE_graphics_OPTION_pure_ACTION='graphics_pure_action' + CHOICE_graphics_OPTION_pure_PRECOND='have_library SDL 1.2.8' + graphics_pure_action() { + CFLAGS="$CFLAGS -DGFXMODULE_SDL -DSDL_DIR=SDL" + CCOMMONFLAGS="$CCOMMONFLAGS -DGFXMODULE_SDL" + GFXMODULE=sdl + HAVE_OPENGL=0 + use_library SDL 1.2.8 + } + CHOICE_graphics_OPTION_opengl_TITLE="SDL1 with OpenGL graphics support" + CHOICE_graphics_OPTION_opengl_ACTION='graphics_opengl_action' + CHOICE_graphics_OPTION_opengl_PRECOND="have_library SDL 1.2.8 && have_library opengl" + graphics_opengl_action() { + CFLAGS="$CFLAGS -DGFXMODULE_SDL -DHAVE_OPENGL -DSDL_DIR=SDL" + GFXMODULE=sdl + HAVE_OPENGL=1 + use_library SDL 1.2.8 && use_library opengl + } + CHOICE_graphics_OPTION_sdl2_TITLE="SDL2 with modern graphics support" + CHOICE_graphics_OPTION_sdl2_ACTION='graphics_sdl2_action' + CHOICE_graphics_OPTION_sdl2_PRECOND='have_library SDL2' + graphics_sdl2_action() { + CFLAGS="$CFLAGS -DGFXMODULE_SDL -DSDL_DIR=SDL2" + GFXMODULE=sdl + HAVE_OPENGL=0 + use_library SDL2 + } + if have_library SDL2; then + CHOICE_graphics_DEFAULT=sdl2 + elif have_library opengl; then + CHOICE_graphics_DEFAULT=opengl + else + CHOICE_graphics_DEFAULT=pure + fi + + CHOICE_sound_OPTIONS="mixsdl openal" + CHOICE_sound_TITLE="Sound backend" + CHOICE_sound_OPTION_mixsdl_TITLE="Use MixSDL for sound (internal)" + CHOICE_sound_OPTION_mixsdl_ACTION=sound_mixsdl_action + sound_mixsdl_action() { + SOUNDMODULE=mixsdl + } + CHOICE_sound_OPTION_openal_TITLE="Include OpenAL support (experimental)" + CHOICE_sound_OPTION_openal_PRECOND="have_library openal" + CHOICE_sound_OPTION_openal_ACTION=sound_openal_action + sound_openal_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DHAVE_OPENAL" + SOUNDMODULE=openal + use_library openal + } + CHOICE_sound_DEFAULT=mixsdl + + CHOICE_ovcodec_OPTIONS="standard tremor none" + CHOICE_ovcodec_TITLE="Ogg Vorbis codec" + CHOICE_ovcodec_OPTION_standard_TITLE="Xiph libogg + libvorbis" + CHOICE_ovcodec_OPTION_standard_PRECOND="have_library vorbisfile" + CHOICE_ovcodec_OPTION_standard_ACTION=ovcodec_standard_action + ovcodec_standard_action() { + use_library vorbisfile + OGGVORBIS=vorbisfile + } + CHOICE_ovcodec_OPTION_tremor_TITLE="Tremor (avoids floating point math)" + CHOICE_ovcodec_OPTION_tremor_PRECOND="have_library tremor" + CHOICE_ovcodec_OPTION_tremor_ACTION=ovcodec_tremor_action + ovcodec_tremor_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DOVCODEC_TREMOR" + OGGVORBIS=tremor + use_library tremor + } + CHOICE_ovcodec_OPTION_none_TITLE="No Ogg Vorbis support" + CHOICE_ovcodec_OPTION_none_ACTION=ovcodec_none_action + ovcodec_none_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DOVCODEC_NONE" + OGGVORBIS=none + } + CHOICE_ovcodec_DEFAULT=standard + + CHOICE_mikmod_OPTIONS="internal external" + CHOICE_mikmod_TITLE="Tracker music support" + CHOICE_mikmod_OPTION_internal_TITLE="Included libmikmod" + CHOICE_mikmod_OPTION_internal_ACTION=mikmod_internal_action + mikmod_internal_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DUSE_INTERNAL_MIKMOD" + USE_INTERNAL_MIKMOD=1 + } + CHOICE_mikmod_OPTION_external_TITLE="System libmikmod" + CHOICE_mikmod_OPTION_external_PRECOND="have_library libmikmod" + CHOICE_mikmod_OPTION_external_ACTION=mikmod_external_action + mikmod_external_action() { + USE_INTERNAL_MIKMOD="" + use_library libmikmod + } + CHOICE_mikmod_DEFAULT=internal + + CHOICE_joystick_OPTIONS="enabled disabled" + CHOICE_joystick_TITLE="Joystick support" + CHOICE_joystick_OPTION_enabled_TITLE="enabled" + #CHOICE_joystick_OPTION_enabled_PRECOND="have_symbol SDL_Joystick" + # TODO: Check whether SDL has joystick support. + CHOICE_joystick_OPTION_enabled_ACTION=joystick_enabled_action + joystick_enabled_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DHAVE_JOYSTICK" + } + CHOICE_joystick_OPTION_disabled_TITLE="disabled" + case "$HOST_SYSTEM" in + ARMV5|WINSCW|GCCE) + CHOICE_joystick_DEFAULT=disabled + ;; + *) + CHOICE_joystick_DEFAULT=enabled + ;; + esac + + + CHOICE_netplay_OPTIONS="none full ipv4" + CHOICE_netplay_TITLE="Network Supermelee support" + CHOICE_netplay_OPTION_none_TITLE="disabled" + CHOICE_netplay_OPTION_none_ACTION=netplay_none_action + netplay_none_action() { + NETPLAY="" + } + CHOICE_netplay_OPTION_full_TITLE="IPv4 and IPv6" + CHOICE_netplay_OPTION_full_PRECOND="have_library netlibs" + CHOICE_netplay_OPTION_full_ACTION=netplay_full_action + netplay_full_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DNETPLAY=NETPLAY_FULL" + if [ -n "$MACRO_WIN32" ]; then + LDFLAGS="$LDFLAGS -lws2_32" + fi + NETPLAY="FULL" + use_library netlibs + } + CHOICE_netplay_OPTION_ipv4_TITLE="IPv4; no IPv6" + CHOICE_netplay_OPTION_ipv4_PRECOND="have_library netlibs" + CHOICE_netplay_OPTION_ipv4_ACTION=netplay_ipv4_action + netplay_ipv4_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DNETPLAY=NETPLAY_IPV4" + NETPLAY="IPV4" + use_library netlibs + } + CHOICE_netplay_DEFAULT=full + + CHOICE_ioformat_OPTIONS="stdio stdio_zip" + CHOICE_ioformat_TITLE="Supported file i/o methods" + CHOICE_ioformat_OPTION_stdio_TITLE="Only direct file i/o" + CHOICE_ioformat_OPTION_stdio_zip_TITLE="Direct & .zip file i/o" + CHOICE_ioformat_OPTION_stdio_zip_PRECOND="have_library zlib" + CHOICE_ioformat_OPTION_stdio_zip_ACTION="ioformat_stdio_zip_action" + ioformat_stdio_zip_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DHAVE_ZIP=1" + USE_ZIP_IO=1 + use_library zlib + } + CHOICE_ioformat_DEFAULT=stdio_zip + + CHOICE_accel_OPTIONS="asm plainc" + CHOICE_accel_TITLE="Graphics/Sound optimizations" + CHOICE_accel_OPTION_asm_TITLE="Platform acceleration (asm, etc.)" + CHOICE_accel_OPTION_asm_ACTION="accel_asm_action" + accel_asm_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DUSE_PLATFORM_ACCEL" + USE_PLATFORM_ACCEL=1 + } + CHOICE_accel_OPTION_plainc_TITLE="Only plain C code" + CHOICE_accel_OPTION_plainc_ACTION="accel_plainc_action" + accel_plainc_action() { + USE_PLATFORM_ACCEL=0 + } + CHOICE_accel_DEFAULT=asm + + CHOICE_threadlib_OPTIONS="sdl pthread" + CHOICE_threadlib_TITLE="Thread library" + CHOICE_threadlib_OPTION_sdl_TITLE="SDL-controlled thread library" + CHOICE_threadlib_OPTION_sdl_ACTION="threadlib_sdl_action" + threadlib_sdl_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DTHREADLIB_SDL" + THREADLIB="SDL" + } + CHOICE_threadlib_OPTION_pthread_TITLE="Pthread thread library" + CHOICE_threadlib_OPTION_pthread_PRECOND="have_library pthread" + CHOICE_threadlib_OPTION_pthread_ACTION="threadlib_pthread_action" + threadlib_pthread_action() { + CCOMMONFLAGS="$CCOMMONFLAGS -DTHREADLIB_PTHREAD" + THREADLIB="PTHREAD" + use_library pthread + } + CHOICE_threadlib_DEFAULT=sdl + + MENU_install_path_ITEMS="install_prefix install_bindir install_libdir \ + install_sharedir" + MENU_install_path_TITLE="Installation paths" + MENU_install_path_ITEM_install_prefix_TYPE=INPUT + MENU_install_path_ITEM_install_bindir_TYPE=INPUT + MENU_install_path_ITEM_install_libdir_TYPE=INPUT + MENU_install_path_ITEM_install_sharedir_TYPE=INPUT + + INPUT_install_prefix_DEFAULT="/usr/local/games" + INPUT_install_prefix_TITLE="Installation prefix" + INPUT_install_prefix_VALIDATOR=validate_path + INPUT_install_prefix_ACTION='eval INSTALL_PREFIX=$MENU_install_prefix_VALUE' + + INPUT_install_bindir_DEFAULT='$prefix/bin' + INPUT_install_bindir_TITLE="Location for binaries" + INPUT_install_bindir_VALIDATOR=validate_path + + INPUT_install_libdir_DEFAULT='$prefix/lib' + INPUT_install_libdir_TITLE="Location for non-sharable data" + INPUT_install_libdir_VALIDATOR=validate_path + + INPUT_install_sharedir_DEFAULT='$prefix/share' + INPUT_install_sharedir_TITLE="Location for sharable data" + INPUT_install_sharedir_VALIDATOR=validate_path +} + +uqm_do_config() +{ + # Show the menu and let people set things + do_menu MENU main "$BUILD_WORK/config.state" + echo "Configuration complete." +} + +uqm_process_config() { + menu_process MENU main + + # Set INSTALL_LIBDIR, INSTALL_BINDIR, and INSTALL_SHAREDIR to the specified + # values, replacing '$prefix' to the prefix set. + local prefix + prefix="$INPUT_install_prefix_VALUE" + eval INSTALL_BINDIR="${INPUT_install_bindir_VALUE%/}/" + eval INSTALL_LIBDIR="${INPUT_install_libdir_VALUE%/}/" + eval INSTALL_SHAREDIR="${INPUT_install_sharedir_VALUE%/}/" + + # Set the content dir + CONTENTDIR="${INSTALL_SHAREDIR}uqm/content" + + CCOMMONFLAGS="$CCOMMONFLAGS -I\"$BUILD_WORK\"" + + # Set C++ only flags + # These allow use of C++ without the standard library + CXXFLAGS="$CXXFLAGS -fno-rtti -fno-exceptions -nostdinc++" + + # At this point, all the compiler flags must be set. + CFLAGS="$CFLAGS $CCOMMONFLAGS" + CXXFLAGS="$CXXFLAGS $CCOMMONFLAGS" + CCOMMONFLAGS="" + + # Export the HAVE_ symbols to config_unix.h, using config_unix.h.in + # as template (or config_win.h/config_win.h.in). + SUBSTITUTE_VARS="$HAVE_SYMBOLS CONTENTDIR" + case "$HOST_SYSTEM" in + MINGW32*|CYGWIN*) + SUBSTITUTE_FILES="config_win.h" + ;; + *) + SUBSTITUTE_FILES="config_unix.h" + ;; + esac + substitute_vars SUBSTITUTE_VARS SUBSTITUTE_FILES src "$BUILD_WORK" + + # Make build.vars from build.vars.in, substituting variables. + SUBSTITUTE_VARS="BUILD_SYSTEM HOST_SYSTEM CFLAGS CXXFLAGS LDFLAGS LINK \ + PREPROC_C MKDEP_C COMPILE_C \ + PREPROC_CXX MKDEP_CXX COMPILE_CXX \ + PREPROC_OBJC MKDEP_OBJC COMPILE_OBJC \ + MAKE ECHON SED DEBUG JOYSTICK NETPLAY \ + OGGVORBIS SOUNDMODULE USE_INTERNAL_MIKMOD \ + GFXMODULE HAVE_OPENGL \ + HAVE_GETOPT_LONG HAVE_REGEX_H_FLAG \ + USE_ZIP_IO USE_PLATFORM_ACCEL THREADLIB USE_WINSOCK \ + INSTALL_LIBDIR INSTALL_BINDIR INSTALL_SHAREDIR \ + REZ WINDRES $HAVE_SYMBOLS" + SUBSTITUTE_FILES="build.vars" + substitute_vars SUBSTITUTE_VARS SUBSTITUTE_FILES . "$BUILD_WORK" + + # Make 'uqm' shell script from uqm-wrapper.in, substituting variables. + SUBSTITUTE_VARS="INSTALL_LIBDIR INSTALL_BINDIR INSTALL_SHAREDIR uqm_NAME" + SUBSTITUTE_FILES="uqm-wrapper" + substitute_vars SUBSTITUTE_VARS SUBSTITUTE_FILES build/unix "$BUILD_WORK" +} + +uqm_load_config() +{ + do_menu_load MENU main "$BUILD_WORK/config.state" +} + +uqm_save_config() +{ + do_menu_save MENU main "$BUILD_WORK/config.state" +} + +uqm_pre_build() { + : # Nothing to do +} + +uqm_post_build() { + local TARGET_FILE + local RFORK + eval TARGET_FILE="\$BUILD_WORK/\${${BUILD_PROJECT}_NAME}" + RFORK="src/res/darwin/${BUILD_PROJECT}.r" + + test -f "$TARGET_FILE" || return + + # If run from the command-line on OSX, the Window Manager + # will refuse to recognize the window unless the program has + # a resource fork; so we give it a small one here. When + # run from inside an application package, this step is useless + # (the cp command in the install step implicitly strips off + # the resource fork, in fact) + case "$HOST_SYSTEM" in + Darwin) + $REZ "$RFORK" -o "$TARGET_FILE" + ;; + ARMV5) + cp "$TARGET_FILE" "$BUILD_EPOCROOT/epoc32/release/armv5/urel/" + cd src/symbian + cmd \\/C bldmake bldfiles + cmd \\/C abld build armv5 urel + cd ../.. + ;; + WINSCW) + cp "$TARGET_FILE" "$BUILD_EPOCROOT/epoc32/release/winscw/udeb/" + cd src/symbian + cmd \\/C bldmake bldfiles + cmd \\/C abld build winscw udeb + cd ../.. + ;; + GCCE) + cp "$TARGET_FILE" "$BUILD_EPOCROOT/epoc32/release/armv5/urel/" + cd src/symbian + cmd \\/C bldmake bldfiles + cmd \\/C abld build gcce urel + cd ../.. + ;; + esac +} + +uqm_pre_install() { + : # Nothing to do +} + +uqm_install() { + case "$HOST_SYSTEM" in + Darwin) + uqm_install_osx + ;; + MINGW32*) + echo "No installation procedure available for MinGW." + echo "Read the manual for more information." + ;; + cegcc*) + echo "No installation procedure available for Windows CE." + echo "Read the manual for more information." + ;; + WINSCW) + uqm_install_winscw + ;; + ARMV5) + uqm_install_armv5 + ;; + GCCE) + uqm_install_gcce + ;; + *) + generic_install + ;; + esac +} + +uqm_post_install() { + : # Nothing to do +} + +uqm_install_osx() { + local VERSION HEADERS HEADER HEADER_FILE FRAMEWORK + + VERSION=`head -1 content/version` + + INSTROOT="$BUILD_WORK/The Ur-Quan Masters.app/Contents" + + # Make directory structure + echo "Creating directory structure..." >&2 + mkdirhier "$INSTROOT/MacOS" 0755 + mkdirhier "$INSTROOT/Frameworks" 0755 + mkdirhier "$INSTROOT/Resources/content/addons" 0755 + mkdirhier "$INSTROOT/Resources/content/packages" 0755 + + # Install misc. resources, icons, etc. + echo "Installing miscellaneous resources..." >&2 + $SED "s/@@VERSION@@/$VERSION/g" src/res/darwin/Info.plist > \ + "$INSTROOT/Info.plist" + cp src/res/darwin/PkgInfo "$INSTROOT" + cp "src/res/darwin/The Ur-Quan Masters.icns" "$INSTROOT/Resources" + + # Find Frameworks and copy them into the application. + echo "Copying dependancy Frameworks..." >&2 + HEADERS="Ogg/Ogg.h SDL/SDL.h SDL_image/SDL_image.h Vorbis/vorbisfile.h" + if [ "$uqm_SOUNDMODULE" = openal ]; then + HEADERS="$HEADERS OpenAL/al.h" + fi + for HEADER in $HEADERS; do + HEADER_FILE=`basename $HEADER` + eval FRAMEWORK=`echo '' | \ + $PREPROC_C -D__MACOSX__ -include $HEADER - | \ + awk '(/'$HEADER_FILE'/ && $2 == 1) { print $3; exit }' | \ + $SED 's/.Headers.*$/"/'` + cp -a "$FRAMEWORK" "$INSTROOT/Frameworks" + done + + # Install game content (it should probably make a zipfile) + echo "Creating base content package..." >&2 + cp content/version "$INSTROOT/Resources/content/" + (cd content && \ + find . -type f -not -path '*/CVS*' -not -path '*/.svn*' -not -path '*/addons*' -print | \ + $SED 's/^..//' | zip -X -q -n .ogg -8 -@ uqm-${VERSION}-prv-content.uqm) + mv content/uqm-$VERSION-prv-content.uqm "$INSTROOT/Resources/content/packages" + + echo "Creating voice content package..." >&2 + (cd content/addons && \ + find 3dovoice -type f -not -path '*/CVS*' -not -path '*/.svn*' -print | \ + zip -X -q -n .ogg -8 -@ ../uqm-${VERSION}-prv-voice.uqm) + mv content/uqm-$VERSION-prv-voice.uqm "$INSTROOT/Resources/content/addons" + + echo "Creating 3do music content package..." >&2 + (cd content/addons && \ + find 3domusic -type f -not -path '*/CVS*' -not -path '*/.svn*' -print | \ + zip -X -q -n .ogg -8 -@ ../uqm-${VERSION}-prv-3domusic.uqm) + mv content/uqm-$VERSION-prv-3domusic.uqm "$INSTROOT/Resources/content/addons" + + # Install game binary (and rename it) + echo "Installing executable..." >&2 + cp $uqm_NAME "$INSTROOT/MacOS/The Ur-Quan Masters" +} + +uqm_install_winscw() { + local PRIVATE_DIR + + PRIVATE_DIR="$BUILD_EPOCROOT/epoc32/winscw/c/private/A000A0C3" + + uqm_create_symbian_content_package + + echo "Creating directory structure to $PRIVATE_DIR ..." + mkdir "$PRIVATE_DIR" + mkdir "$PRIVATE_DIR/content" + mkdir "$PRIVATE_DIR/content/packages" + mkdir "$PRIVATE_DIR/userdata" + + echo "Copying data to $PRIVATE_DIR ..." + cp content/version "$PRIVATE_DIR/content" + cp content.uqm "$PRIVATE_DIR/content/packages" + cp src/symbian/uqm.cfg "$PRIVATE_DIR/userdata" +} + +uqm_install_armv5() { + uqm_create_symbian_content_package + + cd src/symbian + cmd \\/C makekeys -cert -expdays 9999 -password asdfgh -len 2048 -dname "CN=UQM OR=Ur-Quan Masters CO=FI" uqm.key uqm.cer + cmd \\/C makesis uqm-armv5.pkg uqm.sis + cmd \\/C signsis -v uqm.sis uqm.sisx uqm.cer uqm.key asdfgh + mv uqm.sisx ../.. + cd ../.. +} + +uqm_install_gcce() { + uqm_create_symbian_content_package + + cd src/symbian + cmd \\/C makekeys -cert -expdays 9999 -password asdfgh -len 2048 -dname "CN=UQM OR=Ur-Quan Masters CO=FI" uqm.key uqm.cer + cmd \\/C makesis uqm-gcce.pkg uqm.sis + cmd \\/C signsis -v uqm.sis uqm.sisx uqm.cer uqm.key asdfgh + mv uqm.sisx ../.. + cd ../.. +} + +uqm_create_symbian_content_package() { + if [ -e "content.uqm" ]; then + echo "Content package already exists, skipping" + return + fi + + local ANIFILE ANIFILES DNAME ESC_DNAME FONTDIR FONTDIRS FONTFILES + + echo "Building temporary content directory..." + cd content + find . -type f -not -path '*/CVS*' -not -path '*/.svn*' -not -path './addons*' -not -name "version" -not -name '*.png' -not -name '*.ani' -not -name '*.sml' -not -name '*.med' -not -name '*.mid' -not -name '*.big' >../content.lst + tar cf ../tmp1.tar -T ../content.lst + rm ../content.lst + mkdir ../tmpcontent + cd ../tmpcontent + tar xf ../tmp1.tar + rm ../tmp1.tar + cd ../content + + echo "Packing ani files..." + ANIFILES=`find . -regex ".*\(sml\|med\|mid\|big\|ani\)$"` + for ANIFILE in $ANIFILES; do + DNAME=`dirname $ANIFILE`/ + ESC_DNAME=`echo $DNAME|sed "s/\//\\\\\\\\\//g"` + mkdirhier ../tmpcontent/$DNAME 0755 + zip -q -j -0 ../tmpcontent/$ANIFILE $ANIFILE `cat $ANIFILE|cut -d " " -f 1|sed s/^/$ESC_DNAME/` + done + + echo "Packing font files..." + FONTDIRS=`find . -name '*.fon'` + for FONTDIR in $FONTDIRS; do + FONTFILES=`find $FONTDIR -name '*.png'|sort -t. +2.4 -n` + zip -q -j -0 ../tmpcontent/$FONTDIR $FONTFILES + done + + cd ../tmpcontent + echo "Building content package..." + zip -q -r ../content.uqm . + + cd .. + echo "Removing temporary content directory..." + rm -rf tmpcontent +} + +uqm_clean() { + case "$HOST_SYSTEM" in + MINGW32*|CYGWIN*) + rm -f "$BUILD_WORK/config_win.h" + ;; + ARMV5|GCCE) + local TARGET_FILE + eval TARGET_FILE="\$BUILD_WORK/\${${BUILD_PROJECT}_NAME}" + + rm -f "$BUILD_WORK/config_unix.h" + rm -f "$BUILD_EPOCROOT/epoc32/release/armv5/urel/$TARGET_FILE" + rm -f $TARGET_FILE uqm.sisx content.uqm + + cd src/symbian + cmd \\/C abld reallyclean + cmd \\/C bldmake clean + rm -f uqm.sis uqm.key uqm.cer + cd ../.. + ;; + WINSCW) + local TARGET_FILE + eval TARGET_FILE="\$BUILD_WORK/\${${BUILD_PROJECT}_NAME}" + + rm -f "$BUILD_WORK/config_unix.h" + rm -f "$BUILD_EPOCROOT/epoc32/release/winscw/udeb/$TARGET_FILE" + rm -f $TARGET_FILE content.uqm + + cd src/symbian + cmd \\/C abld reallyclean + cmd \\/C bldmake clean + cd ../.. + ;; + *) + rm -f "$BUILD_WORK/config_unix.h" + ;; + esac +} + + diff --git a/build/unix/build.docs b/build/unix/build.docs new file mode 100644 index 0000000..d24620b --- /dev/null +++ b/build/unix/build.docs @@ -0,0 +1,205 @@ +I've made this build system as a replacement for autoconf, autoheader, +automake, and aclocal as I found them to be too limiting and too slow. +This build system is not as complete as the auto* tools, but it's very +easy to extend. + +Some of the most important differences between this system and autoconf: +- it has a menu-driven configuration +- when compiling, the current directory will never change +- the object files are stored in a seperate tree from the source files, + leaving the latter clean, and easier grep-able. +- multiple object trees can be used, so you can have for instance a + debugging tree and a release tree side by side. +- it builds faster, mostly because libtool isn't used. + + +The files +--------- + +These are the files in the directory with the build script. +Of these files only build.config should be modified for a specific build. +For unknown dependencies, additions to config_proginfo_build or +config_proginfo_host might need to be made. The other files should not +be modified. +Only build.sh is to be called directly. + +ansi ansi colour definitions. +build.config configuration options for the program to build. + It contains the description of the configuration + menu, and specifies the dependencies. + The format of the menu description is listed briefly + below. +build.sh the sh script that is to be called for configuration, + building, and installation. +build_functions auxiliary functions to build.sh for building. +config_functions auxiliary functions to build.sh for configuration. +config_proginfo_build contains descriptions of dependencies for the + system where the code is being built. + The information in this file is used in particular + for detecting if those libraries and other external + programs are present. +config_proginfo_host contains descriptions of dependencies for the + system where the software will eventually be run. + The information in this file is used in particular + for detecting if those libraries and other external + programs are present. +menu_functions auxiliary functions to build.sh for menus. + + +The menu (from build.config) +---------------------------- + +There are three types of menu items. + +- Type MENU + A menu with menu items. + - Variables: + - MENU_${NAME}_TITLE + The title of the menu. + - MENU_${NAME}_TEXT (optional) + The text to show with the menu. + - MENU_${NAME}_ITEMS + The names of the menu items (space-seperated). + - MENU_${NAME}_ITEM_${ITEMNAME}_TYPE + The type of a menu item. +- Type CHOICE: + A choice between several options. + - Variables: + - CHOICE_${NAME}_TITLE + The title of the choice menu. + - CHOICE_${NAME}_TEXT (optional) + The text to show with the choice menu. + - CHOICE_${NAME}_OPTIONS + The names of the options (space-seperated). + - CHOICE_${NAME}_OPTION_${OPTIONNAME}_TITLE + The title of a menu option. + - CHOICE_${NAME}_OPTION_${OPTIONNAME}_ACTION + A command to be evaluated if this option is used. + - CHOICE_${NAME}_OPTION_${OPTIONNAME}_VALID (set by the config program) + 0 if the choice has been verified to be a valid choice + 1 if the choice has been verified to be not a valid choice + <empty> if the choice hasn't been verified to be valid + - CHOICE_${NAME}_DEFAULT (optional) + The default choice. + - CHOICE_${NAME}_VALUE (set by the config program) + The current choice. +- Type INPUT: + A string that is user-definable. + - Variables: + - INPUT_${NAME}_TITLE + The title of the input field. + - INPUT_${NAME}_TEXT (optional) + The text to show with the input field. + - INPUT_${NAME}_VALIDATOR (optional) + A function to call after the user supplied a new value which + checks if the value is allowed. It should accept the new value as + an argument, and return 1 if the value is not allowed, or return 0 + and output the (possibly modified) value, to accept it. + - INPUT_${NAME}_DEFAULT (optional) + The default value. + - INPUT_${NAME}_VALUE (set by the config program) + The current value. + - INPUT_${NAME}_OLD_VALUE (set by the config program) + The value as it was at the start of the config program. +- Type CHECK: + An option that can either be on or off, like a checkbox. + - Variables: + - CHECK_${NAME}_TITLE + The title of the input field. + - CHECK_${NAME}_DEFAULT (optional) + The default value, either 'CHECKED' or 'UNCHECKED'. + - CHECK_${NAME}_VALUE (set by the config program) + The current value, either 'CHECKED' or 'UNCHECKED'. + - CHECK_${NAME}_FIXED (optional) + A string that evaluates to 0 if this checkbox may not be changed. + + + +Program info (from config_proginfo_build) +----------------------------------------- + +Information about programs used should be supplied in the following form: + - PROG_${PROGRAM}_NAME + A string describing the program. + - PROG_${PROGRAM}_FILE + A string that evaluates to the executable that should be present if + this program is used. + - PROG_${PROGRAM}_ACTION (optional) + A command to be executed if this program is used, after the user is + done configuring. + - PROG_${PROGRAM}_DETECT (optional) + A command to be executed which should return 0 if the program is present + on the system, 1 if it is not present, or 2 to fallback to the default + detection. If no detect function was set, or it returned 2, 'type' is + used to check for the program in the path. + This command may include a shell command that modifies any of the + variables PROG_${PROGRAM}_FILE, PROG_${PROGRAM}_ACTION, or + PROG_${PROGRAM}_VERSION. + - PROG_${LIB}_DEPEND_DETECT_BIN (optional) + A list of space-separated binaries the detection of this program + depends on. + - PROG_${LIB}_DEPEND_DETECT_LIB (optional) + A list of space-separated libraries the detection of this program + depends on. + - PROG_${PROGRAM}_VERSION (optional) + A string that evaluates to the version of the executable that is + present, if it is present. + - PROG_${PROGRAM}_PRESENT (set by the configuration program) + 0 if the program has been verified to be present + 1 if the program has been verified to be not present + <empty> if presence of the program hasn't been verified + +Information about build tools in general (say "a C compiler"), where you're +not interested in what program is actually called, should be supplied in +the following corm: + - BUILDTOOL_${TOOL}_NAME + A string describing the build tool. + - BUILDTOOL_${TOOL}_COMMAND + The command, with arguments, that is to be executed to run this tool. + - BUILDTOOL_${TOOL}_DEPEND + A whitespace separated list of programs (as described above) + that this tool depends on. + - BUILDTOOL_${TOOL}_PRESENT (set by the configuration program) + 0 if the tool has been verified to be present + 1 if the tool has been verified to be not present + <empty> if presence of the tool hasn't been verified +Each tool described, once detected, will be available through the environment +variable with the name as specified in $TOOL. + + +Library info (from config_proginfo_host) +----------------------------------------- + +Information about libraries used should be supplied in the following form: + - LIB_${LIB}_NAME + A string describing the program. + - LIB_${LIB}_CFLAGS + A string which evaluates to the string to add to CFLAGS if this library + is used. + - LIB_${LIB}_LDLAGS + A string which evaluates to the string to add to LDLAGS if this library + is used. + - PROG_${LIB}_DETECT (optional) + A command to be executed which should return 0 if the library is present + on the system, 1 if it is not present, or 2 to fallback to the default + detection. If no detect function was set, or it returned 2, + an attempt is made to compile and link an empty C program with + the flags as in LIB_${LIB}_CFLAGS and LIB_${LIB}_LDFLAGS. + This command may include a shell command that modifies any of the + variables PROG_${LIB}_CFLAGS, PROG_${LIB}_LDFLAGS, or + PROG_${LIB}_VERSION. + - LIB_${LIB}_DEPEND_DETECT_BIN (optional) + A list of space-separated binaries the detection of this library depends + on. + - LIB_${LIB}_DEPEND_DETECT_LIB (optional) + A list of space-separated libraries the detection of this library depends + on. + - LIB_${LIB}_VERSION (optional) + A string that evaluates to the version of the library that is + present, if it is present. + - LIB_${LIB}_PRESENT (set by the configuration program) + 0 if the library has been verified to be present + 1 if the library has been verified to be not present + <empty> if presence of the library hasn't been verified + + diff --git a/build/unix/build.sh b/build/unix/build.sh new file mode 100644 index 0000000..002ce6a --- /dev/null +++ b/build/unix/build.sh @@ -0,0 +1,143 @@ +#!/bin/sh +# Build script +# Copyright (c) 2002 Serge van den Boom +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# This file contains functions for the general building procedure. +# You shouldn't need to change this file if your project changes. + +# Read in the functions we need +. build/unix/build_functions + +if [ -z "$BUILD_WORK" ]; then + BUILD_WORK=. + export BUILD_WORK +fi + +# Read in the config settings that affect the build, if present. +# Don't reread for every dir when recursing. +if [ -r "$BUILD_WORK/build.vars" ]; then + . "$BUILD_WORK/build.vars" +fi + +# Read in the Makeproject file +. ./Makeproject + +for VAR in TARGETS "$BUILD_PROJECT_NAME" "$BUILD_PROJECT_OBJS"; do + eval VALUE="\$$VAR" + if [ -z "$VALUE" ]; then + echo "$VAR needs to be defined in the top Makeproject file" + exit 1 + fi +done + +############################################## +### Everything below is parsing user input ### + +TOPDIR="$PWD" +export TOPDIR + +if [ $# -lt 1 ]; then + usage 1>&2 + exit 1; +fi + +# Load the configuration functions +. build/unix/build.config + +BUILD_THREADS="" +for i in "$@"; do + shift + if [ "`printf "%s" "$i" | cut -c1-2`" = "-j" ]; then + num="`printf "%s" "$i" | cut -c3-`" + if [ -z "$num" ] || [ "$num" -gt 0 ] 2>/dev/null; then + BUILD_THREADS="-j$num" + else + usage 1>&2 + exit 1 + fi + else + set -- "$@" "$i" + fi +done + +case "$1" in + cleanall) + build_cleanall + exit $? + ;; + distclean) + build_distclean + exit $? + ;; +esac + +unset TARGET +for TEMP in $TARGETS; do + if [ "$1" = "$TEMP" ]; then + TARGET="$1" + break + fi +done +if [ -z "$TARGET" ]; then + echo "Invalid target; choose one from:" + echo " $TARGETS" + exit 1 +fi +BUILD_PROJECT="$TARGET" +export TARGET BUILD_PROJECT ECHON +export PREPROC_C MKDEP_C COMPILE_C PREPROC_CXX MKDEP_CXX COMPILE_CXX PREPROC_OBJC MKDEP_OBJC COMPILE_OBJC WINDRES LINK +export "${BUILD_PROJECT}_CFLAGS" "${BUILD_PROJECT}_CXXFLAGS" "${BUILD_PROJECT}_LDFLAGS" + +# Add trailing / from objs dir +eval ${BUILD_PROJECT}_OBJS=\${${BUILD_PROJECT}_OBJS%/}/ +export "${BUILD_PROJECT}_OBJS" + +if [ $# -lt 2 ]; then + build_check_config + build_check_dependencies + build_compile $BUILD_THREADS + exit $? +fi + +case "$2" in + clean) + build_clean + ;; + config) + build_config + build_process_config + ;; + reprocess_config) + build_reconfig + ;; + depend) + build_check_config + build_depend + ;; + install) + build_check_config + build_check_dependencies + build_check_compile $BUILD_THREADS + build_install + ;; + *) + usage 1>&2 + exit 1; + ;; +esac + + diff --git a/build/unix/build_clean b/build/unix/build_clean new file mode 100644 index 0000000..ffc7440 --- /dev/null +++ b/build/unix/build_clean @@ -0,0 +1,29 @@ +#!/bin/sh + +# Find all the .c, .cpp, .m, and .rc files which are relevant for the project, +# and remove their respective object files in the work directory. + +# Expected to be passed from the environment: +# BUILD_PROJECT - the name of the project +# BUILD_ROOT - The root of the source files. +# BUILD_WORK - The root of the work directory. + +BUILD_ROOT=${BUILD_ROOT%/}/ +BUILD_WORK=${BUILD_WORK%/}/ +eval OBJDIR=\"${BUILD_WORK}\${${BUILD_PROJECT}_OBJS}\" + +. "${BUILD_ROOT}Makeproject" + +build/unix/recurse "$BUILD_PROJECT" "$BUILD_ROOT" | \ + while read TYPE FILE; do + case "$TYPE" in + C|CXX|M|RC) + rm -f -- "${OBJDIR}${REC_PREFIX}$FILE.d" \ + "${OBJDIR}${FILE}.o" + ;; + DIROUT) + rmdir -- "${OBJDIR}${FILE}" 2> /dev/null + ;; + esac +done + diff --git a/build/unix/build_collect b/build/unix/build_collect new file mode 100644 index 0000000..7a5dcb9 --- /dev/null +++ b/build/unix/build_collect @@ -0,0 +1,26 @@ +#!/bin/sh + +# Find all the .c, .cpp, .m, and .rc files which are relevant for the project, +# and map them to the work directory. + +# Expected to be passed from the environment: +# BUILD_PROJECT - the name of the project +# BUILD_ROOT - The root of the source files. +# BUILD_WORK - The root of the work directory. + +BUILD_ROOT=${BUILD_ROOT%/}/ +BUILD_WORK=${BUILD_WORK%/}/ +eval OBJDIR=\"${BUILD_WORK}\${${BUILD_PROJECT}_OBJS}\" + +. "${BUILD_ROOT}Makeproject" +. "${BUILD_WORK}build.vars" + +build/unix/recurse "$BUILD_PROJECT" "$BUILD_ROOT" | \ + while read TYPE FILE; do + case "$TYPE" in + C|CXX|M|RC) + echo "$OBJDIR$FILE" + ;; + esac +done + diff --git a/build/unix/build_functions b/build/unix/build_functions new file mode 100644 index 0000000..5f5d20b --- /dev/null +++ b/build/unix/build_functions @@ -0,0 +1,311 @@ +# Auxiliary functions for build.sh +# Copyright (c) 2002 Serge van den Boom +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +DEPEND_NAME=make.depend + +# Show usage information +usage() { + echo "Main build script" + echo + echo "Syntax:" + echo " ./build.sh [-j[#JOBS]] <target>" + echo " ./build.sh <target> config" + echo " ./build.sh <target> depend" + echo " ./build.sh <target> clean" + echo " ./build.sh [-j[#JOBS]] <target> install" + echo " ./build.sh cleanall" + echo " ./build.sh distclean" + echo + echo "Valid targets:" + for TARGET in $TARGETS; do + echo " $TARGET" + done + echo +} + +escape_string() { + $SED -e s,[\\\'\"\`\ \ \$\&\\\*\\\?\#\!],\\\\\&,g << EOF +$1 +EOF +} + +# Start the configure program. +# $1 = target +build_config() { + set_system + prepare_build_system + config_requirements + prepare_host_system + if [ "$BUILD_SYSTEM" '!=' "$HOST_SYSTEM" ]; then + build_message "Cross-compiling to $HOST_SYSTEM." + fi + eval "${TARGET}_requirements" + eval "${TARGET}_prepare_config" + eval "${TARGET}_load_config" + eval "${TARGET}_do_config" + eval "${TARGET}_save_config" +} + +build_reconfig() { + if [ ! -e "$BUILD_WORK/config.state" ]; then + echo "*** Warning: file 'config.state' not found - using defaults." + fi + + prepare_build_system + config_requirements + prepare_host_system + if [ "$BUILD_SYSTEM" '!=' "$HOST_SYSTEM" ]; then + build_message "Cross-compiling to $HOST_SYSTEM." + fi + eval "${TARGET}_requirements" + eval "${TARGET}_prepare_config" + eval "${TARGET}_load_config" + build_process_config + + echo "Reconfiguring complete..." >&2 +} + +# Process the configuration information +build_process_config() { + eval "${TARGET}_process_config" +} + +# Recursively build dependency index +build_depend() { + local DEPEND_FILE EXTRA_OFILES + + echo "Building file dependency index..." >&2 + + eval mkdir -p "\$BUILD_WORK/\${${BUILD_PROJECT}_OBJS}" + eval DEPEND_FILE="\$BUILD_WORK/\${${BUILD_PROJECT}_OBJS}\$DEPEND_NAME" + + # Remove the old dependency file, if it exists. + # The .tmp file is used to detect interrupted dependency builds. + rm -f -- "$DEPEND_FILE".tmp "$DEPEND_FILE" + + BUILD_ROOT=./ $SH ./build/unix/build_collect > "$DEPEND_FILE".tmp + mv -f -- "$DEPEND_FILE".tmp "$DEPEND_FILE" +} + +# Compile the lot. +# With the depend info set up, we can leave everything to make. +# $1 - additional arguments to pass to make (at the moment just +# an optional -j arg for parallel builds). +build_compile() { + local CFLAGS CXXFLAGS LDFLAGS TARGET_FILE DEPEND_FILE OBJDIR + + eval CFLAGS="\${${BUILD_PROJECT}_CFLAGS}" + eval CXXFLAGS="\${${BUILD_PROJECT}_CXXFLAGS}" + eval LDFLAGS="\${${BUILD_PROJECT}_LDFLAGS}" + eval OBJDIR=\""\$BUILD_WORK/\${${BUILD_PROJECT}_OBJS}"\" + eval TARGET_FILE=\""\$BUILD_WORK/\${${BUILD_PROJECT}_NAME}"\" + DEPEND_FILE=$OBJDIR$DEPEND_NAME + + eval "${TARGET}_pre_build" + + CFLAGS=$CFLAGS CXXFLAGS=$CXXFLAGS LDFLAGS=$LDFLAGS \ + OBJDIR=$OBJDIR \ + BUILD_ROOT= \ + TARGET_FILE=$TARGET_FILE DEPEND_FILE=$DEPEND_FILE \ + SED=$SED \ + $MAKE $1 -f Makefile.build "$TARGET_FILE" + + eval "${TARGET}_post_build" +} + +build_clean() { + local DEPEND_FILE + + BUILD_ROOT=./ $SH ./build/unix/build_clean + + eval DEPEND_FILE="\$BUILD_WORK/\${${BUILD_PROJECT}_OBJS}${DEPEND_NAME}" + rm -f "$DEPEND_FILE" "$BUILD_WORK/build.vars" \ + "$BUILD_WORK/uqm-wrapper" \ + "$BUILD_WORK/config.state" + eval "${TARGET}_clean" +} + +build_cleanall() { + export BUILD_PROJECT + for TARGET in $TARGETS; do + BUILD_PROJECT="$TARGET" + build_clean + done + BUILD_PROJECT="" +} + +build_distclean() { + build_cleanall +} + + +# Description: check if the config files are present and load them. +# If they're not present, remake them. +build_check_config() { + if [ ! -e "$BUILD_WORK/build.vars" ]; then + build_config || exit $? + build_process_config + fi + . "$BUILD_WORK/build.vars" + . "${BUILD_REC_PATH:=./}Makeproject" +} + +# Description: check if the necessary depend file is present, +# if not, build it. +build_check_dependencies() { + eval DEPEND_FILE="\$BUILD_WORK/\${${BUILD_PROJECT}_OBJS}${DEPEND_NAME}" + [ ! -e "$DEPEND_FILE" -o -n "$BUILD_RUN_DEPEND" ] || return + + build_depend || exit $? +} + +# Description: check if the program is compiled, and otherwise compile +# $1 - additional arguments to pass to make (at the moment just +# an optional -j arg for parallel builds). +build_check_compile() { + local NAME + eval NAME="\${${BUILD_PROJECT}_NAME}" + [ ! -e "$NAME" ] || return + + build_compile "$1" || exit $? +} + +# Make a directory path, with mode and owner specified. +# $1 - name of directory path +# $2 - mode of the directories (may be empty) +# $3 - owner of the directories (may be empty) +mkdirhier() { + local REST DIR MODE OWNER + REST="$1" + MODE="$2" + OWNER="$3" + case "$REST" in + /*) + REST="${REST%/}" + DIR="/" + ;; + *) + DIR="" + ;; + esac + case "$REST" in + */) + ;; + *) + REST="${REST}/" + ;; + esac + while [ -n "$REST" ]; do + DIR="$DIR${REST%%/*}" + REST="${REST#*/}" + if [ ! -d "$DIR" ]; then + mkdir "$DIR" + [ -n "$MODE" ] && chmod "$MODE" "$DIR" + [ -n "$OWNER" ] && chown "$OWNER" "$DIR" + fi + DIR="${DIR}/" + done +} + +# Install a file or directory +# $1 - Source file/directory +# $2 - Destination directory/file +# $3 - Mode of destination file/directory +# $4 - Owner of destination file/directory +installsome() { + local SRC DEST MODE OWNDER DESTDIR SRCNAME + SRC="$1" + DEST="$2" + MODE="$3" + OWNDER="$4" + + DESTDIR="${DEST%/*}" + if [ ! -d "$DESTDIR" ]; then + mkdirhier "$DESTDIR" 0755 + fi + SRCNAME="${SRC##*/}" + cp -pr -- "$SRC" "$DEST" + if [ -n "$MODE" ]; then + if [ -d "$DEST" ]; then + chmod -R "$MODE" "${DEST}${SRCNAME}" + else + chmod "$MODE" "$DEST" + fi + fi + if [ -n "$OWNER" ]; then + if [ -d "$DEST" ]; then + chown -R "$OWNER" "${DEST}${SRCNAME}" + else + chown "$OWNER" "$DEST" + fi + fi +} + +# Install the program +build_install() { + eval "${TARGET}_install" +} + +# Generic installation routine +generic_install() { + local SRC DEST MODE OWNER + + eval "${TARGET}_pre_install" + + local LIB LIBS LIBDIR + echo "Installing system-dependent data..." >&2 + eval LIBS="\${${BUILD_PROJECT}_INSTALL_LIBS}" + eval LIBDIR="\${${BUILD_PROJECT}_INSTALL_LIBDIR%/}/" + mkdirhier "$LIBDIR" 0755 + for LIB in $LIBS; do + eval SRC="\${${BUILD_PROJECT}_INSTALL_LIB_${LIB}_SRC%/}" + eval DEST="\$LIBDIR\${${BUILD_PROJECT}_INSTALL_LIB_${LIB}_DEST}" + eval MODE="\${${BUILD_PROJECT}_INSTALL_LIB_${LIB}_MODE}" + eval OWNER="\${${BUILD_PROJECT}_INSTALL_LIB_${LIB}_OWNER}" + installsome "$SRC" "$DEST" "$MODE" "$OWNER" + done + + local SHARE SHARED SHAREDIR + echo "Installing system-independent data..." >&2 + eval SHARED="\${${BUILD_PROJECT}_INSTALL_SHARED}" + eval SHAREDIR="\${${BUILD_PROJECT}_INSTALL_SHAREDIR%/}/" + mkdirhier "$SHAREDIR" 0755 + for SHARE in $SHARED; do + eval SRC="\${${BUILD_PROJECT}_INSTALL_SHARED_${SHARE}_SRC%/}" + eval DEST="\$SHAREDIR\${${BUILD_PROJECT}_INSTALL_SHARED_${SHARE}_DEST}" + eval MODE="\${${BUILD_PROJECT}_INSTALL_SHARED_${SHARE}_MODE}" + eval OWNER="\${${BUILD_PROJECT}_INSTALL_SHARED_${SHARE}_OWNER}" + installsome "$SRC" "$DEST" "$MODE" "$OWNER" + done + + local BINS BINDIR + echo "Installing binaries..." >&2 + eval BINS="\${${BUILD_PROJECT}_INSTALL_BINS}" + eval BINDIR="\${${BUILD_PROJECT}_INSTALL_BINDIR%/}/" + mkdirhier "$BINDIR" 0755 + for BIN in $BINS; do + eval SRC="\${${BUILD_PROJECT}_INSTALL_BIN_${BIN}_SRC%/}" + eval DEST="\$BINDIR\${${BUILD_PROJECT}_INSTALL_BIN_${BIN}_DEST}" + eval MODE="\${${BUILD_PROJECT}_INSTALL_BIN_${BIN}_MODE}" + eval OWNER="\${${BUILD_PROJECT}_INSTALL_BIN_${BIN}_OWNER}" + installsome "$SRC" "$DEST" "$MODE" "$OWNER" + done + + eval "${TARGET}_post_install" +} + + diff --git a/build/unix/config_functions b/build/unix/config_functions new file mode 100644 index 0000000..23adc2d --- /dev/null +++ b/build/unix/config_functions @@ -0,0 +1,1139 @@ +# Auxiliary functions for custom build system +# Copyright (c) 2002 Serge van den Boom +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +BUILDLOG=/dev/null +TEMPFILE="/tmp/build.$$.tmp" +#KEEPTEMPFILES=keeptempfiles + + +# Description: perform a command, and set the exit status to the opposite. +# (true +# Arguments: $1 - the command to run +# rest - arguments to the command +not() { + local CMD + CMD=$1 + shift + "$CMD" "$@" + return "$(($? == 0))" +} + +# Description: prints a command to stdout and then executes it +# Arguments: command with arguments +# Returns: the return value of the command +echo_and_perform() { + cat << EOF +$@ +EOF + "$@" +} + +# Description: Get the contents of a variable with a specific name, +# but don't expand it. (evalVar does expand it) +# Use this instead of 'eval', so that you won't have to +# worry about escaping. +# NB. this function only works on global variables. +# Arguments: $1 - the name of the variable +# Returns: 0 +# Prints: the value of the variable +getVar() { + local RESULT + eval RESULT=\$$1 + cat << EOF +$RESULT +EOF +} + +# Description: Get the contents of a variable with a specific name, +# and expand it. (getVar doesn't expand it) +# Use this instead of 'eval', so that you won't have to +# worry about escaping. +# NB. this function only works on global variables. +# Arguments: $1 - the name of the variable +# Returns: 0 +# Prints: the value of the variable +evalVar() { + local RESULT + eval RESULT=\$$1 + eval RESULT=\""$RESULT"\" + cat << EOF +$RESULT +EOF +} + +# Description: Set the value of a variable with a specific name, +# and expand it. +# Use this instead of 'eval', so that you won't have to +# worry about escaping. +# NB. this function only works on global variables. +# Arguments: $1 - the name of the variable +# $2 - the value to assign to it (will not be expanded) +setVar() { + eval $1=\$2 +} + +# Description: delete the files passed as arguments, unless +# $KEEPTEMPFILES is set. +deleteTempFiles() { + if [ -n "$KEEPTEMPFILES" ]; then + return + fi + + rm -f -- "$@" +} + +# Description: read text from stdin to use as a c file to compile +# Arguments: $1 - CFLAGS to use for compilation (optional) +# $2 - LDFLAGS to use for linking (optional) +# Returns: 0 - if compile successful +# something else - if compile failed +try_compile_c() { + local SYSTEM_FLAGS RESULT + + if [ -z "$COMPILE_C" ]; then + echo "Fatal: Program \$COMPILE_C is not defined!" >&2 + exit 1 + fi + + SYSTEM_FLAGS="$SYSTEM_BUILD_CFLAGS $SYSTEM_BUILD_LDFLAGS $SYSTEM_HOST_CFLAGS $SYSTEM_HOST_LDFLAGS" + cat > "$TEMPFILE.c" + + echo_and_perform $COMPILE_C $SYSTEM_FLAGS $1 "$TEMPFILE.c" \ + -o "$TEMPFILE.c.o" >> "$BUILDLOG" 2>&1 + RESULT=$? + + if [ $RESULT -eq 0 ]; then + echo_and_perform $LINK $SYSTEM_FLAGS $2 "$TEMPFILE.c.o" \ + -o "$TEMPFILE.out" >> "$BUILDLOG" 2>&1 + RESULT=$? + fi + + if [ $RESULT -ne 0 ]; then + echo "Failed program was:" >> "$BUILDLOG" + echo "+++ START $TEMPFILE.c" >> "$BUILDLOG" + cat "$TEMPFILE.c" >> "$BUILDLOG" + echo "+++ END $TEMPFILE.c" >> "$BUILDLOG" + fi + + deleteTempFiles "$TEMPFILE.c $TEMPFILE.c.o $TEMPFILE.out" + + echo >> "$BUILDLOG" + return $RESULT +} + +# Description: read text from stdin to use as a c file to compile +# Arguments: $1 - CFLAGS to use for compilation (optional) +# $2 - LDFLAGS to use for linking (optional) +# Returns: 128 - if compiling or linking failed +# otherwise - exit status of the program +try_compile_and_run_c() { + local SYSTEM_FLAGS RESULT + + if [ -z "$COMPILE_C" ]; then + echo "Fatal: Program \$COMPILE_C is not defined!" >&2 + exit 1 + fi + + SYSTEM_FLAGS="$SYSTEM_BUILD_CFLAGS $SYSTEM_BUILD_LDFLAGS $SYSTEM_HOST_CFLAGS $SYSTEM_HOST_LDFLAGS" + cat > "$TEMPFILE.c" + + echo_and_perform $COMPILE_C $SYSTEM_FLAGS $1 "$TEMPFILE.c" \ + -o "$TEMPFILE.c.o" >> "$BUILDLOG" 2>&1 + RESULT=$? + + if [ $RESULT -eq 0 ]; then + echo_and_perform $LINK $SYSTEM_FLAGS $2 "$TEMPFILE.c.o" \ + -o "$TEMPFILE.out" >> "$BUILDLOG" 2>&1 + RESULT=$? + fi + + if [ $RESULT -eq 0 ]; then + "$TEMPFILE.out" + RESULT=$? + fi + + deleteTempFiles "$TEMPFILE.c $TEMPFILE.c.o $TEMPFILE.out" + + echo >> "$BUILDLOG" + return $RESULT +} + +# Description: Output a message to stderr, unless BUILD_SILENT is set +# Arguments: the message +build_message() { + if [ -z "$BUILD_SILENT" ]; then + cat >&2 << EOF +$@ +EOF + fi +} + +# Description: check if a string is lexicographically before +# another string +# Arguments: $1 - the first string +# $2 - the second string +# Returns: 0 if $1 is lexicographically before $2 +# 1 otherwise +lexlt() { + # The 'test' builtin in some sh shells can't do this. + # To execute the non-builtin 'test' you need the path, and + # that differs per system (/bin/test or /usr/bin/test). + # It says '>=' instead of '<' because expr prints '1' for true, + # and sh uses 0. + return `expr "$1" ">=" "$2"` +} + +# Description: Check if one version is sufficiently new. +# Arguments: $1 - the required version +# $2 - the available version +# Returns: 0 - if $2 is at least as new as $1 +# 1 - if $2 is older than $1, or the two strings don't compare +version_match() { + # To compare the two version strings, the numbers in the version + # compared numerically, and all string parts should be equal. + local REST1 REST2 NUM1 NUM2 STR1 STR2 CHECKNUMS + REST1=$1 + REST2=$2 + CHECKNUMS=0 + + while [ -n "$REST1" -a -n "$REST2" ]; do + NUM1=`$SED -e 's/^\([0-9]*\).*$/\1/' << EOF +$REST1 +EOF +` + NUM2=`$SED -e 's/^\([0-9]*\).*$/\1/' << EOF +$REST2 +EOF +` + REST1=`$SED -e 's/^[0-9]*//' << EOF +$REST1 +EOF +` + REST2=`$SED -e 's/^[0-9]*//' << EOF +$REST2 +EOF +` + if [ "(" -n "$NUM1" -a -z "$NUM2" ")" -o \ + "(" -z "$NUM1" -a -n "$NUM2" ")" ]; then + # Only one of the versions contains a number here. No match. + return 1 + fi + if [ "(" -n "$NUM1" -a -z "$NUM2" ")" -o \ + "(" -z "$NUM1" -a -n "$NUM2" ")" ]; then + # Only one of the versions contains a number here. No match. + return 1 + fi + + if [ "$CHECKNUMS" -eq 0 ]; then + if [ "$NUM1" -gt "$NUM2" ]; then + # Too old. + return 1 + fi + if [ "$NUM1" -lt "$NUM2" ]; then + # A major number is larger. Minor numbers may be smaller. + CHECKNUMS=1 + fi + fi + + STR1=`$SED -e 's/^\([^0-9]*\).*$/\1/' << EOF +$REST1 +EOF +` + STR2=`$SED -e 's/^\([^0-9]*\).*$/\1/' << EOF +$REST2 +EOF +` + REST1=`$SED -e 's/^[^0-9]*//' << EOF +$REST1 +EOF +` + REST2=`$SED -e 's/^[^0-9]*//' << EOF +$REST2 +EOF +` + + if [ "x$STR1" "!=" "x$STR2" ]; then + # String parts don't match + return 1 + fi + done + + if [ -n "$REST1" -o -n "$REST2" ]; then + # One version string contains extra information. No match. + return 1 + fi + + return 0 +} + +# Description: try to detect a list of program dependencies. +# This only makes sure the PROG_xxx_PRESENT flag is set. +# It does not bail out if a dependency is not found. +# This function is called for programs in +# PROG_xxx_DEPEND_DETECT_BIN or LIB_xxx_DEPEND_DETECT_BIN. +# Using have_program in the respective depend functions would +# not save the PRESENT flag, as it is executed in a subshell. +# Arguments: $1 - the list of programs +detect_dependencies_program() { + local PROGS PROG + PROGS=$1 + for PROG in $PROGS; do + have_program "$PROG" + done +} + +# Description: try to detect a list of library dependencies. +# This only makes sure the LIB_xxx_PRESENT flag is set. +# It does not bail out if a dependency is not found. +# This function is called for libraries in +# PROG_xxx_DEPEND_DETECT_LIB or LIB_xxx_DEPEND_DETECT_LIB. +# Using have_library in the respective depend functions would +# not save the PRESENT flag, as it is executed in a subshell. +# Arguments: $1 - the list of libaries +detect_dependencies_library() { + local LIBS LIB + LIBS=$1 + for LIB in $LIBS; do + have_library "$LIB" + done +} + +# Description: check if a program is present in the path or as a built-in +# command. +# Arguments: $1 - The name of the program as it is executed +# Returns: 0 - if the command is found +# 1 - if the command is not found +have_command() { + type "$1" > /dev/null 2>&1 || false + # The '|| false' is because if 'type' does not recognise the + # command, it might return a different value than 1, on some + # shells. +} + +# Description: check if a program is present in the path or as a built-in +# command. +# Arguments: $1 - The name of the program as used in config_proginfo after +# "BIN_" +have_program() { + local PROG TEMP_NAME TEMP_FILE TEMP_VERSION TEMP_PRESENT TEMP_DETECT + local TEMP_DEPEND_DETECT_BIN TEMP_DEPEND_DETECT_LIB + + PROG=$1 + TEMP_NAME=`evalVar "PROG_${PROG}_NAME"` + if [ -z "$TEMP_NAME" ]; then + echo "Fatal: Program '$PROG' is not defined!" >&2 + exit 1 + fi + + TEMP_PRESENT=`getVar "PROG_${PROG}_PRESENT"` + if [ -n "$TEMP_PRESENT" ]; then + return "$TEMP_PRESENT" + fi + + # If a detection method is specified, try that one first. + TEMP_DETECT=`evalVar "PROG_${PROG}_DETECT"` + if [ -n "$TEMP_DETECT" ]; then + TEMP_DEPEND_DETECT_BIN=`evalVar "PROG_${PROG}_DEPEND_DETECT_BIN"` + TEMP_DEPEND_DETECT_LIB=`evalVar "PROG_${PROG}_DEPEND_DETECT_LIB"` + detect_dependencies_program "$TEMP_DEPEND_DETECT_BIN" + detect_dependencies_library "$TEMP_DEPEND_DETECT_LIB" + $TEMP_DETECT + # NB. TEMP_DETECT should make sure PROG_${PROG}_VERSION and + # PROG_${PROG}_FILE are set. + case $? in + 0) # Program found + setVar "PROG_${PROG}_PRESENT" 0 + ;; + 1) # Lib not found + setVar "PROG_${PROG}_PRESENT" 1 + ;; + 2) # Use default detection + ;; + esac + fi + + # If detection via a specified detection method was inconclusive, + # or no detection method was specified, try default detection + # based on whether the command name exists. + TEMP_PRESENT=`getVar "$PROG_${PROG}_PRESENT"` + if [ -z "$TEMP_PRESENT" ]; then + TEMP_FILE=`evalVar "PROG_${PROG}_FILE"` + have_command "${TEMP_FILE%% *}" + if [ $? -eq 0 ]; then + # Program found + setVar "PROG_${PROG}_PRESENT" 0 + fi + fi + + # If detection has yielded no results so far, we're calling it + # "not found". + TEMP_PRESENT=`getVar "PROG_${PROG}_PRESENT"` + if [ -z "$TEMP_PRESENT" ]; then + setVar "PROG_${PROG}_PRESENT" 1 + fi + + TEMP_PRESENT=`getVar "PROG_${PROG}_PRESENT"` + if [ "$TEMP_PRESENT" -eq 1 ]; then + build_message "$TEMP_NAME not found." + return 1 + fi + + # We have found the program. + # Test whether the version is sufficient. + if [ $# -gt 1 ]; then + # Minimum version supplied + TEMP_VERSION=`evalVar "PROG_${PROG}_VERSION"` + if [ -z "$TEMP_VERSION" ]; then + setVar "PROG_${PROG}_PRESENT" 1 + echo "Fatal: Could not determine the version of $TEMP_NAME" >&2 + exit 1 + fi + if not version_match "$2" "$TEMP_VERSION"; then + setVar "PROG_${PROG}_PRESENT" 1 + build_message "Found version $TEMP_VERSION of $TEMP_NAME, \ +but version $2 is required!" + return 1 + fi + setVar "PROG_${PROG}_PRESENT" 0 + build_message "$TEMP_NAME version $TEMP_VERSION found." + return 0 + fi + + setVar "PROG_${PROG}_PRESENT" 0 + build_message "$TEMP_NAME found." + return 0 +} + +# Description: check if a build tool is present, and define the appropriate +# environment variable for it. +# Arguments: $1 - The type of compile tool. One of PREPROC_C, MKDEP_C, +# COMPILE_C, PREPROC_OBJC, MKDEP_OBJC, COMPILE_OBJC, +# and LINK. +have_build_tool() { + local TOOL TEMP_NAME TEMP_PRESENT DEPENDS DEPEND SUCCESS COMMAND + + TOOL=$1 + + TEMP_NAME=`evalVar "BUILDTOOL_${TOOL}_NAME"` + if [ -z "$TEMP_NAME" ]; then + echo "Fatal: Build tool '$TOOL' is not defined!" >&2 + exit 1 + fi + + TEMP_PRESENT=`getVar "BUILDTOOL_${TOOL}_PRESENT"` + if [ -n "$TEMP_PRESENT" ]; then + return "$TEMP_PRESENT" + fi + + SUCCESS=0 + DEPENDS=`getVar "BUILDTOOL_${TOOL}_DEPEND"` + for DEPEND in $DEPENDS; do + if not have_program "$DEPEND"; then + SUCCESS=1 + fi + done + + setVar "BUILDTOOL_${TOOL}_PRESENT" "$SUCCESS" + + COMMAND=`evalVar "BUILDTOOL_${TOOL}_COMMAND"` + # Environment variables in $BUILDTOOL_xxx_COMMAND are expanded. + + if [ $SUCCESS -eq 0 ]; then + build_message "We have a $TEMP_NAME." + setVar "$TOOL" "$COMMAND" + else + build_message "No $TEMP_NAME found." + fi + + return $SUCCESS +} + +have_build_tools_language() { + local LANGUAGE + + LANGUAGE=$1 + + have_build_tool "PREPROC_$LANGUAGE" || return 1 + have_build_tool "MKDEP_$LANGUAGE" || return 1 + have_build_tool "COMPILE_$LANGUAGE" || return 1 + + return 0 +} + + +# Description: check if a library is present on the system +# Arguments: $1 - The name of the library as used in config_proginfo after +# "LIB_" +# $2 - (optional) minimum version required +# Pre: variables LIB_${1}_NAME, LIB_${1}_CFLAGS, and +# LIB_${1}_LDFLAGS are expected to exist. If two arguments are +# supplied, so is LIB_${1}_VERSION. +# Returns: 0 - if the library is found +# 1 - if the library is not found +have_library() { + local LIB TEMP_NAME TEMP_PRESENT TEMP_LDFLAGS TEMP_CFLAGS \ + TEMP_VERSION TEMP_DETECT + local TEMP_DEPEND_DETECT_BIN TEMP_DEPEND_DETECT_LIB + + LIB=$1 + TEMP_NAME=`evalVar "LIB_${LIB}_NAME"` + if [ -z "$TEMP_NAME" ]; then + echo "Fatal: Library '$LIB' is not defined!" >&2 + exit 1 + fi + + TEMP_PRESENT=`getVar "LIB_${LIB}_PRESENT"` + if [ -n "$TEMP_PRESENT" ]; then + return "$TEMP_PRESENT" + fi + + # If a detection method is specified, try that one first. + TEMP_DETECT=`evalVar "LIB_${LIB}_DETECT"` + if [ -n "$TEMP_DETECT" ]; then + TEMP_DEPEND_DETECT_BIN=`evalVar "LIB_${LIB}_DEPEND_DETECT_BIN"` + TEMP_DEPEND_DETECT_LIB=`evalVar "LIB_${LIB}_DEPEND_DETECT_LIB"` + detect_dependencies_program "$TEMP_DEPEND_DETECT_BIN" + detect_dependencies_library "$TEMP_DEPEND_DETECT_LIB" + $TEMP_DETECT + # NB. TEMP_DETECT should make sure PROG_$LIB_VERSION is set. + # return value of $TEMP_DETECT is used below. + case $? in + 0) # Lib found + setVar "LIB_${LIB}_PRESENT" 0 + ;; + 1) # Lib not found + setVar "LIB_${LIB}_PRESENT" 1 + ;; + 2) # Use default detection + ;; + esac + fi + + # If detection via a specified detection method was inconclusive, + # or no detection method was specified, try default detection + # based on whether we can compile against the library. + TEMP_PRESENT=`getVar "LIB_${LIB}_PRESENT"` + if [ -z "$TEMP_PRESENT" ]; then + TEMP_CFLAGS=`evalVar "LIB_${LIB}_CFLAGS"` + TEMP_LDFLAGS=`evalVar "LIB_${LIB}_LDFLAGS"` + + try_compile_c "$CFLAGS $TEMP_CFLAGS" "$LDFLAGS $TEMP_LDFLAGS" << EOF +int main(void) { + return 0; +} +EOF + if [ $? -eq 0 ]; then + # Build successful + setVar "LIB_${LIB}_PRESENT" 0 + fi + fi + + # If detection has yielded no results so far, we're calling it + # "not found". + TEMP_PRESENT=`getVar "LIB_${LIB}_PRESENT"` + if [ -z "$TEMP_PRESENT" ]; then + setVar "LIB_${LIB}_PRESENT" 1 + fi + + TEMP_PRESENT=`getVar "LIB_${LIB}_PRESENT"` + if [ "$TEMP_PRESENT" -eq 1 ]; then + build_message "$TEMP_NAME not found." + return 1 + fi + + # We have found the library. + # Test whether the version is sufficient. + if [ $# -gt 1 ]; then + # Minimum version supplied + TEMP_VERSION=`evalVar "LIB_${LIB}_VERSION"` + if [ -z "$TEMP_VERSION" ]; then + setVar "LIB_${LIB}_PRESENT" 1 + echo "Fatal: Could not determine the version of $TEMP_NAME" >&2 + exit 1 + fi + if not version_match "$2" "$TEMP_VERSION"; then + setVar "LIB_${LIB}_PRESENT" 1 + build_message "Found version $TEMP_VERSION of $TEMP_NAME, \ +but version $2 is required!" + return 1 + fi + setVar "LIB_${LIB}_PRESENT" 0 + build_message "$TEMP_NAME version $TEMP_VERSION found." + return 0 + fi + + setVar "LIB_${LIB}_PRESENT" 0 + build_message "$TEMP_NAME found." + return 0 +} + +# Description: check if a library is present on the system. +# If it is, add the appropriate flags to CFLAGS and LDFLAGS. +# If not, bail out. +# Arguments: $1 - The name of the library as used in config_proginfo after +# "LIB_" +# $2 - (optional) minimum version required +# Pre: variables LIB_${1}_NAME, LIB_${1}_CFLAGS, and +# LIB_${1}_LDFLAGS are expected to exist. If two arguments are +# supplied, so is LIB_${1}_VERSION. +use_library() { + local TEMP_CFLAGS TEMP_LDFLAGS + have_library "$@" + [ $? -eq 0 ] || exit 1 + + TEMP_CFLAGS=`evalVar "LIB_${1}_CFLAGS"` + TEMP_LDFLAGS=`evalVar "LIB_${1}_LDFLAGS"` + CFLAGS="$CFLAGS $TEMP_CFLAGS" + LDFLAGS="$LDFLAGS $TEMP_LDFLAGS" + return 0 +} + +# Description: check if a library are being provided by a framework outside +# of the normal system build process. +# If it is, mark it as found and add appropriate flags +# If not, do nothing. Do not even mark it as not found; it might +# be available by some other means. +# This function is currently specific to macOS builds. +# Arguments: $1 - The name of the library as used in config_proginfo +# $2 - (optional, default $1) the name of the framework +# DEPS_PATH - environment variable that if set specifies where to +# check for the framework. +# Pre: LIB_${1}_NAME is expected to exist. +have_framework() { + local TEMP_LIBNAME LIB LIBVAR FRAMEWORK_PATH + # If we aren't on a Mac, there is no framework + if [[ "x$HOST_SYSTEM" != "xDarwin" ]]; then + return 1 + fi + # If DEPS_PATH was not configured, there is no framework + if [[ -z "$DEPS_PATH" ]]; then + return 1 + fi + LIBVAR=$1 + LIB=$2 + if [[ -z "$2" ]]; then + LIB=$LIBVAR + fi + TEMP_LIBNAME=`evalVar "LIB_${LIBVAR}_NAME"` + FRAMEWORK_PATH="${DEPS_PATH}/${LIB}.framework" + if [[ -d "$FRAMEWORK_PATH" ]]; then + build_message "${TEMP_LIBNAME} found in ${DEPS_PATH}." + setVar "LIB_${LIBVAR}_PRESENT" 0 + setVar "LIB_${LIBVAR}_CFLAGS" "-F${DEPS_PATH} -I${FRAMEWORK_PATH}/Headers" + setVar "LIB_${LIBVAR}_LDFLAGS" "-F${DEPS_PATH} -framework ${LIB}" + return 0 + fi + build_message "${TEMP_LIBNAME} not found in ${DEPS_PATH}." + return 1 +} + +# Description: check if a symbol is defined +# Arguments: $1 - the name of the symbol +# $2 - the C code that does the actual checking +have_symbol_generic() { + local CODE DETECT EXTRA + + DETECT=`evalVar "SYMBOL_${1}_DETECT"` + if [ -n "$DETECT" ]; then + $DETECT + return $? + fi + + EXTRA=`evalVar "SYMBOL_${1}_EXTRA"` + CODE=`evalVar "SYMBOL_${1}_CODE"` + if [ -z "$CODE" ]; then + CODE=$2 + fi + + try_compile_c "$CFLAGS $TEMP_CFLAGS" "$LDFLAGS $TEMP_LDFLAGS" << EOF > /dev/null 2>&1 +#include <sys/types.h> +$EXTRA + +$CODE +EOF +} + +# Description: check if a symbol is defined. +# Arguments: $1 - the name of the symbol +have_symbol() { + local SYMBOL TEMP_PRESENT CODE + SYMBOL=$1 + + TEMP_PRESENT=`getVar "SYMBOL_${SYMBOL}_PRESENT"` + if [ -n "$TEMP_PRESENT" ]; then + return "$TEMP_PRESENT" + fi + + CODE=`cat << EOF +int main(void) { + (void) $SYMBOL; + return 0; +} +EOF +` + + have_symbol_generic "$SYMBOL" "$CODE" + if [ $? -gt 0 ]; then + build_message "Symbol '$SYMBOL' not found." + setVar "SYMBOL_${SYMBOL}_PRESENT" 1 + return 1 + fi + build_message "Symbol '$SYMBOL' found." + setVar "SYMBOL_${SYMBOL}_PRESENT" 0 + return 0 +} + +# Description: check if a type is present. +# Arguments: $1 - the name of the symbol +have_type() { + local TYPE TEMP_PRESENT CODE + TYPE=$1 + + TEMP_PRESENT=`getVar "TYPE_${TYPE}_PRESENT"` + if [ -n "$TEMP_PRESENT" ]; then + return "$TEMP_PRESENT" + fi + + CODE=`cat << EOF +int main(void) { + $TYPE var; + (void) var; + return 0; +} +EOF + ` + + have_symbol_generic "$TYPE" "$CODE" + if [ $? -gt 0 ]; then + build_message "Type '$TYPE' not found." + setVar "TYPE_${TYPE}_PRESENT" 1 + return 1 + fi + build_message "Type '$TYPE' found." + setVar "TYPE_${TYPE}_PRESENT" 0 + return 0 +} + +# Description: check if a symbol is defined. +# sets HAVE_<NAME> accordingly, where <NAME> is the capitalized +# name of the symbol. +# Arguments: $1 - the name of the symbol +define_have_symbol() { + local NAME VALUE DEFNAME + + DEFNAME=`getVar "SYMBOL_${1}_DEFNAME"` + if [ -z "$DEFNAME" ]; then + # Why not "tr [:lower:] [:upper:]"? Because the capital "i" is not + # "I" in Turkish... An alternative would be setting LC_CTYPE to POSIX. + NAME=`$TR "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + << EOF +$1 +EOF + ` + DEFNAME="HAVE_$NAME" + fi + + if have_symbol "$1"; then + add_symbol "$DEFNAME" "#define $DEFNAME" + add_symbol "${DEFNAME}_FLAG" 1 + else + add_symbol "$DEFNAME" "#undef $DEFNAME" + add_symbol "${DEFNAME}_FLAG" 0 + fi +} + +# Description: check if a type is present. +# set HAVE_<NAME> accordingly, where <NAME> is the capitalized +# name of the symbol. +# Arguments: $1 - the name of the symbol +define_have_type() { + local NAME VALUE DEFNAME + + DEFNAME=`getVar "TYPE_${1}_DEFNAME"` + if [ -z "$DEFNAME" ]; then + # Why not "tr [:lower:] [:upper:]"? Because the capital "i" is not + # "I" in Turkish... An alternative would be setting LC_CTYPE to POSIX. + NAME=`$TR "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + << EOF +$1 +EOF + ` + DEFNAME="HAVE_$NAME" + fi + + if have_type "$1"; then + add_symbol "$DEFNAME" "#define $DEFNAME" + add_symbol "${DEFNAME}_FLAG" 1 + else + add_symbol "$DEFNAME" "#undef $DEFNAME" + add_symbol "${DEFNAME}_FLAG" 0 + fi +} + +# Description: check if a header is available. +# Arguments: $1 - the name of the header file +have_header() { + local HEADER NAME EXTRA + HEADER=$1 + + NAME=${HEADER%.h} + EXTRA=`evalVar "HEADER_${NAME}_EXTRA"` + + try_compile_c "$CFLAGS $TEMP_CFLAGS" "$LDFLAGS $TEMP_LDFLAGS" << EOF > /dev/null 2>&1 +$EXTRA +#include <$HEADER> +int main(void) { + return 0; +} +EOF + if [ $? -gt 0 ]; then + build_message "Header '$HEADER' not found." + return 1 + fi + build_message "Header '$HEADER' found." + return 0 +} + +# Description: check if a header is available. +# sets HAVE_<NAME> accordingly, where <NAME> is the capitalized +# name of the header file. "sys/time.h" becomes "SYS_TIME_H". +# Arguments: $1 - the name of the header file +define_have_header() { + local NAME VALUE DEFNAME + + DEFNAME=`getVar "HEADER_${1%.h}_DEFNAME"` + if [ -z "$DEFNAME" ]; then + # Why not "tr [:lower:] [:upper:]"? Because the capital "i" is not + # "I" in Turkish... An alternative would be setting LC_CTYPE to POSIX. + NAME=`$TR "/.abcdefghijklmnopqrstuvwxyz" \ + "__ABCDEFGHIJKLMNOPQRSTUVWXYZ" << EOF +$1 +EOF + ` + DEFNAME="HAVE_$NAME" + fi + + if have_header "$1"; then + add_symbol "$DEFNAME" "#define $DEFNAME" + add_symbol "${DEFNAME}_FLAG" 1 + else + add_symbol "$DEFNAME" "#undef $DEFNAME" + add_symbol "${DEFNAME}_FLAG" 0 + fi +} + +# Description: check if a macro is available. +# Arguments: $1 - the name of the macro +have_macro() { + local MACRO EXTRA + MACRO=$1 + + EXTRA=`evalVar "MACRO_${NAME}_EXTRA"` + + try_compile_c "$CFLAGS $TEMP_CFLAGS" "$LDFLAGS $TEMP_LDFLAGS" << EOF > /dev/null 2>&1 +$EXTRA +#ifndef $MACRO +# error +#endif +int main(void) { + return 0; +} +EOF + if [ $? -gt 0 ]; then + build_message "Preprocessor macro '$MACRO' not found." + return 1 + fi + build_message "Preprocessor macro '$MACRO' found." + return 0 +} + +# Description: check if a macro is defined +# sets MACRO_<NAME> to a non-empty string if the macro with +# the specified name is defined, and to an empty string if it +# is not. +# Arguments: $1 - the name of the symbol +define_have_macro() { + local NAME + + NAME=$1 + + if have_macro "$1"; then + add_symbol "MACRO_$NAME" "1" + else + add_symbol "MACRO_$NAME" "" + fi +} + +# Description: Add a symbol to be replaced by substitute_vars +# $HAVE_SYMBOLS will contain the variable names of all +# symbols added by define_have_symbol and should be passed to +# substitute_vars for the file you want them in. +# Arguments: $1 - the symbol to add +# $2 - the value of the symbol +add_symbol() { + local NAME + + eval NAME="$1" + eval "$NAME"=\"\$2\" + HAVE_SYMBOLS="$HAVE_SYMBOLS $NAME" +} + +check_endianness() { + local ENDIAN + + if [ "$BUILD_SYSTEM" '!=' "$HOST_SYSTEM" ]; then + case "$BUILD_HOST_ENDIAN" in + "") + build_message "Cross-compiling - assuming little-endian host." + ENDIAN=little + ;; + big) + build_message "Cross-compiling for a big-endian host." + ENDIAN=big + ;; + little) + build_message "Cross-compiling for a little-endian host." + ENDIAN=little + ;; + *) + build_message "Bad endianness specified. Use \"little\" or \"big\"" + exit 1 + ;; + esac + else + # Detect endianness + try_compile_and_run_c "$CFLAGS" "$LDFLAGS" << EOF +int main(void) { + int i; + + i = 1; + return *((unsigned char *) &i); +} +EOF + if [ $? -eq 0 ]; then + build_message "Big-endian machine detected." + ENDIAN=big + else + build_message "Little-endian machine detected." + ENDIAN=little + fi + fi + + case "$ENDIAN" in + big) + add_symbol WORDS_BIGENDIAN "#define WORDS_BIGENDIAN" + add_symbol "WORDS_BIGENDIAN_FLAG" 1 + ;; + little) + add_symbol WORDS_BIGENDIAN "#undef WORDS_BIGENDIAN" + add_symbol "WORDS_BIGENDIAN_FLAG" 0 + ;; + esac +} + + +# Description: If pkg-config is installed, check if there's a pkg-config +# entry for some binary dependency. +# If successful, it sets the appropriate BIN_xxx_VERSION. +# Arguments: $1 - The name of the program as it is known in +# config_proginfo after "BIN_" +# $2 - The name of the dependency as it would be known to +# pkg-config. +try_pkgconfig_prog() { + have_program pkgconfig || return 1 + + local PROG PKG_NAME TEMP_NAME + PROG=$1 + PKG_NAME=$2 + + TEMP_NAME=`evalVar "PROG_${PROG}_NAME"` + if [ -z "$TEMP_NAME" ]; then + echo "Fatal: Program '$PROG' is not defined!" >&2 + exit 1 + fi + + if $PROG_pkgconfig_FILE --exists "$PKG_NAME"; then + local TEMP_VERSION + TEMP_VERSION=$($PROG_pkgconfig_FILE --modversion "$PKG_NAME") + setVar "PROG_${PROG}_VERSION" "$TEMP_VERSION" + return 0 + else + return 2 + fi +} + + +# Description: If pkg-config is installed, check if there's a pkg-config +# entry for some dependency. +# If successful, it sets the appropriate LIB_xxx_VERSION, +# LIB_xxx_CFLAGS and LIB_xxx_LDFLAGS. +# Arguments: $1 - The name of the library as it is known in +# config_proginfo after "LIB_" +# $2 - The name of the dependency as it would be known to +# pkg-config. +try_pkgconfig_lib() { + have_program pkgconfig || return 1 + + local LIB PKG_NAME TEMP_NAME + LIB=$1 + PKG_NAME=$2 + + TEMP_NAME=`evalVar "LIB_${LIB}_NAME"` + if [ -z "$TEMP_NAME" ]; then + echo "Fatal: Library '$LIB' is not defined!" >&2 + exit 1 + fi + + if $PROG_pkgconfig_FILE --exists "$PKG_NAME"; then + local TEMP_VERSION TEMP_CFLAGS TEMP_LDFLAGS + TEMP_VERSION=$($PROG_pkgconfig_FILE --modversion "$PKG_NAME") + TEMP_CFLAGS=$($PROG_pkgconfig_FILE --cflags "$PKG_NAME") + TEMP_LDFLAGS=$($PROG_pkgconfig_FILE --libs "$PKG_NAME") + setVar "LIB_${LIB}_VERSION" "$TEMP_VERSION" + setVar "LIB_${LIB}_CFLAGS" "$TEMP_CFLAGS" + setVar "LIB_${LIB}_LDFLAGS" "$TEMP_LDFLAGS" + return 2 # Force testing using the new CFLAGS and LDFLAGS + #return 0 + else + return 2 + fi +} + + +# Description: substitute variables in files. +# Every supplied variable name found between @'s in the +# supplied files, is replaced by its value. +# Arguments: $1 - The name of the variable which contains a list of +# variables to substitute in the files. +# $2 - The name of the variable which contains a list of +# files to substitute variables in. +# If a filename ends on .in, that filename is used as +# source, and the filename without .in as target. +# If a filename doesn't end on .in, that filename is used +# as target, and the filename with .in attached as source. +# $3 - A path to which the input file names are relative +# $4 - A path to which the output file names are relative +substitute_vars() { + local VARS VAR VALUE FILES FILE SRC_PATH DST_PATH + + eval VARS=\"\$$1\" + eval FILES=\"\$$2\" + SRC_PATH="$3" + DST_PATH="$4" + + for VAR in $VARS; do + # Escape all / in VAR so that we can use / as seperator char for sed + eval VALUE=\"\$$VAR\" + VALUE=$(echo "$VALUE" | $SED -e 's,\([\&/]\),\\\1,g') + cat << EOF +s/@${VAR}@/${VALUE}/g +EOF + done > "${TEMPFILE}.sed" + + for FILE in $FILES; do + FILE="${FILE%.in}" + cp -p -- "$SRC_PATH/$FILE".in "$DST_PATH/$FILE" + # The copy is done so that the file modes are equal. + $SED -f "${TEMPFILE}.sed" < "$SRC_PATH/$FILE".in > "$DST_PATH/$FILE" + done + deleteTempFiles "${TEMPFILE}.sed" +} + +# Define the build system type. +set_build_system() { + BUILD_SYSTEM=`uname -s` +} + +# Define the host system type. +set_host_system() { + local UHOST + + if [ -z "$BUILD_HOST" ]; then + HOST_SYSTEM=$BUILD_SYSTEM + else + case "$BUILD_HOST" in + *-*-*) + HOST_SYSTEM="${BUILD_HOST#*-}" + HOST_SYSTEM="${HOST_SYSTEM%-*}" + ;; + esac + + # Use a single capitalization. + # What is used is whatever 'uname -s' would give on such a platform. + case "$BUILD_HOST" in + [Ll][Ii][Nn][Uu][Xx]) + HOST_SYSTEM="Linux" ;; + [Ff][Rr][Ee][Ee][Bb][Ss][Dd]) + HOST_SYSTEM="FreeBSD" ;; + [Oo][Pp][Ee][Nn][Bb][Ss][Dd]) + HOST_SYSTEM="OpenBSD" ;; + [Mm][Ii][Nn][Gg][Ww]|[Mm][Ii][Nn][Gg][Ww]32) + HOST_SYSTEM="MINGW32" ;; + [Cc][Yy][Gg][Ww][Ii][Nn]*) + HOST_SYSTEM="CYGWIN" ;; + [Dd][Aa][Rr][Ww][Ii][Nn]) + HOST_SYSTEM="Darwin" ;; + [Ss][Uu][Nn][Oo][Ss]) + HOST_SYSTEM="SunOS" ;; + [Qq][Nn][Xx]) + HOST_SYSTEM="QNX" ;; + [Cc][Ee][Gg][Cc][Cc]) + HOST_SYSTEM="cegcc" ;; + [Ww][Ii][Nn][Ss][Cc][Ww]) + HOST_SYSTEM="WINSCW" ;; + [Aa][Rr][Mm][Vv]5) + HOST_SYSTEM="ARMV5" ;; + [Gg][Cc][Cc][Ee]) + HOST_SYSTEM="GCCE" ;; + *) + build_message "Warning: host type '$BUILD_HOST' unknown. Using defaults." + ;; + esac + fi + +} + +set_system() { + set_build_system + set_host_system +} + +prepare_build_system() { + # Include information about programs we can detect for the build system. + . build/unix/config_proginfo_build +} + +prepare_host_system() { + # Include information about programs we can detect for the host system. + . build/unix/config_proginfo_host +} + +# Some initialisations +HAVE_SYMBOLS="" + +config_requirements() { + # Requirements for the config program itself + have_program echon || exit 1 + ECHON="$PROG_echon_FILE" + have_program sed || exit 1 + SED="$PROG_sed_FILE" + have_program tr || exit 1 + TR="$PROG_tr_FILE" + have_program make || exit 1 + MAKE="$PROG_make_FILE" +} + diff --git a/build/unix/config_proginfo_build b/build/unix/config_proginfo_build new file mode 100644 index 0000000..b01cf09 --- /dev/null +++ b/build/unix/config_proginfo_build @@ -0,0 +1,336 @@ +# Set information on used programs and libraries +# This file contains the information for the programs that test the +# system on which the software is built. +# Copyright (c) 2002 Serge van den Boom +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +############################################################################## +# System specific build flags # +############################################################################## + + +# CFLAGS +SYSTEM_BUILD_CFLAGS="" + +# CXXFLAGS +SYSTEM_BUILD_CXXFLAGS="" + +# LDFLAGS +SYSTEM_BUILD_LDFLAGS="" + +# Compilers etc. +BUILDTOOL_PREPROC_C_NAME="C preprocessor" +BUILDTOOL_MKDEP_C_NAME="C dependency generator" +BUILDTOOL_COMPILE_C_NAME="C compiler" +BUILDTOOL_PREPROC_CXX_NAME="C++ preprocessor" +BUILDTOOL_MKDEP_CXX_NAME="C++ dependency generator" +BUILDTOOL_COMPILE_CXX_NAME="C++ compiler" +BUILDTOOL_PREPROC_OBJC_NAME="Objective-C preprocessor" +BUILDTOOL_MKDEP_OBJC_NAME="Objective-C dependency generator" +BUILDTOOL_COMPILE_OBJC_NAME="Objective-C compiler" +BUILDTOOL_LINK_NAME="linker" +useGccBuildTools() { + # These strings will be evaluated later. + BUILDTOOL_PREPROC_C_COMMAND="\$PROG_gcc_FILE -E $EXTRA_PLATFORM_GCC_FLAGS_PREPROC_C" + BUILDTOOL_PREPROC_C_DEPEND='gcc' + + BUILDTOOL_MKDEP_C_COMMAND="\$PROG_gcc_FILE -MM $EXTRA_PLATFORM_GCC_FLAGS_MKDEP_C" + BUILDTOOL_MKDEP_C_DEPEND='gcc' + + BUILDTOOL_COMPILE_C_COMMAND="\$PROG_gcc_FILE -c $EXTRA_PLATFORM_GCC_FLAGS_COMPILE_C" + BUILDTOOL_COMPILE_C_DEPEND='gcc' + + BUILDTOOL_PREPROC_CXX_COMMAND="\$PROG_gcc_FILE -E $EXTRA_PLATFORM_GCC_FLAGS_PREPROC_CXX" + BUILDTOOL_PREPROC_CXX_DEPEND='gcc' + + BUILDTOOL_MKDEP_CXX_COMMAND="\$PROG_gcc_FILE -MM $EXTRA_PLATFORM_GCC_FLAGS_MKDEP_CXX" + BUILDTOOL_MKDEP_CXX_DEPEND='gcc' + + BUILDTOOL_COMPILE_CXX_COMMAND="\$PROG_gcc_FILE -c $EXTRA_PLATFORM_GCC_FLAGS_COMPILE_CXX" + BUILDTOOL_COMPILE_CXX_DEPEND='gcc' + + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_gcc_FILE -E $EXTRA_PLATFORM_GCC_FLAGS_PREPROC_OBJC" + BUILDTOOL_PREPROC_OBJC_DEPEND='gcc' + + BUILDTOOL_MKDEP_OBJC_COMMAND="\$PROG_gcc_FILE -MM $EXTRA_PLATFORM_GCC_FLAGS_MKDEP_OBJC" + BUILDTOOL_MKDEP_OBJC_DEPEND='gcc' + + BUILDTOOL_COMPILE_OBJC_COMMAND="\$PROG_gcc_FILE -c $EXTRA_PLATFORM_GCC_FLAGS_COMPILE_OBJC" + BUILDTOOL_COMPILE_OBJC_DEPEND='gcc' + + BUILDTOOL_LINK_COMMAND="\$PROG_gcc_FILE $EXTRA_PLATFORM_GCC_FLAGS_LINK" + BUILDTOOL_LINK_DEPEND='gcc' +} +case "$HOST_SYSTEM" in + Darwin) + EXTRA_PLATFORM_GCC_FLAGS_COMPILE_C='-mmacosx-version-min=10.6 -arch x86_64' + EXTRA_PLATFORM_GCC_FLAGS_COMPILE_OBJC='-mmacosx-version-min=10.6 -arch x86_64' + EXTRA_PLATFORM_GCC_FLAGS_LINK='-mmacosx-version-min=10.6 -arch x86_64' + useGccBuildTools + ;; + WINSCW) + EXTRA_WINSCW_FLAGS_COMPILE="-msgstyle gcc -gccinc -dialect c99 -relax_pointers -wchar_t off -align 4 -warnings on -w nohidevirtual,nounusedexpr -enum int -str pool -exc ms -trigraphs on -nostdinc -d _UNICODE -d __SYMBIAN32__ -d __SERIES60_30__ -d __SERIES60_3X__ -d __CW32__ -d __WINS__ -d __WINSCW__ -d __EXE__ -d __SUPPORT_CPP_EXCEPTIONS__ -I$BUILD_EPOCROOT/epoc32/include -I$BUILD_EPOCROOT/epoc32/include/stdapis -I$BUILD_EPOCROOT/epoc32/include/variant" + EXTRA_WINSCW_FLAGS_LINK='-library -msgstyle gcc -stdlib -noimplib -search' + + BUILDTOOL_PREPROC_C_COMMAND="\$PROG_mwccsym2_FILE -E $EXTRA_WINSCW_FLAGS_COMPILE" + BUILDTOOL_PREPROC_C_DEPEND='mwccsym2' + + BUILDTOOL_MKDEP_C_COMMAND="\$PROG_mwccsym2_FILE -MM -ext .o -gccdep $EXTRA_WINSCW_FLAGS_COMPILE" + BUILDTOOL_MKDEP_C_DEPEND='mwccsym2' + + BUILDTOOL_COMPILE_C_COMMAND="\$PROG_mwccsym2_FILE -c $EXTRA_WINSCW_FLAGS_COMPILE" + BUILDTOOL_COMPILE_C_DEPEND='mwccsym2' + + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_mwccsym2_FILE -E" + BUILDTOOL_PREPROC_OBJC_DEPEND='mwccsym2' + + BUILDTOOL_MKDEP_OBJC_COMMAND="\$PROG_mwccsym2_FILE -MM" + BUILDTOOL_MKDEP_OBJC_DEPEND='mwccsym2' + + BUILDTOOL_COMPILE_OBJC_COMMAND="\$PROG_mwccsym2_FILE -c" + BUILDTOOL_COMPILE_OBJC_DEPEND='mwccsym2' + + BUILDTOOL_LINK_COMMAND="\$PROG_mwldsym2_FILE $EXTRA_WINSCW_FLAGS_LINK" + BUILDTOOL_LINK_DEPEND='mwldsym2' + ;; + ARMV5) + EXTRA_ARMV5_FLAGS_COMPILE='--gnu --apcs //inter --diag_suppress 66,161,611,654,997,1152,1300,1464,1488,6318,6331 --diag_error 1267 --arm --cpu ARM926EJ-S --fpu softvfp --exceptions --exceptions_unwind -D__MARM_INTERWORK__ --enum_is_int -Ono_known_library --fpmode ieee_no_fenv --export_all_vtbl --no_vfe --dllimport_runtime -D_UNICODE -D__SYMBIAN32__ -D__SERIES60_30__ -D__SERIES60_3X__ -D__ARMCC__ -D__EPOC32__ -D__MARM__ -D__EABI__ -D__ARMCC_2__ -D__ARMCC_2_2__ -D__MARM_ARMV5__ -D__SUPPORT_CPP_EXCEPTIONS__ -J$BUILD_EPOCROOT/epoc32/include -J$BUILD_EPOCROOT/epoc32/include/stdapis -J$BUILD_EPOCROOT/epoc32/include/variant --preinclude $BUILD_EPOCROOT/epoc32/include/RVCT2_2/RVCT2_2.h' + EXTRA_ARMV5_FLAGS_LINK='' + + BUILDTOOL_PREPROC_C_COMMAND="\$PROG_armcc_FILE -E $EXTRA_ARMV5_FLAGS_COMPILE" + BUILDTOOL_PREPROC_C_DEPEND='armcc' + + BUILDTOOL_MKDEP_C_COMMAND="\$PROG_armcc_FILE -MM --unix_depend_format $EXTRA_ARMV5_FLAGS_COMPILE" + BUILDTOOL_MKDEP_C_DEPEND='armcc' + + BUILDTOOL_COMPILE_C_COMMAND="\$PROG_armcc_FILE -c $EXTRA_ARMV5_FLAGS_COMPILE" + BUILDTOOL_COMPILE_C_DEPEND='armcc' + + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_armcc_FILE -E" + BUILDTOOL_PREPROC_OBJC_DEPEND='armcc' + + BUILDTOOL_MKDEP_OBJC_COMMAND="\$PROG_armcc_FILE -MM" + BUILDTOOL_MKDEP_OBJC_DEPEND='armcc' + + BUILDTOOL_COMPILE_OBJC_COMMAND="\$PROG_armcc_FILE -c" + BUILDTOOL_COMPILE_OBJC_DEPEND='armcc' + + BUILDTOOL_LINK_COMMAND="\$PROG_armar_FILE $EXTRA_ARMV5_FLAGS_LINK" + BUILDTOOL_LINK_DEPEND='armar' + ;; + GCCE) + EXTRA_GCCE_FLAGS_COMPILE='-Wno-unknown-pragmas -march=armv5t -mapcs -pipe -nostdinc -msoft-float -D_UNICODE -D__GCCE__ -D__SYMBIAN32__ -D__SERIES60_30__ -D__SERIES60_3X__ -D__GCCE__ -D__EPOC32__ -D__MARM__ -D__EABI__ -D__MARM_ARMV5__ -D __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ -x c -include $BUILD_EPOCROOT/EPOC32/INCLUDE/GCCE/GCCE.h -I$BUILD_EPOCROOT/epoc32/include -I$BUILD_EPOCROOT/epoc32/include/stdapis -I$BUILD_EPOCROOT/epoc32/include/variant' + EXTRA_GCCE_FLAGS_LINK='' + + BUILDTOOL_PREPROC_C_COMMAND="\$PROG_gcce_FILE -E $EXTRA_GCCE_FLAGS_COMPILE" + BUILDTOOL_PREPROC_C_DEPEND='gcce' + + BUILDTOOL_MKDEP_C_COMMAND="\$PROG_gcce_FILE -MM $EXTRA_GCCE_FLAGS_COMPILE" + BUILDTOOL_MKDEP_C_DEPEND='gcce' + + BUILDTOOL_COMPILE_C_COMMAND="\$PROG_gcce_FILE -c $EXTRA_GCCE_FLAGS_COMPILE" + BUILDTOOL_COMPILE_C_DEPEND='gcce' + + BUILDTOOL_PREPROC_OBJC_COMMAND="\$PROG_gcce_FILE -E" + BUILDTOOL_PREPROC_OBJC_DEPEND='gcce' + + BUILDTOOL_MKDEP_OBJC_COMMAND="\$PROG_gcce_FILE -MM" + BUILDTOOL_MKDEP_OBJC_DEPEND='gcce' + + BUILDTOOL_COMPILE_OBJC_COMMAND="\$PROG_gcce_FILE -c" + BUILDTOOL_COMPILE_OBJC_DEPEND='gcce' + + BUILDTOOL_LINK_COMMAND="\$PROG_gcce_FILE $EXTRA_GCCE_FLAGS_LINK" + BUILDTOOL_LINK_DEPEND='gcce' + ;; + *) + useGccBuildTools + ;; +esac +case "$HOST_SYSTEM" in + Darwin) + BUILDTOOL_REZ_NAME="MacOS X resource compiler (Rez)" + BUILDTOOL_REZ_COMMAND='$PROG_Rez_FILE' + BUILDTOOL_REZ_DEPEND='Rez' + ;; + MINGW32*|CYGWIN*|cegcc) + BUILDTOOL_WINDRES_NAME="Windows resource linker (windres)" + BUILDTOOL_WINDRES_COMMAND='$PROG_windres_FILE' + BUILDTOOL_WINDRES_DEPEND='windres' + ;; +esac + + +############################################################################## +# Describe the programs (possibly) used: # +############################################################################## + + +### gcc ### +PROG_gcc_NAME="GNU C compiler" +PROG_gcc_FILE="gcc" +PROG_gcc_ACTION="" +PROG_gcc_VERSION='$(gcc --version)' + + +### sed ### +PROG_sed_NAME="Sed stream editor" +PROG_sed_FILE="sed" +PROG_sed_ACTION="" +PROG_sed_VERSION='' + + +### echo -n ### +PROG_echon_NAME="'echo -n' capable echo" +PROG_echon_FILE="" +PROG_echon_ACTION="" +PROG_echon_VERSION='' +PROG_echon_DETECT="echon_detect" +echon_detect() { + local TEST LOCATIONS LOCATION + + # Default echo (probably builtin) + TEST=`echo -n X` + if [ "$TEST" = X ]; then + PROG_echon_FILE="echo -n" + return 0; + fi + + # External echo + LOCATIONS="/bin/ /usr/ucb/" + for LOCATION in $LOCATIONS; do + if [ -x ${LOCATION}echo ]; then + TEST=`${LOCATION}echo -n X` + if [ "$TEST" = X ]; then + PROG_echon_FILE="${LOCATION}echo -n" + return 0; + fi + fi + done + + # Using printf as echo + TEST=`printf %s X` + if [ "$TEST" = X ]; then + PROG_echon_FILE="printf %s" + return 0; + fi + + # No good echo found + return 1 +} + + +### GNU Make ### +PROG_make_NAME="Make" +case "$BUILD_SYSTEM" in + FreeBSD|OpenBSD|SunOS) + PROG_make_FILE="gmake" + ;; + *) + PROG_make_FILE="make" + ;; +esac +PROG_make_ACTION="" +PROG_make_VERSION='' + + +### tr ### +PROG_tr_NAME="tr" +PROG_tr_FILE="tr" +PROG_tr_ACTION="" +PROG_tr_VERSION='' + + +### windres (for Windows) ### +PROG_windres_NAME=windres +PROG_windres_FILE=windres +PROG_windres_ACTION="" +PROG_windres_VERSION='windres --version' + + +### Rez resource compiler (for MacOS X) ### +PROG_Rez_NAME="Rez resource compiler (Apple Developer Tools)" +PROG_Rez_FILE="/usr/bin/Rez" +PROG_Rez_ACTION="" +PROG_Rez_VERSION='' + + +### pkg-config ### +PROG_pkgconfig_NAME="pkg-config" +PROG_pkgconfig_FILE="pkg-config" +PROG_pkgconfig_ACTION="" +PROG_pkgconfig_VERSION='$(pkg-config --version)' + + +### mwccsym2 ### +PROG_mwccsym2_NAME="Nokia CodeWarrior C/C++ Compiler for Windows/x86" +PROG_mwccsym2_FILE="mwccsym2" +PROG_mwccsym2_ACTION="" +PROG_mwccsym2_VERSION='$(mwccsym2 -version)' + + +### mwldsym2 ### +PROG_mwldsym2_NAME="Nokia CodeWarrior Linker for Windows/x86" +PROG_mwldsym2_FILE="mwldsym2" +PROG_mwldsym2_ACTION="" +PROG_mwldsym2_VERSION='$(mwldsym2 -version)' + + +### armcc ### +PROG_armcc_NAME="ARM/Thumb C/C++ Compiler" +PROG_armcc_FILE="armcc" +PROG_armcc_ACTION="" +PROG_armcc_VERSION='$(armcc --vsn)' + + +### armlink ### +PROG_armlink_NAME="ARM Linker" +PROG_armlink_FILE="armlink" +PROG_armlink_ACTION="" +PROG_armlink_VERSION='$(armlink --vsn)' + + +### armar ### +PROG_armar_NAME="ARM Archiver" +PROG_armar_FILE="armar" +PROG_armar_ACTION="" +PROG_armar_VERSION='$(armar --vsn)' + + +### gcce ### +PROG_gcce_NAME="GNU C Compiler (CodeSourcery ARM)" +PROG_gcce_FILE="arm-none-symbianelf-gcc" +PROG_gcce_ACTION="" +PROG_gcce_VERSION='$(arm-none-symbianelf-gcc --version)' + + +### mingw-gcc ### +PROG_mingw_gcc_NAME="GNU C MinGW Cross-compiler" +PROG_mingw_gcc_FILE="i686-pc-mingw32-gcc" +PROG_mingw_gcc_ACTION="" +PROG_mingw_gcc_VERSION='$(i686-pc-mingw32-gcc --version)' + + +############################################################################## +# Describe the libaries (possibly) used: # +############################################################################## + + + +############################################################################## +# Describe the symbols (possibly) used: # +############################################################################## diff --git a/build/unix/config_proginfo_host b/build/unix/config_proginfo_host new file mode 100644 index 0000000..748ffbd --- /dev/null +++ b/build/unix/config_proginfo_host @@ -0,0 +1,356 @@ +# Set information on used programs and libraries +# This file contains the information for the programs that test the +# system on which the software will be run. +# Copyright (c) 2002 Serge van den Boom +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +############################################################################## +# System specific build flags # +############################################################################## + + +# CFLAGS +SYSTEM_HOST_CFLAGS="" + +# LDFLAGS +SYSTEM_HOST_LDFLAGS="" + + +############################################################################## +# Describe the programs (possibly) used: # +############################################################################## + + + +############################################################################## +# Describe the libaries (possibly) used: # +############################################################################## + + +### SDL ### +LIB_SDL_NAME="Simple DirectMedia Layer" +case "$HOST_SYSTEM" in + WINSCW|GCCE) + LIB_SDL_CFLAGS='-I$BUILD_EPOCROOT/epoc32/include/SDL' + LIB_SDL_LDFLAGS='' + LIB_SDL_VERSION='1.2.13' + LIB_SDL_DETECT="true" + ;; + ARMV5) + LIB_SDL_CFLAGS='-J$BUILD_EPOCROOT/epoc32/include/SDL' + LIB_SDL_LDFLAGS='' + LIB_SDL_VERSION='1.2.13' + LIB_SDL_DETECT="true" + ;; + Darwin) + if not have_framework SDL; then + LIB_SDL_DETECT="have_command sdl-config" + LIB_SDL_CFLAGS='$(sdl-config --cflags)' + LIB_SDL_LDFLAGS='$(sdl-config --libs)' + LIB_SDL_VERSION='$(sdl-config --version)' + fi + LIB_SDL_LDFLAGS="$LIB_SDL_LDFLAGS -lobjc -framework Cocoa" + ;; + *) + LIB_SDL_DETECT="have_command sdl-config" + LIB_SDL_CFLAGS='$(sdl-config --cflags)' + LIB_SDL_LDFLAGS='$(sdl-config --libs)' + LIB_SDL_VERSION='$(sdl-config --version)' + ;; +esac + + +### SDL2 ### +LIB_SDL2_NAME="Simple DirectMedia Layer version 2.x" +case "$HOST_SYSTEM" in + WINSCW|GCCE|ARMV5) + LIB_SDL2_DETECT="false" + ;; + Darwin) + if not have_framework SDL2; then + LIB_SDL2_DETECT="have_command sdl2-config" + LIB_SDL2_CFLAGS='$(sdl2-config --cflags)' + LIB_SDL2_LDFLAGS='$(sdl2-config --libs)' + LIB_SDL2_VERSION='$(sdl2-config --version)' + fi + LIB_SDL2_LDFLAGS="$LIB_SDL2_LDFLAGS -lobjc -framework Cocoa" + ;; + *) + LIB_SDL2_DETECT="have_command sdl2-config" + LIB_SDL2_CFLAGS='$(sdl2-config --cflags)' + LIB_SDL2_LDFLAGS='$(sdl2-config --libs)' + LIB_SDL2_VERSION='$(sdl2-config --version)' + ;; +esac + + +### libpng ### +LIB_libpng_NAME="libpng" +# libpng generally integrates with pkg-config, but that also generally +# only matters if we're building against a non-systemwide version. UQM +# should not need to do that. +# +# To link against a static libpng, set LDFLAGS with an appropriate -L +# argument before calling `build.sh uqm config`. +case "$HOST_SYSTEM" in + Darwin) + if not have_framework libpng; then + LIB_libpng_CFLAGS="" + LIB_libpng_LDFLAGS="-lpng" + fi + ;; + *) + LIB_libpng_CFLAGS="" + LIB_libpng_LDFLAGS="-lpng" + ;; +esac + + +### OpenAL ### +LIB_openal_NAME="OpenAL" +LIB_openal_CFLAGS="" +case "$HOST_SYSTEM" in + FreeBSD|OpenBSD) + LIB_openal_LDFLAGS="-L/usr/local/lib -pthread -lopenal" + ;; + MINGW32*|CYGWIN*|cegcc) + LIB_openal_LDFLAGS="-lopenal32" + ;; + Darwin) + LIB_openal_CFLAGS='' + LIB_openal_LDFLAGS="-framework OpenAL" + ;; + *) + LIB_openal_LDFLAGS="-lopenal" + ;; +esac +LIB_openal_VERSION="" +case "$HOST_SYSTEM" in + Darwin) + ## Apple does not ship pkg-config on Mac OSX + ;; + *) + LIB_openal_DETECT="try_pkgconfig_lib openal openal" + LIB_openal_DEPEND_DETECT_BIN="pkgconfig" + ;; +esac + + +### OpenGL ### +LIB_opengl_NAME="OpenGL" +case "$HOST_SYSTEM" in + FreeBSD|OpenBSD) + LIB_opengl_CFLAGS="-I/usr/X11R6/include -D_THREAD_SAFE" + LIB_opengl_LDFLAGS="-L/usr/X11R6/lib -lX11 -lXext -pthread -lGL" + ;; + MINGW32*|CYGWIN*|cegcc) + LIB_opengl_CFLAGS="" + LIB_opengl_LDFLAGS="-lopengl32" + ;; + Darwin) + LIB_opengl_CFLAGS="" + LIB_opengl_LDFLAGS="-framework OpenGL" + ;; + ARMV5|WINSCW|GCCE) + LIB_opengl_DETECT="false" + ;; + *) + LIB_opengl_CFLAGS="" + LIB_opengl_LDFLAGS="-lGL" + ;; +esac +LIB_opengl_VERSION="" + + +### Vorbisfile ### +LIB_vorbisfile_NAME="vorbisfile" +case "$HOST_SYSTEM" in + FreeBSD|OpenBSD) + LIB_vorbisfile_CFLAGS="-I/usr/local/include" + LIB_vorbisfile_LDFLAGS="-L/usr/local/lib -lvorbisfile -lvorbis" + ;; + MINGW32*|CYGWIN*|cegcc) + LIB_vorbisfile_CFLAGS="" + LIB_vorbisfile_LDFLAGS="-lvorbisfile -lvorbis -lm -logg" + ;; + Darwin) + if not have_framework vorbisfile Vorbis; then + LIB_vorbisfile_CFLAGS="-D__MACOSX__" + LIB_vorbisfile_LDFLAGS="-lvorbisfile -lvorbis" + fi + ;; + QNX) + LIB_vorbisfile_CFLAGS="" + LIB_vorbisfile_LDFLAGS="-lvorbisfile -lvorbis -logg -lm" + ;; + *) + LIB_vorbisfile_CFLAGS="" + LIB_vorbisfile_LDFLAGS="-lvorbisfile -lvorbis" + ;; +esac +LIB_vorbisfile_VERSION="" +case "$HOST_SYSTEM" in + ARMV5|WINSCW|GCCE) + LIB_vorbisfile_DETECT="false" + ;; + Darwin) + ## Apple does not ship pkg-config on Mac OSX + ;; + *) + LIB_vorbisfile_DETECT="try_pkgconfig_lib vorbisfile vorbisfile" + LIB_vorbisfile_DEPEND_DETECT_BIN="pkgconfig" + ;; +esac + + +### Tremor ### +LIB_tremor_NAME="tremor" +case "$HOST_SYSTEM" in + FreeBSD|OpenBSD) + LIB_tremor_CFLAGS="-I/usr/local/include" + LIB_tremor_LDFLAGS="-L/usr/local/lib -lvorbisidec" + ;; + Darwin) + if not have_framework tremor Tremor; then + # Assumed values - please let me know if you can verify this. + LIB_tremor_CFLAGS="" + LIB_tremor_LDFLAGS="-framework Tremor" + fi + ;; + ARMV5|WINSCW|GCCE) + LIB_tremor_DETECT="true" + ;; + *) + LIB_tremor_CFLAGS="" + LIB_tremor_LDFLAGS="-lvorbisidec" + ;; +esac +LIB_tremor_VERSION="" + + +### libmikmod ### +LIB_libmikmod_NAME="libmikmod" +case "$HOST_SYSTEM" in + ARMV5|WINSCW|GCCE) + LIB_libmikmod_DETECT="false" + ;; + *) + LIB_libmikmod_DETECT="have_command libmikmod-config" + LIB_libmikmod_CFLAGS="$(libmikmod-config --cflags)" + LIB_libmikmod_LDFLAGS="$(libmikmod-config --libs)" + LIB_libmikmod_VERSION="$(libmikmod-config --version)" + ;; +esac + + +### zlib ### +LIB_zlib_NAME="zlib" +LIB_zlib_CFLAGS="" +case "$HOST_SYSTEM" in + MINGW32*|CYGWIN*|cegcc) + LIB_zlib_LDFLAGS="-lzdll" + ;; + ARMV5|WINSCW|GCCE) + LIB_zlib_LDFLAGS="" + ;; + *) + LIB_zlib_LDFLAGS="-lz" + ;; +esac +LIB_zlib_VERSION="" +case "$HOST_SYSTEM" in + ARMV5|WINSCW|GCCE) + LIB_zlib_DETECT="true" + ;; + Darwin) + ## Apple does not ship pkg-config on Mac OSX + ;; + *) + LIB_zlib_DETECT="try_pkgconfig_lib zlib zlib" + LIB_zlib_DEPEND_DETECT_BIN="pkgconfig" + ;; +esac + + + +### pthread ### +LIB_pthread_NAME="pthread" +case "$HOST_SYSTEM" in + Linux) + LIB_pthread_CFLAGS="" + LIB_pthread_LDFLAGS="" + LIB_pthread_VERSION="" + ;; + FreeBSD|OpenBSD) + LIB_pthread_DETECT="have_command pthread-config" + LIB_pthread_CFLAGS="$(pthread-config --cflags)" + LIB_pthread_LDFLAGS="$(pthread-config --ldflags)" + LIB_pthread_VERSION="$(pthread-config --version)" + ;; + WINSCW|ARMV5|GCCE) + LIB_pthread_DETECT="true" + ;; + *) + LIB_pthread_CFLAGS="" + LIB_pthread_LDFLAGS="-lpthread" + LIB_pthread_VERSION="" + ;; +esac + + +# Additional platform-specific libraries for networking. +LIB_netlibs_NAME="Platform-specific network libraries" +case "$HOST_SYSTEM" in + SunOS) + LIB_netlibs_CFLAGS="" + LIB_netlibs_LDFLAGS="-lsocket" + LIB_netlibs_VERSION="" + ;; + ARMV5|WINSCW|GCCE) + LIB_netlibs_DETECT="false" + ;; +esac + + +############################################################################## +# Describe the symbols (possibly) used: # +############################################################################## + +HEADER_regex_EXTRA="#include <sys/types.h>" + +SYMBOL_readdir_r_EXTRA="#include <dirent.h>" + +SYMBOL_setenv_EXTRA="#include <stdlib.h>" + +SYMBOL_strcasecmp_EXTRA="#include <strings.h>" + +SYMBOL_strcasecmp_DEFNAME="HAVE_STRCASECMP_UQM" + # HAVE_STRCASECMP would conflict with SDL (SDL_config.h). + +SYMBOL_stricmp_EXTRA="#include <string.h>" + +SYMBOL_strupr_EXTRA="#include <string.h>" + +SYMBOL_wchar_t_EXTRA="#include <stddef.h>" + +SYMBOL_wint_t_EXTRA="#include <wchar.h>" + +SYMBOL_iswgraph_EXTRA="#include <wctype.h>" + +SYMBOL_getopt_long_EXTRA="#include <getopt.h>" + + diff --git a/build/unix/make/buildtools-armv5 b/build/unix/make/buildtools-armv5 new file mode 100644 index 0000000..bf73689 --- /dev/null +++ b/build/unix/make/buildtools-armv5 @@ -0,0 +1,17 @@ +# Definitions for build tools for the makefile used by the UQM build system. +# This file defines the build commands for ARM tools. + +include build/unix/make/buildtools-generic + +define act_mkdep_c + $(MKDEP_C) $(CFLAGS) -o "$(@D)/$(<F).o" "$<" --depend "$@" +endef + +define act_mkdep_cxx + $(MKDEP_CXX) $(CXXFLAGS) -o "$(@D)/$(<F).o" "$<" --depend "$@" +endef + +define act_link + $(LINK) --create "$@" $^ $(LDFLAGS) +endef + diff --git a/build/unix/make/buildtools-gcce b/build/unix/make/buildtools-gcce new file mode 100644 index 0000000..2a5b6ca --- /dev/null +++ b/build/unix/make/buildtools-gcce @@ -0,0 +1,8 @@ +# Definitions for build tools for the makefile used by the UQM build system. +# This file defines the build commands for GCCE tools. + +include build/unix/make/buildtools-generic + +define act_link + arm-none-symbianelf-ar cr "$@" $^ $(LDFLAGS) +endef diff --git a/build/unix/make/buildtools-generic b/build/unix/make/buildtools-generic new file mode 100644 index 0000000..b3ea464 --- /dev/null +++ b/build/unix/make/buildtools-generic @@ -0,0 +1,36 @@ +# Definitions for build tools for the makefile used by the UQM build system. +# This file defines the build commands for tools using a gcc-like syntax +# for arguments. + +define act_mkdep_c + $(MKDEP_C) $(CFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@" +endef + +define act_mkdep_cxx + $(MKDEP_CXX) $(CXXFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@" +endef + +define act_mkdep_m + $(MKDEP_OBJC) $(CFLAGS) "$<" -MT "$(@D)/$(<F).o" -MF "$@" +endef + +define act_windres + $(WINDRES) --include-dir $(dir $<) -o "$@" "$<" +endef + +define act_cc + $(COMPILE_C) -o "$@" $(CFLAGS) "$<" +endef + +define act_cxx + $(COMPILE_CXX) -o "$@" $(CXXFLAGS) "$<" +endef + +define act_objcc + $(COMPILE_OBJC) -o "$@" $(CFLAGS) "$<" +endef + +define act_link + $(LINK) -o "$@" $^ $(LDFLAGS) +endef + diff --git a/build/unix/make/buildtools-winscw b/build/unix/make/buildtools-winscw new file mode 100644 index 0000000..4a2b6bc --- /dev/null +++ b/build/unix/make/buildtools-winscw @@ -0,0 +1,19 @@ +# Definitions for build tools for the makefile used by the UQM build system. +# This file defines the build commands for Nokia CodeWarrior tools. + +include build/unix/make/buildtools-generic + +define act_mkdep_c + $(MKDEP_C) $(CFLAGS) "$<" -o "$@.tmp" + @echo -n "$(@D)/" > $@ + @cat "$@.tmp" >> $@ + @rm -f "$@.tmp" +endef + +define act_mkdep_cxx + $(MKDEP_C) $(CXXFLAGS) "$<" -o "$@.tmp" + @echo -n "$(@D)/" > $@ + @cat "$@.tmp" >> $@ + @rm -f "$@.tmp" +endef + diff --git a/build/unix/menu_functions b/build/unix/menu_functions new file mode 100644 index 0000000..8de5ff4 --- /dev/null +++ b/build/unix/menu_functions @@ -0,0 +1,662 @@ +# Auxiliary functions for menu system for custom build system +# Copyright (c) 2002 Serge van den Boom +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +MENU_ITEM_TYPES="MENU CHOICE INPUT CHECK" + +MENU_ITEM_TYPE_MENU_INIT=menu_init_menu +MENU_ITEM_TYPE_MENU_PRINT_VALUE=menu_print_value_menu +MENU_ITEM_TYPE_MENU_HANDLER=menu_handle_menu +MENU_ITEM_TYPE_MENU_SAVE=menu_save_menu +MENU_ITEM_TYPE_MENU_PROCESS=menu_process_menu + +MENU_ITEM_TYPE_CHOICE_INIT=menu_init_choice +MENU_ITEM_TYPE_CHOICE_PRINT_VALUE=menu_print_value_choice +MENU_ITEM_TYPE_CHOICE_HANDLER=menu_handle_choice +MENU_ITEM_TYPE_CHOICE_SAVE=menu_save_choice +MENU_ITEM_TYPE_CHOICE_PROCESS=menu_process_choice + +MENU_ITEM_TYPE_INPUT_INIT=menu_init_input +MENU_ITEM_TYPE_INPUT_PRINT_VALUE=menu_print_value_input +MENU_ITEM_TYPE_INPUT_HANDLER=menu_handle_input +MENU_ITEM_TYPE_INPUT_SAVE=menu_save_input +MENU_ITEM_TYPE_INPUT_PROCESS=menu_process_input + +MENU_ITEM_TYPE_CHECK_INIT=menu_init_check +MENU_ITEM_TYPE_CHECK_PRINT_VALUE=menu_print_value_check +MENU_ITEM_TYPE_CHECK_HANDLER=menu_handle_check +MENU_ITEM_TYPE_CHECK_SAVE=menu_save_check +MENU_ITEM_TYPE_CHECK_PROCESS=menu_process_check + +# Description: Check if a string can be used as a path. +# No checks are done if the path really exists. +# Arguments: $1 - the string to check +# Returns: 0 if the string makes a valid path +# 1 if the string doesn't make a valid path +# Outputs: the path, possibly modified +validate_path() { + if [ "$1" = "/" ]; then + echo "/" + return + fi + cat << EOF +${1%/} +EOF + return 0 +} + +# Description: Initialise a menu, setting unset values to default +# Arguments: $1 - the type of menu item +# $2 - the name of the menu item +menu_init() { + local INIT_FUN + + eval INIT_FUN="\$MENU_ITEM_TYPE_$1_INIT" + "$INIT_FUN" "$2" +} + +# Description: Initialise this menu +# Arguments: $1 - the name of the menu +menu_init_menu() { + local MENU TEMP_ITEMS ITEM TEMP_TYPE + + MENU="$1" + eval TEMP_ITEMS="\$MENU_${MENU}_ITEMS" + for ITEM in $TEMP_ITEMS; do + eval TEMP_TYPE="\$MENU_${MENU}_ITEM_${ITEM}_TYPE" + if [ -z "$TEMP_TYPE" ]; then + echo "Fatal: \$MENU_${MENU}_ITEM_${ITEM}_TYPE is not defined!" >&2 + exit 1 + fi + menu_init "$TEMP_TYPE" "$ITEM" + done +} + +# Description: Check if this choice is available +# Arguments: $1 - the name of the choice menu +# $2 - the name of the choice +# Returns: 0 - if the choice is available +# 1 - if the choice is not available +menu_have_choice() { + local MENU CHOICE TEMP_VALID TEMP_PRECOND + MENU="$1" + CHOICE="$2" + eval TEMP_VALID="\$CHOICE_${MENU}_OPTION_${CHOICE}_VALID" + if [ -n "$TEMP_VALID" ]; then + return "$TEMP_VALID" + fi + eval TEMP_PRECOND="\$CHOICE_${MENU}_OPTION_${CHOICE}_PRECOND" + if [ -z "$TEMP_PRECOND" ] || $TEMP_PRECOND; then + eval "CHOICE_${MENU}_OPTION_${CHOICE}_VALID"=0 + return 0 + fi + eval "CHOICE_${MENU}_OPTION_${CHOICE}_VALID"=1 + return 1 +} + +# Description: Initialise this choice menu +# Arguments: $1 - the name of the choice menu +menu_init_choice() { + local MENU TEMP_VALUE TEMP_DEFAULT TEMP_OPTIONS OPTION TEMP_TITLE + MENU="$1" + eval TEMP_VALUE="\$CHOICE_${MENU}_VALUE" + eval TEMP_DEFAULT="\$CHOICE_${MENU}_DEFAULT" + eval TEMP_OPTIONS="\$CHOICE_${MENU}_OPTIONS" + for OPTION in $TEMP_VALUE $TEMP_DEFAULT $TEMP_OPTIONS; do + if menu_have_choice "$MENU" "$OPTION"; then + eval CHOICE_${MENU}_VALUE="$OPTION" + eval CHOICE_${MENU}_OLD_VALUE="$OPTION" + return + fi + done + eval TEMP_VALUE="\$CHOICE_${MENU}_TITLE" + echo "Error: No option for '$TEMP_VALUE' is available for your system." + exit 1 +} + +# Description: Initialise this input menu +# Arguments: $1 - the name of the input menu +menu_init_input() { + local MENU TEMP_VALUE + MENU="$1" + eval TEMP_VALUE="\$INPUT_${MENU}_VALUE" + if [ -z "$TEMP_VALUE" ]; then + eval TEMP_VALUE="\$INPUT_${MENU}_DEFAULT" + eval INPUT_${MENU}_VALUE="\$TEMP_VALUE" + fi + eval INPUT_${MENU}_OLD_VALUE="\$TEMP_VALUE" +} + +# Description: Initialise this checkbox +# Arguments: $1 - the name of the checkbox +menu_init_check() { + local CHECKBOX TEMP_VALUE TEMP_DEFAULT + CHECKBOX="$1" + + eval TEMP_VALUE="\$CHECK_${CHECKBOX}_VALUE" + eval TEMP_DEFAULT="\$CHECK_${CHECKBOX}_DEFAULT" + + # Make sure the default is either 'CHECKED' or 'UNCHECKED' + case "$TEMP_DEFAULT" in + yes|Yes|YES|checked|Checked|CHECKED|1|true|True|TRUE) + TEMP_DEFAULT=CHECKED + ;; + *) + TEMP_DEFAULT=UNCHECKED + ;; + esac + eval CHECK_${CHECKBOX}_DEFAULT="\$TEMP_DEFAULT" + + if [ -z "$TEMP_VALUE" ]; then + TEMP_VALUE="$TEMP_DEFAULT" + eval CHECK_${CHECKBOX}_VALUE="\$TEMP_DEFAULT" + fi + eval CHECK_${CHECKBOX}_OLD_VALUE="\$TEMP_VALUE" +} + +# Description: Print the string describing the value of a menu item. +# Arguments: $1 - the type of menu item +# $2 - the name of the menu item +# Outputs: The string describing the value of the menu item +menu_print_value() { + local PRINT_VALUE + + eval PRINT_VALUE="\$MENU_ITEM_TYPE_$1_PRINT_VALUE" + "$PRINT_VALUE" "$2" +} + +# Description: Print the string describing the value of this menu +# Arguments: $1 - the name of the menu item +# Outputs: The string describing the value of this menu +menu_print_value_menu() { + echo "[...]" +} + +# Description: Print the string describing the value this choice menu +# Arguments: $1 - the name of the choice menu item +# Outputs: The string describing the value of this choice menu +menu_print_value_choice() { + local TEMP_VALUE TEMP_TITLE + eval TEMP_VALUE="\$CHOICE_$1_VALUE" + eval TEMP_TITLE=\"\$CHOICE_$1_OPTION_${TEMP_VALUE}_TITLE\" + cat << EOF +$TEMP_TITLE +EOF +} + +# Description: Print the value of this input menu +# Arguments: $1 - the name of the input menu item +# Outputs: The value of the given input menu +menu_print_value_input() { + local TEMP_VALUE + eval TEMP_VALUE="\$INPUT_$1_VALUE" + cat << EOF +$TEMP_VALUE +EOF +} + +# Description: Print the value of this checkbox +# Arguments: $1 - the name of the checkbox item +# Outputs: The value of the given checkbox +menu_print_value_check() { + local TEMP_VALUE TEMP_DEFAULT TEMP_FIXED RESULT EXTRA + eval TEMP_VALUE="\$CHECK_$1_VALUE" + eval TEMP_DEFAULT="\$CHECK_$1_DEFAULT" + eval TEMP_FIXED="\$CHECK_$1_FIXED" + + if [ "$TEMP_VALUE" = "CHECKED" ]; then + RESULT="Yes" + else + RESULT="No" + fi + + EXTRA="" + if [ "$TEMP_VALUE" = "$TEMP_DEFAULT" ]; then + EXTRA="default" + fi + + if [ "$TEMP_FIXED" = "TRUE" ]; then + EXTRA="${EXTRA:+$EXTRA, }unchangable" + fi + + RESULT="$RESULT${EXTRA:+ ($EXTRA)}" + echo "$RESULT" +} + +# Description: Print the string describing the value of a menu item. +# Arguments: $1 - the type of menu item +# $2 - the name of the menu item +# Outputs: The string describing the value of the menu item +menu_handle() { + local HANDLER + + eval HANDLER="\$MENU_ITEM_TYPE_$1_HANDLER" + "$HANDLER" "$2" +} + +# Description: Process a menu-type menu item +# Arguments: $1 - The name of the menu +menu_handle_menu() { + local TEMP_ITEMS I CHOICE NUM_ITEMS TEMP_TYPE MENU ITEM TEMP_TITLE \ + TEMP_TEXT + eval TEMP_ITEMS="\$MENU_$1_ITEMS" + eval TEMP_TEXT="\$MENU_$1_TEXT" + + MENU="$1" + while :; do + echo + eval TEMP_TITLE="\$MENU_${MENU}_TITLE" + cat << EOF + $ANSI_BOLD-= $TEMP_TITLE =-$ANSI_NORMAL +EOF + + if [ -n "$TEMP_TEXT" ]; then + cat << EOF +$TEMP_TEXT +EOF + fi + + # Count the number of options + I=0 + for ITEM in $TEMP_ITEMS; do + I=$(($I + 1)) + done + NUM_ITEMS="$I" + + I=0 + for ITEM in $TEMP_ITEMS; do + I=$(($I + 1)) + eval TEMP_TYPE="\$MENU_${MENU}_ITEM_${ITEM}_TYPE" + eval TEMP_TITLE="\$${TEMP_TYPE}_${ITEM}_TITLE" + printf " %${#NUM_ITEMS}i. %-36s %s\n" $I "$TEMP_TITLE" \ + "$(menu_print_value $TEMP_TYPE $ITEM)" + done + + echo + echo "Press a number plus <ENTER> if you want to change something, " + $ECHON "or just <ENTER> if everything is ok: " + read CHOICE + + # Check if the choice was empty + if [ -z "$CHOICE" ]; then + # We're done + return + fi + + # Check if what the user entered was a number + egrep '^[0-9]+$' << EOF > /dev/null +$CHOICE +EOF + if [ $? -ne 0 ]; then + echo "Invalid choice." + continue + fi + + # Check if the number the user entered if valid + if [ "$CHOICE" -lt 1 -o "$CHOICE" -gt "$NUM_ITEMS" ]; then + echo "Invalid choice." + continue + fi + + # Now look up the choice + I=0 + for ITEM in $TEMP_ITEMS; do + I=$(($I + 1)) + if [ "$I" -eq "$CHOICE" ]; then + eval TEMP_TYPE="\$MENU_${MENU}_ITEM_${ITEM}_TYPE" + menu_handle "$TEMP_TYPE" "$ITEM" + break + fi + done + done +} + +# Description: Process a choice-type menu item +# Arguments: $1 - The name of the menu +menu_handle_choice() { + local TEMP_OPTIONS I CHOICE NUM_OPTIONS TEMP_TYPE MENU OPTION \ + TEMP_VALUE TEMP_TITLE SELECTED TEMP_TEXT + eval TEMP_OPTIONS="\$CHOICE_$1_OPTIONS" + eval TEMP_TEXT="\$CHOICE_$1_TEXT" + + MENU="$1" + while :; do + echo + eval TEMP_TITLE="\$CHOICE_${MENU}_TITLE" + cat << EOF + $ANSI_BOLD-= $TEMP_TITLE =-$ANSI_NORMAL +EOF + if [ -n "$TEMP_TEXT" ]; then + cat << EOF +$TEMP_TEXT +EOF + fi + + eval TEMP_VALUE="\$CHOICE_${MENU}_VALUE" + + # Check in advance which options are present, so that that + # is echoed before the menu is printed. + # menu_have_choice caches results. + # Also, count the number of options + I=0 + for OPTION in $TEMP_OPTIONS; do + I=$(($I + 1)) + menu_have_choice "$MENU" "$OPTION" + done + NUM_OPTIONS="$I" + + I=0 + for OPTION in $TEMP_OPTIONS; do + I=$(($I + 1)) + eval TEMP_TITLE="\$CHOICE_${MENU}_OPTION_${OPTION}_TITLE" + if [ "$TEMP_VALUE" = "$OPTION" ]; then + SELECTED="-->" + else + SELECTED=" " + fi + if menu_have_choice "$MENU" "$OPTION"; then + printf " %${#NUM_OPTIONS}i. %s %s\n" "$I" "$SELECTED" \ + "$TEMP_TITLE" + else + printf " %-${#NUM_OPTIONS}s %s (N/A) %s\n" "-" \ + "$SELECTED" "$TEMP_TITLE" + fi + done + + echo + echo "Select the option you want by typing a number plus <ENTER>" + $ECHON "or just <ENTER> if everything is ok: " + read CHOICE + echo + + # Check if the choice was empty + if [ -z "$CHOICE" ]; then + # We're done + return + fi + + # Check if what the user entered was a number + egrep '^[0-9]+$' << EOF > /dev/null +$CHOICE +EOF + if [ $? -ne 0 ]; then + echo "Invalid choice." + continue + fi + + # Check if the number the user entered if valid + if [ "$CHOICE" -lt 1 -o "$CHOICE" -gt "$NUM_ITEMS" ]; then + echo "Invalid choice." + continue + fi + + # Now look up the choice + I=0 + for OPTION in $TEMP_OPTIONS; do + I=$(($I + 1)) + if [ "$I" -eq "$CHOICE" ]; then + if menu_have_choice "$MENU" "$OPTION"; then + eval "CHOICE_${MENU}_VALUE"="$OPTION" + return + else + echo "That option is unavailable on your system." + fi + fi + done + done +} + +# Description: Process an input-type menu item +# Arguments: $1 - The name of the menu +menu_handle_input() { + local ITEM TEMP_TITLE TEMP_VALUE TEMP_DEFAULT NEW_VALUE \ + TEMP_VALIDATOR TEMP_TEXT + + ITEM="$1" + eval TEMP_TITLE="\$INPUT_${ITEM}_TITLE" + eval TEMP_TEXT="\$INPUT_${ITEM}_TEXT" + + while :; do + echo + cat << EOF + $ANSI_BOLD-= $TEMP_TITLE =-$ANSI_NORMAL +EOF + + if [ -n "$TEMP_TEXT" ]; then + cat << EOF +$TEMP_TEXT +EOF + fi + + eval TEMP_VALUE="\$INPUT_${ITEM}_VALUE" + eval TEMP_DEFAULT="\$INPUT_${ITEM}_DEFAULT" + echo " Default value: $TEMP_DEFAULT" + echo " Current value: $TEMP_VALUE" + $ECHON " New value: " + read NEW_VALUE + + # If no new value is entered, keep the old one. + if [ -z "$NEW_VALUE" ]; then + return + fi + + # If a validator function is present, validate the new value + eval TEMP_VALIDATOR="\$INPUT_${ITEM}_VALIDATOR" + if [ -n "$TEMP_VALIDATOR" ]; then + NEW_VALUE=`$TEMP_VALIDATOR "$NEW_VALUE"` + if [ $? -ne 0 ]; then + echo "Invalid value" + continue + fi + fi + break + done + eval "INPUT_${ITEM}_VALUE"=\"\$NEW_VALUE\" +} + +# Description: Process an checkbox-type menu item +# Arguments: $1 - The name of the checkbox +menu_handle_check() { + local CHECKBOX OLD_VALUE NEW_VALUE TEMP_FIXED + + CHECKBOX="$1" + eval TEMP_FIXED="\$CHECK_${CHECKBOX}_FIXED" + + if [ "$TEMP_FIXED" = "TRUE" ]; then + # Unchangable + return; + fi + + eval OLD_VALUE="\$CHECK_${CHECKBOX}_VALUE" + if [ "$OLD_VALUE" = "CHECKED" ]; then + NEW_VALUE="UNCHECKED" + else + NEW_VALUE="CHECKED" + fi + eval "CHECK_${CHECKBOX}_VALUE"=\"\$NEW_VALUE\" +} + +# Description: echo the current state of a menu item in a form that can be +# executed to restore the state. +# Arguments: $1 - the type of menu item +# $2 - the name of the menu item +# Outputs: The string describing the value of the menu item +menu_save() { + local SAVE_FUN + eval SAVE_FUN="\$MENU_ITEM_TYPE_$1_SAVE" + "$SAVE_FUN" "$2" +} + +# Description: echo the current state of a menu in a form that can be +# executed to restore the state. +# Arguments: $1 - the name of the menu +# Outputs: The string describing the value of the menu +menu_save_menu() { + local MENU TEMP_ITEMS ITEM TEMP_TYPE + + MENU="$1" + eval TEMP_ITEMS="\$MENU_${MENU}_ITEMS" + for ITEM in $TEMP_ITEMS; do + eval TEMP_TYPE="\$MENU_${MENU}_ITEM_${ITEM}_TYPE" + menu_save "$TEMP_TYPE" "$ITEM" + done +} + +# Description: echo the current state of a choice menu in a form that can be +# executed to restore the state. +# Arguments: $1 - the name of the choice menu +# Outputs: The string describing the value of the choice menu +menu_save_choice() { + local MENU TEMP_VALUE + MENU="$1" + eval TEMP_VALUE="\$CHOICE_${MENU}_VALUE" + cat << EOF +CHOICE_${MENU}_VALUE='$TEMP_VALUE' +EOF +} + +# Description: echo the current state of an input menu in a form that can be +# executed to restore the state. +# Arguments: $1 - the name of the input menu +# Outputs: The string describing the value of the input menu +menu_save_input() { + local MENU TEMP_VALUE + MENU="$1" + eval TEMP_VALUE="\$INPUT_${MENU}_VALUE" + cat << EOF +INPUT_${MENU}_VALUE='$TEMP_VALUE' +EOF +} + +# Description: echo the current state of an check box in a form that can be +# executed to restore the state. +# Arguments: $1 - the name of the checkbox +# Outputs: The string describing the value of the checkbox +menu_save_check() { + local CHECKBOX TEMP_VALUE + CHECKBOX="$1" + eval TEMP_VALUE="\$CHECK_${CHECKBOX}_VALUE" + cat << EOF +CHECK_${CHECKBOX}_VALUE='$TEMP_VALUE' +EOF +} + +# Description: Perform the actions associated with the choice made for a +# menu items. +# Arguments: $1 - the type of menu item +# $2 - the name of the menu item +menu_process() { + local PROCESS_FUN + eval PROCESS_FUN="\$MENU_ITEM_TYPE_$1_PROCESS" + "$PROCESS_FUN" "$2" +} + +# Description: Perform the actions associated with the chosen menu items +# for a menu. +# Arguments: $1 - the name of the menu +menu_process_menu() { + local MENU TEMP_ITEMS ITEM TEMP_TYPE + + MENU="$1" + eval TEMP_ITEMS="\$MENU_${MENU}_ITEMS" + for ITEM in $TEMP_ITEMS; do + eval TEMP_TYPE="\$MENU_${MENU}_ITEM_${ITEM}_TYPE" + menu_process "$TEMP_TYPE" "$ITEM" + done +} + +# Description: Perform the actions associated with the choice made for +# a choice menu. +# Arguments: $1 - the name of the choice menu +menu_process_choice() { + local MENU TEMP_VALUE TEMP_ACTION + MENU="$1" + eval TEMP_VALUE="\$CHOICE_${MENU}_VALUE" + eval TEMP_ACTION="\$CHOICE_${MENU}_OPTION_${TEMP_VALUE}_ACTION" + if [ -n "$TEMP_ACTION" ]; then + $TEMP_ACTION + fi +} + +# Description: Perform the actions associated with the input menu. +# Arguments: $1 - the name of the input menu +menu_process_input() { + # Nothing to do + : +} + +# Description: Perform the actions associated with the status of a +# check box. +# Arguments: $1 - the name of the check box +menu_process_check() { + local CHECKBOX TEMP_VALUE TEMP_ACTION + CHECKBOX="$1" + eval TEMP_VALUE="\$CHECK_${CHECKBOX}_VALUE" + eval TEMP_ACTION="\$CHECK_${CHECKBOX}_OPTION_${TEMP_VALUE}_ACTION" + if [ -n "$TEMP_ACTION" ]; then + $TEMP_ACTION + fi +} + +# Description: Start processing a menu +# Arguments: $1 - the type of the main menu +# $2 - the name of the main menu +do_menu() { + local MENU_TYPE START_MENU SAVE_FILE + + MENU_TYPE=$1 + START_MENU=$2 + + menu_init "$MENU_TYPE" "$START_MENU" + menu_handle "$MENU_TYPE" "$START_MENU" + echo +} + +# Description: Load the menu settings from file +# Arguments: $1 - the type of the menu (currently ignored) +# $2 - the name of the menu (currently ignored) +# $3 - the name of the file to load from +# Returns: 0 - if the file was loaded successfully +# 1 - if the file did not exist +do_menu_load() { + SAVE_FILE=$3 + + if [ ! -e "$SAVE_FILE" ]; then + return 1 + fi + + . "$SAVE_FILE" + return 0 +} + +# Description: Save the menu settings to file +# Arguments: $1 - the type of the menu +# $2 - the name of the menu +# $3 - the name of the file to save to +# Returns: 0 - if the file was saved successfully +do_menu_save() { + MENU_TYPE=$1 + START_MENU=$2 + SAVE_FILE=$3 + + echo "Saving choices..." + menu_save "$MENU_TYPE" "$START_MENU" > "$SAVE_FILE" + return 0 +} + + + + diff --git a/build/unix/recurse b/build/unix/recurse new file mode 100755 index 0000000..0d39efa --- /dev/null +++ b/build/unix/recurse @@ -0,0 +1,88 @@ +#!/bin/sh + +# Generic code for traversing the source code directory structure according to +# the Makeinfo files. + +usage() { + cat << EOF +Usage: + recurse <project> <root> + +With the parameters: + <project> + The name identifying the project, used as prefix in variables in + 'Makeproject' and 'Makeinfo'. + + <root> + The root directory, containing 'Makeproject'. +EOF +} + +if [ $# -ne 2 ]; then + usage >&2 + exit 1 +fi + +BUILD_PROJECT=$1 +BUILD_ROOT=${2%/}/ + +# $1 - The prefix up to this point +# $2 - The name of the current subdir +recurse_subdir() { + local REC_PREFIX SUBDIRS SUBDIR CFILES CXXFILES HFILES MFILES RCFILES FILE + eval local ${BUILD_PROJECT}_CFILES \ + ${BUILD_PROJECT}_CXXFILES \ + ${BUILD_PROJECT}_HFILES \ + ${BUILD_PROJECT}_MFILES \ + ${BUILD_PROJECT}_RCFILES \ + ${BUILD_PROJECT}_SUBDIRS + + REC_PREFIX="$1$2/" + if [ "$REC_PREFIX" = "/" ]; then + REC_PREFIX= + fi + + eval ${BUILD_PROJECT}_CFILES= + eval ${BUILD_PROJECT}_CXXFILES= + eval ${BUILD_PROJECT}_HFILES= + eval ${BUILD_PROJECT}_MFILES= + eval ${BUILD_PROJECT}_RCFILES= + eval ${BUILD_PROJECT}_SUBDIRS= + + . "${BUILD_ROOT}${REC_PREFIX}Makeinfo" + + eval CFILES=\$${BUILD_PROJECT}_CFILES + eval CXXFILES=\$${BUILD_PROJECT}_CXXFILES + eval HFILES=\$${BUILD_PROJECT}_HFILES + eval MFILES=\$${BUILD_PROJECT}_MFILES + eval RCFILES=\$${BUILD_PROJECT}_RCFILES + + for FILE in $CFILES; do + echo "C ${OBJDIR}${REC_PREFIX}$FILE" + done + for FILE in $CXXFILES; do + echo "CXX ${OBJDIR}${REC_PREFIX}$FILE" + done + for FILE in $HFILES; do + echo "H ${OBJDIR}${REC_PREFIX}$FILE" + done + for FILE in $MFILES; do + echo "M ${OBJDIR}${REC_PREFIX}$FILE" + done + for FILE in $RCFILES; do + echo "RC ${OBJDIR}${REC_PREFIX}$FILE" + done + + eval SUBDIRS=\$${BUILD_PROJECT}_SUBDIRS + + for SUBDIR in $SUBDIRS; do + echo "DIRIN ${OBJDIR}${REC_PREFIX}$SUBDIR" + recurse_subdir "$REC_PREFIX" "$SUBDIR" + echo "DIROUT ${OBJDIR}${REC_PREFIX}$SUBDIR" + done +} + +. "${BUILD_ROOT}Makeproject" + +recurse_subdir "" "" + diff --git a/build/unix/todo b/build/unix/todo new file mode 100644 index 0000000..d156e61 --- /dev/null +++ b/build/unix/todo @@ -0,0 +1,15 @@ +- flag for an option to set if changing it will trigger a new 'make depend' +- same for 'make clean' +- Specify files to be removed on clean. +- static compilationa (?) +- Let the dependency index depend on the Makeinfo files + (What about the internal dependencies among Makeinfo) + +some docs +- uqm_LDFLAGS etc are only relevant in the top dir +- some variables are 'inherited' from parent dir + update: this is not true anymore. The behavior was not needed and + would just complicate things. +- files are sourced (.) + + diff --git a/build/unix/uqm-wrapper.in b/build/unix/uqm-wrapper.in new file mode 100755 index 0000000..262f7f4 --- /dev/null +++ b/build/unix/uqm-wrapper.in @@ -0,0 +1,4 @@ +#!/bin/sh +# Wrapper script for starting The Ur-Quan Masters +exec "@INSTALL_LIBDIR@uqm/uqm" "--contentdir=@INSTALL_SHAREDIR@uqm/content" "$@" + |