From: Niki Roo Date: Fri, 21 Jun 2024 12:32:25 +0000 (+0200) Subject: Makefile improvements X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=85810b2d0062b54b304ae9a79bbc79fca20d0e6e;p=cutils.git Makefile improvements --- diff --git a/Makefile b/Makefile index 48d3e3d..a71c67a 100644 --- a/Makefile +++ b/Makefile @@ -1,83 +1,10 @@ -# Note: 99+ required for for-loop initial declaration (CentOS 6) -# Note: gnu99 (instead of c99) required for libcutils-net +# Simply pass everything to makefile.d, but calling from "../" -CFLAGS += -Wall -pedantic -I./ -std=gnu99 -CXXFLAGS += -Wall -pedantic -I./ -PREFIX = /usr/local +.PHONY: MK all install uninstall clean mrpropre mrpropre \ + utils check net -ifdef DEBUG -CFLAGS += -ggdb -O0 -CXXFLAGS += -ggdb -O0 -endif - -.PHONY: all cutils check net install uninstall clean mrpropre mrpropre debug - -all: utils check net - -utils: ../../bin/libcutils.o - -check: ../../bin/libcutils-check.o - -net: ../../bin/libcutils-net.o - -SOURCES=$(wildcard *.c) -HEADERS=$(wildcard *.h) -OBJECTS=$(SOURCES:%.c=%.o) - -array.o: array.[ch] -desktop.o: desktop.[ch] array.h - -../../bin/libcutils.o: $(OBJECTS) - mkdir -p ../../bin - # note: -r = --relocatable, but former also works with Clang - $(LD) -r $(OBJECTS) -o $@ - -../../bin/libcutils-check.o: check/launcher.o - mkdir -p ../../bin - # note: -r = --relocatable, but former also works with Clang - $(LD) -r check/launcher.o -o $@ - -../../bin/libcutils-net.o: net/net.o - mkdir -p ../../bin - # note: -r = --relocatable, but former also works with Clang - $(LD) -r net/net.o -o $@ - -debug: - $(MAKE) -f makefile.d DEBUG=1 - -clean: - rm -f *.o check/*.o net/*.o - -mrproper: mrpropre - -mrpropre: clean - rm -f ../../bin/libcutils.o - rm -f ../../bin/libcutils-check.o - rm -f ../../bin/lubcutils-net.o - rmdir ../../bin 2>/dev/null || true - -install: - @echo "installing cutils to $(PREFIX)..." - mkdir -p "$(PREFIX)/lib/cutils/" - cp ../../bin/libcutils.o "$(PREFIX)/lib/cutils/" - cp ../../bin/libcutils-check.o "$(PREFIX)/lib/cutils/" - cp ../../bin/libcutils-net.o "$(PREFIX)/lib/cutils/" - mkdir -p "$(PREFIX)/include/cutils/check/" - mkdir -p "$(PREFIX)/include/cutils/net/" - cp *.h "$(PREFIX)/include/cutils/" - cp check/*.h "$(PREFIX)/include/cutils/check/" - cp net/*.h "$(PREFIX)/include/cutils/net/" - -uninstall: - @echo "uninstalling utils from $(PREFIX)..." - rm -f "$(PREFIX)/lib/cutils/libcutils.o" - rm -f "$(PREFIX)/lib/cutils/libcutils-check.o" - rm -f "$(PREFIX)/lib/cutils/libcutils-net.o" - rmdir "$(PREFIX)/lib/cutils/" 2>/dev/null || true - rm -f "$(PREFIX)/include/cutils/net/"*.h - rm -f "$(PREFIX)/include/cutils/check/"*.h - rm -f "$(PREFIX)/include/cutils/"*.h - rmdir "$(PREFIX)/include/cutils/net" 2>/dev/null || true - rmdir "$(PREFIX)/include/cutils/check" 2>/dev/null || true - rmdir "$(PREFIX)/include/cutils" 2>/dev/null || true +$(MAKECMDGOALS): MK +MK: + @$(MAKE) --no-print-directory -C ../ -f $(CURDIR)/makefile.d \ + $(MAKECMDGOALS) diff --git a/check/launcher.h b/check/launcher.h index b1e6e63..8df774a 100644 --- a/check/launcher.h +++ b/check/launcher.h @@ -13,6 +13,7 @@ START_TEST(name) {\ END_TEST\ #define FAIL(...) \ +/* TODO: test_failure(); ??? */ \ ck_abort_msg(__VA_ARGS__)\ #define ASSERT_EQUALS_STR(title, expected, received) \ diff --git a/makefile.d b/makefile.d new file mode 100644 index 0000000..fe4b713 --- /dev/null +++ b/makefile.d @@ -0,0 +1,86 @@ +# Note: 99+ required for for-loop initial declaration (CentOS 6) +# Note: gnu99 (instead of c99) required for libcutils-net + +NAME = cutils +srcdir = cutils +dstdir = ../bin + +CFLAGS += -Wall -pedantic -I./ -std=gnu99 +CXXFLAGS += -Wall -pedantic -I./ +PREFIX = /usr/local + +ifdef DEBUG +CFLAGS += -ggdb -O0 +CXXFLAGS += -ggdb -O0 +endif + +.PHONY: all install uninstall clean mrpropre mrpropre \ + utils check net + +all: utils check net + +utils: $(dstdir)/libcutils.o + +check: $(dstdir)/libcutils-check.o + +net: $(dstdir)/libcutils-net.o + +SOURCES=$(wildcard $(srcdir)/*.c) +HEADERS=$(wildcard $(srcdir)/*.h) +OBJECTS=$(SOURCES:%.c=%.o) + +$(srcdir)/array.o: $(srcdir)/array.[ch] +$(srcdir)/desktop.o: $(srcdir)/desktop.[ch] $(srcdir)/array.h + +$(dstdir)/libcutils.o: $(OBJECTS) + mkdir -p $(dstdir) + # note: -r = --relocatable, but former also works with Clang + $(LD) -r $(OBJECTS) -o $@ + +$(dstdir)/libcutils-check.o: $(srcdir)/check/launcher.o + mkdir -p $(dstdir) + # note: -r = --relocatable, but former also works with Clang + $(LD) -r $(srcdir)/check/launcher.o -o $@ + +$(dstdir)/libcutils-net.o: $(srcdir)/net/net.o + mkdir -p $(dstdir) + # note: -r = --relocatable, but former also works with Clang + $(LD) -r $(srcdir)/net/net.o -o $@ + +debug: + $(MAKE) -f $(srcdir)/makefile.d DEBUG=1 + +clean: + rm -f $(srcdir)/*.o $(srcdir)/check/*.o $(srcdir)/net/*.o + +mrproper: mrpropre + +mrpropre: clean + rm -f $(dstdir)/libcutils.o + rm -f $(dstdir)/libcutils-check.o + rm -f $(dstdir)/libcutils-net.o + rmdir $(dstdir) 2>/dev/null || true + +install: + mkdir -p "$(PREFIX)/lib/$(srcdir)/" + cp $(dstdir)/libcutils.o "$(PREFIX)/lib/$(srcdir)/" + cp $(dstdir)/libcutils-check.o "$(PREFIX)/lib/$(srcdir)/" + cp $(dstdir)/libcutils-net.o "$(PREFIX)/lib/$(srcdir)/" + mkdir -p "$(PREFIX)/include/$(srcdir)/check/" + mkdir -p "$(PREFIX)/include/$(srcdir)/net/" + cp $(srcdir)/*.h "$(PREFIX)/include/$(srcdir)/" + cp $(srcdir)/check/*.h "$(PREFIX)/include/$(srcdir)/check/" + cp $(srcdir)/net/*.h "$(PREFIX)/include/$(srcdir)/net/" + +uninstall: + rm -f "$(PREFIX)/lib/$(srcdir)/libcutils.o" + rm -f "$(PREFIX)/lib/$(srcdir)/libcutils-check.o" + rm -f "$(PREFIX)/lib/$(srcdir)/libcutils-net.o" + rmdir "$(PREFIX)/lib/$(srcdir)/" 2>/dev/null || true + rm -f "$(PREFIX)/include/$(srcdir)/net/"*.h + rm -f "$(PREFIX)/include/$(srcdir)/check/"*.h + rm -f "$(PREFIX)/include/$(srcdir)/"*.h + rmdir "$(PREFIX)/include/$(srcdir)/net" 2>/dev/null || true + rmdir "$(PREFIX)/include/$(srcdir)/check" 2>/dev/null || true + rmdir "$(PREFIX)/include/$(srcdir)" 2>/dev/null || true +