Makefile: Remove unused uname_rs.
[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 := 1
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
48 libname := osl
49
50 ifeq ($(uname_s),Linux)
51 format := elf
52 LDFLAGS += -Wl,-soname,$(soname)
53 # disallow undefined symbols
54 LDFLAGS += -Wl,-z,defs
55 endif
56 ifeq ($(uname_s),Darwin)
57 # Darwin has its own idea on version numbers:
58 realname := lib$(libname).$(x).dylib
59 soname := $(realname)
60 linkername := lib$(libname).dylib
61 # The minor version number is an incremental number using the format
62 # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
63 # the gcc -current_version option.
64 LDFLAGS += -current_version $(y).$(z)
65 #
66 # The compatibility version number of a library release specifies the
67 # earliest minor version of the clients linked against that release can
68 # use.
69 LDFLAGS += -compatibility_version $(y).0
70 LDFLAGS += -dynamiclib
71 endif
72 ifeq ($(uname_s),SunOS)
73 format := elf
74 # Solaris needs another set of flags
75 LDFLAGS += -z text
76 LDFLAGS += -z defs
77 CPPFLAGS += -I/opt/csw/include
78 LDFLAGS += -lc
79 endif
80
81 ifeq ($(uname_s),NetBSD)
82 format := elf
83 LDFLAGS += -Wl,-soname,$(soname)
84 endif
85
86 ifeq ($(uname_s),FreeBSD)
87 format := elf
88 LDFLAGS += -Wl,-soname,$(soname)
89 endif
90
91 ifeq ($(format),elf)
92 # On ELf-based systems, the following conventions apply (see dhweeler's
93 # Program Library HOWTO):
94 #
95 # The soname has the prefix ``lib'', the name of the library, the
96 # phrase ``.so'', followed by a period and a version number that is
97 # incremented whenever the interface changes.
98 soname := lib$(libname).so.$(x)
99
100 # The real name adds to the soname a period, a minor number, another
101 # period, and the release number.
102 realname := $(soname).$(y).$(z)
103
104 # In addition, there's the name that the compiler uses when requesting
105 # a library, (I'll call it the ``linker name''), which is simply the
106 # soname without any version number.
107 linkername := lib$(libname).so
108 LDFLAGS += --shared
109 endif
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 \
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)
140
141 oslfsck.1: oslfsck
142 help2man -h --detailed-help -N ./$< > $@
143
144 $(realname): $(objects)
145 $(CC) $(LDFLAGS) -o $@ $(objects)
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-bin: $(executables)
172 $(MKDIR) $(bindir)
173 $(INSTALL) -m 755 $(executables) $(bindir)
174
175 install-man: $(man_pages)
176 $(MKDIR) $(mandir)
177 $(INSTALL) -m 644 $(man_pages) $(mandir)
178
179 install-lib: $(realname) $(headers)
180 $(MKDIR) $(libdir) $(includedir)
181 $(RM) $(libdir)/$(linkername)
182 $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
183 $(INSTALL) -m 755 $(realname) $(libdir)
184 $(INSTALL) -m 644 $(headers) $(includedir)
185
186 install: all install-bin install-man install-lib
187
188 .PHONY: all clean install install-bin install-man install-lib
189
190 web/%.1.html: %.1
191 man2html $< > $@
192
193 web/osl.png: web/osl.pdf Makefile
194 convert -scale 200x200 $< $@
195
196 web/index.html: web/oslfsck.1.html web/index.html.in INSTALL README
197 sed -e '/@README@/,$$d' web/index.html.in > $@
198 grutatxt -nb < README >> $@
199 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
200 grutatxt -nb < INSTALL >> $@
201 sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
202 sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' web/oslfsck.1.html >> $@
203 sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@