Makefile.shlib 9.71 KB
Newer Older
1 2 3 4 5 6 7 8
#-------------------------------------------------------------------------
#
# Makefile.shlib
#    Common rules for building shared libraries
#
# Copyright (c) 1998, Regents of the University of California
#
# IDENTIFICATION
9
#    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.65 2002/10/09 16:21:54 momjian Exp $
10 11 12
#
#-------------------------------------------------------------------------

13 14 15 16
# This file should be included by any Postgres module Makefile that
# wants to build a shared library (if possible for the current
# platform). A static library is also built from the same object
# files. Only one library can be built per makefile.
17
#
18 19
# Before including this file, the module Makefile must define these
# variables:
20
#
21 22 23 24 25 26 27
# NAME                  Name of library to build (no suffix nor "lib" prefix)
# SO_MAJOR_VERSION      Major version number to use for shared library
# SO_MINOR_VERSION      Minor version number to use for shared library
# OBJS                  List of object files to include in library
# SHLIB_LINK            If shared library relies on other libraries,
#                       additional stuff to put in its link command
# (If you want a patchlevel, include it in SO_MINOR_VERSION, e.g., "6.2".)
28
#
29 30 31
# The module Makefile must also include
# $(top_builddir)/src/Makefile.global before including this file.
# (Makefile.global sets PORTNAME and other needed symbols.)
32
#
33
# This makefile provides the following (phony) targets:
34
#
35 36 37 38
# all-lib               build the static and shared (if applicable) libraries
# install-lib           install the libraries into $(libdir)
# uninstall-lib         remove the libraries from $(libdir)
# clean-lib             delete the static and shared libraries from the build dir
39
#
40 41 42 43 44 45 46 47 48 49 50 51 52
# Since `all-lib' is the first rule in this file you probably want to
# have the `all' target before including this file. In the most simple
# case it would look like this:
#
#     all: all-lib
#
# Similarly, the install rule might look like
#
#     install: install-lib
#
# plus any additional things you want to install. Et cetera.
#
# Got that?  Look at src/interfaces/libpq/Makefile for an example.
Bruce Momjian's avatar
Bruce Momjian committed
53 54 55 56 57 58 59
#
# While the linker allows creation of most shared libraries,
# -Bsymbolic requires resolution of all symbols, making the
# compiler a better choice for shared library creation on ELF platforms.
# With the linker, -Bsymbolic requires the crt1.o startup object file.
# bjm 2001-02-10

60

61
COMPILER = $(CC) $(CFLAGS)
62 63 64 65 66 67 68 69 70
LINK.static = $(AR) $(AROPT)



ifeq ($(enable_shared), yes)

# For each platform we support shared libraries on, set shlib to the
# name of the library, LINK.shared to the command to link the library,
# and adjust SHLIB_LINK if necessary.
71

72
# Try to keep the sections in some kind of order, folks...
73

74
override CFLAGS += $(CFLAGS_SL)
75

76
soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
77

78
ifeq ($(PORTNAME), aix)
79
  shlib			:= lib$(NAME)$(DLSUFFIX)
80
#   SHLIB_LINK		+= -lc
81 82
endif

83 84
ifeq ($(PORTNAME), darwin)
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
85
  LINK.shared		= $(COMPILER) $(DARWIN_NAMESPACE_SPEC) -bundle -undefined suppress
86 87
endif

88
ifeq ($(PORTNAME), openbsd)
89 90
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
  ifdef ELF_SYSTEM
91 92
    LINK.shared		= $(COMPILER) -shared -Wl,-x,-soname,$(soname)
    SHLIB_LINK		+= -lc
93 94
  else
    LINK.shared		= $(LD) -x -Bshareable -Bforcearchive
95 96 97 98
  endif
endif

ifeq ($(PORTNAME), bsdi)
99 100
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
  ifeq ($(DLSUFFIX), .so)
101
    LINK.shared		= $(COMPILER) -shared -Wl,-x,-soname,$(soname)
102
    SHLIB_LINK		+= -lc
103 104 105
  endif
  ifeq ($(DLSUFFIX), .o)
    LINK.shared		= shlicc -O $(LDREL)
106 107 108
  endif
endif

109
ifeq ($(PORTNAME), freebsd)
110 111
  ifdef ELF_SYSTEM
    shlib		:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
112
    LINK.shared		= $(COMPILER) -shared -Wl,-x,-soname,$(soname)
113 114 115
  else
    shlib		:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
    LINK.shared		= $(LD) -x -Bshareable -Bforcearchive
116 117 118
  endif
endif

119
ifeq ($(PORTNAME), netbsd)
120 121
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
  ifdef ELF_SYSTEM
122
    LINK.shared		= $(COMPILER) -shared -Wl,-x,-soname,$(soname)
123 124
  else
    LINK.shared		= $(LD) -x -Bshareable -Bforcearchive
125 126 127
  endif
endif

128 129
ifeq ($(PORTNAME), hpux)
# HPUX doesn't believe in version numbers for shlibs
130
  shlib			:= lib$(NAME)$(DLSUFFIX)
131
  LINK.shared		= $(LD) -b +b $(libdir)
132 133
endif

134
ifeq ($(PORTNAME), irix5)
135
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
136
  LINK.shared		= $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
137 138
endif

139
ifeq ($(PORTNAME), linux)
140
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
141
  LINK.shared		= $(COMPILER) -shared -Wl,-soname,$(soname)
142 143
endif

144
ifeq ($(PORTNAME), solaris)
145
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
146 147
  ifeq ($(GCC), yes)
    LINK.shared		= $(CC) -shared
148
  else
149
    LINK.shared		= $(CC) -G
150
  endif
151
  ifeq ($(with_gnu_ld), yes)
Bruce Momjian's avatar
Bruce Momjian committed
152
    LINK.shared		+= -Wl,-soname,$(soname)
153
  else
154
    LINK.shared		+= -h $(soname)
155
  endif
156 157
endif

158 159 160 161 162
ifeq ($(PORTNAME), sunos4)
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
  LINK.shared		= $(LD) -assert pure-text -Bdynamic
endif
 
163
ifeq ($(PORTNAME), osf)
Bruce Momjian's avatar
Bruce Momjian committed
164
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
165
  LINK.shared		= $(LD) -shared -expect_unresolved '*'
Bruce Momjian's avatar
Bruce Momjian committed
166 167
endif

168 169
ifeq ($(PORTNAME), sco)
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
170 171
  ifeq ($(GCC), yes)
    LINK.shared		= $(CC) -shared
172
  else
173
    LINK.shared		= $(CC) -G
174 175 176 177
    endif
  LINK.shared		+= -Wl,-z,text -Wl,-h,$(soname)
endif

178
ifeq ($(PORTNAME), svr4)
179
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
180
  LINK.shared		= $(LD) -G
181 182 183
endif

ifeq ($(PORTNAME), univel)
184
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
185
  LINK.shared		= $(LD) -G -z text
186 187 188
endif

ifeq ($(PORTNAME), unixware)
189
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
190 191
  ifeq ($(GCC), yes)
    LINK.shared		= $(CC) -shared
192
  else
193
    LINK.shared		= $(CC) -G
194
  endif
195
  LINK.shared		+= -Wl,-z,text -Wl,-h,$(soname)
196 197
endif

198
ifeq ($(PORTNAME), win)
199
  shlib			:= $(NAME)$(DLSUFFIX)
200
endif
201

202
ifeq ($(PORTNAME), beos)
203 204 205
  shlib			:= lib$(NAME)$(DLSUFFIX)
  LINK.shared		= $(LD) -nostart
  SHLIB_LINK		+= -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
206
endif
207

208
SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
209 210 211 212
ifeq ($(enable_rpath), yes)
SHLIB_LINK += $(rpath)
endif

213 214
endif # enable_shared

215 216 217 218 219 220


##
## BUILD
##

221 222 223 224 225 226 227
.PHONY: all-lib all-static-lib all-shared-lib

all-lib: all-static-lib all-shared-lib

all-static-lib: lib$(NAME).a

all-shared-lib: $(shlib)
228

229
ifneq ($(PORTNAME), win)
230

231 232 233 234
ifndef LORDER
MK_NO_LORDER := true
endif

235 236
lib$(NAME).a: $(OBJS)
ifdef MK_NO_LORDER
237
	$(LINK.static) $@ $^
238
else
239
	$(LINK.static) $@ `$(LORDER) $^ | tsort`
240 241
endif
	$(RANLIB) $@
242

243
endif # not win
244

245 246
ifeq ($(enable_shared), yes)

247
ifneq ($(PORTNAME), beos)
248
ifneq ($(PORTNAME), win)
249
ifneq ($(PORTNAME), aix)
250

251
# Normal case
252
$(shlib): $(OBJS)
253
	$(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
254 255 256 257 258 259 260 261 262 263
# If we're using major and minor versions, then make a symlink to major-version-only.
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
	rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
	$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
endif
# Make sure we have a link to a name without any version numbers
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
	rm -f lib$(NAME)$(DLSUFFIX)
	$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
endif
264

265
else # PORTNAME == aix
266

267 268
# AIX case
$(shlib): lib$(NAME).a
269
	$(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
270 271
	$(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
	
272
endif # PORTNAME == aix
273

274
else # PORTNAME == win
275 276

# WIN case
277
$(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
278
	$(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
279
	$(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(DLLINIT) $(SHLIB_LINK)
280 281
	$(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a

282
$(DLLINIT): $(DLLINIT:%.o=%.c)
283
	$(MAKE) -C $(@D) $(@F)
284 285

endif # PORTNAME == win
286 287 288 289 290 291 292 293 294

else # PORTNAME == beos

# BEOS case
$(shlib): $(OBJS)
	ln -fs $(top_srcdir)/src/backend/postgres _APP_
	$(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)

endif # PORTNAME == beos
295 296

endif # enable_shared
297

298

299 300 301
##
## INSTALL
##
302

303 304
.PHONY: install-lib install-lib-static install-lib-shared
install-lib: install-lib-static install-lib-shared
305

306
install-lib-static: lib$(NAME).a
307
	$(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
308

309
ifeq ($(enable_shared), yes)
310
install-lib-shared: $(shlib)
311
	$(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
312
ifneq ($(PORTNAME), win)
313
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
314
	cd $(DESTDIR)$(libdir) && \
315 316
	rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
	$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
317
endif
318
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
319
	cd $(DESTDIR)$(libdir) && \
320 321 322 323 324
	rm -f lib$(NAME)$(DLSUFFIX) && \
	$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
endif

endif # not win
325
endif # enable_shared
326 327 328 329 330 331 332 333


##
## UNINSTALL
##

.PHONY: uninstall-lib
uninstall-lib:
334
	rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
335
ifeq ($(enable_shared), yes)
336 337 338
	rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
	  $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
	  $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
339
endif # enable_shared
340 341


342 343 344
##
## CLEAN
##
345

346 347 348
.PHONY: clean-lib
clean-lib:
	rm -f lib$(NAME).a
349
ifeq ($(enable_shared), yes)
350 351 352 353
	rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
ifdef EXPSUFF
	rm -f lib$(NAME)$(EXPSUFF)
endif
354
endif
Bruce Momjian's avatar
Hi,  
Bruce Momjian committed
355
ifeq ($(PORTNAME), win)
356
	rm -f $(NAME).dll $(NAME).def
Bruce Momjian's avatar
Hi,  
Bruce Momjian committed
357
endif