Fix target osl_errors.h on MacOS.
[osl.git] / Makefile
1 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
2 uname_rs := $(shell uname -rs)
3
4 objects := osl.o fd.o rbtree.o sha1.o
5 major_version := 0
6 minor_version := 1
7 patchlevel_version := 0
8 libname := osl
9
10
11 ifeq ($(uname_s),Linux)
12         dso_opts := --shared -Wl,-soname,libosl.so.$(major_version)
13         dso_filename :=lib$(libname).so.$(major_version).$(minor_version).$(patchlevel_version)
14         # disallow undefined symbols
15         LDFLAGS += -Wl,-z,defs
16 endif
17 ifeq ($(uname_s),Darwin)
18         # Darwin has its own idea on version numbers:
19         #
20         # The minor version number is an incremental number using the format
21         # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
22         # the gcc -current_version option.
23         #
24         # The compatibility version number of a library release specifies the
25         # earliest minor version of the clients linked against that release can
26         # use.
27         dso_opts := -dynamiclib -current_version $(minor_version).$(patchlevel_version) \
28                 -compatibility_version $(minor_version).0 -fvisibility=hidden
29         dso_filename := lib$(libname).$(major_version).dylib
30 endif
31 ifeq ($(uname_s),SunOS)
32         dso_opts := --shared -z text -z defs
33         dso_filename :=lib$(libname).so.$(major_version).$(minor_version).$(patchlevel_version)
34         CPPFLAGS += -I/opt/csw/include
35 endif
36 ifeq ($(uname_s),FreeBSD)
37         dso_opts := --shared -Wl,-soname,libosl.so.$(major_version)
38         dso_filename :=lib$(libname).so.$(major_version).$(minor_version).$(patchlevel_version)
39 endif
40 ifeq ($(uname_s),NetBSD)
41         dso_opts := --shared -Wl,-soname,libosl.so.$(major_version)
42         dso_filename :=lib$(libname).so.$(major_version).$(minor_version).$(patchlevel_version)
43 endif
44 all: $(dso_filename)
45
46 DEBUG_CPPFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
47 DEBUG_CPPFLAGS += -Wredundant-decls
48 CPPFLAGS += -Os
49 CPPFLAGS += -Wall
50 CPPFLAGS += -Wuninitialized
51 CPPFLAGS += -Wchar-subscripts
52 CPPFLAGS += -Wformat-security
53 CPPFLAGS += -Werror-implicit-function-declaration
54 CPPFLAGS += -Wmissing-format-attribute
55 CPPFLAGS += -Wunused-macros
56 CPPFLAGS += -Wbad-function-cast
57 CPPFLAGS += -fPIC
58 CPPFLAGS += -fvisibility=hidden
59
60 Makefile.deps: $(wildcard *.c *.h)
61         gcc -MM -MG *.c > $@
62
63 -include Makefile.deps
64
65 %.o: %.c Makefile
66         $(CC) -c $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
67 $(dso_filename): $(objects)
68         $(CC) $(dso_opts) -o $@ $(objects) $(LDFLAGS) -lcrypto
69
70 osl_errors.h: errlist
71         sed -e 's/\([A-Z_]*\)   .*/     E_OSL_\1/' \
72                 -e '1s/^/enum osl_errors {/1' \
73                 -e '$$!s/$$/,/g' \
74                 -e '$$s/$$/};/1' $< > $@
75
76 errtab.h: errlist
77         sed -e 's/^\([A-Z_]*\)\s*\(.*\)/_S(E_OSL_\1, \2)/g' $< > $@
78 osl.h: osl.h.in osl_errors.h
79         cat $^ > $@
80 clean:
81         rm -f *.o $(dso_filename) osl.h osl_errors.h errtab.h