From 4f252751eed3c4337340d83c512c3727c54e8da1 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 8 May 2024 23:52:35 +0200 Subject: [PATCH] build: Generate intermediate files in build/. This way the intermediate files don't clobber the top level of the working directory. Also the clean phony target becomes simpler. --- .gitignore | 8 +------- Makefile | 46 +++++++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index aedd74e..c8ab019 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,5 @@ Makefile.local -version.c -*.o -*.d *.swp -dss.lsg.* +build/* dss -dss.suite dss.1.gz -dss.1.html -index.html diff --git a/Makefile b/Makefile index e6fd7e0..3be6b21 100644 --- a/Makefile +++ b/Makefile @@ -41,12 +41,12 @@ INSTALL ?= install INSTALL_PROGRAM ?= $(INSTALL) INSTALL_DATA ?= $(INSTALL) -m 644 MKDIR_P := mkdir -p -VERSION := $(shell ./version-gen.sh $(PACKAGE) version.c) +B := build +VERSION := $(shell $(MKDIR_P) $(B) && ./version-gen.sh $(PACKAGE) $(B)/version.c) RM := rm -f LSG := lopsubgen GROFF := groff -m man -Thtml -P -l -P -r GZIP := gzip -cfn9 -units := $(PACKAGE) $(PACKAGE).lsg str file exec sig daemon df tv snap ipc version M4 := m4 \ -D "AUTHOR=$(AUTHOR)" \ -D "PACKAGE=$(PACKAGE)" \ @@ -62,16 +62,19 @@ M4 := m4 \ -D "DESCRIPTION1=$(DESCRIPTION1)" \ -D "DESCRIPTION2=$(DESCRIPTION2)" \ -D "DESCRIPTION3=$(DESCRIPTION3)" -objs := $(addsuffix .o, $(units)) -deps := $(addsuffix .d, $(units)) +c_source := $(PACKAGE) str file exec sig daemon df tv snap ipc +c_generated := $(B)/$(PACKAGE).lsg $(B)/version +objs := $(addsuffix .o, $(c_generated) $(addprefix $(B)/, $(c_source))) +deps := $(objs:.o=.d) all := $(PACKAGE) $(PACKAGE).1.gz all: $(all) man: $(PACKAGE).1.gz -$(objs): $(PACKAGE).lsg.h Makefile +$(objs): $(B)/$(PACKAGE).lsg.h Makefile -include $(deps) DSS_CPPFLAGS += -Wunused-macros +DSS_CPPFLAGS += -I$(B) DSS_CFLAGS := -Wno-sign-compare -g -Wunused -Wundef DSS_CFLAGS += -Wredundant-decls @@ -86,6 +89,9 @@ DSS_CFLAGS += -Wunused-parameter DSS_CFLAGS += -Wbad-function-cast DSS_CFLAGS += -Wshadow +CC_CMD = $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \ + -MMD -MF $(B)/$(*F).d -MT $@ $< + .ONESHELL: .SHELLFLAGS := -ec ifeq ("$(origin V)", "command line") @@ -93,40 +99,42 @@ ifeq ("$(origin V)", "command line") else SAY = @printf '%s\n' '$(strip $(1))' endif -version.c: +$(B)/version.c: $(call SAY, VG $@) ./version-gen.sh $(PACKAGE) version.c > /dev/null $(PACKAGE): $(objs) $(call SAY, LD $@) $(CC) -o $@ $(objs) $(LDFLAGS) -llopsub -%.o: %.c +$(B)/%.o: $(B)/%.c + $(call SAY, CC $<) + $(CC_CMD) +$(B)/%.o: %.c $(call SAY, CC $<) - $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \ - -MMD -MF $(*F).d -MT $@ $< + $(CC_CMD) + .PHONY: all clean install README -.PRECIOUS: %.lsg.c %.lsg.h %.suite %.1 -$(PACKAGE).suite: $(PACKAGE).suite.m4 Makefile +.PRECIOUS: $(B)/%.lsg.c $(B)/%.lsg.h $(B)/%.suite $(B)/%.1 +$(B)/$(PACKAGE).suite: $(PACKAGE).suite.m4 Makefile $(call SAY, M4 $<) $(M4) $< > $@ -%.lsg.h: %.suite +$(B)/%.lsg.h: $(B)/%.suite $(call SAY, LSGH $<) $(LSG) --gen-h=$@ < $< -%.lsg.c: %.suite +$(B)/%.lsg.c: $(B)/%.suite $(call SAY, LSGC $<) $(LSG) --gen-c=$@ < $< -%.1: %.suite +$(B)/%.1: $(B)/%.suite $(call SAY, LSGM $<) $(LSG) --gen-man=$@ --version-string=$(VERSION) < $< -%.1.gz: %.1 +%.1.gz: $(B)/%.1 $(call SAY, GZIP $<) $(GZIP) < $< > $@ -%.1.html: %.1 +$(B)/%.1.html: $(B)/%.1 $(call SAY, GROFF $<) $(GROFF) $< > $@ clean: $(call SAY, CLEAN) - $(RM) *.[od] $(all) *.html $(PACKAGE).1 $(PACKAGE).suite \ - $(PACKAGE).lsg.[ch] version.c + $(RM) -r $(B) $(all) ifneq ($(findstring strip, $(MAKECMDGOALS)),) strip_option := -s @@ -159,7 +167,7 @@ endef README: @printf '%s\n' "$(README)" -index.html: index.html.m4 Makefile +$(B)/index.html: index.html.m4 Makefile $(call SAY, M4 $@) $(M4) $< > $@ -- 2.39.5