89af3155989c81a5ce3adab83ef6f1f6914f14d8
[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
22 DATE := $(shell date '+%B %Y')
23 GIT_VERSION := $(shell ./version-gen.sh)
24
25 m4_man_pages := lopsub-suite.5 lopsub.7
26 all := $(m4_man_pages) liblopsub.a lopsubgen lopsubgen.1 \
27         lopsubex lopsubex.1
28 all: $(all)
29
30 # deps
31 lopsubgen.o: lsg.h
32 lopsub.o lsg.o: lopsub.h lopsub-internal.h
33 lsg.o: lopsubgen.lsg.h lopsub-internal.h
34 lopsubex.o: lopsubex.lsg.h lopsub.h
35 config_file.c: lopsub-internal.h lopsub.h
36 version.o: version.c
37
38 # m4 stuff
39 gendoc := gendoc/gendoc.m4
40 %.h: %.h.m4 $(gendoc)
41         $(M4) -DOUTPUT_MODE=C $(gendoc) $< > $@
42 $(m4_man_pages): %: %.m4 version.c
43         $(M4) -DGIT_VERSION=$(GIT_VERSION) -DDATE="$(DATE)" $< > $@
44
45 # flex
46 %.c: %.l
47         $(LEX) -o $@ $<
48
49 # lopsubgen
50 lopsubgen.lsg.c lopsubgen.lsg.h: lopsubgen.suite lopsubgen-stage1 \
51                 lopsub-internal.h
52         ./lopsubgen-stage1 < $<
53 %.lsg.c: %.suite lopsubgen
54         ./lopsubgen --gen-c < $<
55 %.lsg.h: %.suite lopsubgen
56         ./lopsubgen --gen-header < $<
57 %.1: %.suite lopsubgen
58         ./lopsubgen --gen-man=$@ --version-string $(GIT_VERSION) < $<
59
60 # compiling
61 lsg1_objs := lopsubgen.o lsg1.o version.o
62 lsg_objs := lopsubgen.o lsg.o lopsubgen.lsg.o lopsub.o version.o
63 liblopsub_objs := config_file.o lopsub.o version.o
64 lopsubex_objs := lopsubex.o lopsubex.lsg.o version.o
65
66 $(lsg_objs) $(liblopsub_objs) $(lopsubex_objs): %.o: %.c
67 lopsubgen.o config_file.o:
68         $(CC) -g -c -o $@ ${@:.o=.c}
69 lsg1.o: lsg.c lsg.h
70         $(CC) -g -DSTAGE1 -Wall -g -c $< -o $@
71 %.o: %.c
72         $(CC) -Wall -I. -g -c -o $@ $<
73
74 # linking
75 lopsubgen-stage1: $(lsg1_objs)
76         $(CC) -Wall -g $(lsg1_objs) -o $@
77 lopsubgen: $(lsg_objs)
78         $(CC) -Wall -g -o $@ $(lsg_objs)
79 liblopsub.a: $(liblopsub_objs)
80         $(AR) -rcs $@ $^
81 lopsubex: $(lopsubex_objs) liblopsub.a
82         $(CC) -Wall -g -o $@ $^
83
84 # web
85 html := $(addprefix web/, $(addsuffix .html, \
86         index lopsub-api lopsubgen.1 lopsubex.1 $(m4_man_pages)))
87 $(html): $(addprefix web/, $(addsuffix .html, header footer))
88
89 www: $(html)
90
91 web/lopsub-api.html: lopsub.h.m4
92         $(M4) -DOUTPUT_MODE=HTML web/header.html $(gendoc) \
93                 $< web/footer.html > $@
94 web/index.html: web/lopsub.7.html
95         $(LN) -s $(notdir $<) $@
96 web/%.html: %
97         $(CP) web/header.html $@
98         $(GROFF) -m man -Thtml $< | sed -e '1,/^<body>/d' >> $@
99
100 install: liblopsub.a lopsub.7
101         $(INSTALL) -d $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/man/man1 \
102                  $(PREFIX)/man/man5 $(PREFIX)/man/man7 $(PREFIX)/bin
103         $(INSTALL) -m 755 liblopsub.a $(PREFIX)/lib
104         $(INSTALL) -m 755 lopsubgen $(PREFIX)/bin
105         $(INSTALL) -m 644 lopsub.h $(PREFIX)/include
106         $(INSTALL) -m 644 lopsub-internal.h $(PREFIX)/include
107         $(INSTALL) -m 644 lopsubgen.1 $(PREFIX)/man/man1
108         $(INSTALL) -m 644 lopsub-suite.5 $(PREFIX)/man/man5
109         $(INSTALL) -m 644 lopsub.7 $(PREFIX)/man/man7
110
111 clean:
112         $(RM) $(all) $(html) *.o *.man *.lsg.c *.lsg.h \
113                 lopsubgen.c config_file.c lopsubgen-stage1 \
114                 lopsub.h lopsub.7 lopsub-suite.5 version.c
115