From a6e0785b84993fa3a5192a66ee816ed7c0e0a43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 5 Jan 2014 17:55:43 +0100 Subject: [PATCH] Create `configure` script to generate a cross-platform Makefile The previous Makefile only worked on OS X. The dynamically generated Makefile (from `Makefile.in`) should now work on multiple platforms (tested on OS X and Ubuntu). --- .gitignore | 1 + src/Makefile | 10 ---------- src/Makefile.in | 25 +++++++++++++++++++++++++ src/configure | 39 +++++++++++++++++++++++++++++++++++++++ test/run | 1 + 5 files changed, 66 insertions(+), 10 deletions(-) delete mode 100644 src/Makefile create mode 100644 src/Makefile.in create mode 100755 src/configure diff --git a/.gitignore b/.gitignore index e64b015..84639e7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /sources /cache /libexec/*.dylib +/src/Makefile /src/*.o diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 6b31fd0..0000000 --- a/src/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -SHOBJ_LDFLAGS = -dynamiclib - -.c.o: - $(CC) $(CFLAGS) -c -o $@ $< - -../libexec/rbenv-realpath.dylib: realpath.o - $(CC) $(CFLAGS) $(SHOBJ_LDFLAGS) -o $@ realpath.o - -clean: - rm -f *.o ../libexec/*.dylib diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..b4b1825 --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,25 @@ +CC = @CC@ + +CFLAGS = @CFLAGS@ +LOCAL_CFLAGS = @LOCAL_CFLAGS@ +DEFS = @DEFS@ +LOCAL_DEFS = @LOCAL_DEFS@ + +CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS) + +SHOBJ_CC = @SHOBJ_CC@ +SHOBJ_CFLAGS = @SHOBJ_CFLAGS@ +SHOBJ_LD = @SHOBJ_LD@ +SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ +SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@ +SHOBJ_LIBS = @SHOBJ_LIBS@ +SHOBJ_STATUS = @SHOBJ_STATUS@ + +.c.o: + $(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) -c -o $@ $< + +../libexec/rbenv-realpath.dylib: realpath.o + $(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ realpath.o $(SHOBJ_LIBS) + +clean: + rm -f *.o ../libexec/*.dylib diff --git a/src/configure b/src/configure new file mode 100755 index 0000000..f54f09d --- /dev/null +++ b/src/configure @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -e + +src_dir="${0%/*}" + +CC="${CC:-gcc}" + +if ! which "$CC" &>/dev/null; then + echo "no compiler found: $CC" >&2 + exit 1 +fi + +case "$(uname -s)" in +Darwin* ) + host_os="darwin$(uname -r)" + ;; +OpenBSD* ) + host_os="openbsd$(uname -r)" + ;; +* ) + host_os="linux-gnu" +esac + +eval "$("$src_dir"/shobj-conf -C "$CC" -o "$host_os")" + +sed " + s,@CC@,${CC}, + s,@CFLAGS@,${CFLAGS}, + s,@LOCAL_CFLAGS@,${LOCAL_CFLAGS}, + s,@DEFS@,${DEFS}, + s,@LOCAL_DEFS@,${LOCAL_DEFS}, + s,@SHOBJ_CC@,${SHOBJ_CC}, + s,@SHOBJ_CFLAGS@,${SHOBJ_CFLAGS}, + s,@SHOBJ_LD@,${SHOBJ_LD}, + s,@SHOBJ_LDFLAGS@,${SHOBJ_LDFLAGS//,/\,}, + s,@SHOBJ_XLDFLAGS@,${SHOBJ_XLDFLAGS//,/\,}, + s,@SHOBJ_LIBS@,${SHOBJ_LIBS}, + s,@SHOBJ_STATUS@,${SHOBJ_STATUS}, +" "$src_dir"/Makefile.in > "$src_dir"/Makefile diff --git a/test/run b/test/run index 44f4128..9d3b9e5 100755 --- a/test/run +++ b/test/run @@ -2,6 +2,7 @@ set -e if [ -n "$RBENV_NATIVE_EXT" ]; then + src/configure make -C src fi