Sun, 30 Nov 2025 16:52:33 +0100
update uwproj
#!/bin/sh # some utility functions isplatform() { for p in $PLATFORM do if [ "$p" = "$1" ]; then return 0 fi done return 1 } notisplatform() { for p in $PLATFORM do if [ "$p" = "$1" ]; then return 1 fi done return 0 } istoolchain() { for t in $TOOLCHAIN do if [ "$t" = "$1" ]; then return 0 fi done return 1 } notistoolchain() { for t in $TOOLCHAIN do if [ "$t" = "$1" ]; then return 1 fi done return 0 } # clean abort abort_configure() { rm -Rf "$TEMP_DIR" exit 1 } # Test for availability of pkg-config PKG_CONFIG=`command -v pkg-config` : ${PKG_CONFIG:="false"} # Simple uname based platform detection # $PLATFORM is used for platform dependent dependency selection OS=`uname -s` OS_VERSION=`uname -r` ARCH=`uname -m` printf "detect platform... " if [ "$OS" = "SunOS" ]; then PLATFORM="solaris sunos unix svr4" elif [ "$OS" = "Linux" ]; then PLATFORM="linux unix" elif [ "$OS" = "FreeBSD" ]; then PLATFORM="freebsd bsd unix" elif [ "$OS" = "OpenBSD" ]; then PLATFORM="openbsd bsd unix" elif [ "$OS" = "NetBSD" ]; then PLATFORM="netbsd bsd unix" elif [ "$OS" = "Darwin" ]; then PLATFORM="macos osx bsd unix" elif echo "$OS" | grep -i "MINGW" > /dev/null; then PLATFORM="windows mingw" fi : ${PLATFORM:="unix"} PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` echo "$PLATFORM_NAME" # help text printhelp() { echo "Usage: $0 [OPTIONS]..." echo 'Configuration:' if true \ ; then : if test -z "$TOOLKIT_HOME__described__"; then TOOLKIT_HOME__described__=1 cat << '__EOF__' --toolkit-home location of the toolkit installation (default: /usr) __EOF__ fi fi cat << '__EOF__' Build Types: --debug add extra compile flags for debug builds --release add extra compile flags for release builds Optional Features: --enable-asan enable address sanitization --enable-tools enable compilation of tools __EOF__ abort_configure } # create temporary directory TEMP_DIR=".tmp-`uname -n`" rm -Rf "$TEMP_DIR" if mkdir -p "$TEMP_DIR"; then : else echo "Cannot create tmp dir $TEMP_DIR" echo "Abort" exit 1 fi touch "$TEMP_DIR/options" touch "$TEMP_DIR/features" # config variables if true \ ; then : if test -z "$srcdir__initialized__"; then srcdir__initialized__=1 srcdir=`pwd` fi if test -z "$TOOLKIT_HOME__initialized__"; then TOOLKIT_HOME__initialized__=1 TOOLKIT_HOME='/usr' fi fi # features # # parse arguments # BUILD_TYPE="default" for ARG in "$@" do case "$ARG" in "--toolkit-home="*) TOOLKIT_HOME=${ARG#--toolkit-home=} ;; "--help"*) printhelp ;; "--debug") BUILD_TYPE="debug" ;; "--release") BUILD_TYPE="release" ;; "--enable-asan") FEATURE_ASAN=on ;; "--disable-asan") unset FEATURE_ASAN ;; "--enable-tools") FEATURE_TOOLS=on ;; "--disable-tools") unset FEATURE_TOOLS ;; "-"*) echo "unknown option: $ARG"; abort_configure ;; esac done # toolchain detection utilities . make/toolchain.sh # check languages lang_c= lang_cpp= if detect_c_compiler ; then lang_c=1 fi # set defaults for dir variables : ${exec_prefix:="$prefix"} : ${bindir:='${exec_prefix}/bin'} : ${sbindir:='${exec_prefix}/sbin'} : ${libdir:='${exec_prefix}/lib'} : ${libexecdir:='${exec_prefix}/libexec'} : ${datarootdir:='${prefix}/share'} : ${datadir:='${datarootdir}'} : ${sharedstatedir:='${prefix}/com'} if [ -z "$sysconfdir" ]; then if [ "$prefix" = '/usr' ]; then sysconfdir='/etc' else sysconfdir='${prefix}/etc' fi fi if [ -z "$localstatedir" ]; then if [ "$prefix" = '/usr' ]; then localstatedir='/var' else localstatedir='${prefix}/var' fi fi if [ -z "$runstatedir" ]; then if [ "$prefix" = '/usr' ]; then runstatedir='/var/run' else runstatedir='${prefix}/var' fi fi : ${includedir:='${prefix}/include'} : ${infodir:='${datarootdir}/info'} : ${mandir:='${datarootdir}/man'} : ${localedir:='${datarootdir}/locale'} # check if a config.site exists and load it CONFIG_SITE_OK=0 if [ -n "$CONFIG_SITE" ]; then # CONFIG_SITE may contain space separated file names for cs in $CONFIG_SITE; do printf "loading defaults from $cs... " if [ -f "$cs" ]; then . "$cs" echo ok CONFIG_SITE_OK=1 break else echo "not found" fi done elif [ -f "$prefix/share/config.site" ]; then printf "loading site defaults... " . "$prefix/share/config.site" echo ok CONFIG_SITE_OK=1 elif [ -f "$prefix/etc/config.site" ]; then printf "loading site defaults... " . "$prefix/etc/config.site" echo ok CONFIG_SITE_OK=1 fi if [ $CONFIG_SITE_OK -eq 0 ]; then # try to detect the correct libdir on our own, except it was changed by the user if [ "$libdir" = '${exec_prefix}/lib' ] ; then if [ "$TOOLCHAIN_WSIZE" = "64" ] ; then if [ "$OS" = "SunOS" ]; then [ -d "${exec_prefix}/lib/64" ] && libdir='${exec_prefix}/lib/64' else [ -d "${exec_prefix}/lib64" ] && libdir='${exec_prefix}/lib64' fi elif [ "$TOOLCHAIN_WSIZE" = "32" ] ; then if [ "$OS" = "SunOS" ]; then [ -d "${exec_prefix}/lib/32" ] && libdir='${exec_prefix}/lib/32' else [ -d "${exec_prefix}/lib32" ] && libdir='${exec_prefix}/lib32' fi fi fi fi # generate vars.mk cat > "$TEMP_DIR/vars.mk" << __EOF__ srcdir=$srcdir TOOLKIT_HOME=$TOOLKIT_HOME __EOF__ # # DEPENDENCIES # # create buffer for make variables required by dependencies echo > "$TEMP_DIR/make.mk" test_pkg_config() { if "$PKG_CONFIG" --exists "$1" ; then : else return 1 ; fi if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then : else return 1 ; fi if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then : else return 1 ; fi if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then : else return 1 ; fi return 0 } print_check_msg() { if [ -z "$1" ]; then shift printf "$@" fi } dependency_error_asan() { print_check_msg "$dep_checked_asan" "checking for asan... " # dependency asan toolchain="gnuc" while true do if notistoolchain "gnuc"; then break fi TEMP_CFLAGS="$TEMP_CFLAGS -fsanitize=address" TEMP_LDFLAGS="$TEMP_LDFLAGS -fsanitize=address" print_check_msg "$dep_checked_asan" "yes\n" dep_checked_asan=1 return 1 done print_check_msg "$dep_checked_asan" "no\n" dep_checked_asan=1 return 0 } dependency_error_sdl3_ttf() { print_check_msg "$dep_checked_sdl3_ttf" "checking for sdl3_ttf... " # dependency sdl3_ttf while true do if [ -z "$PKG_CONFIG" ]; then break fi if test_pkg_config "sdl3-ttf" "" "" "" ; then TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sdl3-ttf`" TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sdl3-ttf`" else break fi print_check_msg "$dep_checked_sdl3_ttf" "yes\n" dep_checked_sdl3_ttf=1 return 1 done print_check_msg "$dep_checked_sdl3_ttf" "no\n" dep_checked_sdl3_ttf=1 return 0 } dependency_error_gtk3() { print_check_msg "$dep_checked_gtk3" "checking for gtk3... " # dependency gtk3 while true do if [ -z "$PKG_CONFIG" ]; then break fi if test_pkg_config "gtk+-3.0" "" "" "" ; then TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-3.0`" TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-3.0`" else break fi TEMP_CFLAGS="$TEMP_CFLAGS -DUI_GTK3" TEMP_LDFLAGS="$TEMP_LDFLAGS -lpthread" print_check_msg "$dep_checked_gtk3" "yes\n" dep_checked_gtk3=1 return 1 done print_check_msg "$dep_checked_gtk3" "no\n" dep_checked_gtk3=1 return 0 } dependency_error_toolkit() { print_check_msg "$dep_checked_toolkit" "checking for toolkit... " # dependency toolkit while true do if test -n "$TOOLKIT_HOME" > /dev/null 2>&1 ; then : else break fi if test -f "$TOOLKIT_HOME/lib/libuitk.a" > /dev/null 2>&1 ; then : else break fi if test -f "$TOOLKIT_HOME/include/ui/ui.h" > /dev/null 2>&1 ; then : else break fi TEMP_CFLAGS="$TEMP_CFLAGS -I$TOOLKIT_HOME/include" TEMP_LDFLAGS="$TEMP_LDFLAGS $TOOLKIT_HOME/lib/libuitk.a" print_check_msg "$dep_checked_toolkit" "yes\n" dep_checked_toolkit=1 return 1 done print_check_msg "$dep_checked_toolkit" "no\n" dep_checked_toolkit=1 return 0 } dependency_error_glew() { print_check_msg "$dep_checked_glew" "checking for glew... " # dependency glew while true do if [ -z "$PKG_CONFIG" ]; then break fi if test_pkg_config "glew" "" "" "" ; then TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags glew`" TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs glew`" else break fi print_check_msg "$dep_checked_glew" "yes\n" dep_checked_glew=1 return 1 done print_check_msg "$dep_checked_glew" "no\n" dep_checked_glew=1 return 0 } dependency_error_sdl3_image() { print_check_msg "$dep_checked_sdl3_image" "checking for sdl3_image... " # dependency sdl3_image while true do if [ -z "$PKG_CONFIG" ]; then break fi if test_pkg_config "sdl3-image" "" "" "" ; then TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sdl3-image`" TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sdl3-image`" else break fi print_check_msg "$dep_checked_sdl3_image" "yes\n" dep_checked_sdl3_image=1 return 1 done print_check_msg "$dep_checked_sdl3_image" "no\n" dep_checked_sdl3_image=1 return 0 } dependency_error_ucx() { print_check_msg "$dep_checked_ucx" "checking for ucx... " # dependency ucx while true do if [ -z "$PKG_CONFIG" ]; then break fi if test_pkg_config "ucx" "3.2" "" "" ; then TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags ucx`" TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs ucx`" else break fi print_check_msg "$dep_checked_ucx" "yes\n" dep_checked_ucx=1 return 1 done print_check_msg "$dep_checked_ucx" "no\n" dep_checked_ucx=1 return 0 } dependency_error_sdl3() { print_check_msg "$dep_checked_sdl3" "checking for sdl3... " # dependency sdl3 while true do if [ -z "$PKG_CONFIG" ]; then break fi if test_pkg_config "sdl3" "" "" "" ; then TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sdl3`" TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sdl3`" else break fi print_check_msg "$dep_checked_sdl3" "yes\n" dep_checked_sdl3=1 return 1 done print_check_msg "$dep_checked_sdl3" "no\n" dep_checked_sdl3=1 return 0 } # start collecting dependency information echo > "$TEMP_DIR/flags.mk" DEPENDENCIES_FAILED= ERROR=0 # unnamed dependencies TEMP_CFLAGS="$CFLAGS" TEMP_CXXFLAGS="$CXXFLAGS" TEMP_LDFLAGS="$LDFLAGS" while true do while true do if [ -z "$lang_c" ] ; then ERROR=1 break fi TEMP_LDFLAGS="$TEMP_LDFLAGS -lm" break done break done # build type if [ "$BUILD_TYPE" = "debug" ]; then TEMP_CFLAGS="\${DEBUG_CFLAGS} $TEMP_CFLAGS" TEMP_CXXFLAGS="\${DEBUG_CXXFLAGS} $TEMP_CXXFLAGS" fi if [ "$BUILD_TYPE" = "release" ]; then TEMP_CFLAGS="\${RELEASE_CFLAGS} $TEMP_CFLAGS" TEMP_CXXFLAGS="\${RELEASE_CXXFLAGS} $TEMP_CXXFLAGS" fi # add general dependency flags to flags.mk echo "# general flags" >> "$TEMP_DIR/flags.mk" if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" fi if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" fi if [ -n "${TEMP_LDFLAGS}" ]; then echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" fi # # OPTION VALUES # # # TARGETS # echo >> "$TEMP_DIR/flags.mk" echo "configuring global target" echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk" TEMP_CFLAGS= TEMP_CXXFLAGS= TEMP_LDFLAGS= if dependency_error_ucx; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ucx " ERROR=1 fi if dependency_error_sdl3; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl3 " ERROR=1 fi if dependency_error_sdl3_ttf; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl3_ttf " ERROR=1 fi if dependency_error_sdl3_image; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl3_image " ERROR=1 fi if dependency_error_glew; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED glew " ERROR=1 fi # Features if [ -n "$FEATURE_ASAN" ]; then # check dependency if dependency_error_asan ; then # "auto" features can fail and are just disabled in this case if [ "$FEATURE_ASAN" = "auto" ]; then DISABLE_FEATURE_ASAN=1 else DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED asan " ERROR=1 fi fi if [ -n "$DISABLE_FEATURE_ASAN" ]; then unset FEATURE_ASAN fi fi if [ -n "$FEATURE_ASAN" ]; then : else : fi if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" fi if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" fi if [ -n "${TEMP_LDFLAGS}" ]; then echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" fi echo >> "$TEMP_DIR/flags.mk" echo "configuring target: tools" echo "# flags for target tools" >> "$TEMP_DIR/flags.mk" TEMP_CFLAGS= TEMP_CXXFLAGS= TEMP_LDFLAGS= # Features if [ -n "$FEATURE_TOOLS" ]; then # check dependency if dependency_error_toolkit ; then # "auto" features can fail and are just disabled in this case if [ "$FEATURE_TOOLS" = "auto" ]; then DISABLE_FEATURE_TOOLS=1 else DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED toolkit " ERROR=1 fi fi # check dependency if dependency_error_gtk3 ; then # "auto" features can fail and are just disabled in this case if [ "$FEATURE_TOOLS" = "auto" ]; then DISABLE_FEATURE_TOOLS=1 else DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED gtk3 " ERROR=1 fi fi # check dependency if dependency_error_ucx ; then # "auto" features can fail and are just disabled in this case if [ "$FEATURE_TOOLS" = "auto" ]; then DISABLE_FEATURE_TOOLS=1 else DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ucx " ERROR=1 fi fi if [ -n "$DISABLE_FEATURE_TOOLS" ]; then unset FEATURE_TOOLS fi fi if [ -n "$FEATURE_TOOLS" ]; then : else : cat >> "$TEMP_DIR/make.mk" << __EOF__ NO_TOOLS=1 __EOF__ fi if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then echo "TOOLS_CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" fi if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then echo "TOOLS_CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" fi if [ -n "${TEMP_LDFLAGS}" ]; then echo "TOOLS_LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" fi # final result if [ $ERROR -ne 0 ]; then echo echo "Error: Unresolved dependencies" echo "$DEPENDENCIES_FAILED" abort_configure fi echo "configure finished" echo echo "Toolchain:" echo " name: $TOOLCHAIN_NAME" if [ -n "$TOOLCHAIN_CC" ]; then echo " cc: $TOOLCHAIN_CC" fi if [ -n "$TOOLCHAIN_CXX" ]; then echo " cxx: $TOOLCHAIN_CXX" fi if [ -n "$TOOLCHAIN_WSIZE" ]; then echo " word size: $TOOLCHAIN_WSIZE bit" fi if [ -n "$TOOLCHAIN_CSTD" ]; then echo " default C std: $TOOLCHAIN_CSTD" fi echo echo "Config:" printf ' %-16s' 'toolkit-home:' echo "$TOOLKIT_HOME" echo echo "Features:" printf ' %-16s' 'asan:' if [ -n "$FEATURE_ASAN" ]; then echo 'on' else echo 'off' fi printf ' %-16s' 'tools:' if [ -n "$FEATURE_TOOLS" ]; then echo 'on' else echo 'off' fi echo # generate the config.mk file pwd=`pwd` cat > "$TEMP_DIR/config.mk" << __EOF__ # # config.mk generated by: # pwd: $pwd # $0 $@ # __EOF__ write_toolchain_defaults "$TEMP_DIR/toolchain.mk" cat "$TEMP_DIR/config.mk" "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk rm -Rf "$TEMP_DIR"