Skip to content

Commit

Permalink
Create configure script to generate a cross-platform Makefile
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
mislav committed Oct 13, 2014
1 parent 302b317 commit a6e0785
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/sources
/cache
/libexec/*.dylib
/src/Makefile
/src/*.o
10 changes: 0 additions & 10 deletions src/Makefile

This file was deleted.

25 changes: 25 additions & 0 deletions src/Makefile.in
Original file line number Diff line number Diff line change
@@ -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 changes: 39 additions & 0 deletions src/configure
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -e

if [ -n "$RBENV_NATIVE_EXT" ]; then
src/configure
make -C src
fi

Expand Down

0 comments on commit a6e0785

Please sign in to comment.