lua build scripts
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 11 Jun 2010 04:19:07 +0000 (22:19 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 11 Jun 2010 04:19:07 +0000 (22:19 -0600)
Makefile
build/compile.lua [new file with mode: 0755]
build/compile.sh [deleted file]
build/functions.sh [deleted file]
build/process.sh [deleted file]
configure
doc/man2html.lua
doc/yoink.6.in
src/Main.cc

index ead9c51cc3c5d1d9b52e4ee09878d25b4b8fd904..9a0099550635212f5db05199854b86d741e2ab1a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -66,20 +66,21 @@ include $(dir)/rules.mk
 # Define some common rules.
 #
 
-CC_WRAPPER  = ./build/compile.sh $(CC)
-CXX_WRAPPER = ./build/compile.sh $(CXX)
-
-COMMAND_CC         = $(CC_WRAPPER)  $(CFLAGS)   $(CF_TGT) -o $@ -c $<
-COMMAND_CXX        = $(CXX_WRAPPER) $(CXXFLAGS) $(CF_TGT) -o $@ -c $<
-COMMAND_LD         = $(CC)  $(LDFLAGS)  $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
-COMMAND_LDX        = $(CXX) $(LDFLAGS)  $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
-COMMAND_CCLD       = $(CC_WRAPPER)  $(CFLAGS)   $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
-COMMAND_CXXLD      = $(CXX_WRAPPER) $(CXXFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
-COMMAND_AR         = $(AR) rcs $@ $^; $(RANLIB) $@
-COMMAND_RC         = $(WINDRES)     $(DDEFINES) $(DF_TGT) -o $@ -i $<
+ifeq ($(DEP_TRACKING),true)
+COMPILE = ./build/compile.lua
+endif
+
+COMMAND_CC         = $(COMPILE) $(CC)  $(CFLAGS)    $(CF_TGT) -o $@ -c $<
+COMMAND_CXX        = $(COMPILE) $(CXX) $(CXXFLAGS)  $(CF_TGT) -o $@ -c $<
+COMMAND_LD         = $(CC)  $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
+COMMAND_LDX        = $(CXX) $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS)
+COMMAND_CCLD       = $(COMPILE) $(CC)  $(CFLAGS)    $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
+COMMAND_CXXLD      = $(COMPILE) $(CXX) $(CXXFLAGS)  $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS)
+COMMAND_AR         = $(AR) rcs $@ $^;  $(RANLIB)    $@
+COMMAND_RC         = $(WINDRES)        $(DDEFINES)  $(DF_TGT) -o $@ -i $<
 COMMAND_INSTALL    = ./build/install.sh -m $1 $2 -d $3
 COMMAND_RM         = rm -f $1
-COMMAND_IN         = ./build/process.sh $1 $2
+COMMAND_IN         = sed -f config.sed <"$1" >"$2"
 
 ifeq ($(verbose),yes)
 DO_CC              = $(COMMAND_CC)
diff --git a/build/compile.lua b/build/compile.lua
new file mode 100755 (executable)
index 0000000..31b20fd
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/env lua
+
+--
+-- Yoink
+-- This script wraps around the compiler command to handle the creation of
+-- dependency files.  It works with new versions of GCC.
+--
+
+
+-- Get the next argument passed to the script.
+function shift()
+       var = arg[1]
+       table.remove(arg, 1)
+       arguments = string.format("%s %q", tostring(arguments), tostring(var))
+       return var
+end
+
+
+-- The compiler command is the first argument.
+compiler       = shift()
+arguments      = ""
+
+
+-- Consume each compiler argument, appending it to the arguments variable.
+while 0 < #arg do
+       local v = shift(arg)
+       if v == "-o" then product = shift(arg) end
+end
+if not product then print("No output file specified.") os.exit(1) end
+
+
+-- Now try the actual compile WITH dependency generation.
+if os.execute(compiler.." -MD"..arguments) ~= 0 then
+       -- Try it without dependency generation.
+       if os.execute(compiler..arguments) ~= 0 then
+               print("The compile failed.  :-(")
+               os.exit(1)
+       end
+       print("The compile succeeded without dependency generation.")
+       os.exit(0)
+end
+
+
+-- Remove the old dependency file.
+dep = product..".d"
+os.remove(dep)
+
+
+-- GCC outputs file.d for a product named file.o.
+gccdep = product:gsub("^.*/(.*)%.o$", "%1.d")
+tmpname = gccdep..".tmp"
+
+-- Fix up the dependency file with correct paths.
+if os.execute("test -f "..gccdep) == 0 and os.rename(gccdep, tmpname) then
+       os.execute(string.format("sed -e 's|.*:|%s %s:|' <%s >>%s", product, dep, tmpname, dep))
+       os.execute(string.format("sed -e 's/^.*://' -e 's/^ *//' -e 's/ *\\\\$//' -e 's/$/:/' <%s >>%s", tmpname, dep))
+       os.remove(tmpname)
+else
+       print("Couldn't find the dependency file at "..gccdep..".")
+       os.exit(1)
+end
+
diff --git a/build/compile.sh b/build/compile.sh
deleted file mode 100755 (executable)
index 75aec0a..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-#!/bin/sh
-#
-# CCDEPS-GCC (C) 2002 Emile van Bergen. Distribution of this file is allowed
-# under the conditions detailed in the GNU General Public License (GPL). See 
-# the file COPYING for more information.
-#
-# This script compiles and/or links one or more source or object files into a
-# object file or executable target, and outputs all extra dependencies found
-# while doing so in a file named target.d, which can be used by GNU Make.
-#
-# The script should be invoked the same way as your C compiler, that is,
-# specifying the target using a -o option and the source or object files as 
-# non-option arguments. It will generate dependencies in the form
-#
-# target target.d: dir/file1.c dir/file2.c header1.h header2.h
-# dir/file1.c dir/file2.c header1.h header2.h:
-#
-# This version is intended for GCC, which can do compilation and dependency
-# generation in one step. The name of the GCC version (default gcc) can be
-# overridden using the CC environment variable.
-#
-# CHANGELOG
-#
-# 2003/1/8: EvB: adapted for gcc 3.2, still handles 2.95 as well.
-#
-#   This was necessary because gcc 3.2 handles -MD differently than gcc 2.95:
-#   where the old version generated a .d file for each source, in the current
-#   directory, the new one does almost completely what this script intended to
-#   do: generate one .d file in the same directory and with the same file name
-#   as the target.
-#
-#   The only fixups 3.2's .d files still need are:
-#
-#   - changing the file name; gcc 3.2 strips the suffix of the target before 
-#     appending the .d, so targets x and x.o will both produce x.d, which is
-#     not what we want;
-#
-#   - adding the implicit dependencies as prerequisiteless targets, so that
-#     make will just consider the target out of date if one does not exist
-#     anymore; 
-#
-#   - adding the .d file as depending on the same prerequisites as our real
-#     target so that it will be considered out of date if one of the files
-#     mentioned in it are updated or missing.
-#
-#   Basically, this version does all that by simply including the file
-#   <strippedtarget>.d file in the list of .d files we look for. We may end
-#   up generating the same file name, but that already was handled correctly.
-#   Otherwise we perform the normal routine, so that we /know/ the targets will
-#   be correct, directories and all, regardless of variations in gcc behaviour.
-
-test -x "functions.sh" && . "functions.sh"
-test -x "build/functions.sh" && . "build/functions.sh"
-
-export CC=$1
-shift
-
-
-cmdline=""
-# After having passed the arguments, they have already been parsed once by
-# the shell, so they needed to be re-quoted.
-for arg in "$@"
-do
-       arg="$(quote_string "$arg")"
-       cmdline="$cmdline $arg"
-done
-
-
-while [ x"$1" != x ]
-do
-       case "$1" in
-               -o) tgt="$2" ; shift ;; # target specifier option
-               -x|-u|-b|-V) shift ;;   # options with arg after space
-               -*) ;;                  # standard options
-               *) fil="$fil $1" ;;     # source or object files
-       esac
-       shift
-done
-
-#if [ x"$CC" = x ]
-#then
-       #CC=gcc
-       #export CC
-#fi
-
-# If we're not processing any .c files (link only), run gcc as-is and we're done
-
-expr "$fil" : ".*\.c" >/dev/null || exec $CC $cmdline
-
-# Otherwise, run the gcc with the -MD option, which generates a .d file
-# in the current directory for each .c or .cc source file processed.
-#
-# These files are post-processed (replacing the incorrectly named target
-# with the real target specified with -o, and adding the .d file), concatenated
-# into one .d file that is named based on the target name, and put in the
-# correct directory. Further, all prerequisites are added as bare targets,
-# preventing errors when files are missing due to renaming or restructuring
-# headers, but causing the files dependent on them to be considered out of
-# date. (GNU Make feature).
-#
-# Makefiles must include the .d files like this: -include $(OBJS_$(d):.o=.d)
-# or, when compiling and linking in one step: -include $(TGTS_$(d):%=%.d)
-
-dep=$tgt.d
-rm -f $dep
-
-#echo $CC -MD $cmdline
-eval "$CC -MD $cmdline"
-res=$?
-
-dgcc3=`echo $tgt | sed -e 's/\.[^.]*$//'`.d
-dgcc=`echo $fil | sed -e 's/[^         ]*\.[^c]//' -e 's/\.cpp/\.d/g' -e 's/\.cc/\.d/g' -e 's/\.c/\.d/g' -e 's%.*/%%g'`
-
-for tf in $dgcc3 $dgcc
-do
-       if [ -f $tf ] && mv $tf $dep.tmp
-       then
-               sed -e "s%.*:%$tgt $dep:%" < $dep.tmp >> $dep
-               sed -e 's%^.*:%%' -e 's%^ *%%' -e 's% *\\$%%' -e 's%$%:%' \
-                       < $dep.tmp >> $dep
-               rm -f $dep.tmp
-               found=1
-       fi
-done
-
-[ x"$found" = x"1" ] && exit $res
-
-echo ERROR: $0: Cannot find any compiler-generated dependency files\!
-exit 1
-
diff --git a/build/functions.sh b/build/functions.sh
deleted file mode 100755 (executable)
index c330d93..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-
-
-# Print error message to stderr and exit.  The error message can either be
-# given as parameters or from stdin.
-die()
-{
-       echo -n "fatal: " >/dev/stderr
-       if [ "x$*" != x ]
-       then
-               echo $* >/dev/stderr
-       else
-               while read line;
-               do
-                       echo $line >/dev/stderr
-               done
-       fi
-       exit 1
-}
-
-# Parse an argument from an option in the form --option=argument.
-parse_argument()
-{
-       echo $(echo $2 | sed -e "s/--$1=\\(.*\\)$/\\1/")
-       return $?
-}
-
-# Insert all the escapes necessary to correctly quote a string for use in a
-# shell command.
-quote_string()
-{
-       for arg in "$@"
-       do
-               echo $1 | sed -e "s/'/\\'/g" \
-                                         -e 's/"/\\"/g' \
-                                         -e 's/|/\\|/g' \
-                                         -e 's/&/\\&/g' \
-                                         -e 's/;/\\;/g' \
-                                         -e 's/;/\\;/g' \
-                                         -e 's/(/\\(/g' \
-                                         -e 's/)/\\)/g' \
-                                         -e 's/</\\</g' \
-                                         -e 's/>/\\>/g' \
-                                         -e 's/ /\\ /g' \
-                                         -e "s/\t/\\\t/g" \
-                                         -e 's/\$/\\\$/g'
-       done
-}
-
-# Add a definition to the compiler flags.  The optional second parameter is
-# the unquoted value.
-define()
-{
-       if test "x$2" = x
-       then
-               defines="$defines -D$1"
-       else
-               defines="$defines -D$1=$2"
-       fi
-}
-
-# Add a definition to the compiler flags with a quoted value.
-define_string()
-{
-       arg=$(quote_string "$2")
-       define "$1" "\\\"$arg\\\""
-}
-
-undefine()
-{
-       for arg in "$@"
-       do
-               defines="$defines -U$arg"
-       done
-}
-
-is_defined()
-{
-       for arg in "$@"
-       do
-               echo "$defines" | grep -e "-D$arg" 2>&1 >/dev/null || return 1
-       done
-       return 0
-}
-
-is_undefined()
-{
-       for arg in "$@"
-       do
-               echo "$defines" | grep -e "-U$arg" 2>&1 >/dev/null || return 1
-       done
-       return 0
-}
-
diff --git a/build/process.sh b/build/process.sh
deleted file mode 100755 (executable)
index d173a79..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-#
-# Yoink
-# Run this as a filter to process `.in' files.
-#
-
-test -x "functions.sh" && . "functions.sh"
-test -x "build/functions.sh" && . "build/functions.sh"
-
-tmpfile=$(mktemp "tmp-XXXXXXXX") || die "could not create temp file"
-vars=$(export -p)
-echo "$vars" | sed -n "s/^export \([A-Za-z0-9_]*\)\{1,\}=[\"']\{0,1\}\([^\"'=]*\)[\"']\{0,1\}$/s=@\1@=\2=g/g p" >"$tmpfile"
-sed -f "$tmpfile" <"$1" >"$2"
-rm -f "$tmpfile"
-
index 06a303d39c002ec9a9432ca170dd8178f0be31f7..5e691c171eacb6b4b11a9f02aba5e4285de63638 100755 (executable)
--- a/configure
+++ b/configure
-#!/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"
+package                = project:lower()
+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 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
-}
-
-
-#
-# 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
+       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.
+       
+       if not host then host = ReadCommand("build/config.guess") end
+       alt_host = ReadCommand("build/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
-       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 <stdio.h>
 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 <iostream>
 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 <<END
-A working version of one or more of these required tools is missing:
-  CC      = $CC
-  CXX     = $CXX
-  AR      = $AR
-  RANLIB  = $RANLIB
-END
-fi
-
-
-#
-# Check for the libraries we need.
-#
-
-deps="sdl gl glu libpng openal vorbisfile lua"
-
-if test x$gtk = xyes
-then
-       deps="$deps gtk+-2.0"
-elif test x$qt4 = xyes
-then
-       deps="$deps QtGui"
-fi
-
-pc_cflags=$(pkg-config --cflags $deps)
-CFLAGS="$CFLAGS $pc_cflags"
-CXXFLAGS="$CXXFLAGS $pc_cflags"
-
-pc_ldflags=$(pkg-config --libs-only-L $deps)
-LDFLAGS="$LDFLAGS $pc_ldflags"
-
-pc_libs=$(pkg-config --libs-only-l $deps)
-LIBS="$LIBS $pc_libs"
-
-# Windows sockets are in libws2_32.
-if test x$HOST = xwin32
-then
-       LIBS="$LIBS -lws2_32"
-       EXEEXT=".exe"
-fi
-
-
-#
-# Find the game resources to install.
-#
-
-#data_files=$(echo $(find . -name "*.lua" \
-                                               #-o -name "*.ogg" \
-                                               #-o -name "*.png" \
-                                               #-o -name "yoinkrc"))
-# FIXME: doesn't work yet
-
-
-#
-# Define version components needed by src/yoink.rc.
-#
-
-vmajor=$(echo $VERSION | cut -d. -f1)
-vminor=$(echo $VERSION | cut -d. -f2)
-vrevis=$(echo $VERSION | cut -d. -f3)
-
-define "VERSION_MAJOR"    "${vmajor:-0}"
-define "VERSION_MINOR"    "${vminor:-0}"
-define "VERSION_REVISION" "${vrevis:-0}"
-
-
-#
-# Determine and define the git revision.
-#
-
-if githead=$(git log -n1 --date=short --pretty=format:"%h (%ad)")
-then
-       define_string "YOINK_GITHEAD" "$githead"
-fi
-
-
-#
-# Finalize the compiler flags, linker flags, and library list.
-#
-
-define_string "PACKAGE"           "$PACKAGE"
-define_string "PACKAGE_NAME"      "$PACKAGE"
-define_string "VERSION"           "$VERSION"
-define_string "PACKAGE_VERSION"   "$VERSION"
-define_string "PACKAGE_STRING"    "$PACKAGE $VERSION"
-define_string "PACKAGE_BUGREPORT" "$BUGREPORT"
-
-CFLAGS=$(echo $CFLAGS $cflags $defines)
-CXXFLAGS=$(echo $CXXFLAGS $cflags $defines)
-LDFLAGS=$(echo $LDFLAGS)
-LIBS=$(echo $LIBS)
-
-
-#
-# All done; output the configuration file.
-#
-
-cat >config.mk <<END
-
-HOST       = $HOST
-
-CC         = $CC
-CXX        = $CXX
-AR         = $AR
-RANLIB     = $RANLIB
-WINDRES    = $WINDRES
-
-CFLAGS     = $CFLAGS
-CXXFLAGS   = $CXXFLAGS
-LDFLAGS    = $LDFLAGS
-LIBS       = $LIBS
+       function extra() if not cross_compile then return "ranlib" end end
+       RANLIB = FindCommand({
+               RANLIB,
+               host.."-ranlib",
+               alt_host.."-ranlib",
+               extra()}, "--version")
+       if not RANLIB then Die("Can't find a working library indexer.") end
+end
+
+-- Check for WINDRES.
+if platform == "win32" then
+       function extra() if not cross_compile then return "windres" end end
+       WINDRES = FindCommand({
+               WINDRES,
+               host.."-windres",
+               alt_host.."-windres",
+               extra()}, "--version")
+       if not WINDRES then Die("Can't find a working win32 resource compiler.") end
+end
+
+
+--
+-- Configure the features and packages.
+--
+
+if GetFeature("debug") then
+       cflags = cflags.." -O0 -Wall -Wno-uninitialized"
+       config.DEBUG = true
+else
+       config.NDEBUG = true
+end
+
+if GetFeature("double-precision") then
+       config.USE_DOUBLE_PRECISION = true
+end
+
+if GetFeature("profile") then
+       cflags = cflags.." -pg"
+       config.PROFILING_ENABLED = true
+end
+
+if GetFeature("extra-warnings") then
+       cflags = cflags.." -Wextra -Wno-unused-parameter"
+end
+
+if GetFeature("link-sh") then
+       -- TODO
+end
+
+if GetFeature("clock_gettime") then
+       -- TODO
+end
+
+if GetFeature("threads") then
+       config.USE_THREADS = true
+end
+
+if GetFeature("hotloading") then
+       print("FYI: Hotloading is very experimental and only works on Linux.");
+       config.USE_HOTLOADING = true
+end
+
+if GetPackage("gtk") then
+       -- TODO
+end
+
+if GetPackage("qt4") then
+       -- TODO
+end
+
+
+--
+-- Check for the libraries we need.
+--
 
-prefix     = $prefix
-bindir     = $bindir
-datadir    = $datadir
-libdir     = $libdir
-mandir     = $mandir
-
-EXEEXT     = $EXEEXT
+do
+       local command   = "PKG_CONFIG_PATH="..libdir.."/pkgconfig:$PKG_CONFIG_PATH pkg-config"
+       local deps              = "sdl gl glu libpng openal vorbisfile lua"
+
+       if GetPackage("gtk") then
+               deps = deps.." gtk+-2.0"
+       elseif GetPackage("qt4") then
+               deps = deps.." QtGui"
+       end
+
+       local pc_cflags = ReadCommand(command.." --cflags "..deps)
+       if not pc_cflags then Die("Couldn't determine CFLAGS.") end
+       CFLAGS = CFLAGS.." "..pc_cflags
+       CXXFLAGS = CXXFLAGS.." "..pc_cflags
+
+       local pc_libs = ReadCommand(command.." --libs "..deps)
+       if not pc_libs then Die("Couldn't determine LDFLAGS or LIBS.") end
+       for lib in pc_libs:gmatch("%-l%S+") do
+               LIBS = LIBS.." "..lib
+       end
+       for ldflag in pc_libs:gmatch("%-[^l]%S*") do
+               LDFLAGS = LDFLAGS.." "..ldflag
+       end
+
+       if platform == "win32" then
+               LIBS = LIBS.." -lws2_32"
+               exe_extension = ".exe"
+       else
+               exe_extension = ""
+       end
+end
+
+CFLAGS         = Reduce(CFLAGS.." "..cflags)
+CXXFLAGS       = Reduce(CXXFLAGS.." "..cflags)
+LDFLAGS                = Reduce(LDFLAGS)
+LIBS           = Reduce(LIBS)
+
+
+--
+-- Define the exports and definitions.
+--
+
+config.YOINK_DATADIR = datadir
+export.YOINK_DATADIR = datadir
 
-END
+do
+       local vmajor = ReadCommand("v=$(echo "..version.." | cut -d. -f1); echo ${v:-0}")
+       local vminor = ReadCommand("v=$(echo "..version.." | cut -d. -f2); echo ${v:-0}")
+       local vrevis = ReadCommand("v=$(echo "..version.." | cut -d. -f3); echo ${v:-0}")
 
+       config.VERSION_MAJOR            = tonumber(vmajor)
+       config.VERSION_MINOR            = tonumber(vminor)
+       config.VERSION_REVISION         = tonumber(vrevis)
+end
 
-echo ""
-echo " Configuration complete!  Review your configuration in \`config.mk'":
-echo ""
-cat config.mk | grep -e "^prefix" \
-                                        -e "^datadir" \
-                                        -e "^CXX"  \
-                                        -e "^CXXFLAGS" \
-                                        -e "^LDFLAGS" \
-                                        -e "^LIBS"
-echo ""
-echo " To finish the installation, type:"
-echo "  make"
-echo "  make install"
-echo ""
+do
+       -- Determine and define the git revision.
+       local head = ReadCommand("git log -n1 --date=short --pretty=format:\"%h (%ad)\"")
+       config.YOINK_GITHEAD = head
+end
+
+config.PACKAGE                         = project
+config.PACKAGE_NAME                    = project
+config.VERSION                         = version
+config.PACKAGE_VERSION         = version
+config.PACKAGE_STRING          = project.." "..version
+config.PACKAGE_BUGREPORT       = bugreport
+
+define.TARGET          = host
+define.PLATFORM                = platform
+define.CC                      = CC
+define.CXX                     = CXX
+define.AR                      = AR
+define.RANLIB          = RANLIB
+define.WINDRES         = WINDRES
+define.CFLAGS          = CFLAGS
+define.CXXFLAGS                = CXXFLAGS
+define.LDFLAGS         = LDFLAGS
+define.LIBS                    = LIBS
+define.prefix          = prefix
+define.bindir          = bindir
+define.datadir         = datadir
+define.mandir          = mandir
+define.EXEEXT          = exe_extension
+
+
+--
+-- All done; output the configuration files.
+--
+
+-- Print the program options.
+output = io.open("config.h", "w")
+for key,value in pairs(config) do
+       key = tostring(key)
+       if type(value) == "boolean" then
+               if value then
+                       output:write("#define "..key)
+               else
+                       output:write("#undef "..key)
+               end
+       elseif type(value) == "string" then
+               output:write(string.format("#define %s %q", key, tostring(value)))
+       else
+               output:write(string.format("#define %s %s", key, tostring(value)))
+       end
+       output:write("\n")
+end
+output:close()
+
+-- Print the make definitions.
+output = io.open("config.mk", "w")
+for key,value in pairs(define) do
+       key             = tostring(key)
+       value   = tostring(value)
+       output:write(string.format("%s = %s\n", key, value))
+end
+output:close()
+
+
+-- Print the exported variables.
+output = io.open("config.sed", "w")
+for key,value in pairs(export) do
+       key             = key:gsub("/", "\\/")
+       value   = value:gsub("/", "\\/")
+       output:write(string.format("s/@%s@/%s/g\n", key, value))
+end
+output:close()
+
+
+print([[
+
+ Configuration complete!  You can review your configuration in `config.mk'.
+
+ To finish the installation, type:
+  make
+  make install
+]])
 
index 0fa3d5ba67bc59bab4a737209113947ba86ed974..9a305b092cb9ba5d10c0f993da04e655b69b34b2 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/lua
+#!/usr/bin/env lua
 
 --
 -- Yoink
index 500cb8964fd90547693981b90c4184b4d490009b..9eb2b430680d88677d849631aa3c4f4dc8c30e15 100644 (file)
@@ -50,7 +50,7 @@ You have a certain level of control over the operation of \fByoink\fP
 through options passed as program arguments or given in config files.
 \fByoink\fP looks for config files in several locations and in this order:
 .TP
-1. \fI@HOME@/yoinkrc\fP
+1. \fI@YOINK_DATADIR@/yoinkrc\fP
 This is the base config file which should be considered read-only.  Look to
 this file as an example of the format used for config files.
 .TP
index 2df3f1e93da9e96cf114f998df45b5e063c7d03e..fb442d33ceb8cc2181be21559be625472d3ea090 100644 (file)
@@ -27,6 +27,7 @@
 #include "Main.hh"
 #include "TitleLayer.hh"
 
+#include "../config.h"
 #include "version.h"
 
 
@@ -340,6 +341,7 @@ public:
 int main(int argc, char* argv[])
 {
        moof::resource::register_type<MyAsset>("mine");
+       
        //moof::resource::add_type<AnotherAsset>("k");
        
        //{
This page took 0.047252 seconds and 4 git commands to generate.