Change the osl slogan.
[osl.git] / Makefile
1 # where to install
2 prefix := /usr/local
3 libdir := $(prefix)/lib
4 includedir := $(prefix)/include
5 bindir := $(prefix)/bin
6 mandir := $(prefix)/man/man1
7
8 objects := osl.o util.o rbtree.o sha1.o
9 fsck_objects := fsck.fsck.o osl.fsck.o util.fsck.o rbtree.fsck.o sha1.fsck.o fsck.cmdline.o
10 headers := osl.h
11 executables := oslfsck
12 man_pages := oslfsck.1
13
14 INSTALL := install
15 CC := gcc
16 MKDIR := mkdir -p
17 RM := rm -f
18 LN := ln
19
20 # libosl's versioning consists of three numbers. Let's call them x, y and z.
21 # The way x, y and z are interpreted depends on the OS.
22 x := 0
23 y := 1
24 z := 0
25 VERSION := $(x).$(y).$(z)
26
27 # common flags
28 CFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
29 CFLAGS += -Wredundant-decls
30 CFLAGS += -Os
31 CFLAGS += -Wall
32 CFLAGS += -Wuninitialized
33 CFLAGS += -Wchar-subscripts
34 CFLAGS += -Wformat-security
35 CFLAGS += -Werror-implicit-function-declaration
36 CFLAGS += -Wmissing-format-attribute
37 CFLAGS += -Wunused-macros
38 CFLAGS += -Wbad-function-cast
39
40 # cflags used only for building library objects
41 LIBCFLAGS += -fPIC
42 LIBCFLAGS += -fvisibility=hidden
43
44 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
45 uname_rs := $(shell uname -rs)
46
47 libname := osl
48
49 ifeq ($(uname_s),Linux)
50         format := elf
51         LDFLAGS += -Wl,-soname,$(soname)
52         # disallow undefined symbols
53         LDFLAGS += -Wl,-z,defs
54 endif
55 ifeq ($(uname_s),Darwin)
56         # Darwin has its own idea on version numbers:
57         realname := lib$(libname).$(x).dylib
58         soname := $(realname)
59         linkername := lib$(libname).so
60         # The minor version number is an incremental number using the format
61         # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
62         # the gcc -current_version option.
63         LDFLAGS += -current_version $(y).$(z)
64         #
65         # The compatibility version number of a library release specifies the
66         # earliest minor version of the clients linked against that release can
67         # use.
68         LDFLAGS += -compatibility_version $(y).0
69         LDFLAGS += -dynamiclib
70 endif
71 ifeq ($(uname_s),SunOS)
72         format := elf
73         # Solaris needs another set of flags
74         LDFLAGS += -z text
75         LDFLAGS += -z defs
76         CPPFLAGS += -I/opt/csw/include
77         LDFLAGS += -lc
78 endif
79
80 ifeq ($(uname_s),NetBSD)
81         format := elf
82         LDFLAGS += -Wl,-soname,$(soname)
83 endif
84
85 ifeq ($(uname_s),FreeBSD)
86         format := elf
87         LDFLAGS += -Wl,-soname,$(soname)
88 endif
89
90 ifeq ($(format),elf)
91         # On ELf-based systems, the following conventions apply (see dhweeler's
92         # Program Library HOWTO):
93         #
94         # The soname has the prefix ``lib'', the name of the library, the
95         # phrase ``.so'', followed by a period and a version number that is
96         # incremented whenever the interface changes.
97         soname := lib$(libname).so.$(x)
98
99         # The real name adds to the soname a period, a minor number, another
100         # period, and the release number.
101         realname := $(soname).$(y).$(z)
102
103         # In addition, there's the name that the compiler uses when requesting
104         # a library, (I'll call it the ``linker name''), which is simply the
105         # soname without any version number.
106         linkername := lib$(libname).so
107         LDFLAGS += --shared
108 endif
109
110
111 all: $(realname) $(executables) $(man_pages)
112 Makefile.deps: $(wildcard *.c *.h)
113         $(CC) -MM -MG *.c > $@
114 osl.c fsck.c:
115
116 -include Makefile.deps
117
118 fsck.cmdline.o: fsck.cmdline.c fsck.cmdline.h
119         $(CC) -c -DVERSION='"$(VERSION)"' $<
120
121 %.fsck.o: %.c Makefile fsck.cmdline.c fsck.cmdline.h osl.h errtab.h
122         $(CC) -c -DVERSION='"$(VERSION)"' $(CPPFLAGS) $(CFLAGS) $< -o $@
123
124 %.o: %.c Makefile errtab.h
125         $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $<
126
127 fsck.cmdline.h fsck.cmdline.c: fsck.ggo Makefile
128         gengetopt $$O \
129                 --conf-parser \
130                 --unamed-opts=table \
131                 --no-handle-version \
132                 --file-name=fsck.cmdline \
133                 --func-name=fsck_cmdline_parser \
134                 --set-package="oslfsck" \
135                 --arg-struct-name=fsck_args_info \
136                 < $<
137
138 oslfsck: $(fsck_objects)
139         $(CC) -o $@ $(fsck_objects) -lcrypto
140
141 oslfsck.1: oslfsck
142         help2man -h --detailed-help -N ./$< > $@
143
144 $(realname): $(objects)
145         $(CC) $(LDFLAGS) -o $@ $(objects) -lcrypto
146
147 osl_errors.h: errlist
148         echo '/** public error codes of the osl library. */' > $@
149         sed -e 's/\([A-Z_]*\)   .*/     E_OSL_\1/' \
150                 -e '1s/^/enum osl_errors {/1' \
151                 -e '1s/$$/=1/1' \
152                 -e '$$!s/$$/,/g' \
153                 -e '$$s/$$/};/1' $< >> $@
154
155 errtab.h: errlist
156         sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
157
158 osl.h: osl.h.in osl_errors.h Makefile
159         echo '#ifndef _OSL_H' > $@
160         echo '#define _OSL_H' >> $@
161         cat osl.h.in osl_errors.h >> $@
162         echo '#endif /* _OSL_H */' >> $@
163 clean:
164         rm -f *.o $(realname) osl.h osl_errors.h errtab.h fsck.cmdline.h \
165                 fsck.cmdline.c oslfsck
166
167 distclean: clean
168         rm -f web/index.html web/oslfsck.1.html web/osl.png
169         rm -rf web/doxygen
170
171 install: all
172         $(MKDIR) $(libdir) $(includedir)
173         $(RM) $(libdir)/$(linkername)
174         $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
175         $(INSTALL) -s -m 755 $(realname) $(libdir)
176         $(INSTALL) -m 644 $(headers) $(includedir)
177         $(INSTALL) -m 644 $(executables) $(bindir)
178         $(INSTALL) -m 644 $(man_pages) $(mandir)
179
180 .PHONY: all clean install
181
182 web/%.1.html: %.1
183         man2html $< > $@
184
185 web/osl.png: web/osl.pdf
186         convert $< $@
187
188 web/index.html: web/oslfsck.1.html web/index.html.in INSTALL README
189         sed -e '/@README@/,$$d' web/index.html.in > $@
190         grutatxt -nb < README >> $@
191         sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
192         grutatxt -nb < INSTALL >> $@
193         sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
194         sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' web/oslfsck.1.html >> $@
195         sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@