compile a subset on darwin
authorFelix Fietkau <nbd@openwrt.org>
Fri, 3 Dec 2010 18:16:10 +0000 (19:16 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 3 Dec 2010 18:16:10 +0000 (19:16 +0100)
.gitignore
Makefile

index 140f8cf80f2c88e66c141b1c4074b92b29fde4e6..9784b6a719127313e742c08d792afacd999efc64 100644 (file)
@@ -1 +1,2 @@
 *.so
+*.dylib
index 8af237d274800db2552f579420bc89637c17446a..3c0399a148aafed37fee3478c2e99d67d9b7d680 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,10 +8,23 @@ INCLUDE_DIR=$(PREFIX)/include/libubox
 LIBDIR=$(PREFIX)/lib
 CPPFLAGS=
 
-all: libubox.so
+OS=$(shell uname)
+FILES=blob.c blobmsg.c hash.c uhtbl.c
+ifeq ($(OS),Linux)
+  FILES += ucix.c usock.c uloop.c unl.c
+  LIBS += -luci $(LIBNL)
+  LDFLAGS_SHARED=-shared -Wl,-soname,$@
+  SHLIB_EXT=so
+endif
+ifeq ($(OS),Darwin)
+  LDFLAGS_SHARED=-dynamiclib
+  SHLIB_EXT=dylib
+endif
 
-libubox.so: ucix.c blob.c blobmsg.c hash.c uhtbl.c usock.c uloop.c unl.c
-       $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -shared -Wl,-soname,libubox.so $^ $(LDFLAGS) -luci $(LIBNL)
+all: libubox.$(SHLIB_EXT)
+
+libubox.$(SHLIB_EXT): $(FILES)
+       $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(LDFLAGS_SHARED)
 
 install-headers:
        mkdir -p $(INCLUDE_DIR)
@@ -19,10 +32,10 @@ install-headers:
 
 install-lib:
        mkdir -p $(LIBDIR)
-       cp libubox.so $(LIBDIR)/
+       cp libubox.$(SHLIB_EXT) $(LIBDIR)/
 
 install: install-lib install-headers
 
 clean:
-       rm -f *.so
+       rm -f *.$(SHLIB_EXT)