]> git.cworth.org Git - glaze/commitdiff
Add a configure script
authorCarl Worth <cworth@cworth.org>
Mon, 12 Aug 2013 20:18:37 +0000 (13:18 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 12 Aug 2013 20:40:23 +0000 (13:40 -0700)
The primary motivation is a new install target. And it's just plain
rude to provide an install target without also supporting --prefix and
DESTDIR, so we need this simple configure script at least.

.gitignore
Makefile
configure [new file with mode: 0755]

index 463ea60e0617d546d95c64fbb3baa9c059592c84..52ed726e1e5570cfc79e80b3f76f9561a8d7edaf 100644 (file)
@@ -1,2 +1,5 @@
 lib32
 lib64
 lib32
 lib64
+libglaze.so*
+Makefile.config
+*~
index c9db5c8f7a18300d037c542b54b7d689376d825e..3ccb7fa3d94772a059b42f0510e0085aea86e7f8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,18 @@
-CC     ?= gcc
-CFLAGS ?= -g
-CFLAGS += -Wall -Wextra -Wmissing-declarations -Werror=attributes
+LIBGLAZE_VERSION_MAJOR   = 0
+LIBGLAZE_VERSION_MINOR   = 0
+LIBGLAZE_VERSION_RELEASE = 0
+
+LIBGLAZE_LINKER_NAME = libglaze.so
+LIBGLAZE_SONAME = $(LIBGLAZE_LINKER_NAME).$(LIBGLAZE_VERSION_MAJOR)
+LIBGLAZE_LIBNAME = $(LIBGLAZE_SONAME).$(LIBGLAZE_VERSION_MINOR).$(LIBGLAZE_VERSION_RELEASE)
 
 TARGETS = lib64/libGL.so.1 lib32/libGL.so.1
 
 all: $(TARGETS)
 
 
 TARGETS = lib64/libGL.so.1 lib32/libGL.so.1
 
 all: $(TARGETS)
 
+$(LIBGLAZE_LIBNAME): glaze.c
+       $(CC) $(CFLAGS) -fPIC -shared -Wl,-Bsymbolic,-soname=$(LIBGLAZE_SONAME) -o $@ $<
+
 lib64/libGL.so.1: glaze-gl.c glapi.def
        mkdir -p lib64
        $(CC) $(CFLAGS) -m64 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
 lib64/libGL.so.1: glaze-gl.c glapi.def
        mkdir -p lib64
        $(CC) $(CFLAGS) -m64 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
@@ -14,5 +21,32 @@ lib32/libGL.so.1: glaze-gl.c specs/gl.def
        mkdir -p lib32
        $(CC) $(CFLAGS) -m32 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
 
        mkdir -p lib32
        $(CC) $(CFLAGS) -m32 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
 
+.PHONY: install
+install: all
+       mkdir -p $(DESTDIR)$(LIBDIR)/glaze/lib64
+       install -m0644 lib64/libGL.so.1 $(DESTDIR)$(LIBDIR)/glaze/lib64
+       mkdir -p $(DESTDIR)$(LIBDIR)/glaze/lib32
+       install -m0644 lib32/libGL.so.1 $(DESTDIR)$(LIBDIR)/glaze/lib32
+
 clean:
        rm -f $(TARGETS)
 clean:
        rm -f $(TARGETS)
+
+# Get settings from the output of configure by running it to generate
+# Makefile.config if it doesn't exist yet.
+
+# If Makefile.config doesn't exist, then srcdir won't be
+# set. Conditionally set it (assuming a plain srcdir build) so that
+# the rule to generate Makefile.config can actually work.
+srcdir ?= .
+
+include Makefile.config
+Makefile.config: $(srcdir)/configure
+ifeq ($(configure_options),)
+       @echo ""
+       @echo "Note: Calling ./configure with no command-line arguments. This is often fine,"
+       @echo "      but if you want to specify any arguments (such as an alternate prefix"
+       @echo "      into which to install), call ./configure explicitly and then make again."
+       @echo "      See \"./configure --help\" for more details."
+       @echo ""
+endif
+       $(srcdir)/configure $(configure_options)
diff --git a/configure b/configure
new file mode 100755 (executable)
index 0000000..6195562
--- /dev/null
+++ b/configure
@@ -0,0 +1,261 @@
+#! /bin/sh
+
+PROJECT=glaze
+PROJECT_BLURB="a shiny way to wrap OpenGL"
+
+srcdir=$(dirname "$0")
+
+# For a non-srcdir configure invocation (such as ../configure), create
+# the directory structure and copy Makefiles.
+if [ "$srcdir" != "." ]; then
+
+    for dir in . $(grep "^subdirs *=" "$srcdir"/Makefile | sed -e "s/subdirs *= *//"); do
+       mkdir -p "$dir"
+       cp "$srcdir"/"$dir"/Makefile.local "$dir"
+       cp "$srcdir"/"$dir"/Makefile "$dir"
+    done
+fi
+
+# Set several defaults (optionally specified by the user in
+# environment variables)
+CC=${CC:-gcc}
+CFLAGS=${CFLAGS:--O2}
+LDFLAGS=${LDFLAGS:-}
+
+# Set the defaults for values the user can specify with command-line
+# options.
+PREFIX=/usr/local
+
+usage ()
+{
+    cat <<EOF
+Usage: ./configure [options]...
+
+This script configures ${PROJECT} to build on your system.
+
+It verifies that dependencies are available, determines flags needed
+to compile and link against various required libraries, and identifies
+whether various system functions can be used or if locally-provided
+replacements will be built instead.
+
+Finally, it allows you to control various aspects of the build and
+installation process.
+
+First, some common variables can specified via environment variables:
+
+       CC              The C compiler to use
+       CFLAGS          Flags to pass to the C compiler
+       LDFLAGS         Flags to pass when linking
+
+Each of these values can further be controlled by specifying them
+later on the "make" command line.
+
+Additionally, various options can be specified on the configure
+command line.
+
+       --prefix=PREFIX Install files in PREFIX [$PREFIX]
+
+By default, "make install" will install the resulting program to
+$PREFIX/bin, documentation to $PREFIX/man, etc. You can
+specify an installation prefix other than $PREFIX using
+--prefix, for instance:
+
+       ./configure --prefix=\$HOME
+
+Fine tuning of some installation directories is available:
+
+       --bindir=DIR            Install executables to DIR [PREFIX/bin]
+       --libdir=DIR            Install libraries to DIR [PREFIX/lib]
+       --mandir=DIR            Install man pages to DIR [PREFIX/share/man]
+       --sysconfdir=DIR        Read-only single-machine data [PREFIX/etc]
+
+Additional options are accepted for compatibility with other
+configure-script calling conventions, but don't do anything yet:
+
+       --build=<cpu>-<vendor>-<os>     Currently ignored
+       --host=<cpu>-<vendor>-<os>      Currently ignored
+       --infodir=DIR                   Currently ignored
+       --datadir=DIR                   Currently ignored
+       --localstatedir=DIR             Currently ignored
+       --libexecdir=DIR                Currently ignored
+       --disable-maintainer-mode       Currently ignored
+       --disable-dependency-tracking   Currently ignored
+
+EOF
+}
+
+# Parse command-line options
+for option; do
+    if [ "${option}" = '--help' ] ; then
+       usage
+       exit 0
+    elif [ "${option%%=*}" = '--prefix' ] ; then
+       PREFIX="${option#*=}"
+    elif [ "${option%%=*}" = '--bindir' ] ; then
+       BINDIR="${option#*=}"
+    elif [ "${option%%=*}" = '--libdir' ] ; then
+       LIBDIR="${option#*=}"
+    elif [ "${option%%=*}" = '--mandir' ] ; then
+       MANDIR="${option#*=}"
+    elif [ "${option%%=*}" = '--sysconfdir' ] ; then
+       SYSCONFDIR="${option#*=}"
+    elif [ "${option%%=*}" = '--build' ] ; then
+       true
+    elif [ "${option%%=*}" = '--host' ] ; then
+       true
+    elif [ "${option%%=*}" = '--infodir' ] ; then
+       true
+    elif [ "${option%%=*}" = '--datadir' ] ; then
+       true
+    elif [ "${option%%=*}" = '--localstatedir' ] ; then
+       true
+    elif [ "${option%%=*}" = '--libexecdir' ] ; then
+       true
+    elif [ "${option}" = '--disable-maintainer-mode' ] ; then
+       true
+    elif [ "${option}" = '--disable-dependency-tracking' ] ; then
+       true
+    else
+       echo "Unrecognized option: ${option}"
+       echo "See:"
+       echo "  $0 --help"
+       echo ""
+       exit 1
+    fi
+done
+
+printf "Checking for working C compiler (${CC})... "
+printf "int main(void){return 42;}\n" > minimal.c
+if ${CC} -o minimal minimal.c > /dev/null 2>&1
+then
+    printf "Yes.\n"
+else
+    printf "No.\n"
+    cat <<EOF
+
+*** Error: No functioning C compiler found. Either set the CC environment
+to a working C compiler, or else install gcc:
+
+       http://gcc.gnu.org/
+
+You may be able to install gcc with a command such as:
+
+       sudo apt-get install build-essential
+    or:
+       sudo yum install make automake gcc gcc-c++ kernel-devel
+
+EOF
+
+exit 1
+
+fi
+
+WARN_CFLAGS=""
+printf "Checking for available C compiler warning flags:\n"
+for flag in -Wall -Wextra -Wmissing-declarations -Werror=attributes; do
+    if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
+    then
+       WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
+    fi
+done
+printf "\t${WARN_CFLAGS}\n"
+
+rm -f minimal minimal.c
+
+printf "#include <features.h>\nint main(void){return 0;}\n" > arch-minimal.c
+
+printf "Checking for machine-dependent compiler support:\n"
+
+printf "       Compiler can create 32-bit binaries... "
+have_m32=Yes
+if ${CC} -m32 -o arch-minimal arch-minimal.c > /dev/null 2>&1
+then
+    printf "Yes.\n"
+else
+    printf "No.\n"
+    have_m32=No
+fi
+
+printf "       Compiler can create 64-bit binaries... "
+have_m64=Yes
+if ${CC} -m64 -o arch-minimal arch-minimal.c > /dev/null 2>&1
+then
+    printf "Yes.\n"
+else
+    printf "No.\n"
+    have_m64=No
+fi
+
+if [ "$have_m32" = "No" ] || [ "$have_m64" = "No" ]; then
+    cat <<EOF
+
+* Warning: Cannot create both 32 and 64-bit glaze libraries. Glaze will not
+           support applications of the non-native size. Fixing this may be
+           as simple as running a command such as:
+
+               sudo apt-get install gcc-multilib
+EOF
+fi
+
+rm -f arch-minimal arch-minimal.c
+
+cat <<EOF
+
+You may now run the following commands to compile and install ${PROJECT}:
+
+       make
+       sudo make install
+
+EOF
+
+# construct the Makefile.config
+cat > Makefile.config <<EOF
+# This Makefile.config was automatically generated by the ./configure
+# script of ${PROJECT}. If the configure script identified anything
+# incorrectly, then you can edit this file to try to correct things,
+# but be warned that if configure is run again it will destroy your
+# changes, (and this could happen by simply calling "make" if the
+# configure script is updated).
+
+# The top-level directory for the source, (the directory containing
+# the configure script). This may be different than the build
+# directory (the current directory at the time configure was run).
+srcdir = ${srcdir}
+
+configure_options = $@
+
+# We use vpath directives (rather than the VPATH variable) since the
+# VPATH variable matches targets as well as prerequisites, (which is
+# not useful since then a target left-over from a srcdir build would
+# cause a target to not be built in the non-srcdir build).
+vpath % \$(srcdir)
+
+# The C compiler to use
+CC = ${CC}
+
+# Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
+CFLAGS = ${CFLAGS}
+
+# Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
+LDFLAGS = ${LDFLAGS}
+
+# Flags to enable warnings when using the C compiler
+WARN_CFLAGS=${WARN_CFLAGS}
+
+# The prefix to which ${PROJECT} should be installed
+PREFIX = ${PREFIX}
+
+# The directory to which executables should be installed
+BINDIR = ${BINDIR:=\$(PREFIX)/bin}
+
+# The directory to which libraries should be installed
+LIBDIR = ${LIBDIR:=\$(PREFIX)/lib}
+
+# The directory to which headers should be installed
+INCLUDEDIR = ${INCLUDEDIR:=\$(PREFIX)/include}
+
+# Whether compiler can create 32 or 64-bit binaries
+COMPILER_SUPPORTS_32 = ${have_m32}
+COMPILER_SUPPORTS_64 = ${have_m64}
+
+EOF