Use ?:= as the assignement operator for PREFIX.
[adu.git] / Makefile
index 8dcf26dbbcc573a1114933231e3b07ce00cf7b14..78c9b1697b647cb6a56c9814ea2a94d8b86b8bdd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,35 +1,93 @@
-objects := adu.o string.o cmdline.o fd.o select.o create.c
+objects := adu.o string.o cmdline.o fd.o select.o create.o interactive.o select.cmdline.o format.o user.o bloom.o
 all: adu
+version := 0.0.5
+uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
 
 DEBUG_CPPFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
 DEBUG_CPPFLAGS += -Wredundant-decls
-#CPPFLAGS += -Os
+CPPFLAGS += -Os
 CPPFLAGS += -Wall
-#CPPFLAGS += -Wuninitialized
+CPPFLAGS += -Wuninitialized
 CPPFLAGS += -Wchar-subscripts
 CPPFLAGS += -Wformat-security
 CPPFLAGS += -Werror-implicit-function-declaration
 CPPFLAGS += -Wmissing-format-attribute
 CPPFLAGS += -Wunused-macros
 CPPFLAGS += -Wbad-function-cast
+CPPFLAGS += -DVERSION='"$(version)"'
+CPPFLAGS += -I/usr/local/include
+
+LDFLAGS += -L/usr/local/lib
+
+PREFIX ?:= /usr/local
+ifeq "$(origin CC)" "default"
+       CC := gcc
+endif
+
+
+ifeq (,$(findstring BSD,$(uname_S)))
+       CPPFLAGS += -D_LARGEFILE64_SOURCE
+       CPPFLAGS += $(shell getconf LFS64_CFLAGS)
+       LDFLAGS += -D_LARGEFILE64_SOURCE
+       LDFLAGS += $(shell getconf LFS64_LDFLAGS)
+       LDFLAGS += $(shell getconf LFS64_LIBS)
+       CPPFLAGS += -DHAVE_STAT64=1
+endif
+
 
 Makefile.deps: $(wildcard *.c *.h)
-       gcc -MM -MG *.c > $@
+       $(CC) -MM -MG *.c > $@
 
 -include Makefile.deps
 
 adu: $(objects)
-       $(CC) -o $@ $(objects) -lcrypto -losl
+       $(CC) -o $@ $(LDFLAGS) $(objects) -lcrypto -losl
 
 cmdline.o: cmdline.c cmdline.h
        $(CC) -c $(CPPFLAGS) $<
 
 cmdline.c cmdline.h: adu.ggo
-       gengetopt --conf-parser < $<
+       gengetopt --no-handle-error --no-handle-help --conf-parser < $<
 
 
 %.o: %.c Makefile
        $(CC) -c $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
 
+%.ppm: %.sk
+       sk2ppm $< > $@
+%.png: %.ppm
+       convert $< $@
+
+select.cmdline.c select.cmdline.h: select.ggo
+       gengetopt --set-package=select \
+               --no-handle-help \
+               --no-handle-error \
+               --no-handle-version \
+               --arg-struct-name=select_args_info \
+               --file-name=$(subst .ggo,,$<).cmdline \
+               --func-name $(subst .ggo,,$<)_cmdline_parser < $<
+
+select.cmdline.o: select.cmdline.c select.cmdline.h
+       $(CC) -c $(CPPFLAGS) $<
+
+adu.1: adu adu.1.inc
+       help2man -h --detailed-help --include adu.1.inc -N ./$< > $@
+
+%.1.html: %.1
+       man2html $< | sed -e 's|^<DT><DD>$$|<DT><DD><br>|g' > $@
+
 clean:
-       rm -f *.o adu
+       rm -f *.o adu *cmdline.c *cmdline.h adu.1 adu.1.html adu.png index.html adu.sk~
+
+index.html: adu.1.html index.html.in INSTALL README
+       sed -e '/@README@/,$$d' index.html.in > $@
+       grutatxt -nb < README >> $@
+       sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' index.html.in >> $@
+       grutatxt -nb < INSTALL >> $@
+       sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' index.html.in >> $@
+       sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' adu.1.html >> $@
+       sed -e '1,/@MAN_PAGE@/d' index.html.in >> $@
+
+install: adu adu.1
+       install -s adu $(PREFIX)/bin
+       install -m 0644 adu.1 $(PREFIX)/man/man1