aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 7d85257de8db35bfccb40fc7b90388396d91e3bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# bus - simple message broadcasting IPC system
# See LICENSE file for copyright and license details.

PREFIX = /usr
BIN = /bin
BINDIR = ${PREFIX}${BIN}
LIB = /lib
LIBDIR = ${PREFIX}${LIB}
INCLUDE = /include
INCLUDEDIR = ${PREFIX}${INCLUDE}
DATA = /share
DATADIR = ${PREFIX}${DATA}
LICENSEDIR = ${DATADIR}/licenses
MANDIR = ${DATADIR}/man
INFODIR = $(DATADIR)/info
DOCDIR = $(DATADIR)/doc

PKGNAME = bus


MAN1 = bus bus-broadcast bus-create bus-listen bus-remove bus-wait bus-chmod bus-chown bus-chgrp
MAN3 = bus_create bus_unlink bus_open bus_close bus_read bus_write bus_poll bus_chmod bus_chown
MAN5 = bus
MAN7 = libbus

EXAMPLES = audio-volume-control daemon-dependencies nonblocking telephony-and-music timed
EXAMPLE_audio-volume-control = amixer cleanup init monitor README
EXAMPLE_daemon-dependencies = announce.c await-ready.c await-started.c cleanup.c d-network d-ntp \
                             d-ssh init.c Makefile README require.c start-daemon.c test-daemon.c
EXAMPLE_nonblocking = cleanup.c init.c Makefile poll.c README write.c
EXAMPLE_telephony-and-music = cleanup.c end-call.c init.c Makefile monitor.c README receive-or-make-call.c
EXAMPLE_timed = cleanup.c init.c Makefile poll.c read.c README slow-poll.c write.c


FLAGS = -std=c99 -Wall -Wextra -pedantic -O2

LIB_MAJOR = 3
LIB_MINOR = 1
LIB_VERSION = ${LIB_MAJOR}.${LIB_MINOR}
VERSION = 3.1.5



default: bus man info
all: bus doc
doc: man info pdf dvi ps
man: man1 man3 man5 man7
bus: bin lib
bin: bin/bus
lib: so a
so: bin/libbus.so.${LIB_VERSION} bin/libbus.so.${LIB_MAJOR} bin/libbus.so
a: bin/libbus.a
man1: $(foreach M,${MAN1},bin/${M}.1)
man3: $(foreach M,${MAN3},bin/${M}.3)
man5: $(foreach M,${MAN5},bin/${M}.5)
man7: $(foreach M,${MAN7},bin/${M}.7)
info: bin/bus.info
pdf: bin/bus.pdf
dvi: bin/bus.dvi
ps: bin/bus.ps

bin/%.1: doc/man/%.1
	@echo SED $@
	@mkdir -p bin
	@sed 's/%VERSION%/${VERSION}/g' < $< > $@

bin/%.3: doc/man/%.3
	@echo SED $@
	@mkdir -p bin
	@sed 's/%VERSION%/${VERSION}/g' < $< > $@

bin/%.5: doc/man/%.5
	@echo SED $@
	@mkdir -p bin
	@sed 's/%VERSION%/${VERSION}/g' < $< > $@

bin/%.7: doc/man/%.7
	@echo SED $@
	@mkdir -p bin
	@sed 's/%VERSION%/${VERSION}/g' < $< > $@

bin/libbus.a: obj/bus-fpic.o
	@echo AR $@
	@mkdir -p bin
	@ar rcs $@ $^

bin/bus: obj/cmdline-nofpic.o obj/bus-nofpic.o
	@echo CC -o $@
	@mkdir -p bin
	@${CC} ${FLAGS} -lrt -o $@ $^ ${LDFLAGS}

bin/libbus.so.${LIB_VERSION}: obj/bus-fpic.o
	@echo CC -o $@
	@mkdir -p bin
	@${CC} ${FLAGS} -lrt -shared -Wl,-soname,libbus.so.${LIB_MAJOR} -o $@ $^ ${LDFLAGS}

bin/libbus.so.${LIB_MAJOR}:
	@echo LN -s $@
	@mkdir -p bin
	@ln -sf libbus.so.${LIB_VERSION} $@

bin/libbus.so:
	@echo LN -s $@
	@mkdir -p bin
	@ln -sf libbus.so.${LIB_VERSION} $@

obj/%-nofpic.o: src/%.c src/*.h
	@echo CC -c $@
	@mkdir -p obj
	@${CC} ${FLAGS} -c -o $@ ${CPPFLAGS} ${CFLAGS} $<

obj/%-fpic.o: src/%.c src/*.h
	@echo CC -c $@
	@mkdir -p obj
	@${CC} ${FLAGS} -fPIC -c -o $@ ${CPPFLAGS} ${CFLAGS} $<

bin/%.info: doc/info/%.texinfo
	@echo MAKEINFO $@
	@mkdir -p bin
	@$(MAKEINFO) $<
	@mv $*.info $@

bin/%.pdf: doc/info/%.texinfo
	@echo TEXI2PDF $@
	@! test -d obj/pdf || rm -rf obj/pdf
	@mkdir -p bin obj/pdf
	@cd obj/pdf && texi2pdf ../../"$<" < /dev/null
	@mv obj/pdf/$*.pdf $@

bin/%.dvi: doc/info/%.texinfo
	@echo TEXI2DVI $@
	@! test -d obj/dvi || rm -rf obj/dvi
	@mkdir -p bin obj/dvi
	@cd obj/dvi && $(TEXI2DVI) ../../"$<" < /dev/null
	@mv obj/dvi/$*.dvi $@

bin/%.ps: doc/info/%.texinfo
	@echo TEXI2PS $@
	@! test -d obj/ps || rm -rf obj/ps
	@mkdir -p bin obj/ps
	@cd obj/ps && texi2pdf --ps ../../"$<" < /dev/null
	@mv obj/ps/$*.ps $@



install: install-bus install-man install-info install-examples
install-all: install-bus install-doc
install-lib: install-so install-a install-h
install-doc: install-man install-info install-pdf install-dvi install-ps install-examples
install-man: install-man1 install-man3 install-man5 install-man7
install-bus: install-bin install-lib install-license

install-bin: bin/bus
	@echo INSTALL bus
	@install -dm755 -- "${DESTDIR}${BINDIR}"
	@install -m755 $^ -- "${DESTDIR}${BINDIR}"

install-so: bin/libbus.so.${LIB_VERSION}
	@echo INSTALL libbus.so
	@install -dm755 -- "${DESTDIR}${LIBDIR}"
	@install -m755 $^ -- "${DESTDIR}${LIBDIR}"
	@ln -sf -- "libbus.so.${LIB_VERSION}" "${DESTDIR}${LIBDIR}/libbus.so.${LIB_MAJOR}"
	@ln -sf -- "libbus.so.${LIB_VERSION}" "${DESTDIR}${LIBDIR}/libbus.so"

install-a: bin/libbus.a
	@echo INSTALL libbus.a
	@install -dm755 -- "${DESTDIR}${LIBDIR}"
	@install -m644 $^ -- "${DESTDIR}${LIBDIR}"

install-h:
	@echo INSTALL bus.h
	@install -dm755 -- "${DESTDIR}${INCLUDEDIR}"
	@install -m644 src/bus.h -- "${DESTDIR}${INCLUDEDIR}"

install-license:
	@echo INSTALL LICENSE
	@install -dm755 -- "${DESTDIR}${LICENSEDIR}/${PKGNAME}"
	@install -m644 LICENSE -- "${DESTDIR}${LICENSEDIR}/${PKGNAME}"

install-man1: $(foreach M,${MAN1},bin/${M}.1)
	@echo INSTALL $(foreach M,${MAN1},${M}.1)
	@install -dm755 -- "${DESTDIR}${MANDIR}/man1"
	@install -m644 $^ -- "${DESTDIR}${MANDIR}/man1"

install-man3: $(foreach M,${MAN3},bin/${M}.3)
	@echo INSTALL $(foreach M,${MAN3},${M}.3)
	@install -dm755 -- "${DESTDIR}${MANDIR}/man3"
	@install -m644 $^ -- "${DESTDIR}${MANDIR}/man3"
	@ln -sf -- "bus_poll.3" "${DESTDIR}${MANDIR}/man3/bus_poll_start.3"
	@ln -sf -- "bus_poll.3" "${DESTDIR}${MANDIR}/man3/bus_poll_stop.3"

install-man5: $(foreach M,${MAN5},bin/${M}.5)
	@echo INSTALL $(foreach M,${MAN5},${M}.5)
	@install -dm755 -- "${DESTDIR}${MANDIR}/man5"
	@install -m644 $^ -- "${DESTDIR}${MANDIR}/man5"

install-man7: $(foreach M,${MAN7},bin/${M}.7)
	@echo INSTALL $(foreach M,${MAN7},${M}.7)
	@install -dm755 -- "${DESTDIR}${MANDIR}/man7"
	@install -m644 $^ -- "${DESTDIR}${MANDIR}/man7"

install-info: bin/bus.info
	@echo INSTALL bus.info
	@install -dm755 -- "$(DESTDIR)$(INFODIR)"
	@install -m644 $< -- "$(DESTDIR)$(INFODIR)/$(PKGNAME).info"

install-pdf: bin/bus.pdf
	@echo INSTALL bus.pdf
	@install -dm755 -- "$(DESTDIR)$(DOCDIR)"
	@install -m644 $< -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).pdf"

install-dvi: bin/bus.dvi
	@echo INSTALL bus.dvi
	@install -dm755 -- "$(DESTDIR)$(DOCDIR)"
	@install -m644 $< -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).dvi"

install-ps: bin/bus.ps
	@echo INSTALL bus.ps
	@install -dm755 -- "$(DESTDIR)$(DOCDIR)"
	@install -m644 $< -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).ps"

install-examples:
	@echo INSTALL examples
	@install -dm755 -- $(foreach E,$(EXAMPLES),"$(DESTDIR)$(DOCDIR)/$(PKGNAME)/examples/$(E)")
	@$(foreach E,$(EXAMPLES),cp -- $(foreach F,$(EXAMPLE_$(E)),doc/examples/$(E)/$(F))  \
	    "$(DESTDIR)$(DOCDIR)/$(PKGNAME)/examples/$(E)" &&) true



uninstall:
	-rm -- "${DESTDIR}${BINDIR}/bus"
	-rm -- "${DESTDIR}${LIBDIR}/libbus.so.${LIB_VERSION}"
	-rm -- "${DESTDIR}${LIBDIR}/libbus.so.${LIB_MAJOR}"
	-rm -- "${DESTDIR}${LIBDIR}/libbus.so"
	-rm -- "${DESTDIR}${LIBDIR}/libbus.a"
	-rm -- "${DESTDIR}${INCLUDEDIR}/bus.h"
	-rm -- "${DESTDIR}${LICENSEDIR}/${PKGNAME}/LICENSE"
	-rmdir -- "${DESTDIR}${LICENSEDIR}/${PKGNAME}"
	-rm -- $(foreach M,${MAN1},"${DESTDIR}${MANDIR}/man1/${M}.1")
	-rm -- $(foreach M,${MAN3},"${DESTDIR}${MANDIR}/man3/${M}.3")
	-rm -- "${DESTDIR}${MANDIR}/man3/bus_poll_start.3"
	-rm -- "${DESTDIR}${MANDIR}/man3/bus_poll_stop.3"
	-rm -- "${DESTDIR}${MANDIR}/man3/bus_poll_timed.3"
	-rm -- "${DESTDIR}${MANDIR}/man3/bus_read_timed.3"
	-rm -- "${DESTDIR}${MANDIR}/man3/bus_write_timed.3"
	-rm -- $(foreach M,${MAN5},"${DESTDIR}${MANDIR}/man5/${M}.5")
	-rm -- $(foreach M,${MAN7},"${DESTDIR}${MANDIR}/man7/${M}.7")
	-rm -- "$(DESTDIR)$(INFODIR)/$(PKGNAME).info"
	-rm -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).pdf"
	-rm -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).dvi"
	-rm -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).ps"
	-$(foreach E,$(EXAMPLES),rm --  \
	    $(foreach F,$(EXAMPLE_$(E)),"$(DESTDIR)$(DOCDIR)/$(PKGNAME)/examples/$(E)/$(F)");)
	-rmdir -- $(foreach E,$(EXAMPLES),"$(DESTDIR)$(DOCDIR)/$(PKGNAME)/examples/$(E)")



clean:
	@echo cleaning
	@-rm -rf obj bin



.PHONY: default all doc bin bus lib so a man man1 man3 man5 man7 info pdf dvi \
        ps install install-all install-doc install-man install-bin install-so \
        install-a install-h install-lib install-license install-man1 install-bus \
        install-man3 install-man5 install-man7 install-info install-pdf install-dvi \
        install-ps install-examples uninstall clean