cc4447890f6ddbc5dcb65f23b4ed9109e81fc3c4
[osl.git] / Makefile
1 # where to install
2 prefix := /usr/local
3 libdir := $(prefix)/lib
4 includedir := $(prefix)/include
5
6 objects := osl.o util.o rbtree.o sha1.o
7 fsck_objects := fsck.fsck.o osl.fsck.o util.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         soname := lib$(libname).so.$(x)
90         realname := $(soname).$(y).$(z)
91         linkername := lib$(libname).so
92         CPPFLAGS += -I/opt/csw/include
93         LDFLAGS += -lc
94 endif
95
96 all: $(realname) oslfsck
97 Makefile.deps: $(wildcard *.c *.h)
98         $(CC) -MM -MG *.c > $@
99 osl.c fsck.c: errtab.h
100
101 -include Makefile.deps
102
103 fsck.cmdline.o: fsck.cmdline.c fsck.cmdline.h
104         $(CC) -c -DVERSION='"$(VERSION)"' $<
105
106 %.fsck.o: %.c Makefile fsck.cmdline.c fsck.cmdline.h
107         $(CC) -c -DVERSION='"$(VERSION)"' $(CPPFLAGS) $(CFLAGS) $< -o $@
108
109 %.o: %.c Makefile
110         $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $<
111
112 fsck.cmdline.h fsck.cmdline.c: fsck.ggo Makefile
113         gengetopt $$O \
114                 --conf-parser \
115                 --unamed-opts=table \
116                 --no-handle-version \
117                 --file-name=fsck.cmdline \
118                 --func-name=fsck_cmdline_parser \
119                 --set-package="oslfsck" \
120                 --arg-struct-name=fsck_args_info \
121                 < $<
122
123 oslfsck: $(fsck_objects)
124         $(CC) -o $@ $(fsck_objects) -lcrypto
125
126 $(realname): $(objects)
127         $(CC) $(LDFLAGS) -o $@ $(objects) -lcrypto
128
129 osl_errors.h: errlist
130         sed -e 's/\([A-Z_]*\)   .*/     E_OSL_\1/' \
131                 -e '1s/^/enum osl_errors {/1' \
132                 -e '1s/$$/=1/1' \
133                 -e '$$!s/$$/,/g' \
134                 -e '$$s/$$/};/1' $< > $@
135
136 errtab.h: errlist
137         sed -e 's/^\([A-Z_]*\)\s*\(.*\)/_S(E_OSL_\1, \2)/g' $< > $@
138
139 osl.h: osl.h.in osl_errors.h Makefile
140         cat osl.h.in osl_errors.h > $@
141 clean:
142         rm -f *.o $(realname) osl.h osl_errors.h errtab.h fsck.cmdline.h fsck.cmdline.c
143
144 install: all
145         $(MKDIR) $(libdir) $(includedir)
146         $(RM) $(libdir)/$(linkername)
147         $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
148         $(INSTALL) -s -m 755 $(realname) $(libdir)
149         $(INSTALL) -m 644 $(headers) $(includedir)
150
151 .PHONY: all clean install