From: Niki Roo Date: Tue, 2 Jul 2024 14:41:56 +0000 (+0200) Subject: Merge branch 'c-libtree' of git.nikiroo.be:workspace/template into subtree X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=f5c570b80c570c8247fcb81a01d2243902bf2e0e;p=cutils.git Merge branch 'c-libtree' of git.nikiroo.be:workspace/template into subtree --- f5c570b80c570c8247fcb81a01d2243902bf2e0e diff --cc Makefile index d3398f0,95a670f..a621824 mode 100644,100755..100755 --- a/Makefile +++ b/Makefile @@@ -1,10 -1,10 +1,10 @@@ # Simply pass everything to makefile.d, but calling from "../" - .PHONY: all build install uninstall clean mrpropre mrpropre \ - run test run-test run-test-more default \ - utils check net + .PHONY: default $(MAKECMDGOALS) default $(MAKECMDGOALS): - @$(MAKE) --no-print-directory -C ../ -f $(CURDIR)/makefile.d \ - $(MAKECMDGOALS) - @for mk in makefile.d; do \ ++ @for mk in makefile.d makefile.check.d makefile.net.d; do \ + $(MAKE) --no-print-directory -C ../ -f "$(CURDIR)/$$mk" \ + $(MAKECMDGOALS); + done; diff --cc makefile.check.d index 0000000,0000000..bdd7db7 new file mode 100755 --- /dev/null +++ b/makefile.check.d @@@ -1,0 -1,0 +1,97 @@@ ++# ++# Makefile for C libraries ++# > NAME : the name of the main program (if programs, make a single .d file ++# per program, link them up in Makfile and use a $ssrcdir) ++# > srcdir : the source directory ++# > ssrcdir: the sub-sources directory (defaults to $srcdir) ++# > dstdir : the destination directory (defaults to $srcdir/bin) ++# ++# Environment variables: ++# > PREFIX: where to (un)install (defaults to /usr/local) ++# > DEBUG: define it to build with all debug symbols ++# ++NAME = cutils-check ++srcdir = cutils ++ssrcdir = cutils/check ++ ++# Note: c99+ required for for-loop initial declaration (not default in CentOS 6) ++# Note: gnu99 can be required for some projects (i.e.: libcutils-net) ++CFLAGS += -Wall -pedantic -I./ -std=c99 ++CXXFLAGS += -Wall -pedantic -I./ ++PREFIX = /usr/local ++ ++# Required *locally compiled* libraries if any: ++# LIBS = cutils ++ ++################################################################################ ++ ++ifeq ($(dstdir),) ++dstdir = $(srcdir)/bin ++endif ++ ++ifdef DEBUG ++CFLAGS += -ggdb -O0 ++CXXFLAGS += -ggdb -O0 ++endif ++ ++# Default target ++.PHONY: all ++all: ++ ++.PHONY: build rebuild install uninstall clean mrpropre mrpropre \ ++ $(NAME) test run run-test run-test-more ++ ++SOURCES=$(wildcard $(ssrcdir)/*.c) ++OBJECTS=$(SOURCES:%.c=%.o) ++DEPENDS =$(SOURCES:%.c=%.d) ++ ++# Autogenerate dependencies from code ++-include $(DEPENDS) ++%.o: %.c ++ $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ ++ ++# Main targets ++ ++all: build ++ ++build: $(NAME) ++ ++rebuild: clean build ++ ++$(NAME): $(dstdir)/lib$(NAME).a ++ ++# Library, so no test and no run ++test run run-test run-test-more: ++ @echo $(NAME) is a library, look at the tests instead ++ ++$(dstdir)/lib$(NAME).a: $(OBJECTS) ++ mkdir -p $(dstdir) ++ ## OLD: #note: -r = --relocatable, but former also works with Clang ++ ## OLD: $(LD) -r $(OBJECTS) -o $@ $(LDFLAGS) ++ $(AR) rcs $@ $(OBJECTS) ++ ++clean: ++ $(foreach lib,$(LIBS),$(MAKE) --no-print-directory \ ++ -C $(lib)/ $@ dstdir=$(dstdir)) ++ rm -f $(OBJECTS) ++ rm -f $(DEPENDS) ++ ++mrproper: mrpropre ++mrpropre: clean ++ $(foreach lib,$(LIBS),$(MAKE) --no-print-directory \ ++ -C $(lib)/ $@ dstdir=$(dstdir)) ++ rm -f $(dstdir)/lib$(NAME).a ++ rmdir $(dstdir) 2>/dev/null || true ++ ++install: build ++ mkdir -p "$(PREFIX)/lib" ++ cp "$(dstdir)/lib$(NAME).a" "$(PREFIX)/lib/" ++ cp "$(ssrcdir)"/*.h "$(PREFIX)/include/$(srcdir)/" ++ ++uninstall: ++ rm "$(PREFIX)/lib/lib$(NAME).a" ++ rmdir "$(PREFIX)/lib" 2>/dev/null ++ rm "$(PREFIX)/include/$(srcdir)/"*.h ++ rmdir "$(PREFIX)/include/$(srcdir)" 2>/dev/null ++ rmdir "$(PREFIX)/include" 2>/dev/null ++ diff --cc makefile.d index 1afb344,330adad..de97c3c mode 100644,100755..100755 --- a/makefile.d +++ b/makefile.d @@@ -1,9 -1,29 +1,29 @@@ - # Note: 99+ required for for-loop initial declaration (CentOS 6) - # Note: gnu99 (instead of c99) required for libcutils-net + # + # Makefile for C libraries + # > NAME : the name of the main program (if programs, make a single .d file + # per program, link them up in Makfile and use a $ssrcdir) + # > srcdir : the source directory + # > ssrcdir: the sub-sources directory (defaults to $srcdir) + # > dstdir : the destination directory (defaults to $srcdir/bin) + # + # Environment variables: + # > PREFIX: where to (un)install (defaults to /usr/local) + # > DEBUG: define it to build with all debug symbols + # -NAME = library ++NAME = cutils + srcdir = $(NAME) + ssrcdir = $(srcdir) + + # Note: c99+ required for for-loop initial declaration (not default in CentOS 6) + # Note: gnu99 can be required for some projects (i.e.: libcutils-net) -CFLAGS += -Wall -pedantic -I./ -std=c99 ++CFLAGS += -Wall -pedantic -I./ -std=gnu99 + CXXFLAGS += -Wall -pedantic -I./ + PREFIX = /usr/local + + # Required *locally compiled* libraries if any: + # LIBS = cutils - NAME = cutils - NAMES = $(NAME) check net - srcdir = $(NAME) + ################################################################################ ifeq ($(dstdir),) dstdir = $(srcdir)/bin diff --cc makefile.net.d index 0000000,0000000..282f2df new file mode 100755 --- /dev/null +++ b/makefile.net.d @@@ -1,0 -1,0 +1,97 @@@ ++# ++# Makefile for C libraries ++# > NAME : the name of the main program (if programs, make a single .d file ++# per program, link them up in Makfile and use a $ssrcdir) ++# > srcdir : the source directory ++# > ssrcdir: the sub-sources directory (defaults to $srcdir) ++# > dstdir : the destination directory (defaults to $srcdir/bin) ++# ++# Environment variables: ++# > PREFIX: where to (un)install (defaults to /usr/local) ++# > DEBUG: define it to build with all debug symbols ++# ++NAME = cutils-net ++srcdir = cutils ++ssrcdir = cutils/net ++ ++# Note: c99+ required for for-loop initial declaration (not default in CentOS 6) ++# Note: gnu99 can be required for some projects (i.e.: libcutils-net) ++CFLAGS += -Wall -pedantic -I./ -std=gnu99 ++CXXFLAGS += -Wall -pedantic -I./ ++PREFIX = /usr/local ++ ++# Required *locally compiled* libraries if any: ++# LIBS = cutils ++ ++################################################################################ ++ ++ifeq ($(dstdir),) ++dstdir = $(srcdir)/bin ++endif ++ ++ifdef DEBUG ++CFLAGS += -ggdb -O0 ++CXXFLAGS += -ggdb -O0 ++endif ++ ++# Default target ++.PHONY: all ++all: ++ ++.PHONY: build rebuild install uninstall clean mrpropre mrpropre \ ++ $(NAME) test run run-test run-test-more ++ ++SOURCES=$(wildcard $(ssrcdir)/*.c) ++OBJECTS=$(SOURCES:%.c=%.o) ++DEPENDS =$(SOURCES:%.c=%.d) ++ ++# Autogenerate dependencies from code ++-include $(DEPENDS) ++%.o: %.c ++ $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ ++ ++# Main targets ++ ++all: build ++ ++build: $(NAME) ++ ++rebuild: clean build ++ ++$(NAME): $(dstdir)/lib$(NAME).a ++ ++# Library, so no test and no run ++test run run-test run-test-more: ++ @echo $(NAME) is a library, look at the tests instead ++ ++$(dstdir)/lib$(NAME).a: $(OBJECTS) ++ mkdir -p $(dstdir) ++ ## OLD: #note: -r = --relocatable, but former also works with Clang ++ ## OLD: $(LD) -r $(OBJECTS) -o $@ $(LDFLAGS) ++ $(AR) rcs $@ $(OBJECTS) ++ ++clean: ++ $(foreach lib,$(LIBS),$(MAKE) --no-print-directory \ ++ -C $(lib)/ $@ dstdir=$(dstdir)) ++ rm -f $(OBJECTS) ++ rm -f $(DEPENDS) ++ ++mrproper: mrpropre ++mrpropre: clean ++ $(foreach lib,$(LIBS),$(MAKE) --no-print-directory \ ++ -C $(lib)/ $@ dstdir=$(dstdir)) ++ rm -f $(dstdir)/lib$(NAME).a ++ rmdir $(dstdir) 2>/dev/null || true ++ ++install: build ++ mkdir -p "$(PREFIX)/lib" ++ cp "$(dstdir)/lib$(NAME).a" "$(PREFIX)/lib/" ++ cp "$(ssrcdir)"/*.h "$(PREFIX)/include/$(srcdir)/" ++ ++uninstall: ++ rm "$(PREFIX)/lib/lib$(NAME).a" ++ rmdir "$(PREFIX)/lib" 2>/dev/null ++ rm "$(PREFIX)/include/$(srcdir)/"*.h ++ rmdir "$(PREFIX)/include/$(srcdir)" 2>/dev/null ++ rmdir "$(PREFIX)/include" 2>/dev/null ++