MacOs Fixes.
[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).dylib
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 all: $(realname) $(executables) $(man_pages)
111 Makefile.deps: $(wildcard *.c *.h)
112 $(CC) -MM -MG *.c > $@
113 osl.c fsck.c:
114
115 -include Makefile.deps
116
117 fsck.cmdline.o: fsck.cmdline.c fsck.cmdline.h
118 $(CC) -c -DVERSION='"$(VERSION)"' $<
119
120 %.fsck.o: %.c Makefile fsck.cmdline.c fsck.cmdline.h osl.h errtab.h
121 $(CC) -c -DVERSION='"$(VERSION)"' $(CPPFLAGS) $(CFLAGS) $< -o $@
122
123 %.o: %.c Makefile errtab.h
124 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $<
125
126 fsck.cmdline.h fsck.cmdline.c: fsck.ggo Makefile
127 gengetopt \
128 --conf-parser \
129 --unamed-opts=table \
130 --no-handle-version \
131 --file-name=fsck.cmdline \
132 --func-name=fsck_cmdline_parser \
133 --set-package="oslfsck" \
134 --arg-struct-name=fsck_args_info \
135 < $<
136
137 oslfsck: $(fsck_objects)
138 $(CC) -o $@ $(fsck_objects) -lcrypto
139
140 oslfsck.1: oslfsck
141 help2man -h --detailed-help -N ./$< > $@
142
143 $(realname): $(objects)
144 $(CC) $(LDFLAGS) -o $@ $(objects) -lcrypto
145
146 osl_errors.h: errlist
147 echo '/** public error codes of the osl library. */' > $@
148 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
149 -e '1s/^/enum osl_errors {/1' \
150 -e '1s/$$/=1/1' \
151 -e '$$!s/$$/,/g' \
152 -e '$$s/$$/};/1' $< >> $@
153
154 errtab.h: errlist
155 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
156
157 osl.h: osl.h.in osl_errors.h Makefile
158 echo '#ifndef _OSL_H' > $@
159 echo '#define _OSL_H' >> $@
160 cat osl.h.in osl_errors.h >> $@
161 echo '#endif /* _OSL_H */' >> $@
162 clean:
163 rm -f *.o $(realname) osl.h osl_errors.h errtab.h fsck.cmdline.h \
164 fsck.cmdline.c oslfsck
165
166 distclean: clean
167 rm -f web/index.html web/oslfsck.1.html web/osl.png
168 rm -rf web/doxygen
169
170 install: all
171 $(MKDIR) $(libdir) $(includedir) $(mandir) $(bindir)
172 $(RM) $(libdir)/$(linkername)
173 $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
174 $(INSTALL) -m 755 $(realname) $(libdir)
175 $(INSTALL) -m 644 $(headers) $(includedir)
176 $(INSTALL) -m 755 $(executables) $(bindir)
177 $(INSTALL) -m 644 $(man_pages) $(mandir)
178
179 .PHONY: all clean install
180
181 web/%.1.html: %.1
182 man2html $< > $@
183
184 web/osl.png: web/osl.pdf Makefile
185 convert -scale 200x200 $< $@
186
187 web/index.html: web/oslfsck.1.html web/index.html.in INSTALL README
188 sed -e '/@README@/,$$d' web/index.html.in > $@
189 grutatxt -nb < README >> $@
190 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
191 grutatxt -nb < INSTALL >> $@
192 sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
193 sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' web/oslfsck.1.html >> $@
194 sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@