9c34d749eb4071ed43c5a0dd650adcf4c7ef3411
[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
45 ifeq ($(uname_s),Linux)
46 format := elf
47 LDFLAGS += -Wl,-soname,$(soname)
48 # disallow undefined symbols
49 LDFLAGS += -Wl,-z,defs
50 endif
51 ifeq ($(uname_s),Darwin)
52 # Darwin has its own idea on version numbers:
53 realname := lib$(libname).$(x).dylib
54 soname := $(realname)
55 linkername := lib$(libname).so
56 # The minor version number is an incremental number using the format
57 # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
58 # the gcc -current_version option.
59 LDFLAGS += -current_version $(y).$(z)
60 #
61 # The compatibility version number of a library release specifies the
62 # earliest minor version of the clients linked against that release can
63 # use.
64 LDFLAGS += -compatibility_version $(y).0
65 LDFLAGS += -dynamiclib
66 endif
67 ifeq ($(uname_s),SunOS)
68 format := elf
69 # Solaris needs another set of flags
70 LDFLAGS += -z text
71 LDFLAGS += -z defs
72 CPPFLAGS += -I/opt/csw/include
73 LDFLAGS += -lc
74 endif
75
76 ifeq ($(uname_s),NetBSD)
77 format := elf
78 LDFLAGS += -Wl,-soname,$(soname)
79 endif
80
81 ifeq ($(format),elf)
82 # On ELf-based systems, the following conventions apply (see dhweeler's
83 # Program Library HOWTO):
84 #
85 # The soname has the prefix ``lib'', the name of the library, the
86 # phrase ``.so'', followed by a period and a version number that is
87 # incremented whenever the interface changes.
88 soname := lib$(libname).so.$(x)
89
90 # The real name adds to the soname a period, a minor number, another
91 # period, and the release number.
92 realname := $(soname).$(y).$(z)
93
94 # In addition, there's the name that the compiler uses when requesting
95 # a library, (I'll call it the ``linker name''), which is simply the
96 # soname without any version number.
97 linkername := lib$(libname).so
98 LDFLAGS += --shared
99 endif
100
101
102 all: $(realname) oslfsck
103 Makefile.deps: $(wildcard *.c *.h)
104 $(CC) -MM -MG *.c > $@
105 osl.c fsck.c:
106
107 -include Makefile.deps
108
109 fsck.cmdline.o: fsck.cmdline.c fsck.cmdline.h
110 $(CC) -c -DVERSION='"$(VERSION)"' $<
111
112 %.fsck.o: %.c Makefile fsck.cmdline.c fsck.cmdline.h osl.h
113 $(CC) -c -DVERSION='"$(VERSION)"' $(CPPFLAGS) $(CFLAGS) $< -o $@
114
115 %.o: %.c Makefile errtab.h
116 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $<
117
118 fsck.cmdline.h fsck.cmdline.c: fsck.ggo Makefile
119 gengetopt $$O \
120 --conf-parser \
121 --unamed-opts=table \
122 --no-handle-version \
123 --file-name=fsck.cmdline \
124 --func-name=fsck_cmdline_parser \
125 --set-package="oslfsck" \
126 --arg-struct-name=fsck_args_info \
127 < $<
128
129 oslfsck: $(fsck_objects)
130 $(CC) -o $@ $(fsck_objects) -lcrypto
131
132 $(realname): $(objects)
133 $(CC) $(LDFLAGS) -o $@ $(objects) -lcrypto
134
135 osl_errors.h: errlist
136 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
137 -e '1s/^/enum osl_errors {/1' \
138 -e '1s/$$/=1/1' \
139 -e '$$!s/$$/,/g' \
140 -e '$$s/$$/};/1' $< > $@
141
142 errtab.h: errlist
143 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/_S(E_OSL_\1, \2)/g' $< > $@
144
145 osl.h: osl.h.in osl_errors.h Makefile
146 cat osl.h.in osl_errors.h > $@
147 clean:
148 rm -f *.o $(realname) osl.h osl_errors.h errtab.h fsck.cmdline.h fsck.cmdline.c
149
150 install: all
151 $(MKDIR) $(libdir) $(includedir)
152 $(RM) $(libdir)/$(linkername)
153 $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
154 $(INSTALL) -s -m 755 $(realname) $(libdir)
155 $(INSTALL) -m 644 $(headers) $(includedir)
156
157 .PHONY: all clean install