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