-project = "Yoink"
-version = "0.1"
-bugreport = "onefriedrice@brokenzipper.com"
-
-
-function ShowHelp()
- print([[
-
-This script prepares ]]..project..[[ for building on your system.
-Usage: ./configure [OPTION]... [VAR=VALUE]...
-
-This is NOT an autoconf-generated configure script, though it was written
-to be familiar by supporting many of the same options.
-
-Basic configuration:
- -h, --help display this help and exit
- --host=HOST cross-compile the program to run on HOST
-
- --prefix=DIR base directory to install programs to
- --bindir=DIR directory to install executables
- --datadir=DIR directory to install shared data files
- --mandir=DIR directory to install manual pages
-
- --disable-dependency-tracking speed up one-time builds
- --enable-link-sh decrease the number of direct dependencies
-
-Program options:
- --enable-debug include debugging symbols and code paths
- --enable-double-precision use doubles instead of floats
- --enable-profile compile in gprof profiling instructions
- --enable-clock_gettime use clock_gettime() for timing
- --enable-threads use threads for concurrency
- --enable-hotloading watch assets for automatic reloading
-
- --with-gtk use the gtk2 toolkit (overrides --with-qt4)
- --with-qt4 use the qt4 gui toolkit
-]])
-end
-
-
---
--- Define some useful functions.
---
-
-function Die(...)
- for _,value in ipairs(arg) do
- print("fatal: "..tostring(value))
- end
- os.exit(1)
-end
-
-function FileExists(file)
- return os.execute("test -f "..file) == 0
-end
-
-function ReadCommand(command)
- local fd = io.popen(command)
- if fd then
- local stdout = fd:read("*l")
- fd:close()
- return stdout
- end
- return nil
-end
-
-function TryCommand(command)
- return os.execute(command.." 2>&1 >/dev/null") == 0
-end
-
-function Trim(str)
- str = str:gsub("^%s+", "")
- return str:gsub("%s+$", "")
-end
-
-function Reduce(str)
- str = str:gsub("%s+", " ")
- return Trim(str)
-end
-
-
---
--- Perform a quick sanity check.
---
-
-if not FileExists("configure") or not FileExists("Makefile") then
- Die("You must `cd' to the project root where the Makefile is.")
-end
-
-
---
--- Parse the command-line options.
---
-
-do
- 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.
---
-
-do
- local path = os.getenv("PATH")
-
- -- 1. List of possible command names.
- -- 2. Command arguments.
- function FindCommand(commands, args)
- if not args then args = "" end
- for _,command in ipairs(commands) do
- if command then
- for dir in path:gmatch("[^:]+") do
- if FileExists(dir.."/"..command) and TryCommand(command.." "..args) then
- return command
- end
- end
- end
- end
- return nil
- end
-end
-
-
---
--- Look for a working toolchain.
---
-
-print("Please wait...")
-
--- Check for CC.
-tmpname = os.tmpname()..".c"
-tmpfile, err = io.open(tmpname, "w")
-if tmpfile then
- tmpfile:write([[
-#include <stdio.h>
-int main()
-{
- printf("Hello world!\n");
- return 0;