Fri, 22 Sep 2023 23:26:23 +0200
replace autoconf with uwproj
universe@68 | 1 | #!/bin/sh |
universe@68 | 2 | |
universe@68 | 3 | # create temporary directory |
universe@68 | 4 | TEMP_DIR=".tmp-`uname -n`" |
universe@68 | 5 | rm -Rf "$TEMP_DIR" |
universe@68 | 6 | if mkdir -p "$TEMP_DIR"; then |
universe@68 | 7 | : |
universe@68 | 8 | else |
universe@68 | 9 | echo "Cannot create tmp dir $TEMP_DIR" |
universe@68 | 10 | echo "Abort" |
universe@68 | 11 | exit 1 |
universe@68 | 12 | fi |
universe@68 | 13 | touch "$TEMP_DIR/options" |
universe@68 | 14 | touch "$TEMP_DIR/features" |
universe@68 | 15 | |
universe@68 | 16 | # define standard variables |
universe@68 | 17 | PREFIX=/usr |
universe@68 | 18 | EPREFIX= |
universe@68 | 19 | BINDIR= |
universe@68 | 20 | SBINDIR= |
universe@68 | 21 | LIBDIR= |
universe@68 | 22 | LIBEXECDIR= |
universe@68 | 23 | DATADIR= |
universe@68 | 24 | SYSCONFDIR= |
universe@68 | 25 | SHAREDSTATEDIR= |
universe@68 | 26 | LOCALSTATEDIR= |
universe@68 | 27 | INCLUDEDIR= |
universe@68 | 28 | INFODIR= |
universe@68 | 29 | MANDIR= |
universe@68 | 30 | |
universe@68 | 31 | # custom variables |
universe@68 | 32 | |
universe@68 | 33 | # features |
universe@68 | 34 | |
universe@68 | 35 | # clean abort |
universe@68 | 36 | abort_configure() |
universe@68 | 37 | { |
universe@68 | 38 | rm -Rf "$TEMP_DIR" |
universe@68 | 39 | exit 1 |
universe@68 | 40 | } |
universe@68 | 41 | |
universe@68 | 42 | # help text |
universe@68 | 43 | printhelp() |
universe@68 | 44 | { |
universe@68 | 45 | echo "Usage: $0 [OPTIONS]..." |
universe@68 | 46 | cat << __EOF__ |
universe@68 | 47 | Installation directories: |
universe@68 | 48 | --prefix=PREFIX path prefix for architecture-independent files |
universe@68 | 49 | [/usr] |
universe@68 | 50 | --exec-prefix=EPREFIX path prefix for architecture-dependent files |
universe@68 | 51 | [PREFIX] |
universe@68 | 52 | |
universe@68 | 53 | --bindir=DIR user executables [EPREFIX/bin] |
universe@68 | 54 | --sbindir=DIR system admin executables [EPREFIX/sbin] |
universe@68 | 55 | --libexecdir=DIR program executables [EPREFIX/libexec] |
universe@68 | 56 | --sysconfdir=DIR system configuration files [PREFIX/etc] |
universe@68 | 57 | --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] |
universe@68 | 58 | --localstatedir=DIR modifiable single-machine data [PREFIX/var] |
universe@68 | 59 | --libdir=DIR object code libraries [EPREFIX/lib] |
universe@68 | 60 | --includedir=DIR C header files [PREFIX/include] |
universe@68 | 61 | --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] |
universe@68 | 62 | --datadir=DIR read-only architecture-independent data [DATAROOTDIR] |
universe@68 | 63 | --infodir=DIR info documentation [DATAROOTDIR/info] |
universe@68 | 64 | --mandir=DIR man documentation [DATAROOTDIR/man] |
universe@68 | 65 | |
universe@68 | 66 | __EOF__ |
universe@68 | 67 | } |
universe@68 | 68 | |
universe@68 | 69 | # |
universe@68 | 70 | # parse arguments |
universe@68 | 71 | # |
universe@68 | 72 | BUILD_TYPE="default" |
universe@68 | 73 | for ARG in "$@" |
universe@68 | 74 | do |
universe@68 | 75 | case "$ARG" in |
universe@68 | 76 | "--prefix="*) PREFIX=${ARG#--prefix=} ;; |
universe@68 | 77 | "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;; |
universe@68 | 78 | "--bindir="*) BINDIR=${ARG#----bindir=} ;; |
universe@68 | 79 | "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;; |
universe@68 | 80 | "--libdir="*) LIBDIR=${ARG#--libdir=} ;; |
universe@68 | 81 | "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;; |
universe@68 | 82 | "--datadir="*) DATADIR=${ARG#--datadir=} ;; |
universe@68 | 83 | "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;; |
universe@68 | 84 | "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;; |
universe@68 | 85 | "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;; |
universe@68 | 86 | "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;; |
universe@68 | 87 | "--infodir="*) INFODIR=${ARG#--infodir=} ;; |
universe@68 | 88 | "--mandir"*) MANDIR=${ARG#--mandir} ;; |
universe@68 | 89 | "--help"*) printhelp; abort_configure ;; |
universe@68 | 90 | "--debug") BUILD_TYPE="debug" ;; |
universe@68 | 91 | "--release") BUILD_TYPE="release" ;; |
universe@68 | 92 | "-"*) echo "unknown option: $ARG"; abort_configure ;; |
universe@68 | 93 | esac |
universe@68 | 94 | done |
universe@68 | 95 | |
universe@68 | 96 | |
universe@68 | 97 | # set dir variables |
universe@68 | 98 | : ${EPREFIX:="$PREFIX"} |
universe@68 | 99 | : ${BINDIR:="$EPREFIX/bin"} |
universe@68 | 100 | : ${SBINDIR:="$EPREFIX/sbin"} |
universe@68 | 101 | : ${LIBDIR:="$EPREFIX/lib"} |
universe@68 | 102 | : ${LIBEXECDIR:="$EPREFIX/libexec"} |
universe@68 | 103 | : ${DATADIR:="$PREFIX/share"} |
universe@68 | 104 | : ${SYSCONFDIR:="$PREFIX/etc"} |
universe@68 | 105 | : ${SHAREDSTATEDIR:="$PREFIX/com"} |
universe@68 | 106 | : ${LOCALSTATEDIR:="$PREFIX/var"} |
universe@68 | 107 | : ${INCLUDEDIR:="$PREFIX/include"} |
universe@68 | 108 | : ${INFODIR:="$PREFIX/info"} |
universe@68 | 109 | : ${MANDIR:="$PREFIX/man"} |
universe@68 | 110 | |
universe@68 | 111 | # Test for availability of pkg-config |
universe@68 | 112 | PKG_CONFIG=`command -v pkg-config` |
universe@68 | 113 | : ${PKG_CONFIG:="false"} |
universe@68 | 114 | |
universe@68 | 115 | # Simple uname based platform detection |
universe@68 | 116 | # $PLATFORM is used for platform dependent dependency selection |
universe@68 | 117 | OS=`uname -s` |
universe@68 | 118 | OS_VERSION=`uname -r` |
universe@68 | 119 | printf "detect platform... " |
universe@68 | 120 | if [ "$OS" = "SunOS" ]; then |
universe@68 | 121 | PLATFORM="solaris sunos unix svr4" |
universe@68 | 122 | fi |
universe@68 | 123 | if [ "$OS" = "Linux" ]; then |
universe@68 | 124 | PLATFORM="linux unix" |
universe@68 | 125 | fi |
universe@68 | 126 | if [ "$OS" = "FreeBSD" ]; then |
universe@68 | 127 | PLATFORM="freebsd bsd unix" |
universe@68 | 128 | fi |
universe@68 | 129 | if [ "$OS" = "Darwin" ]; then |
universe@68 | 130 | PLATFORM="macos osx bsd unix" |
universe@68 | 131 | fi |
universe@68 | 132 | if echo "$OS" | grep -i "MINGW" > /dev/null; then |
universe@68 | 133 | PLATFORM="windows mingw" |
universe@68 | 134 | fi |
universe@68 | 135 | : ${PLATFORM:="unix"} |
universe@68 | 136 | |
universe@68 | 137 | PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` |
universe@68 | 138 | echo "$PLATFORM_NAME" |
universe@68 | 139 | |
universe@68 | 140 | isplatform() |
universe@68 | 141 | { |
universe@68 | 142 | for p in $PLATFORM |
universe@68 | 143 | do |
universe@68 | 144 | if [ "$p" = "$1" ]; then |
universe@68 | 145 | return 0 |
universe@68 | 146 | fi |
universe@68 | 147 | done |
universe@68 | 148 | return 1 |
universe@68 | 149 | } |
universe@68 | 150 | notisplatform() |
universe@68 | 151 | { |
universe@68 | 152 | for p in $PLATFORM |
universe@68 | 153 | do |
universe@68 | 154 | if [ "$p" = "$1" ]; then |
universe@68 | 155 | return 1 |
universe@68 | 156 | fi |
universe@68 | 157 | done |
universe@68 | 158 | return 0 |
universe@68 | 159 | } |
universe@68 | 160 | |
universe@68 | 161 | |
universe@68 | 162 | # generate vars.mk |
universe@68 | 163 | cat > "$TEMP_DIR/vars.mk" << __EOF__ |
universe@68 | 164 | PREFIX=$PREFIX |
universe@68 | 165 | EPREFIX=$EPREFIX |
universe@68 | 166 | BINDIR=$BINDIR |
universe@68 | 167 | SBINDIR=$SBINDIR |
universe@68 | 168 | LIBDIR=$LIBDIR |
universe@68 | 169 | LIBEXECDIR=$LIBEXECDIR |
universe@68 | 170 | DATADIR=$DATADIR |
universe@68 | 171 | SYSCONFDIR=$SYSCONFDIR |
universe@68 | 172 | SHAREDSTATEDIR=$SHAREDSTATEDIR |
universe@68 | 173 | LOCALSTATEDIR=$LOCALSTATEDIR |
universe@68 | 174 | INCLUDEDIR=$INCLUDEDIR |
universe@68 | 175 | INFODIR=$INFODIR |
universe@68 | 176 | MANDIR=$MANDIR |
universe@68 | 177 | __EOF__ |
universe@68 | 178 | sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk" |
universe@68 | 179 | |
universe@68 | 180 | |
universe@68 | 181 | # toolchain detection utilities |
universe@68 | 182 | . make/toolchain.sh |
universe@68 | 183 | |
universe@68 | 184 | # |
universe@68 | 185 | # DEPENDENCIES |
universe@68 | 186 | # |
universe@68 | 187 | |
universe@68 | 188 | # check languages |
universe@68 | 189 | lang_c= |
universe@68 | 190 | lang_cpp= |
universe@68 | 191 | if detect_c_compiler ; then |
universe@68 | 192 | lang_c=1 |
universe@68 | 193 | fi |
universe@68 | 194 | |
universe@68 | 195 | # create buffer for make variables required by dependencies |
universe@68 | 196 | echo > "$TEMP_DIR/make.mk" |
universe@68 | 197 | |
universe@68 | 198 | test_pkg_config() |
universe@68 | 199 | { |
universe@68 | 200 | if "$PKG_CONFIG" --exists "$1" ; then : |
universe@68 | 201 | else return 1 ; fi |
universe@68 | 202 | if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then : |
universe@68 | 203 | else return 1 ; fi |
universe@68 | 204 | if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then : |
universe@68 | 205 | else return 1 ; fi |
universe@68 | 206 | if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then : |
universe@68 | 207 | else return 1 ; fi |
universe@68 | 208 | return 0 |
universe@68 | 209 | } |
universe@68 | 210 | |
universe@68 | 211 | |
universe@68 | 212 | |
universe@68 | 213 | |
universe@68 | 214 | |
universe@68 | 215 | # start collecting dependency information |
universe@68 | 216 | echo > "$TEMP_DIR/flags.mk" |
universe@68 | 217 | |
universe@68 | 218 | DEPENDENCIES_FAILED= |
universe@68 | 219 | ERROR=0 |
universe@68 | 220 | # unnamed dependencies |
universe@68 | 221 | TEMP_CFLAGS= |
universe@68 | 222 | TEMP_CXXFLAGS= |
universe@68 | 223 | TEMP_LDFLAGS= |
universe@68 | 224 | while true |
universe@68 | 225 | do |
universe@68 | 226 | while true |
universe@68 | 227 | do |
universe@68 | 228 | if [ -z "$lang_c" ] ; then |
universe@68 | 229 | ERROR=1 |
universe@68 | 230 | break |
universe@68 | 231 | fi |
universe@68 | 232 | |
universe@68 | 233 | break |
universe@68 | 234 | done |
universe@68 | 235 | break |
universe@68 | 236 | done |
universe@68 | 237 | |
universe@68 | 238 | # add general dependency flags to flags.mk |
universe@68 | 239 | echo "# general flags" >> "$TEMP_DIR/flags.mk" |
universe@68 | 240 | if [ -n "${TEMP_CFLAGS}" ]; then |
universe@68 | 241 | echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
universe@68 | 242 | fi |
universe@68 | 243 | if [ -n "${TEMP_CXXFLAGS}" ]; then |
universe@68 | 244 | echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
universe@68 | 245 | fi |
universe@68 | 246 | if [ -n "${TEMP_LDFLAGS}" ]; then |
universe@68 | 247 | echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
universe@68 | 248 | fi |
universe@68 | 249 | |
universe@68 | 250 | # |
universe@68 | 251 | # OPTION VALUES |
universe@68 | 252 | # |
universe@68 | 253 | |
universe@68 | 254 | # |
universe@68 | 255 | # TARGETS |
universe@68 | 256 | # |
universe@68 | 257 | |
universe@68 | 258 | echo >> "$TEMP_DIR/flags.mk" |
universe@68 | 259 | # Target: default |
universe@68 | 260 | echo "# flags for target default" >> "$TEMP_DIR/flags.mk" |
universe@68 | 261 | TEMP_CFLAGS= |
universe@68 | 262 | TEMP_CXXFLAGS= |
universe@68 | 263 | TEMP_LDFLAGS= |
universe@68 | 264 | |
universe@68 | 265 | |
universe@68 | 266 | # Features |
universe@68 | 267 | |
universe@68 | 268 | |
universe@68 | 269 | if [ -n "${TEMP_CFLAGS}" ]; then |
universe@68 | 270 | echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
universe@68 | 271 | fi |
universe@68 | 272 | if [ -n "${TEMP_CXXFLAGS}" ]; then |
universe@68 | 273 | echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
universe@68 | 274 | fi |
universe@68 | 275 | if [ "$BUILD_TYPE" = "debug" ]; then |
universe@68 | 276 | echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
universe@68 | 277 | echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
universe@68 | 278 | fi |
universe@68 | 279 | if [ "$BUILD_TYPE" = "release" ]; then |
universe@68 | 280 | echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
universe@68 | 281 | echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
universe@68 | 282 | fi |
universe@68 | 283 | if [ -n "${TEMP_LDFLAGS}" ]; then |
universe@68 | 284 | echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
universe@68 | 285 | fi |
universe@68 | 286 | |
universe@68 | 287 | |
universe@68 | 288 | # final result |
universe@68 | 289 | if [ $ERROR -ne 0 ]; then |
universe@68 | 290 | echo |
universe@68 | 291 | echo "Error: Unresolved dependencies" |
universe@68 | 292 | echo "$DEPENDENCIES_FAILED" |
universe@68 | 293 | abort_configure |
universe@68 | 294 | fi |
universe@68 | 295 | |
universe@68 | 296 | echo "configure finished" |
universe@68 | 297 | echo |
universe@68 | 298 | echo "Build Config:" |
universe@68 | 299 | echo " PREFIX: $PREFIX" |
universe@68 | 300 | echo " TOOLCHAIN: $TOOLCHAIN_NAME" |
universe@68 | 301 | echo |
universe@68 | 302 | |
universe@68 | 303 | # generate the config.mk file |
universe@68 | 304 | cat > "$TEMP_DIR/config.mk" << __EOF__ |
universe@68 | 305 | # |
universe@68 | 306 | # config.mk generated by configure |
universe@68 | 307 | # |
universe@68 | 308 | |
universe@68 | 309 | __EOF__ |
universe@68 | 310 | write_toolchain_defaults "$TEMP_DIR/toolchain.mk" |
universe@68 | 311 | cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk |
universe@68 | 312 | rm -Rf "$TEMP_DIR" |
universe@68 | 313 | |
universe@68 | 314 |