- case $opt in
- -h|--help)
- showhelp
- exit 0
- ;;
-
- --host=*)
- host=$(parse_argument host $opt)
- cross_compile="yes"
- ;;
- --prefix=*)
- prefix=$(parse_argument prefix $opt)
- ;;
- --bindir=*)
- bindir=$(parse_argument bindir $opt)
- ;;
- --libdir=*)
- libdir=$(parse_argument libdir $opt)
- ;;
- --datadir=*)
- datadir=$(parse_argument datadir $opt)
- ;;
- --mandir=*)
- mandir=$(parse_argument mandir $opt)
- ;;
-
- --enable-debug)
- cflags="$cflags -O0 -Wall -Wno-uninitialized"
- define "DEBUG"
- ;;
- --enable-double-precision)
- define "USE_DOUBLE_PRECISION"
- ;;
- --enable-profile)
- cflags="$cflags -pg"
- define "PROFILING_ENABLED"
- ;;
- --enable-extra-warnings)
- cflags="$cflags -Wextra -Wno-unused-parameter"
- ;;
- --enable-link-sh)
- link_sh=yes
- ;;
- --enable-clock_gettime)
- clock_gettime=yes
- ;;
- --enable-threads)
- define "USE_THREADS"
- ;;
- --enable-hotloading)
- define "USE_HOTLOADING"
- ;;
- --with-gtk)
- gtk=yes
- ;;
- --with-qt4)
- qt4=yes
- ;;
- *)
- if echo "$opt" | grep -q '^[A-Za-z0-9_]*=.*'
- then
- export "$opt"
- else
- echo "warning: unknown option: $opt"
- fi
- ;;
- esac
-done
-
-
-#
-# Evaluate any dependent paths.
-#
-
-eval bindir="$bindir"
-eval datadir="$datadir"
-eval libdir="$libdir"
-eval mandir="$mandir"
-
-is_defined "DEBUG" || define "NDEBUG"
-
-export PKG_CONFIG_PATH="$libdir/pkgconfig:$PKG_CONFIG_PATH"
-
-define_string "YOINK_DATADIR" "$datadir"
-
-
-#
-# Determine the target platform.
-#
-
-case $host in
- *mingw32*) HOST=win32 ;;
- *netbsd*) HOST=netbsd ;;
-esac
-
-
-#
-# Define the check functions.
-#
-
-# Run a command and return its exit code. If the third argument is given,
-# stdin will be read and written to the specified file before the command
-# is executed. If the command creates any files inside the current
-# directory, they will be removed automatically.
-# $1 The command to run.
-# $2 The arguments to be passed to the command.
-# $3 Optional filename where stdin will be written.
-check_run_command()
-{
- tmpdir=$(mktemp -d "tmp-XXXXXXXX") || die "could not create temp directory"
- cd $tmpdir || die "could not enter temp directory"
-
- if test "x$3" != x
- then
- while read line
- do
- echo $line
- done >$3
- fi
-
- saved_ifs=$IFS
- IFS=:
- for path in $PATH
- do
- if test -x "$path/$1"
- then
- eval "$1 $2" 2>&1 >/dev/null
- exit_code=$?
-
- cd ..
- rm -rf $tmpdir
- IFS=$saved_ifs
- return $exit_code
- fi
- done
-
- cd ..
- rm -rf $tmpdir
- IFS=$saved_ifs
- return 1
-}
-
+ local features = {}
+ local packages = {}
+ local directories = {}
+ local definitions = {}
+
+ local function AddFeature(feature, value)
+ if value == "yes" or value == "" then value = true end
+ if value == "no" then value = false end
+ features[feature] = value
+ end
+
+ local function AddPackage(package, value)
+ if value == "yes" or value == "" then value = true end
+ if value == "no" then value = false end
+ packages[package] = value
+ end
+
+ local function AddDirectory(directory, path)
+ directories[directory] = path
+ end
+
+ local function AddDefinition(key, value)
+ definitions[key] = value
+ end
+
+ local handlers = {
+ ["--help"] = function() ShowHelp() os.exit(0) end,
+ ["--host=(.+)"] = function(arg) host = arg cross_compile = true end,
+ ["--enable%-([%w_-]+)=?(.*)"] = AddFeature,
+ ["--disable%-([%w_-]+)"] = function(arg) AddFeature(arg, "no") end,
+ ["--with%-([%w_-]+)=?(.*)"] = AddPackage,
+ ["--without%-([%w_-]+)"] = function(arg) AddPackage(arg, "no") end,
+ ["--(%l+)dir=(.+)"] = AddDirectory,
+ ["--prefix=(.+)"] = function(arg) prefix = arg end,
+ ["--exec-prefix=(.+)"] = function(arg) eprefix = arg end,
+ ["([%w_]+)=(.*)"] = AddDefinition,
+ }
+ handlers["-h"] = handlers["--help"]
+
+ local function ParseArg(arg)
+ for key,value in pairs(handlers) do
+ local matches = {arg:match(key)}
+ if matches[1] then
+ value(unpack(matches))
+ return
+ end
+ end
+ print("warning: unknown or incomplete argument "..arg)
+ end
+
+
+ -- Define some default values.
+
+ prefix = "/usr/local"
+
+ CC = ""
+ CXX = ""
+ AR = ""
+ RANLIB = ""
+ WINDRES = ""
+
+ CFLAGS = "-g -O2"
+ CXXFLAGS = CFLAGS
+ LDFLAGS = ""
+ LIBS = ""
+
+ features["dependency-tracking"] = true
+
+
+ -- Read the arguments from the command-line.
+ for _,arg in ipairs(arg) do
+ ParseArg(arg)
+ end
+
+ function GetFeature(feature) return features[feature] end
+ function GetPackage(package) return packages[package] end
+
+ for key,value in pairs(directories) do
+ _G[key.."dir"] = value
+ end
+ for key,value in pairs(definitions) do
+ _G[key] = value
+ end
+
+
+ -- Define the dependent values.
+
+ package = project:lower()
+ tarname = package.."-"..version
+
+ if not host then host = ReadCommand("tools/config.guess") end
+ alt_host = ReadCommand("tools/config.sub "..host)
+
+ if not eprefix then eprefix = prefix end
+ if not bindir then bindir = eprefix.."/bin" end
+ if not sbindir then sbindir = eprefix.."/sbin" end
+ if not libexecdir then libexecdir = eprefix.."/libexec" end
+ if not sysconfdir then sysconfdir = prefix.."/etc" end
+ if not localstatedir then localstatedir = prefix.."/var" end
+ if not libdir then libdir = eprefix.."/lib" end
+ if not includedir then includedir = prefix.."/include" end
+ if not datarootdir then datarootdir = prefix.."/share" end
+ if not datadir then datadir = datarootdir.."/"..package end
+ if not infodir then infodir = datarootdir.."/info" end
+ if not localedir then localedir = datarootdir.."/locale" end
+ if not mandir then mandir = datarootdir.."/man" end
+ if not docdir then docdir = datarootdir.."/doc/"..package end
+
+ cflags = ""
+ config = {}
+ define = {}
+ export = {}
+
+ define.DEP_TRACKING = GetFeature("dependency-tracking")
+end
+
+
+--
+-- Determine the target platform.
+--
+
+if host:match("mingw32") then platform = "win32"
+elseif host:match("netbsd") then platform = "netbsd" end
+
+
+--
+-- Define the check function.
+--