]> git.tuebingen.mpg.de Git - dss.git/blobdiff - Makefile
build: Move m4-only definitions to separate file.
[dss.git] / Makefile
index f5c34af7b590145c99d3a8ced9b2badfd7179048..df56e4889d71cc60785751b310048693c245aa56 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,17 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0
+
+PACKAGE := dss
 PREFIX ?= /usr/local
 INSTALL ?= install
 INSTALL_PROGRAM ?= $(INSTALL)
 INSTALL_DATA ?= $(INSTALL) -m 644
 MKDIR_P := mkdir -p
+B := build
+VERSION := $(shell $(MKDIR_P) $(B) && ./version-gen.sh $(PACKAGE) $(B)/version.c)
+RM := rm -f
+LSG := lopsubgen
+GROFF := groff -m man -t -Thtml -P -l -P -r -P -I -P image
+GZIP := gzip -cfn9
+GIT := git
+M4 := m4 -D "PACKAGE=$(PACKAGE)" defs.m4
+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
+www := $(B)/index.html $(B)/$(PACKAGE).1.html
 
-VERSION_STRING = 0.1.7
-
-dss_objects := dss.o str.o file.o exec.o sig.o daemon.o df.o tv.o snap.o ipc.o dss.lsg.o
-all: dss dss.1
-man: dss.1
+all: $(all)
+www: $(www)
+man: $(PACKAGE).1.gz
+$(objs): $(B)/$(PACKAGE).lsg.h Makefile
+-include $(deps)
 
-DSS_CPPFLAGS := -DVERSION_STRING='"$(VERSION_STRING)"'
 DSS_CPPFLAGS += -Wunused-macros
+DSS_CPPFLAGS += -I$(B)
 
 DSS_CFLAGS := -Wno-sign-compare -g -Wunused -Wundef
 DSS_CFLAGS += -Wredundant-decls
@@ -26,32 +43,62 @@ DSS_CFLAGS += -Wunused-parameter
 DSS_CFLAGS += -Wbad-function-cast
 DSS_CFLAGS += -Wshadow
 
-Makefile.deps: $(wildcard *.c *.h)
-       $(CC) -MM -MG $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) *.c > $@
-
--include Makefile.deps
-
-dss: $(dss_objects)
-       $(CC) -o $@ $(dss_objects) $(LDFLAGS) -llopsub
-
-%.o: %.c Makefile
-       $(CC) -c $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) $<
+CC_CMD = $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \
+               -MMD -MF $(B)/$(*F).d -MT $@ $<
 
-dss.png: mklogo
-       ./mklogo > $@
-
-%.lsg.h: %.suite
-       lopsubgen --gen-h=$@ < $<
-%.lsg.c: %.suite
-       lopsubgen --gen-c=$@ < $<
-%.1: %.suite
-       lopsubgen --gen-man=$@ --version-string=$(VERSION_STRING) < $<
-
-%.1.html: %.1
-       groff -m man -Thtml -P -l -P -r $< | sed -e '1,/^<body>/d; /^<\/body>/,$$d' > $@
+.ONESHELL:
+.SHELLFLAGS := -ec
+ifeq ("$(origin V)", "command line")
+       SAY =
+else
+       SAY = @printf '%s\n' '$(strip $(1))'
+endif
+$(B)/version.c:
+       $(call SAY, VG $@)
+       ./version-gen.sh $(PACKAGE) version.c > /dev/null
+$(PACKAGE): $(objs)
+       $(call SAY, LD $@)
+       $(CC) -o $@ $(objs) $(LDFLAGS) -llopsub
+$(B)/%.o: $(B)/%.c
+       $(call SAY, CC $<)
+       $(CC_CMD)
+$(B)/%.o: %.c
+       $(call SAY, CC $<)
+       $(CC_CMD)
 
+.PHONY: all www clean distclean maintainer-clean install README
+.PRECIOUS: $(B)/%.lsg.c $(B)/%.lsg.h $(B)/%.suite $(B)/%.1
+$(B)/$(PACKAGE).suite: $(PACKAGE).suite.m4 defs.m4 Makefile
+       $(call SAY, M4 $<)
+       $(M4) $< > $@
+$(B)/%.lsg.h: $(B)/%.suite
+       $(call SAY, LSGH $<)
+       $(LSG) --gen-h=$@ < $<
+$(B)/%.lsg.c: $(B)/%.suite
+       $(call SAY, LSGC $<)
+       $(LSG) --gen-c=$@ < $<
+$(B)/%.1: $(B)/%.suite
+       $(call SAY, LSGM $<)
+       $(LSG) --gen-man=$@ --version-string=$(VERSION) < $<
+%.1.gz: $(B)/%.1
+       $(call SAY, GZIP $<)
+       $(GZIP) < $< > $@
+$(B)/%.1.html: $(B)/%.1
+       $(call SAY, GROFF $<)
+       cd $(B)
+       $(GROFF) ../$< > ../$@
+$(B)/index.html: index.html.m4 Makefile defs.m4 dss.svg
+       $(call SAY, M4 $@)
+       $(M4) $< > $@
 clean:
-       rm -f *.o dss dss.1 dss.1.html Makefile.deps *.png *~ index.html dss.lsg.h dss.lsg.c
+       $(call SAY, CLEAN)
+       $(RM) $(B)/*.o $(B)/*.d $(all) $(www)
+distclean: clean
+       $(call SAY, DISTCLEAN)
+       $(RM) -r $(B)
+maintainer-clean: distclean
+       $(call SAY, MAINTANER-CLEAN)
+       $(GIT) clean -dfqxe Makefile.local
 
 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
        strip_option := -s
@@ -60,16 +107,10 @@ bindir := $(DESTDIR)$(PREFIX)/bin
 mandir := $(DESTDIR)$(PREFIX)/share/man/man1
 install install-strip: all
        $(MKDIR_P) $(bindir) $(mandir)
-       $(INSTALL_PROGRAM) $(strip_option) dss $(bindir)
-       $(INSTALL_DATA) dss.1 $(mandir)
+       $(INSTALL_PROGRAM) $(strip_option) $(PACKAGE) $(bindir)
+       $(INSTALL_DATA) $(PACKAGE).1.gz $(mandir)
+
+README:
+       @$(M4) README.m4
 
-index.html: dss.1.html index.html.in INSTALL README NEWS
-       sed -e '/@README@/,$$d' index.html.in > $@
-       markdown README >> $@
-       sed -e '1,/@README@/d' -e '/@NEWS@/,$$d' index.html.in >> $@
-       markdown NEWS >> $@
-       sed -e '1,/@NEWS@/d' -e '/@INSTALL@/,$$d' index.html.in >> $@
-       markdown INSTALL >> $@
-       sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' index.html.in >> $@
-       cat dss.1.html >> $@
-       sed -e '1,/@MAN_PAGE@/d' index.html.in >> $@
+-include Makefile.local