From 1af6acb23d4b00f02a6b520562258e8bb7e38d2b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 19 Feb 2022 21:05:57 +0100 Subject: Improve makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 60 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index ac15b3a..ffa9da4 100644 --- a/Makefile +++ b/Makefile @@ -3,51 +3,69 @@ CONFIGFILE = config.mk include $(CONFIGFILE) -VERSION_MAJOR = 1 -VERSION = 1.2 +OS = linux +# Linux: linux +# Mac OS: macos +# Windows: windows +include mk/$(OS).mk -all: libclut.a libclut.so test +LIB_MAJOR = 1 +LIB_MINOR = 0 +LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) -libclut.o: libclut.c libclut.h - $(CC) -c -o $@ libclut.c $(CPPFLAGS) $(CFLAGS) -libclut.lo: libclut.c libclut.h - $(CC) -fPIC -c -o $@ libclut.c $(CPPFLAGS) $(CFLAGS) +HDR = libclut.h +OBJ = libclut.o -libclut.a: libclut.o - $(AR) rc $@ libclut.o - $(AR) s $@ +LOBJ = $(OBJ:.o=.lo) -libclut.so: libclut.lo - $(CC) -shared -Wl,-soname,libclut.so.$(VERSION_MAJOR) -o $@ $(LDFLAGS) libclut.lo -test.o: test.c libclut.h - $(CC) -c -o $@ test.c $(CPPFLAGS) $(CFLAGS) +all: libclut.a libclut.$(LIBEXT) test +$(OBJ): $(HDR) +$(LOBJ): $(HDR) + +.c.o: + $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) + +.c.lo: + $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS) test: test.o libclut.a $(CC) -o $@ test.o libclut.a $(LDFLAGS) +libclut.$(LIBEXT): $(LOBJ) + $(CC) $(LIBFLAGS) -o $@ $(LOBJ) $(LDFLAGS) + +libclut.a: $(OBJ) + -rm -f -- $@ + $(AR) rc $@ $(OBJ) + $(AR) -s $@ + check: test ./test -install: libclut.a libclut.so +install: libclut.a libclut.$(LIBEXT) mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" mkdir -p -- "$(DESTDIR)$(PREFIX)/include" cp -- libclut.a "$(DESTDIR)$(PREFIX)/lib" - cp -- libclut.so "$(DESTDIR)$(PREFIX)/lib/libclut.so.$(VERSION_MAJOR)" - ln -sf -- libclut.so.$(VERSION_MAJOR) "$(DESTDIR)$(PREFIX)/lib/libclut.so.$(VERSION)" - ln -sf -- libclut.so.$(VERSION_MAJOR) "$(DESTDIR)$(PREFIX)/lib/libclut.so" + cp -- libclut.so "$(DESTDIR)$(PREFIX)/lib/libclut.$(LIBMINOREXT)" + $(FIX_INSTALL_NAME) -- "$(DESTDIR)$(PREFIX)/lib/libclut.$(LIBMINOREXT)" + ln -sf -- "libclut.$(LIBMINOREXT)" "$(DESTDIR)$(PREFIX)/lib/libclut.$(LIBMAJOREXT)" + ln -sf -- "libclut.$(LIBMINOREXT)" "$(DESTDIR)$(PREFIX)/lib/libclut.$(LIBEXT)" cp -- libclut.h "$(DESTDIR)$(PREFIX)/include" uninstall: -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libclut.a" - -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libclut.so.$(VERSION_MAJOR)" - -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libclut.so.$(VERSION)" - -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libclut.so" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libclut.so.$(LIBEXT)" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libclut.so.$(LIBMAJOREXT)" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libclut.so.$(LIBMINOREXT)" -rm -f -- "$(DESTDIR)$(PREFIX)/include/libclut.h" clean: -rm -f -- *.o *.a *.so *.lo *.su test +.SUFFIXES: +.SUFFIXES: .lo .o .c + .PHONY: all check install uninstall clean -- cgit v1.2.3-70-g09d2