fd.c: Avoid gcc warning regarding fchdir().
[adu.git] / Makefile
1 objects := adu.o string.o cmdline.o fd.o select.o create.o interactive.o select.cmdline.o format.o user.o bloom.o
2 all: adu
3 version := 1.0.0
4 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
5
6 DEBUG_CPPFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
7 DEBUG_CPPFLAGS += -Wredundant-decls
8 CPPFLAGS += -Os
9 CPPFLAGS += -Wall
10 CPPFLAGS += -Wuninitialized
11 CPPFLAGS += -Wchar-subscripts
12 CPPFLAGS += -Wformat-security
13 CPPFLAGS += -Werror-implicit-function-declaration
14 CPPFLAGS += -Wmissing-format-attribute
15 CPPFLAGS += -Wunused-macros
16 CPPFLAGS += -Wbad-function-cast
17 CPPFLAGS += -DVERSION='"$(version)"'
18 CPPFLAGS += -I/usr/local/include
19
20 LDFLAGS += -L/usr/local/lib
21
22 PREFIX ?= /usr/local
23 ifeq "$(origin CC)" "default"
24 CC := gcc
25 endif
26
27
28 ifeq (,$(findstring BSD,$(uname_S)))
29 CPPFLAGS += -D_LARGEFILE64_SOURCE
30 CPPFLAGS += $(shell getconf LFS64_CFLAGS)
31 LDFLAGS += -D_LARGEFILE64_SOURCE
32 LDFLAGS += $(shell getconf LFS64_LDFLAGS)
33 LDFLAGS += $(shell getconf LFS64_LIBS)
34 CPPFLAGS += -DHAVE_STAT64=1
35 endif
36
37
38 Makefile.deps: $(wildcard *.c *.h)
39 $(CC) $(CPPFLAGS) -MM -MG *.c > $@
40
41 -include Makefile.deps
42
43 adu: $(objects)
44 $(CC) -o $@ $(LDFLAGS) $(objects) -losl
45
46 cmdline.o: cmdline.c cmdline.h
47 $(CC) -c $(CPPFLAGS) $<
48
49 cmdline.c cmdline.h: adu.ggo
50 gengetopt --no-handle-error --no-handle-help < $<
51
52
53 %.o: %.c Makefile
54 $(CC) -c $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
55
56 select.cmdline.c select.cmdline.h: select.ggo
57 gengetopt --set-package=select \
58 --no-handle-help \
59 --no-handle-error \
60 --no-handle-version \
61 --arg-struct-name=select_args_info \
62 --file-name=$(subst .ggo,,$<).cmdline \
63 --func-name $(subst .ggo,,$<)_cmdline_parser < $<
64
65 select.cmdline.o: select.cmdline.c select.cmdline.h
66 $(CC) -c $(CPPFLAGS) $<
67
68 adu.1: adu adu.1.inc
69 help2man -h --detailed-help --include adu.1.inc -N ./$< > $@
70
71 %.1.html: %.1
72 man2html $< | sed -e 's|^<DT><DD>$$|<DT><DD><br>|g' > $@
73
74 clean:
75 rm -f *.o adu *cmdline.c *cmdline.h adu.1 adu.1.html adu.png index.html adu.sk~
76
77 index.html: adu.1.html index.html.in INSTALL README
78 sed -e '/@README@/,$$d' index.html.in > $@
79 grutatxt -nb < README >> $@
80 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' index.html.in >> $@
81 grutatxt -nb < INSTALL >> $@
82 sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' index.html.in >> $@
83 sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' adu.1.html >> $@
84 sed -e '1,/@MAN_PAGE@/d' index.html.in >> $@
85
86 install: adu adu.1
87 install -s adu $(PREFIX)/bin
88 install -m 0644 adu.1 $(PREFIX)/man/man1