Revert "Use ?:= as the assignement operator for PREFIX."
[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 := 0.0.5
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) -MM -MG *.c > $@
40
41 -include Makefile.deps
42
43 adu: $(objects)
44         $(CC) -o $@ $(LDFLAGS) $(objects) -lcrypto -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 --conf-parser < $<
51
52
53 %.o: %.c Makefile
54         $(CC) -c $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
55
56 %.ppm: %.sk
57         sk2ppm $< > $@
58 %.png: %.ppm
59         convert $< $@
60
61 select.cmdline.c select.cmdline.h: select.ggo
62         gengetopt --set-package=select \
63                 --no-handle-help \
64                 --no-handle-error \
65                 --no-handle-version \
66                 --arg-struct-name=select_args_info \
67                 --file-name=$(subst .ggo,,$<).cmdline \
68                 --func-name $(subst .ggo,,$<)_cmdline_parser < $<
69
70 select.cmdline.o: select.cmdline.c select.cmdline.h
71         $(CC) -c $(CPPFLAGS) $<
72
73 adu.1: adu adu.1.inc
74         help2man -h --detailed-help --include adu.1.inc -N ./$< > $@
75
76 %.1.html: %.1
77         man2html $< | sed -e 's|^<DT><DD>$$|<DT><DD><br>|g' > $@
78
79 clean:
80         rm -f *.o adu *cmdline.c *cmdline.h adu.1 adu.1.html adu.png index.html adu.sk~
81
82 index.html: adu.1.html index.html.in INSTALL README
83         sed -e '/@README@/,$$d' index.html.in > $@
84         grutatxt -nb < README >> $@
85         sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' index.html.in >> $@
86         grutatxt -nb < INSTALL >> $@
87         sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' index.html.in >> $@
88         sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' adu.1.html >> $@
89         sed -e '1,/@MAN_PAGE@/d' index.html.in >> $@
90
91 install: adu adu.1
92         install -s adu $(PREFIX)/bin
93         install -m 0644 adu.1 $(PREFIX)/man/man1