aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--Makefile60
-rw-r--r--config.mk4
-rw-r--r--mk/linux.mk7
-rw-r--r--mk/macos.mk7
-rw-r--r--mk/windows.mk7
5 files changed, 62 insertions, 23 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
diff --git a/config.mk b/config.mk
index 9b1bc39..9aa4de7 100644
--- a/config.mk
+++ b/config.mk
@@ -1,8 +1,8 @@
PREFIX = /usr
MANPREFIX = $(PREFIX)/share/man
-CC = cc
+CC = c99
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
-CFLAGS = -std=c99 -Wall -O2
+CFLAGS = -Wall -O2
LDFLAGS = -lm -s
diff --git a/mk/linux.mk b/mk/linux.mk
new file mode 100644
index 0000000..37ce5a6
--- /dev/null
+++ b/mk/linux.mk
@@ -0,0 +1,7 @@
+LIBEXT = so
+LIBFLAGS = -shared -Wl,-soname,libclut.$(LIBEXT).$(LIB_MAJOR)
+
+LIBMAJOREXT = $(LIBEXT).$(LIB_MAJOR)
+LIBMINOREXT = $(LIBEXT).$(LIB_MAJOR).$(LIB_MINOR)
+
+FIX_INSTALL_NAME = :
diff --git a/mk/macos.mk b/mk/macos.mk
new file mode 100644
index 0000000..c5636bf
--- /dev/null
+++ b/mk/macos.mk
@@ -0,0 +1,7 @@
+LIBEXT = dylib
+LIBFLAGS = -dynamiclib -Wl,-compatibility_version,$(LIB_MAJOR) -Wl,-current_version,$(LIB_VERSION)
+
+LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT)
+LIBMINOREXT = $(LIB_MAJOR).$(LIB_MINOR).$(LIBEXT)
+
+FIX_INSTALL_NAME = install_name_tool -id "$(PREFIX)/lib/libclut.$(LIBMAJOREXT)"
diff --git a/mk/windows.mk b/mk/windows.mk
new file mode 100644
index 0000000..304b6be
--- /dev/null
+++ b/mk/windows.mk
@@ -0,0 +1,7 @@
+LIBEXT = dll
+LIBFLAGS = -shared
+
+LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT)
+LIBMINOREXT = $(LIB_MAJOR).$(LIB_MINOR).$(LIBEXT)
+
+FIX_INSTALL_NAME = :