Add infrastructure to build debian packages.
[lopsub.git] / Makefile
1 # Implicit rules are implemented in make as suffix rules. The following rule
2 # empties the suffix list to disable the predefined implicit rules. This
3 # increases performance and avoids hard-to-debug behaviour.
4 .SUFFIXES:
5 MAKEFLAGS += -Rr
6 ifeq ("$(origin CC)", "default")
7 CC := cc
8 endif
9 .ONESHELL:
10 .SHELLFLAGS := -ec
11
12 PREFIX ?= /usr/local
13 M4 := m4
14 LN := ln -f
15 LEX := lex
16 RM := rm -f
17 AR := ar
18 GROFF := groff
19 CP := cp
20 INSTALL := install
21 GZIP := gzip -f9
22 ZCAT := zcat
23
24 DATE := $(shell date '+%B %Y')
25 GIT_VERSION := $(shell ./version-gen.sh)
26
27 m4_man_pages := lopsub-suite.5.gz lopsub.7.gz
28 all := $(m4_man_pages) liblopsub.a lopsubgen lopsubgen.1.gz \
29 lopsubex lopsubex.1.gz
30 all: $(all)
31
32 # deps
33 lopsubgen.o: lsg.h
34 lopsub.o lsg.o: lopsub.h lopsub-internal.h
35 lsg.o: lopsubgen.lsg.h lopsub-internal.h
36 lopsubex.o: lopsubex.lsg.h lopsub.h
37 config_file.c: lopsub-internal.h lopsub.h
38 version.o: version.c
39
40 # m4 stuff
41 gendoc := gendoc/gendoc.m4
42 %.h: %.h.m4 $(gendoc)
43 $(M4) -DOUTPUT_MODE=C $(gendoc) $< > $@
44 $(m4_man_pages): %.gz: %.m4 version.c
45 $(M4) -DGIT_VERSION=$(GIT_VERSION) -DDATE="$(DATE)" $< | $(GZIP) > $@
46
47 # flex
48 %.c: %.l
49 $(LEX) -o $@ $<
50
51 # lopsubgen
52 lopsubgen.lsg.c lopsubgen.lsg.h: lopsubgen.suite lopsubgen-stage1 \
53 lopsub-internal.h
54 ./lopsubgen-stage1 < $<
55 %.lsg.c: %.suite lopsubgen
56 ./lopsubgen --gen-c < $<
57 %.lsg.h: %.suite lopsubgen
58 ./lopsubgen --gen-header < $<
59 %.1.gz: %.suite lopsubgen
60 ./lopsubgen --gen-man=${@:.gz=} --version-string $(GIT_VERSION) < $<
61 $(GZIP) ${@:.gz=}
62
63 # compiling
64 lsg1_objs := lopsubgen.o lsg1.o version.o
65 lsg_objs := lopsubgen.o lsg.o lopsubgen.lsg.o lopsub.o version.o
66 liblopsub_objs := config_file.o lopsub.o version.o
67 lopsubex_objs := lopsubex.o lopsubex.lsg.o version.o
68
69 $(lsg_objs) $(liblopsub_objs) $(lopsubex_objs): %.o: %.c
70 lopsubgen.o config_file.o:
71 $(CC) -g -c -o $@ ${@:.o=.c}
72 lsg1.o: lsg.c lsg.h
73 $(CC) -g -DSTAGE1 -Wall -g -c $< -o $@
74 %.o: %.c
75 $(CC) -Wall -I. -g -c -o $@ $<
76
77 # linking
78 lopsubgen-stage1: $(lsg1_objs)
79 $(CC) -Wall -g $(lsg1_objs) -o $@
80 lopsubgen: $(lsg_objs)
81 $(CC) -Wall -g -o $@ $(lsg_objs)
82 liblopsub.a: $(liblopsub_objs)
83 $(AR) -rcs $@ $^
84 lopsubex: $(lopsubex_objs) liblopsub.a
85 $(CC) -Wall -g -o $@ $^
86
87 # web
88 html := $(addprefix web/, $(addsuffix .html, \
89 index lopsub-api lopsubgen.1 lopsubex.1 $(m4_man_pages)))
90 $(html): $(addprefix web/, $(addsuffix .html, header footer))
91
92 www: $(html)
93
94 web/lopsub-api.html: lopsub.h.m4
95 $(M4) -DOUTPUT_MODE=HTML web/header.html $(gendoc) \
96 $< web/footer.html > $@
97 web/index.html: web/lopsub.7.html
98 $(LN) -s $(notdir $<) $@
99 web/%.html: %.gz
100 $(CP) web/header.html $@
101 $(ZCAT) $< | $(GROFF) -m man -Thtml | sed -e '1,/^<body>/d' >> $@
102
103 install: $(all)
104 $(INSTALL) -d $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include \
105 $(DESTDIR)$(PREFIX)/share/man/man1 $(DESTDIR)$(PREFIX)/share/man/man5 \
106 $(DESTDIR)$(PREFIX)/share/man/man7 $(DESTDIR)$(PREFIX)/bin
107 $(INSTALL) -m 644 liblopsub.a $(DESTDIR)$(PREFIX)/lib
108 $(INSTALL) -m 755 lopsubgen $(DESTDIR)$(PREFIX)/bin
109 $(INSTALL) -m 644 lopsub.h $(DESTDIR)$(PREFIX)/include
110 $(INSTALL) -m 644 lopsub-internal.h $(DESTDIR)$(PREFIX)/include
111 $(INSTALL) -m 644 lopsubgen.1.gz $(DESTDIR)$(PREFIX)/share/man/man1
112 $(INSTALL) -m 644 lopsub-suite.5.gz $(DESTDIR)$(PREFIX)/share/man/man5
113 $(INSTALL) -m 644 lopsub.7.gz $(DESTDIR)$(PREFIX)/share/man/man7
114
115 clean:
116 $(RM) $(all) $(html) *.o *.man
117 distclean: clean
118 $(RM) *.lsg.c *.lsg.h lopsubgen.c config_file.c lopsubgen-stage1 \
119 lopsub.h lopsub.7 lopsub-suite.5 version.c
120