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