Makefile.shlib 9.83 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.72 2003/10/20 01:34:33 tgl 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) -bundle
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
ifeq ($(PORTNAME), hpux)
129 130
  shlib			:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
  LINK.shared		= $(LD) +h $(soname) -b +b $(libdir)
131 132 133
  ifeq ($(GCC), yes)
    SHLIB_LINK		+= `$(CC) -print-libgcc-file-name`
  endif
134 135
endif

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

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

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

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

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

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

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

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

200
ifeq ($(PORTNAME), cygwin)
201
  shlib			:= $(NAME)$(DLSUFFIX)
202
endif
203

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

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

215 216
endif # enable_shared

217 218 219 220 221 222


##
## BUILD
##

223 224 225 226 227 228 229
.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)
230

231
ifneq ($(PORTNAME), cygwin)
232

233 234 235 236
ifndef LORDER
MK_NO_LORDER := true
endif

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

245
endif # not cygwin
246

247 248
ifeq ($(enable_shared), yes)

249
ifneq ($(PORTNAME), beos)
250
ifneq ($(PORTNAME), cygwin)
251
ifneq ($(PORTNAME), aix)
252

253
# Normal case
254
$(shlib): $(OBJS)
255
	$(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
256 257 258 259 260 261 262 263 264 265
# 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
266

267
else # PORTNAME == aix
268

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

276
else # PORTNAME == cygwin
277

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

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

287
endif # PORTNAME == cygwin
288 289 290 291 292 293 294 295 296

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
297 298

endif # enable_shared
299

300

301 302 303
##
## INSTALL
##
304

305 306
.PHONY: install-lib install-lib-static install-lib-shared
install-lib: install-lib-static install-lib-shared
307

308
install-lib-static: lib$(NAME).a
309
	$(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
310 311 312 313
ifeq ($(PORTNAME), darwin)
	cd $(DESTDIR)$(libdir) && \
	ranlib lib$(NAME).a
endif
314

315
ifeq ($(enable_shared), yes)
316
install-lib-shared: $(shlib)
317
	$(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
318
ifneq ($(PORTNAME), cygwin)
319
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
320
	cd $(DESTDIR)$(libdir) && \
321 322
	rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
	$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
323
endif
324
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
325
	cd $(DESTDIR)$(libdir) && \
326 327 328 329
	rm -f lib$(NAME)$(DLSUFFIX) && \
	$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
endif

330
endif # not cygwin
331
endif # enable_shared
332 333 334 335 336 337 338 339


##
## UNINSTALL
##

.PHONY: uninstall-lib
uninstall-lib:
340
	rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
341
ifeq ($(enable_shared), yes)
342 343 344
	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)
345
endif # enable_shared
346 347


348 349 350
##
## CLEAN
##
351

352 353 354
.PHONY: clean-lib
clean-lib:
	rm -f lib$(NAME).a
355
ifeq ($(enable_shared), yes)
356 357 358 359
	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
360
endif
361
ifeq ($(PORTNAME), cygwin)
362
	rm -f $(NAME).dll $(NAME).def
Bruce Momjian's avatar
Hi,  
Bruce Momjian committed
363
endif