-dss_objects := dss.o cmdline.o string.o fd.o exec.o signal.o daemon.o df.o
-all: dss
-man: dss.1
+# SPDX-License-Identifier: GPL-2.0
+PREFIX ?= /usr/local
+INSTALL ?= install
+INSTALL_PROGRAM ?= $(INSTALL)
+INSTALL_DATA ?= $(INSTALL) -m 644
+MKDIR_P := mkdir -p
+VERSION := $(shell ./version-gen.sh dss version.c)
+RM := rm -f
+LSG := lopsubgen
+GZIP := gzip -fn9
-DEBUG_CPPFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
-DEBUG_CPPFLAGS += -Wredundant-decls
-CPPFLAGS += -Os
-CPPFLAGS += -Wall
-CPPFLAGS += -Wuninitialized
-CPPFLAGS += -Wchar-subscripts
-CPPFLAGS += -Wformat-security
-CPPFLAGS += -Werror-implicit-function-declaration
-CPPFLAGS += -Wmissing-format-attribute
-CPPFLAGS += -Wunused-macros
-CPPFLAGS += -Wbad-function-cast
+units := dss str file exec sig daemon df tv snap ipc dss.lsg version
+objs := $(addsuffix .o, $(units))
+deps := $(addsuffix .d, $(units))
-Makefile.deps: $(wildcard *.c *.h)
- gcc -MM -MG *.c > $@
+all: dss dss.1.gz
+man: dss.1
+$(objs): dss.lsg.h Makefile
+-include $(deps)
-include Makefile.deps
+DSS_CPPFLAGS += -Wunused-macros
-dss: $(dss_objects)
- $(CC) $(CPPFLAGS) $(DEBUG_CPPFLAGS) -o $@ $(dss_objects)
+DSS_CFLAGS := -Wno-sign-compare -g -Wunused -Wundef
+DSS_CFLAGS += -Wredundant-decls
+DSS_CFLAGS += -Os
+DSS_CFLAGS += -Wall
+DSS_CFLAGS += -Wuninitialized
+DSS_CFLAGS += -Wchar-subscripts
+DSS_CFLAGS += -Wformat-security
+DSS_CFLAGS += -Werror-implicit-function-declaration
+DSS_CFLAGS += -Wmissing-format-attribute
+DSS_CFLAGS += -Wunused-parameter
+DSS_CFLAGS += -Wbad-function-cast
+DSS_CFLAGS += -Wshadow
+.ONESHELL:
+.SHELLFLAGS := -ec
+ifeq ("$(origin V)", "command line")
+ SAY =
+else
+ SAY = @echo '$(strip $(1))'
+endif
+version.c:
+ $(call SAY, VG $@)
+ ./version-gen.sh dss version.c
+dss: $(objs)
+ $(call SAY, LD $@)
+ $(CC) -o $@ $(objs) $(LDFLAGS) -llopsub
%.o: %.c
- $(CC) -c $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
-
-%.ppm: %.sk
- sk2ppm $< > $@
-%.png: %.ppm
- convert $< $@
-
-cmdline.c cmdline.h: dss.ggo
- gengetopt --unamed-opts=command --conf-parser < $<
-
-dss.1: dss
- help2man -N ./$< > $@
-
-%.1.html: %.1
- man2html $< > $@
-
+ $(call SAY, CC $<)
+ $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \
+ -MMD -MF $(*F).d -MT $@ $<
+.PRECIOUS: %.lsg.c %.lsg.h %.1.gz
+%.lsg.h: %.suite
+ $(call SAY, LSGH $<)
+ $(LSG) --gen-h=$@ < $<
+%.lsg.c: %.suite
+ $(call SAY, LSGC $<)
+ $(LSG) --gen-c=$@ < $<
+%.1.gz: %.suite
+ $(call SAY, LSGM $<)
+ $(LSG) --gen-man=${@:.gz=} --version-string=$(VERSION) < $<
+ $(GZIP) ${@:.gz=}
+%.1.html: %.1.gz
+ $(call SAY, GROFF $<)
+ zcat $< | groff -m man -Thtml -P -l -P -r \
+ | sed -e '1,/^<body>/d; /^<\/body>/,$$d' > $@
clean:
- rm -f *.o dss dss.1 dss.1.html Makefile.deps *.ppm *.png *~ cmdline.c cmdline.h
+ $(call SAY, CLEAM)
+ $(RM) *.[od] dss dss.1.gz *.html dss.lsg.[ch] version.c
+
+ifneq ($(findstring strip, $(MAKECMDGOALS)),)
+ strip_option := -s
+endif
+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.gz $(mandir)
+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