aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-02-19 21:05:57 +0100
committerMattias Andrée <maandree@kth.se>2022-02-19 21:05:57 +0100
commit1af6acb23d4b00f02a6b520562258e8bb7e38d2b (patch)
treea81ea358a4a58a4ab23fa33b5099c7451ed76a48 /Makefile
parentFix makefile, fix warnings, fix bugs, and otherwise improve code (diff)
downloadlibclut-1af6acb23d4b00f02a6b520562258e8bb7e38d2b.tar.gz
libclut-1af6acb23d4b00f02a6b520562258e8bb7e38d2b.tar.bz2
libclut-1af6acb23d4b00f02a6b520562258e8bb7e38d2b.tar.xz
Improve makefile
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile60
1 files changed, 39 insertions, 21 deletions
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