Browse Source

OS X support

Xℹ Ruoyao 4 years ago
parent
commit
9809eb1bb0
3 changed files with 30 additions and 8 deletions
  1. 2 1
      .gitignore
  2. 20 5
      Makefile
  3. 8 2
      demo/Makefile

+ 2 - 1
.gitignore

@@ -1,3 +1,4 @@
 demo/demo
 *.o
-libjump.so
+*.so
+*.dylib

+ 20 - 5
Makefile

@@ -13,9 +13,24 @@ CFLAGS += -fPIC
 OBJFILES := schmidt_trigger.o ringbuf.o monotonic_queue.o
 OBJFILES += jump_rope_count_device.o
 
-all: libjump.so demo/demo
-
-libjump.so: $(OBJFILES)
+DYLIB_SUFFIX=unknown
+UNAME_S := $(shell uname -s)
+ifeq ($(UNAME_S), Linux)
+	DYLIB_SUFFIX=.so
+endif
+ifeq ($(UNAME_S), Darwin)
+	DYLIB_SUFFIX=.dylib
+endif
+
+ifeq ($(DYLIB_SUFFIX), unknown)
+	$(error Unsupported operating system)
+else
+	DYLIB := libjump$(DYLIB_SUFFIX)
+endif
+
+all: $(DYLIB) demo/demo
+
+$(DYLIB): $(OBJFILES)
 	cc -o $@ -shared $^
 
 schmidt_trigger.o: schmidt_trigger.c schmidt_trigger.h
@@ -30,11 +45,11 @@ jump_rope_count_device.o: jump_rope_count_device.c \
 .PHONY: clean
 
 clean:
-	rm -v -f $(OBJFILES) libjump.so
+	rm -v -f $(OBJFILES) $(DYLIB)
 	make -C demo clean
 
 .PHONY: demo/demo
-demo/demo: libjump.so
+demo/demo: $(DYLIB)
 	make -C demo demo
 
 .PHONY: test

+ 8 - 2
demo/Makefile

@@ -1,8 +1,14 @@
-LDFLAGS=-L.. -Wl,-rpath -Wl,'$${ORIGIN}/..' -ljump -lm
+LIBS=-ljump -lm
+
+UNAME_S := $(shell uname -s)
+ifeq ($(UNAME_S), Linux)
+	LDFLAGS+=-L.. -Wl,-rpath -Wl,'$${ORIGIN}/..'
+endif
+
 CFLAGS=-I..
 
 demo: main.o ../libjump.so
-	cc -o $@ $(LDFLAGS) $<
+	cc -o $@ $(LDFLAGS) $< $(LIBS)
 
 main.o: main.c