aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-02-19 21:24:36 +0100
committerMattias Andrée <maandree@kth.se>2022-02-19 21:24:36 +0100
commit25d5a2b770e86713b2f3ebbf996e012873ffc49c (patch)
tree8814d3f16f4bc7eb10655c204008fc9e0a5d4b14
parentmake clean: remove __pycache__ (diff)
downloadlibcolour-25d5a2b770e86713b2f3ebbf996e012873ffc49c.tar.gz
libcolour-25d5a2b770e86713b2f3ebbf996e012873ffc49c.tar.bz2
libcolour-25d5a2b770e86713b2f3ebbf996e012873ffc49c.tar.xz
Improve makefile
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--.gitignore1
-rw-r--r--Makefile99
-rw-r--r--config.mk3
-rw-r--r--mk/linux.mk7
-rw-r--r--mk/macos.mk7
-rw-r--r--mk/windows.mk7
6 files changed, 67 insertions, 57 deletions
diff --git a/.gitignore b/.gitignore
index a4211ec..1887900 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
*.swo
*.swp
*.o
+*.lo
*.su
*.so.*
*.so
diff --git a/Makefile b/Makefile
index 866caf0..efc9a1c 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,18 @@
CONFIGFILE = config.mk
include $(CONFIGFILE)
-SO_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
+OS = linux
+# Linux: linux
+# Mac OS: macos
+# Windows: windows
+include mk/$(OS).mk
+
+
+LIB_MAJOR = 2
+LIB_MINOR = 3
+LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
+
+
OBJ =\
float.o\
@@ -79,66 +90,48 @@ MAN3_SYMLINKS =\
libcolour_convert_en_masse_llf.3
-all: libcolour.a libcolour.so.$(SO_VERSION) test
-
+all: libcolour.a libcolour.$(LIBEXT) test
+$(OBJ): $(HDR) $(TEMPLATES)
+$(LOBJ): $(HDR) $(TEMPLATES)
+test.o: test.c libcolour.h
conversion-matrices.h: matrices.py
printf '/* This file is generated! */\n' > conversion-matrices.h
./matrices.py >> conversion-matrices.h
+.c.o:
+ $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS)
-float.o: float.c $(TEMPLATES) $(HDR)
- $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ float.c
-
-double.o: double.c $(TEMPLATES) $(HDR)
- $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ double.c
-
-long-double.o: long-double.c $(TEMPLATES) $(HDR)
- $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ long-double.c
-
+.c.lo:
+ $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS)
-float.pic.o: float.c $(TEMPLATES) $(HDR)
- $(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ float.c
-
-double.pic.o: double.c $(TEMPLATES) $(HDR)
- $(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ double.c
-
-long-double.pic.o: long-double.c $(TEMPLATES) $(HDR)
- $(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ long-double.c
+test: test.o libcolour.a
+ $(CC) -o $@ test.o libcolour.a $(LDFLAGS)
+libcolour.$(lIBEXT): $(LOBJ)
+ $(CC) $(LIBFLAGS) -o $@ $(LOBJ) $(LDFLAGS)
libcolour.a: $(OBJ)
- $(AR) rc $@ $?
+ -rm -f -- $@
+ $(AR) rc $@ $(OBJ)
$(AR) -s $@
-libcolour.so.$(SO_VERSION): $(OBJ:.o=.pic.o)
- $(CC) -shared -Wl,-soname,libcolour.so.$(VERSION_MAJOR) -o $@ $(LDFLAGS) $^
-
-
-test.o: test.c libcolour.h
- $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ test.c
-
-test: test.o libcolour.a
- $(CC) -o $@ $^ $(LDFLAGS)
-
+check: test
+ ./test
-install: libcolour.a libcolour.so.$(SO_VERSION)
+install: libcolour.a libcolour.$(LIBEXT)
+ mkdir -p -- "$(DESTDIR)$(PREFIX)/lib"
mkdir -p -- "$(DESTDIR)$(PREFIX)/include"
+ mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3"
+ mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7"
cp -- libcolour.h "$(DESTDIR)$(PREFIX)/include/libcolour.h"
- chmod -- 644 "$(DESTDIR)$(PREFIX)/include/libcolour.h"
- mkdir -p -- "$(DESTDIR)$(PREFIX)/lib"
cp -- libcolour.a "$(DESTDIR)$(PREFIX)/lib/libcolour.a"
- chmod -- 644 "$(DESTDIR)$(PREFIX)/lib/libcolour.a"
- cp -- libcolour.so.$(SO_VERSION) "$(DESTDIR)$(PREFIX)/lib/libcolour.so.$(SO_VERSION)"
- chmod -- 755 "$(DESTDIR)$(PREFIX)/lib/libcolour.so.$(SO_VERSION)"
- ln -sf -- libcolour.so.$(SO_VERSION) "$(DESTDIR)$(PREFIX)/lib/libcolour.so.$(VERSION_MAJOR)"
- ln -sf -- libcolour.so.$(SO_VERSION) "$(DESTDIR)$(PREFIX)/lib/libcolour.so"
- mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7"
- cp -- $(MAN7) "$(DESTDIR)$(MANPREFIX)/man7/"
- cd -- "$(DESTDIR)$(MANPREFIX)/man7" && chmod -- 644 $(MAN7)
- mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3"
+ cp -- libcolour.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libcolour.$(LIBMINOREXT)"
+ $(FIX_INSTALL_NAME) -- "$(DESTDIR)$(PREFIX)/lib/libcolour.$(LIBMINOREXT)"
+ ln -sf -- "libcolour.$(LIBMINOREXT)" "$(DESTDIR)$(PREFIX)/lib/libcolour.$(LIBMAJOREXT)"
+ ln -sf -- "libcolour.$(LIBMAJOREXT)" "$(DESTDIR)$(PREFIX)/lib/libcolour.$(LIBEXT)"
cp -- $(MAN3) "$(DESTDIR)$(MANPREFIX)/man3/"
- cd -- "$(DESTDIR)$(MANPREFIX)/man3" && chmod -- 644 $(MAN3)
+ cp -- $(MAN7) "$(DESTDIR)$(MANPREFIX)/man7/"
ln -sf -- libcolour_convert.3 "$(DESTDIR)$(MANPREFIX)/man3/libcolour_convert_f.3"
ln -sf -- libcolour_convert.3 "$(DESTDIR)$(MANPREFIX)/man3/libcolour_convert_lf.3"
ln -sf -- libcolour_convert.3 "$(DESTDIR)$(MANPREFIX)/man3/libcolour_convert_llf.3"
@@ -167,22 +160,20 @@ install: libcolour.a libcolour.so.$(SO_VERSION)
ln -sf -- libcolour_convert_en_masse.3 "$(DESTDIR)$(MANPREFIX)/man3/libcolour_convert_en_masse_lf.3"
ln -sf -- libcolour_convert_en_masse.3 "$(DESTDIR)$(MANPREFIX)/man3/libcolour_convert_en_masse_llf.3"
-
uninstall:
-rm -f -- "$(DESTDIR)$(PREFIX)/include/libcolour.h"
-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcolour.a"
- -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcolour.so.$(SO_VERSION)"
- -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcolour.so.$(VERSION_MAJOR)"
- -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcolour.so"
+ -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcolour.so.$(LIBEXT)"
+ -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcolour.so.$(LIBMAJOREXT)"
+ -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libcolour.so.$(LIBMINOREXT)"
-cd -- "$(DESTDIR)$(MANPREFIX)/man7" && rm -f -- $(MAN7)
-cd -- "$(DESTDIR)$(MANPREFIX)/man3" && rm -f -- $(MAN3) $(MAN3_SYMLINKS)
-
-check: test
- ./test
-
clean:
- -rm -f -- *.o *.a *.so *.so.* test conversion-matrices.h
+ -rm -f -- *.o *.lo *.a *.so *.so.* test conversion-matrices.h
-rm -rf -- __pycache__/
-.PHONY: all clean check install uninstall
+.SUFFIXES:
+.SUFFIXES: .lo .o .c
+
+.PHONY: all check install uninstall clean
diff --git a/config.mk b/config.mk
index f541cc5..20b6a2e 100644
--- a/config.mk
+++ b/config.mk
@@ -1,6 +1,3 @@
-VERSION_MAJOR = 2
-VERSION_MINOR = 3
-
PREFIX = /usr
MANPREFIX = $(PREFIX)/share/man
diff --git a/mk/linux.mk b/mk/linux.mk
new file mode 100644
index 0000000..b371373
--- /dev/null
+++ b/mk/linux.mk
@@ -0,0 +1,7 @@
+LIBEXT = so
+LIBFLAGS = -shared -Wl,-soname,libcolour.$(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..7e492a1
--- /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/libcolour.$(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 = :