Merge branches 't/debian', 't/dynamic-lib', 't/lls_check_arg_count' and 't/news'
[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 PLAIN_VERSION := $(firstword $(subst -, , $(GIT_VERSION)))
27 MAJOR_VERSION := $(firstword $(subst ., , $(PLAIN_VERSION)))
28 SONAME := liblopsub.so.$(MAJOR_VERSION)
29 REALNAME := liblopsub.so.$(PLAIN_VERSION)
30 LINKERNAME:=liblopsub.so
31
32 m4_man_pages := lopsub-suite.5.gz lopsub.7.gz
33 all := $(m4_man_pages) $(REALNAME) lopsubgen lopsubgen.1.gz \
34 lopsubex lopsubex.1.gz
35 all: $(all)
36
37 # deps
38 lopsubgen.o: lsg.h
39 lopsub.o lsg.o: lopsub.h lopsub-internal.h
40 lsg.o: lopsubgen.lsg.h lopsub-internal.h
41 lopsubex.o: lopsubex.lsg.h lopsub.h
42 config_file.c: lopsub-internal.h lopsub.h
43 version.o: version.c
44
45 # m4 stuff
46 gendoc := gendoc/gendoc.m4
47 %.h: %.h.m4 $(gendoc)
48 $(M4) -DOUTPUT_MODE=C $(gendoc) $< > $@
49 $(m4_man_pages): %.gz: %.m4 version.c
50 $(M4) -DGIT_VERSION=$(GIT_VERSION) -DDATE="$(DATE)" $< | $(GZIP) > $@
51
52 # flex
53 %.c: %.l
54 $(LEX) -o $@ $<
55
56 # lopsubgen
57 lopsubgen.lsg.c lopsubgen.lsg.h: lopsubgen.suite lopsubgen-stage1 \
58 lopsub-internal.h
59 ./lopsubgen-stage1 < $<
60 %.lsg.c: %.suite lopsubgen
61 ./lopsubgen --gen-c < $<
62 %.lsg.h: %.suite lopsubgen
63 ./lopsubgen --gen-header < $<
64 %.1.gz: %.suite lopsubgen
65 ./lopsubgen --gen-man=${@:.gz=} --version-string $(GIT_VERSION) < $<
66 $(GZIP) ${@:.gz=}
67
68 # compiling
69 lsg1_objs := lopsubgen.o lsg1.o version.o
70 lsg_objs := lopsubgen.o lsg.o lopsubgen.lsg.o lopsub.o version.o
71 liblopsub_objs := config_file.o lopsub.o version.o
72 lopsubex_objs := lopsubex.o lopsubex.lsg.o $(liblopsub_objs)
73
74 $(lsg_objs) $(liblopsub_objs) $(lopsubex_objs): %.o: %.c
75 lopsubgen.o config_file.o:
76 $(CC) -g -c -fPIC -o $@ ${@:.o=.c}
77 lsg1.o: lsg.c lsg.h
78 $(CC) -g -DSTAGE1 -Wall -g -c $< -o $@
79 %.o: %.c
80 $(CC) -Wall -I. -g -c -fPIC -o $@ $<
81
82 # linking
83 lopsubgen-stage1: $(lsg1_objs)
84 $(CC) -Wall -g $(lsg1_objs) -o $@
85 lopsubgen: $(lsg_objs)
86 $(CC) -Wall -g -o $@ $(lsg_objs)
87 $(REALNAME): $(liblopsub_objs)
88 $(CC) --shared -Wl,-soname,liblopsub.so.$(MAJOR_VERSION) -o $@ $^
89 lopsubex: $(lopsubex_objs) $(REALNAME)
90 $(CC) -Wall -g -o $@ $(lopsubex_objs)
91
92 # web
93 html := $(addprefix web/, $(addsuffix .html, \
94 index lopsub-api lopsubgen.1 lopsubex.1 $(m4_man_pages)))
95 $(html): $(addprefix web/, $(addsuffix .html, header footer))
96
97 www: $(html)
98
99 web/lopsub-api.html: lopsub.h.m4
100 $(M4) -DOUTPUT_MODE=HTML web/header.html $(gendoc) \
101 $< web/footer.html > $@
102 web/index.html: web/lopsub.7.html
103 $(LN) -s $(notdir $<) $@
104 web/%.html: %.gz
105 $(CP) web/header.html $@
106 $(ZCAT) $< | $(GROFF) -m man -Thtml | sed -e '1,/^<body>/d' >> $@
107
108 install: $(all)
109 $(INSTALL) -d $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include \
110 $(DESTDIR)$(PREFIX)/share/man/man1 $(DESTDIR)$(PREFIX)/share/man/man5 \
111 $(DESTDIR)$(PREFIX)/share/man/man7 $(DESTDIR)$(PREFIX)/bin
112 $(INSTALL) -m 644 $(REALNAME) $(DESTDIR)$(PREFIX)/lib
113 $(LN) -s $(REALNAME) $(DESTDIR)$(PREFIX)/lib/$(SONAME)
114 $(LN) -s $(SONAME) $(DESTDIR)$(PREFIX)/lib/$(LINKERNAME)
115 $(INSTALL) -m 755 lopsubgen $(DESTDIR)$(PREFIX)/bin
116 $(INSTALL) -m 644 lopsub.h $(DESTDIR)$(PREFIX)/include
117 $(INSTALL) -m 644 lopsub-internal.h $(DESTDIR)$(PREFIX)/include
118 $(INSTALL) -m 644 lopsubgen.1.gz $(DESTDIR)$(PREFIX)/share/man/man1
119 $(INSTALL) -m 644 lopsub-suite.5.gz $(DESTDIR)$(PREFIX)/share/man/man5
120 $(INSTALL) -m 644 lopsub.7.gz $(DESTDIR)$(PREFIX)/share/man/man7
121
122 clean:
123 $(RM) $(all) $(html) *.o *.man
124 distclean: clean
125 $(RM) *.lsg.c *.lsg.h lopsubgen.c config_file.c lopsubgen-stage1 \
126 lopsub.h lopsub.7 lopsub-suite.5 version.c
127