From 3c1973e9ef647cafbffb42760a905e79966f43bd Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 8 Apr 2021 21:45:55 +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 | 47 ++++++++++++++++++++++++++++++++++++++--------- mk/linux.mk | 4 ++++ mk/macos.mk | 4 ++++ mk/windows.mk | 4 ++++ 5 files changed, 52 insertions(+), 9 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 f0ff639..dc724f5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,7 @@ *.so *.su *.out +*.dll +*.dylib /test /interactive-test diff --git a/Makefile b/Makefile index b6913f6..59cd5b4 100644 --- a/Makefile +++ b/Makefile @@ -1,44 +1,73 @@ .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 =\ - interactive-test.o\ - libterminput.o + + +LOBJ =\ + libterminput.lo HDR =\ libterminput.h +OBJ =\ + interactive-test.o\ + $(LOBJ:.lo=.o) + -all: libterminput.a interactive-test +all: libterminput.a libterminput.$(LIBEXT) interactive-test $(OBJ): $(@:.o=.c) $(HDR) +$(LOBJ): $(@:.lo=.c) $(HDR) .c.o: $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) +.c.lo: + $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS) + .o.a: + -rm -f -- $@ $(AR) rc $@ $< $(AR) -s $@ +.lo.$(LIBEXT): + $(CC) $(LIBFLAGS) $(LDFLAGS_METHODS) -o $@ $< $(LDFLAGS) + interactive-test: interactive-test.o libterminput.a $(CC) -o $@ interactive-test.o libterminput.a $(LDFLAGS) -install: libterminput.a +install: libterminput.a libterminput.$(LIBEXT) mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" mkdir -p -- "$(DESTDIR)$(PREFIX)/include" cp -- libterminput.a "$(DESTDIR)$(PREFIX)/lib/" cp -- libterminput.h "$(DESTDIR)$(PREFIX)/include/" + cp -- libterminput.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBMINOREXT)" + ln -sf -- libterminput.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBMAJOREXT)" + ln -sf -- libterminput.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBEXT)" uninstall: - rm -- "$(DESTDIR)$(PREFIX)/lib/libterminput.a" - rm -- "$(DESTDIR)$(PREFIX)/include/libterminput.h" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBMAJOREXT)" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBMINOREXT)" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libterminput.$(LIBEXT)" + -rm -rf -- "$(DESTDIR)$(PREFIX)/lib/libterminput.a" + -rm -rf -- "$(DESTDIR)$(PREFIX)/include/libterminput.h" clean: - -rm -f -- *.o *.a interactive-test + -rm -f -- *.o *.a *.lo *.so *.su *.dll *.dylib interactive-test .SUFFIXES: -.SUFFIXES: .a .o .c +.SUFFIXES: .a .o .lo .c .$(LIBEXT) .PHONY: all install uninstall clean diff --git a/mk/linux.mk b/mk/linux.mk new file mode 100644 index 0000000..71922e7 --- /dev/null +++ b/mk/linux.mk @@ -0,0 +1,4 @@ +LIBEXT = so +LIBFLAGS = -shared -Wl,-soname,libterminput.$(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