aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile30
-rw-r--r--mk/linux.mk4
-rw-r--r--mk/macos.mk4
-rw-r--r--mk/windows.mk4
4 files changed, 38 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 0b424bd..490ce9a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,24 @@
.POSIX:
+LIB_MAJOR = 1
+LIB_MINOR = 0
+LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
+
+
CONFIGFILE = config.mk
include $(CONFIGFILE)
+OS = linux
+# Linux: linux
+# Mac OS: macos
+# Windows: windows
+include mk/$(OS).mk
+
-all: libparser.a libparser-generate calc-example/calc
+
+all: libparser.a libparser.$(LIBEXT) libparser-generate calc-example/calc
libparser.o: libparser.c libparser.h
+libparser.lo: libparser.c libparser.h
calc-example/calc-syntax.o: calc-example/calc-syntax.c libparser.h
.c.o:
@@ -21,28 +34,37 @@ libparser.a: libparser.o
$(AR) rc $@ libparser.o
$(AR) -s $@
+libparser.$(LIBEXT): libparser.lo
+ $(CC) $(LIBFLAGS) -o $@ libparser.lo $(LDFLAGS)
+
calc-example/calc: calc-example/calc.o calc-example/calc-syntax.o libparser.a
$(CC) -o $@ calc-example/calc.o calc-example/calc-syntax.o libparser.a $(LDFLAGS)
calc-example/calc-syntax.c: libparser-generate calc-example/calc.syntax
./libparser-generate _expr < calc-example/calc.syntax > $@
-install: libparser.a libparser-generate
+install: libparser.a libparser.$(LIBEXT) libparser-generate
mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
mkdir -p -- "$(DESTDIR)$(PREFIX)/lib"
mkdir -p -- "$(DESTDIR)$(PREFIX)/include"
cp -- libparser-generate "$(DESTDIR)$(PREFIX)/bin"
cp -- libparser.a "$(DESTDIR)$(PREFIX)/lib"
+ cp -- libparser.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libparser.$(LIBMINOREXT)"
+ ln -sf -- libparser.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libparser.$(LIBMAJOREXT)"
+ ln -sf -- libparser.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libparser.$(LIBEXT)"
cp -- libparser.h "$(DESTDIR)$(PREFIX)/include"
uninstall:
-rm -f -- "$(DESTDIR)$(PREFIX)/bin/libparser-generate"
-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libparser.a"
+ -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libparser.$(LIBMAJOREXT)"
+ -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libparser.$(LIBMINOREXT)"
+ -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libparser.$(LIBEXT)"
-rm -f -- "$(DESTDIR)$(PREFIX)/include/libparser.h"
clean:
- -rm -f -- *.o *.lo *.a *.so *.su *-example/*.o *-example/*.su *-example/*-syntax.c libparser-generate
- -rm -f -- calc-example/calc
+ -rm -f -- *.o *.lo *.a *.so *.su *.dylib *.dll *-example/*.o *-example/*.su *-example/*-syntax.c
+ -rm -f -- libparser-generate calc-example/calc
.SUFFIXES:
.SUFFIXES: .c .o .lo
diff --git a/mk/linux.mk b/mk/linux.mk
new file mode 100644
index 0000000..bafa31c
--- /dev/null
+++ b/mk/linux.mk
@@ -0,0 +1,4 @@
+LIBEXT = so
+LIBFLAGS = -shared -Wl,-soname,libparser.$(LIBEXT).$(LIB_MAJOR)
+LIBMAJOREXT = $(LIBEXT).$(LIB_MAJOR)
+LIBMINOREXT = $(LIBEXT).$(LIB_VERSION)
diff --git a/mk/macos.mk b/mk/macos.mk
new file mode 100644
index 0000000..bd92de6
--- /dev/null
+++ b/mk/macos.mk
@@ -0,0 +1,4 @@
+LIBEXT = dylib
+LIBFLAGS = -dynamiclib
+LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT)
+LIBMINOREXT = $(LIB_VERSION).$(LIBEXT)
diff --git a/mk/windows.mk b/mk/windows.mk
new file mode 100644
index 0000000..e9602e1
--- /dev/null
+++ b/mk/windows.mk
@@ -0,0 +1,4 @@
+LIBEXT = dll
+LIBFLAGS = -mdll
+LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT)
+LIBMINOREXT = $(LIB_VERSION).$(LIBEXT)