38af988b70655f2c48c866c7d36d013b5fa436af
[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 endif
15 ifeq ($(uname_s),Darwin)
16         mac_major_version := $(shell expr 41 + $(major_version))
17         dso_opts := -dynamiclib -current_version $(major_version).$(minor_version) \
18                 -compatibility_version $(major_version).$(minor_version) -fvisibility=hidden
19         dso_filename := lib$(libname).$(shell printf "\\x"$(mac_major_version).dylib)
20 endif
21 ifeq ($(uname_s),SunOS)
22         dso_opts := --shared -z text -z defs
23         dso_filename :=lib$(libname).so.$(major_version).$(minor_version).$(patchlevel_version)
24         CPPFLAGS += -I/opt/csw/include
25 endif
26 ifeq ($(uname_s),FreeBSD)
27         dso_opts := --shared -Wl,-soname,libosl.so.$(major_version)
28         dso_filename :=lib$(libname).so.$(major_version).$(minor_version).$(patchlevel_version)
29 endif
30 ifeq ($(uname_s),NetBSD)
31         dso_opts := --shared -Wl,-soname,libosl.so.$(major_version)
32         dso_filename :=lib$(libname).so.$(major_version).$(minor_version).$(patchlevel_version)
33 endif
34 all: $(dso_filename)
35
36 # disallow undefined symbols
37 LDFLAGS += -Wl,-z,defs
38
39 DEBUG_CPPFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
40 DEBUG_CPPFLAGS += -Wredundant-decls
41 #CPPFLAGS += -Os
42 CPPFLAGS += -Wall
43 #CPPFLAGS += -Wuninitialized
44 CPPFLAGS += -Wchar-subscripts
45 CPPFLAGS += -Wformat-security
46 CPPFLAGS += -Werror-implicit-function-declaration
47 CPPFLAGS += -Wmissing-format-attribute
48 CPPFLAGS += -Wunused-macros
49 CPPFLAGS += -Wbad-function-cast
50 CPPFLAGS += -fPIC
51 CPPFLAGS += -fvisibility=hidden
52
53 Makefile.deps: $(wildcard *.c *.h)
54         gcc -MM -MG *.c > $@
55
56 -include Makefile.deps
57
58 %.o: %.c Makefile
59         $(CC) -c $(CPPFLAGS) $(DEBUG_CPPFLAGS) $<
60 $(dso_filename): $(objects)
61         $(CC) $(dso_opts) -o $@ $(objects) $(LDFLAGS) -lcrypto
62
63 osl_errors.h: errlist
64         sed -e 's/\([A-Z_]*\)   .*/     E_OSL_\1/' \
65                 -e '1s/^/enum osl_errors {\n/1' \
66                 -e '$$!s/$$/,/g' \
67                 -e '$$s/$$/\n};/1' $< > $@
68
69 errtab.h: errlist
70         sed -e 's/^\([A-Z_]*\)\s*\(.*\)/_S(E_OSL_\1, \2)/g' $< > $@
71 osl.h: osl.h.in osl_errors.h
72         cat $^ > $@
73 clean:
74         rm -f *.o $(dso_filename) osl.h osl_errors.h errtab.h