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