Fix compilation on FreeBSD.
[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 ($(uname_s),FreeBSD)
82 format := elf
83 LDFLAGS += -Wl,-soname,$(soname)
84 endif
85
86 ifeq ($(format),elf)
87 # On ELf-based systems, the following conventions apply (see dhweeler's
88 # Program Library HOWTO):
89 #
90 # The soname has the prefix ``lib'', the name of the library, the
91 # phrase ``.so'', followed by a period and a version number that is
92 # incremented whenever the interface changes.
93 soname := lib$(libname).so.$(x)
94
95 # The real name adds to the soname a period, a minor number, another
96 # period, and the release number.
97 realname := $(soname).$(y).$(z)
98
99 # In addition, there's the name that the compiler uses when requesting
100 # a library, (I'll call it the ``linker name''), which is simply the
101 # soname without any version number.
102 linkername := lib$(libname).so
103 LDFLAGS += --shared
104 endif
105
106
107 all: $(realname) oslfsck
108 Makefile.deps: $(wildcard *.c *.h)
109 $(CC) -MM -MG *.c > $@
110 osl.c fsck.c:
111
112 -include Makefile.deps
113
114 fsck.cmdline.o: fsck.cmdline.c fsck.cmdline.h
115 $(CC) -c -DVERSION='"$(VERSION)"' $<
116
117 %.fsck.o: %.c Makefile fsck.cmdline.c fsck.cmdline.h osl.h errtab.h
118 $(CC) -c -DVERSION='"$(VERSION)"' $(CPPFLAGS) $(CFLAGS) $< -o $@
119
120 %.o: %.c Makefile errtab.h
121 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $<
122
123 fsck.cmdline.h fsck.cmdline.c: fsck.ggo Makefile
124 gengetopt $$O \
125 --conf-parser \
126 --unamed-opts=table \
127 --no-handle-version \
128 --file-name=fsck.cmdline \
129 --func-name=fsck_cmdline_parser \
130 --set-package="oslfsck" \
131 --arg-struct-name=fsck_args_info \
132 < $<
133
134 oslfsck: $(fsck_objects)
135 $(CC) -o $@ $(fsck_objects) -lcrypto
136
137 $(realname): $(objects)
138 $(CC) $(LDFLAGS) -o $@ $(objects) -lcrypto
139
140 osl_errors.h: errlist
141 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
142 -e '1s/^/enum osl_errors {/1' \
143 -e '1s/$$/=1/1' \
144 -e '$$!s/$$/,/g' \
145 -e '$$s/$$/};/1' $< > $@
146
147 errtab.h: errlist
148 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
149
150 osl.h: osl.h.in osl_errors.h Makefile
151 cat osl.h.in osl_errors.h > $@
152 clean:
153 rm -f *.o $(realname) osl.h osl_errors.h errtab.h fsck.cmdline.h fsck.cmdline.c
154
155 install: all
156 $(MKDIR) $(libdir) $(includedir)
157 $(RM) $(libdir)/$(linkername)
158 $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
159 $(INSTALL) -s -m 755 $(realname) $(libdir)
160 $(INSTALL) -m 644 $(headers) $(includedir)
161
162 .PHONY: all clean install