X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=configure;h=8c88e5bbb72917cce7472d6dcb48151e57e1dc2d;hp=06a303d39c002ec9a9432ca170dd8178f0be31f7;hb=a97500609dc3c1b11f9786d32bc458eb00de4c36;hpb=7ac3aee9efa7f9ce1a966df030b1f76f2b82ef2d diff --git a/configure b/configure index 06a303d..8c88e5b 100755 --- a/configure +++ b/configure @@ -1,448 +1,545 @@ -#!/bin/sh +#!/usr/bin/env lua -# -# Yoink -# Execute this file to configure the build system. -# +-- +-- Yoink +-- Execute this file to configure the build system. +-- -PACKAGE="Yoink" -VERSION="0.1" -BUGREPORT="chaz@dogcows.com" +project = "Yoink" +version = "0.1" +bugreport = "chaz@dogcows.com" -showhelp() -{ - cat <<"END" +function ShowHelp() + print([[ -This script prepares Yoink for building on your system. +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 program to run on HOST + --host=HOST cross-compile the program to run on HOST - --prefix=DIR base directory to install program + --prefix=DIR base directory to install programs to --bindir=DIR directory to install executables - --libdir=DIR directory to install libraries --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-double-precision use doubles instead of floats --enable-profile compile in gprof profiling instructions - --enable-extra-warnings make the gcc compiler give more warnings - --enable-link-sh try to decrease the number of direct dependencies - --enable-clock_gettime use clock_gettime() instead of SDL - --enable-threads use threads for concurrency where appropriate - --enable-hotloading monitor assets and reload them when they change + --enable-clock_gettime use clock_gettime() for timing + --enable-threads use threads for concurrency + --enable-hotloading watch assets for automatic reloading - --with-gtk use gtk2 modal dialogs - --with-qt4 use qt4 modal dialogs; overridden by --with-gtk + --with-gtk use the gtk2 toolkit (overrides --with-qt4) + --with-qt4 use the qt4 gui toolkit +]]) +end -END -} -. "build/functions.sh" +-- +-- Define some useful functions. +-- +function Die(...) + for _,value in ipairs(arg) do + print("fatal: "..tostring(value)) + end + os.exit(1) +end -# -# Perform a quick sanity check. -# +function FileExists(file) + return os.execute("test -f "..file) == 0 +end -test -f configure -a -f Makefile || die <<"END" -You must `cd' to the project root directory where the Makefile resides. -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 -# -# Define some default values. -# +function Trim(str) + str = str:gsub("^%s+", "") + return str:gsub("%s+$", "") +end -CC="" -CXX="" -AR="" -RANLIB="" +function Reduce(str) + str = str:gsub("%s+", " ") + return Trim(str) +end -CFLAGS="-g -O2" -CXXFLAGS="$CFLAGS" -LDFLAGS="" -LIBS="" -prefix='/usr/local' -bindir='$prefix/bin' -libdir='$prefix/lib' -datadir='$prefix/share/yoink' -mandir='$prefix/share/man' +-- +-- Perform a quick sanity check. +-- -host=$(./build/config.guess) -althost=$(./build/config.sub $host) -cross_compile="no" +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. -# +-- +-- Parse the command-line options. +-- -for opt in "$@" do - 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. +-- -# -# Do some common checks. -# - -if test "x$cross_compile" = xno -then - # If we are not cross-compiling, we also want to consider tools without - # host prefixes. - extra_cc="gcc cc" - extra_cxx="g++ c++" - extra_ar="ar" - extra_ranlib="ranlib" - extra_windres="windres" -fi - -for exe in $CC $host-gcc $host-cc $althost-gcc $althost-cc $extra_cc do - if check_run_command "$exe" "test.c" "test.c" <<"END" + 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 int main() { printf("Hello world!\n"); return 0; } -END - then - CC="$exe" - break - fi -done - -for exe in $CXX $host-g++ $host-c++ $althost-g++ $althost-c++ $extra_cxx -do - if check_run_command "$exe" "test.cpp" "test.cpp" <<"END" +]]) + tmpfile:close() + + function extra() if not cross_compile then return "gcc", "cc" end end + CC = FindCommand({ + CC, + host.."-gcc", + host.."-cc", + alt_host.."-gcc", + alt_host.."-cc", + extra()}, tmpname.." -o "..tmpname..".tmp") + os.remove(tmpname) + os.remove(tmpname..".tmp") + if not CC then Die("Can't find a working C compiler.") end +else + Die("failed to create temporary file: "..err) +end + +-- Check for CXX. +tmpname = os.tmpname()..".c" +tmpfile, err = io.open(tmpname, "w") +if tmpfile then + tmpfile:write([[ #include int main() { std::cout << "Hello world!" << std::endl; return 0; } -END - then - CXX="$exe" - break - fi -done - -for exe in $AR $host-ar $althost-ar $extra_ar +]]) + tmpfile:close() + + function extra() if not cross_compile then return "g++", "c++" end end + CXX = FindCommand({ + CXX, + host.."-g++", + host.."-c++", + alt_host.."-g++", + alt_host.."-c++", + extra()}, tmpname.." -o "..tmpname..".tmp") + os.remove(tmpname) + os.remove(tmpname..".tmp") + if not CXX then Die("Can't find a working C++ compiler.") end +else + Die("failed to create temporary file: "..err) +end + +-- Check for AR. do - if check_run_command "$exe" "--version" - then - AR="$exe" - break - fi -done - -for exe in $RANLIB $host-ranlib $althost-ranlib $extra_ranlib + function extra() if not cross_compile then return "ar" end end + AR = FindCommand({ + AR, + host.."-ar", + alt_host.."-ar", + extra()}, "--version") + if not AR then Die("Can't find a working archiver.") end +end + +-- Check for RANLIB. do - if check_run_command "$exe" "--version" - then - RANLIB="$exe" - break - fi -done - -if test x$HOST = xwin32 -then - for exe in $WINDRES $host-windres $althost-windres $extra_windres - do - if check_run_command "$exe" "--version" - then - WINDRES="$exe" - break - fi - done -fi - -if test "x$CC" = x -o "x$CXX" = x -o "x$AR" = x -o "x$RANLIB" = x -then - die <config.mk <