Do not specify LDLAGS twice.
[osl.git] / Makefile
1 # where to install
2 prefix := /usr/local
3 libdir := $(prefix)/lib
4 includedir := $(prefix)/include
5
6 objects := osl.o fd.o rbtree.o sha1.o
7 headers := osl.h
8
9 INSTALL := install
10 CC := gcc
11 MKDIR := mkdir -p
12 RM := rm -f
13 LN := ln
14
15 # libosl's versioning consists of three numbers. Let's call them x, y and z.
16 # The way x, y and z are interpreted depends on the OS.
17 x := 0
18 y := 1
19 z := 0
20
21 # common flags
22 CFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
23 CFLAGS += -Wredundant-decls
24 CFLAGS += -Os
25 CFLAGS += -Wall
26 CFLAGS += -Wuninitialized
27 CFLAGS += -Wchar-subscripts
28 CFLAGS += -Wformat-security
29 CFLAGS += -Werror-implicit-function-declaration
30 CFLAGS += -Wmissing-format-attribute
31 CFLAGS += -Wunused-macros
32 CFLAGS += -Wbad-function-cast
33 CFLAGS += -fPIC
34 CFLAGS += -fvisibility=hidden
35
36 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
37 uname_rs := $(shell uname -rs)
38
39 libname := osl
40 ifeq ($(uname_s),Linux)
41 # On Linux, the following conventions apply (see dhweeler's Program
42 # Library HOWTO):
43 #
44 # The soname has the prefix ``lib'', the name of the library, the
45 # phrase ``.so'', followed by a period and a version number that is
46 # incremented whenever the interface changes.
47 soname := lib$(libname).so.$(x)
48
49 # The real name adds to the soname a period, a minor number, another
50 # period, and the release number.
51 realname := $(soname).$(y).$(z)
52
53 # In addition, there's the name that the compiler uses when requesting
54 # a library, (I'll call it the ``linker name''), which is simply the
55 # soname without any version number.
56 linkername := lib$(libname).so
57
58 LDFLAGS += --shared
59 LDFLAGS += -Wl,-soname,$(soname)
60 # disallow undefined symbols
61 LDFLAGS += -Wl,-z,defs
62 endif
63 ifeq ($(uname_s),Darwin)
64 # Darwin has its own idea on version numbers:
65 #
66 realname := lib$(libname).$(x).dylib
67 soname := $(realname)
68 linkername := lib$(libname).so
69 # The minor version number is an incremental number using the format
70 # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
71 # the gcc -current_version option.
72 LDFLAGS += -current_version $(y).$(z)
73 #
74 # The compatibility version number of a library release specifies the
75 # earliest minor version of the clients linked against that release can
76 # use.
77 LDFLAGS += -compatibility_version $(y).0
78 LDFLAGS += -dynamiclib
79 endif
80 ifeq ($(uname_s),SunOS)
81 # Solaris needs another set of flags
82 LDFLAGS += --shared
83 LDFLAGS += -z text
84 LDFLAGS += -z defs
85 realname := lib$(libname).so.$(major_version).$(minor_version).$(patchlevel_version)
86 CPPFLAGS += -I/opt/csw/include
87 endif
88
89 all: $(realname)
90
91 Makefile.deps: $(wildcard *.c *.h)
92 $(CC) -MM -MG *.c > $@
93
94 -include Makefile.deps
95
96 %.o: %.c Makefile
97 $(CC) -c $(CPPFLAGS) $(CFLAGS) $<
98
99 $(realname): $(objects)
100 $(CC) $(LDFLAGS) -o $@ $(objects) -lcrypto
101
102 osl_errors.h: errlist
103 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
104 -e '1s/^/enum osl_errors {/1' \
105 -e '$$!s/$$/,/g' \
106 -e '$$s/$$/};/1' $< > $@
107
108 errtab.h: errlist
109 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/_S(E_OSL_\1, \2)/g' $< > $@
110
111 osl.h: osl.h.in osl_errors.h
112 cat $^ > $@
113 clean:
114 rm -f *.o $(realname) osl.h osl_errors.h errtab.h
115
116 install: all
117 $(MKDIR) $(libdir) $(includedir)
118 $(RM) $(libdir)/$(linkername)
119 $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
120 $(INSTALL) -s -m 755 $(realname) $(libdir)
121 $(INSTALL) -m 644 $(headers) $(includedir)
122
123 .PHONY: all clean install