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).
This commit is contained in:
Mislav Marohnić 2014-01-05 17:55:43 +01:00
parent 302b317b89
commit a6e0785b84
5 changed files with 66 additions and 10 deletions

1
.gitignore vendored
View file

@ -5,4 +5,5 @@
/sources
/cache
/libexec/*.dylib
/src/Makefile
/src/*.o

View file

@ -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

25
src/Makefile.in Normal file
View file

@ -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

39
src/configure vendored Executable file
View file

@ -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

View file

@ -2,6 +2,7 @@
set -e
if [ -n "$RBENV_NATIVE_EXT" ]; then
src/configure
make -C src
fi