]> git.tuebingen.mpg.de Git - dss.git/commitdiff
build: Generate intermediate files in build/.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 8 May 2024 21:52:35 +0000 (23:52 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 22 May 2024 16:40:17 +0000 (18:40 +0200)
This way all the intermediate files don't clobber the top level of
the working directory. Also the clean phony target becomes simpler.

.gitignore
Makefile

index aedd74e2272067da39fda26661646bb0f6832160..c8ab019759894766aff72cd82775dae13c76b844 100644 (file)
@@ -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
index e6fd7e061f213c14e94ab1eb8a884f3dc198f2a1..3be6b213e52053d25770f34bed935062ac851784 100644 (file)
--- 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) $< > $@