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