From b2da2d6f15e28b755f22bb5557e8c79b3abacd7e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 8 Apr 2021 16:56:42 +0200 Subject: Add build of dynamically linked library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- .gitignore | 2 ++ Makefile | 35 +++++++++++++++++++++++++++++++---- TODO | 3 +-- mk/linux.mk | 4 ++++ mk/macos.mk | 4 ++++ mk/windows.mk | 4 ++++ 6 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 mk/linux.mk create mode 100644 mk/macos.mk create mode 100644 mk/windows.mk diff --git a/.gitignore b/.gitignore index baa5218..bf35bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ *.so *.su *.lo +*.dll +*.dylib diff --git a/Makefile b/Makefile index 4b61012..72f191b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,20 @@ .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 + + OBJ =\ libcontacts_address_destroy.o\ @@ -28,31 +40,46 @@ HDR =\ common.h\ libcontacts.h +LOBJ = $(OBJ:.o=.lo) -all: libcontacts.a + +all: libcontacts.a libcontacts.$(LIBEXT) $(OBJ): $($@:.o=.c) $(HDR) libcontacts.a: $(OBJ) + -rm -f -- $@ $(AR) rc $@ $(OBJ) $(AR) -s $@ +libcontacts.$(LIBEXT): $(LOBJ) + $(CC) $(LIBFLAGS) $(LDFLAGS_METHODS) -o $@ $(LOBJ) $(LDFLAGS) + .c.o: $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -install: libcontacts.a +.c.lo: + $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS) + +install: libcontacts.a libcontacts.$(LIBEXT) mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" mkdir -p -- "$(DESTDIR)$(PREFIX)/include" cp -- libcontacts.a "$(DESTDIR)$(PREFIX)/lib/" cp -- libcontacts.h "$(DESTDIR)$(PREFIX)/include/" + cp -- libcontacts.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libcontacts.$(LIBMINOREXT)" + ln -sf -- libcontacts.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libcontacts.$(LIBMAJOREXT)" + ln -sf -- libcontacts.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libcontacts.$(LIBEXT)" uninstall: + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcontacts.$(LIBMAJOREXT)" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcontacts.$(LIBMINOREXT)" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcontacts.$(LIBEXT)" -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcontacts.a" -rm -f -- "$(DESTDIR)$(PREFIX)/include/libcontacts.h" clean: - -rm -f -- *.o *.a *.lo *.so *.su + -rm -f -- *.o *.a *.lo *.so *.dylib *.dll *.su .SUFFIXES: -.SUFFIXES: .c .o +.SUFFIXES: .c .o .lo .PHONY: all install uninstall clean diff --git a/TODO b/TODO index aadad29..87edc04 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ -Add dynamically linked library +Add support for different calendars Add man pages Add readme Add tests -Add handle different calendars diff --git a/mk/linux.mk b/mk/linux.mk new file mode 100644 index 0000000..e248fc9 --- /dev/null +++ b/mk/linux.mk @@ -0,0 +1,4 @@ +LIBEXT = so +LIBFLAGS = -shared -Wl,-soname,libcontacts.$(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) -- cgit v1.2.3-70-g09d2