diff --git a/Makefile b/Makefile index 964a694..255b3da 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,14 @@ -include scripts/config.mk +# SPDX-License-Identifier: MIT + +include config.mk -GOALS := all clean clobber mrproper install TARGETS := include lib tests utils commands -$(GOALS): +$(MAIN_GOALS): @for target in $(TARGETS); do \ $(MAKE) -C $$target O=$(O_DIR)/$$target V=$(V) $@; \ done -$(TARGETS): - $(Q)$(MAKE) -C $@ O=$(O_DIR)/$@ V=$(V) - lib: include tests utils: lib - -.PHONY: $(GOALS) $(TARGETS) diff --git a/commands/Makefile b/commands/Makefile index 76d683f..c1d4a0e 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -1,4 +1,6 @@ -include ../scripts/config.mk +# SPDX-License-Identifier: MIT + +include ../config.mk CMDFILES := $(wildcard *.c) BINARIES = $(CMDFILES:%.c=%) @@ -22,6 +24,4 @@ clean clobber mrproper: $(O_DIR)/%: %.c $(call ccld-cmd,$@,$(Q)$(CC) -o $(@) $< $(CFLAGS) $(LDFLAGS)) -.PHONY: all install clean clobber mrproper - -include $(DEPFILES) diff --git a/scripts/config.mk b/config.mk similarity index 92% rename from scripts/config.mk rename to config.mk index e7ba696..4e48cb2 100644 --- a/scripts/config.mk +++ b/config.mk @@ -1,10 +1,7 @@ # SPDX-License-Identifier: MIT -LIBSERIAL := 0 -LIBIVERSION := 0 - ARCH ?= $(shell uname -m | sed \ - -e s/arm.*/arm/ \ + -e s/arm.*/arm/ \ -e s/aarch64.*/arm64/ ) CROSS_COMPILE ?= CC = $(CROSS_COMPILE)gcc @@ -85,5 +82,12 @@ ccld-cmd = $(call run-cc,CCLD,$(1),$(2)) ld-cmd = $(call run-cmd,LD,$(notdir $(1)),$(2)) ar-cmd = $(call run-cmd,AR,$(notdir $(1)),$(2) $(if $(Q),2>/dev/null)) +MAIN_GOALS := all clean clobber mrproper install + +$(TARGETS): + $(Q)$(MAKE) -C $@ O=$(O_DIR)/$@ V=$(V) + $(O_DIR)/%.d: %.c $(call dep-cmd,$@,@$(CC) -MM $(CFLAGS) $< | sed 's$(comma)\($*\)\.o[ :]*$(comma)$(O_DIR)/\1.o $@: $(comma)g' > $@ || rm -f $@) + +.PHONY: $(MAIN_GOALS) $(TARGETS) diff --git a/include/Makefile b/include/Makefile index 4efb77e..1a90add 100644 --- a/include/Makefile +++ b/include/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT -include ../scripts/config.mk +include ../config.mk O_UAPI = $(O_DIR)/uapi @@ -29,5 +29,3 @@ install: all $(Q)$(MKDIR_P) $(DESTDIR)/$(includedir)/uapi $(Q)(cd $(O_UAPI) && find -L evenless \! \( -name '*~' \) -type f | $(CPIO) -Lpdum $(DESTDIR)/$(includedir)/uapi) $(Q)(find evenless \! \( -name '*~' \) -type f | $(CPIO) -Lpdum $(DESTDIR)/$(includedir)) - -.PHONY: clean clobber mrproper install diff --git a/lib/Makefile b/lib/Makefile index 07cd8a6..909f6f9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,10 +1,11 @@ # SPDX-License-Identifier: MIT -include ../scripts/config.mk +include ../config.mk +include ../libversion.mk -DTSONAME := libevenless.so.$(LIBIVERSION) -SOLIBNAME := libevenless-$(LIBSERIAL).so.$(LIBIVERSION) -ARLIBNAME := libevenless-$(LIBSERIAL).a +DTSONAME := libevenless.so.$(EVL_IVERSION) +SOLIBNAME := libevenless-$(EVL_SERIAL).so.$(EVL_IVERSION) +ARLIBNAME := libevenless-$(EVL_SERIAL).a TARGETS := $(O_DIR)/$(SOLIBNAME) $(O_DIR)/$(ARLIBNAME) SRCFILES := $(wildcard *.c arch/$(ARCH)/*.c) @@ -46,7 +47,7 @@ $(O_DIR)/$(ARLIBNAME): $(OBJFILES) $(O_DIR)/syscall-pic.o $(O_DIR)/syscall.o: override CFLAGS := $(CFLAGS) -fomit-frame-pointer -$(O_DIR)/version-pic.o $(O_DIR)/version.o: override CFLAGS := $(CFLAGS) -DLIBSERIAL=\"$(LIBSERIAL)\" +$(O_DIR)/version-pic.o $(O_DIR)/version.o: override CFLAGS := $(CFLAGS) -DLIBSERIAL=\"$(EVL_SERIAL)\" version.c: $(O_DIR)/git-stamp.h $(O_DIR)/git-stamp.h: git-stamp @@ -60,12 +61,12 @@ $(O_DIR)/git-stamp.h: git-stamp $(RM) -f $@ && touch $@; \ fi; true +.PHONY: git-stamp + $(O_DIR)/%-pic.o: %.c $(call cc-pic-cmd,$@,$(CC) $(CFLAGS) -fPIC -c -o $@ $<) $(O_DIR)/%.o: %.c $(call cc-cmd,$@,$(CC) $(CFLAGS) -c -o $@ $<) -.PHONY: all install clean clobber mrproper git-stamp - -include $(DEPFILES) diff --git a/libversion.mk b/libversion.mk new file mode 100644 index 0000000..73272b0 --- /dev/null +++ b/libversion.mk @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: MIT + +EVL_SERIAL := 0 +EVL_IVERSION := 0 diff --git a/tests/Makefile b/tests/Makefile index 8c833e7..9e9411c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,4 +1,7 @@ -include ../scripts/config.mk +# SPDX-License-Identifier: MIT + +include ../config.mk +include ../libversion.mk TESTFILES := $(wildcard *.c) BINARIES = $(TESTFILES:%.c=%) @@ -13,7 +16,7 @@ TEST_CPPFLAGS := $(BASE_CPPFLAGS) \ TEST_CFLAGS := $(TEST_CPPFLAGS) $(BASE_CFLAGS) override CFLAGS := $(TEST_CFLAGS) $(CFLAGS) -TEST_LDFLAGS := $(O_DIR)/../lib/libevenless.so.$(LIBIVERSION) -lpthread -lrt +TEST_LDFLAGS := $(O_DIR)/../lib/libevenless.so.$(EVL_IVERSION) -lpthread -lrt override LDFLAGS := $(TEST_LDFLAGS) $(LDFLAGS) all: $(TARGETS) @@ -29,6 +32,4 @@ clean clobber mrproper: $(O_DIR)/%: %.c $(call ccld-cmd,$@,$(Q)$(CC) -o $(@) $< $(CFLAGS) $(LDFLAGS)) -.PHONY: all install clean clobber mrproper - -include $(DEPFILES) diff --git a/utils/Makefile b/utils/Makefile index a36bcab..c6ffa15 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -1,4 +1,7 @@ -include ../scripts/config.mk +# SPDX-License-Identifier: MIT + +include ../config.mk +include ../libversion.mk UTILFILES := $(wildcard *.c) BINARIES = $(UTILFILES:%.c=%) @@ -13,7 +16,7 @@ UTIL_CPPFLAGS := $(BASE_CPPFLAGS) \ UTIL_CFLAGS := $(UTIL_CPPFLAGS) $(BASE_CFLAGS) override CFLAGS := $(UTIL_CFLAGS) $(CFLAGS) -UTIL_LDFLAGS := $(O_DIR)/../lib/libevenless.so.$(LIBIVERSION) -lpthread -lrt +UTIL_LDFLAGS := $(O_DIR)/../lib/libevenless.so.$(EVL_IVERSION) -lpthread -lrt override LDFLAGS := $(UTIL_LDFLAGS) $(LDFLAGS) all: $(TARGETS) @@ -29,6 +32,4 @@ clean clobber mrproper: $(O_DIR)/%: %.c $(call ccld-cmd,$@,$(Q)$(CC) -o $(@) $< $(CFLAGS) $(LDFLAGS)) -.PHONY: all install clean clobber mrproper - -include $(DEPFILES)