]> granicus.if.org Git - postgresql/blob - src/Makefile.shlib
Portability fixes found needed for SunOS 4.1.x:
[postgresql] / src / Makefile.shlib
1 #-------------------------------------------------------------------------
2 #
3 # Makefile.shlib
4 #    Common rules for building shared libraries
5 #
6 # Copyright (c) 1998, Regents of the University of California
7 #
8 # IDENTIFICATION
9 #    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.5 1998/11/30 00:30:03 tgl Exp $
10 #
11 #-------------------------------------------------------------------------
12
13 # This file should be included by any Postgres module Makefile that wants
14 # to build a shared library (if possible for the current platform).
15 # A static library is also built from the same object files.
16 # RESTRICTION: only one library can be built per makefile...
17
18 # Before including this file, the module Makefile must define these variables:
19 # NAME                          Name of library to build (no suffix nor "lib" prefix)
20 # SO_MAJOR_VERSION      Major version number to use for shared library
21 # SO_MINOR_VERSION      Minor version number to use for shared library
22 # OBJS                          List of object files to include in library
23 # SHLIB_LINK            If shared library relies on other libraries, additional
24 #                                       stuff to put in its link command
25 # (If you want a patchlevel, include it in SO_MINOR_VERSION, eg, "6.2".)
26 #
27 # The module Makefile must also include $(SRCDIR)/Makefile.global before
28 # including this file (Makefile.global sets PORTNAME and other needed symbols).
29 #
30 # The first rule in this file is a rule for "all", which causes both the
31 # static and shared libraries to be built (as well as all the object files).
32 # If you have other files that need to be made before building object files
33 # and libraries, put another rule for "all" before you include this file.
34 #
35 # Your install rule should look like
36 #
37 #       install: install-headers install-lib $(install-shlib-dep)
38 #
39 # where install-headers is only needed if you have header files to install
40 # (and, of course, it has to be provided by your makefile).  The rules
41 # install-lib and install-shlib are provided by this makefile --- they
42 # automatically install the plain and shared libraries into $(LIBDIR).
43 # install-shlib-dep is a variable that expands to install-shlib if the
44 # shared library needs to be installed, empty if not.
45 #
46 # Got that?  Look at src/interfaces/libpq/Makefile.in for an example.
47
48
49 # shlib and install-shlib-dep default to empty, and stay that way if we're
50 # on a platform where we don't know how to build a shared library.
51 shlib := 
52 install-shlib-dep :=
53
54 # For each platform we support shlibs on, set shlib and install-shlib-dep,
55 # and update flags as needed to build a shared lib.  Note we depend on
56 # Makefile.global (or really Makefile.port) to supply DLSUFFIX and other
57 # symbols.
58
59 ifeq ($(PORTNAME), freebsd)
60   ifdef BSD_SHLIB
61     install-shlib-dep   := install-shlib
62     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
63     ifdef ELF_SYSTEM
64       LDFLAGS_SL        := -x -Bshareable
65     else
66       LDFLAGS_SL        := -x -Bshareable -Bforcearchive
67     endif
68     CFLAGS              += $(CFLAGS_SL)
69   endif
70 endif
71
72 ifeq ($(PORTNAME), bsd)
73   ifdef BSD_SHLIB
74     install-shlib-dep   := install-shlib
75     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
76     LDFLAGS_SL          := -x -Bshareable -Bforcearchive
77     CFLAGS              += $(CFLAGS_SL)
78   endif
79 endif
80
81 ifeq ($(PORTNAME), bsdi)
82   ifdef BSD_SHLIB
83     ifeq ($(DLSUFFIX), .so)
84       install-shlib-dep := install-shlib
85       shlib                             := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
86       LDFLAGS_SL                += -shared
87       CFLAGS                    += $(CFLAGS_SL)
88     endif
89     ifeq ($(DLSUFFIX), .o)
90       install-shlib-dep := install-shlib
91       shlib                             := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
92       LD                                := shlicc
93       LDFLAGS_SL                += -O -r
94       CFLAGS                    += $(CFLAGS_SL)
95     endif
96   endif
97 endif
98
99 ifeq ($(PORTNAME), hpux)
100   install-shlib-dep     := install-shlib
101 # HPUX doesn't believe in version numbers for shlibs
102   shlib                         := lib$(NAME)$(DLSUFFIX)
103   LDFLAGS_SL            := -b
104   CFLAGS                        += $(CFLAGS_SL)
105 endif
106
107 ifeq ($(PORTNAME), linux)
108   install-shlib-dep     := install-shlib
109   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
110   LDFLAGS_SL            := -Bdynamic -shared -soname $(shlib)
111   LDFLAGS_ODBC          := -Bsymbolic -lc -lm
112   SHLIB_LINK            += -lc
113   CFLAGS                        += $(CFLAGS_SL)
114 endif
115
116 ifeq ($(PORTNAME), solaris_i386)
117   install-shlib-dep     := install-shlib
118   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
119   LDFLAGS_SL            := -G
120   CFLAGS                        += $(CFLAGS_SL)
121 endif
122
123 ifeq ($(PORTNAME), solaris_sparc)
124   install-shlib-dep     := install-shlib
125   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
126   LDFLAGS_SL            := -G
127   CFLAGS                        += $(CFLAGS_SL)
128 endif
129
130 ifeq ($(PORTNAME), svr4)
131   install-shlib-dep     := install-shlib
132   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
133   LDFLAGS_SL            := -G
134   CFLAGS                        += $(CFLAGS_SL)
135 endif
136
137 ifeq ($(PORTNAME), univel)
138   install-shlib-dep     := install-shlib
139   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
140   LDFLAGS_SL            := -G -z text
141   CFLAGS                        += $(CFLAGS_SL)
142   ifeq ($(CXX), CC)
143     CXXFLAGS += -Xw
144     COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
145   endif
146 endif
147
148 ifeq ($(PORTNAME), unixware)
149   install-shlib-dep     := install-shlib
150   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
151   LDFLAGS_SL            := -G -z text
152   CFLAGS                        += $(CFLAGS_SL)
153   ifeq ($(CXX), CC)
154     CXXFLAGS += -Xw
155     COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
156   endif
157 endif
158
159
160 # Default target definition.  Note shlib is empty if not building a shlib.
161
162 all: lib$(NAME).a $(shlib)
163
164 # Rules to build regular and shared libraries
165
166 lib$(NAME).a: $(OBJS)
167 ifdef MK_NO_LORDER
168         $(AR) $(AROPT) $@ $(OBJS) 
169 else
170         $(AR) $(AROPT) $@ `lorder $(OBJS) | tsort`
171 endif
172         $(RANLIB) $@
173
174 ifneq ($(shlib),)
175 $(shlib): $(OBJS)
176         $(LD) $(LDFLAGS_SL) -o $@ $(OBJS) $(SHLIB_LINK)
177 endif
178
179 # Rules to install regular and shared libraries
180
181 .PHONY: all install-lib install-shlib
182
183 install-lib: lib$(NAME).a
184         $(INSTALL) $(INSTL_LIB_OPTS) lib$(NAME).a $(LIBDIR)/lib$(NAME).a
185
186 install-shlib: $(shlib)
187         $(INSTALL) $(INSTL_SHLIB_OPTS) $(shlib) $(LIBDIR)/$(shlib)
188         if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)" ]; then \
189                 cd $(LIBDIR); \
190                 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
191                 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
192         fi
193         if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX)" ]; then \
194                 cd $(LIBDIR); \
195                 rm -f lib$(NAME)$(DLSUFFIX); \
196                 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX); \
197         fi