postgresql/src/Makefile.shlib

416 lines
11 KiB
Makefile
Raw Normal View History

#-------------------------------------------------------------------------
#
# Makefile.shlib
# Common rules for building shared libraries
#
# Copyright (c) 1998, Regents of the University of California
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.62 2002/09/04 15:45:50 tgl Exp $
#
#-------------------------------------------------------------------------
# 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.
#
# Before including this file, the module Makefile must define these
# variables:
#
# 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".)
#
# The module Makefile must also include
# $(top_builddir)/src/Makefile.global before including this file.
# (Makefile.global sets PORTNAME and other needed symbols.)
#
# This makefile provides the following (phony) targets:
#
# 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
#
# 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.
2001-02-10 19:46:34 +01:00
#
# 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
ifndef cplusplus
COMPILER = $(CC) $(CFLAGS)
else
COMPILER = $(CXX) $(CXXFLAGS)
endif
# First, a few hacks for building *static* libraries.
LINK.static = $(AR) $(AROPT)
ifdef cplusplus
ifeq ($(PORTNAME), irix5)
ifneq ($(GXX), yes)
LINK.static = $(CXX) -ar -o
endif
endif
ifeq ($(PORTNAME), solaris)
ifneq ($(GXX), yes)
LINK.static = $(CXX) -xar -o
endif
endif
endif # cplusplus
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.
# Try to keep the sections in some kind of order, folks...
1999-07-08 02:15:03 +02:00
ifndef cplusplus
override CFLAGS += $(CFLAGS_SL)
else
ifndef CXXFLAGS_SL
CXXFLAGS_SL = $(CFLAGS_SL)
endif
override CXXFLAGS += $(CXXFLAGS_SL)
endif
soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
ifeq ($(PORTNAME), aix)
shlib := lib$(NAME)$(DLSUFFIX)
SHLIB_LINK += -lc
endif
ifeq ($(PORTNAME), darwin)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
2001-10-05 23:15:38 +02:00
LINK.shared = $(COMPILER) $(DARWIN_NAMESPACE_SPEC) -bundle -undefined suppress
endif
ifeq ($(PORTNAME), openbsd)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
ifdef ELF_SYSTEM
LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
SHLIB_LINK += -lc
else
LINK.shared = $(LD) -x -Bshareable -Bforcearchive
endif
endif
ifeq ($(PORTNAME), bsdi)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
ifeq ($(DLSUFFIX), .so)
LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
2001-02-10 17:51:40 +01:00
SHLIB_LINK += -lc
endif
ifeq ($(DLSUFFIX), .o)
LINK.shared = shlicc -O $(LDREL)
endif
endif
ifeq ($(PORTNAME), freebsd)
ifdef ELF_SYSTEM
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
else
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
LINK.shared = $(LD) -x -Bshareable -Bforcearchive
endif
endif
ifeq ($(PORTNAME), netbsd)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
ifdef ELF_SYSTEM
LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
else
LINK.shared = $(LD) -x -Bshareable -Bforcearchive
endif
endif
ifeq ($(PORTNAME), hpux)
# HPUX doesn't believe in version numbers for shlibs
shlib := lib$(NAME)$(DLSUFFIX)
LINK.shared = $(LD) -b +b $(libdir)
endif
ifeq ($(PORTNAME), irix5)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
LINK.shared = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
endif
ifeq ($(PORTNAME), linux)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
endif
ifeq ($(PORTNAME), solaris)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
ifndef cplusplus
ifeq ($(GCC), yes)
LINK.shared = $(CC) -shared
else
LINK.shared = $(CC) -G
endif
else
ifeq ($(GXX), yes)
LINK.shared = $(CXX) -shared
else
LINK.shared = $(CXX) -G
endif
endif
ifeq ($(with_gnu_ld), yes)
2001-02-10 17:26:38 +01:00
LINK.shared += -Wl,-soname,$(soname)
else
LINK.shared += -h $(soname)
endif
endif
2001-02-27 09:13:31 +01:00
ifeq ($(PORTNAME), sunos4)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
LINK.shared = $(LD) -assert pure-text -Bdynamic
endif
ifeq ($(PORTNAME), osf)
1999-05-19 20:04:51 +02:00
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
LINK.shared = $(LD) -shared -expect_unresolved '*'
1999-05-19 20:04:51 +02:00
endif
ifeq ($(PORTNAME), sco)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
ifndef cplusplus
ifeq ($(GCC), yes)
LINK.shared = $(CC) -shared
else
LINK.shared = $(CC) -G
endif
else
ifeq ($(GXX), yes)
LINK.shared = $(CXX) -shared
else
LINK.shared = $(CXX) -G
endif
endif
LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
endif
ifeq ($(PORTNAME), svr4)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
LINK.shared = $(LD) -G
endif
ifeq ($(PORTNAME), univel)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
LINK.shared = $(LD) -G -z text
endif
ifeq ($(PORTNAME), unixware)
shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
ifndef cplusplus
ifeq ($(GCC), yes)
LINK.shared = $(CC) -shared
else
LINK.shared = $(CC) -G
endif
else
ifeq ($(GXX), yes)
LINK.shared = $(CXX) -shared
else
LINK.shared = $(CXX) -G
endif
endif
LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
endif
1999-01-17 07:20:06 +01:00
ifeq ($(PORTNAME), win)
shlib := $(NAME)$(DLSUFFIX)
ifdef cplusplus
SHLIB_LINK += --driver-name g++
endif
1999-01-17 07:20:06 +01:00
endif
ifeq ($(PORTNAME), beos)
shlib := lib$(NAME)$(DLSUFFIX)
LINK.shared = $(LD) -nostart
SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
endif
SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
ifeq ($(enable_rpath), yes)
SHLIB_LINK += $(rpath)
endif
endif # enable_shared
##
## BUILD
##
.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)
1999-01-17 07:20:06 +01:00
ifneq ($(PORTNAME), win)
ifndef LORDER
MK_NO_LORDER := true
endif
lib$(NAME).a: $(OBJS)
ifdef MK_NO_LORDER
$(LINK.static) $@ $^
else
$(LINK.static) $@ `$(LORDER) $^ | tsort`
endif
$(RANLIB) $@
endif # not win
ifeq ($(enable_shared), yes)
ifneq ($(PORTNAME), beos)
1999-01-17 07:20:06 +01:00
ifneq ($(PORTNAME), win)
ifneq ($(PORTNAME), aix)
# Normal case
$(shlib): $(OBJS)
$(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
# 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
else # PORTNAME == aix
# AIX case
$(shlib): lib$(NAME).a
$(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
$(COMPILER) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) $(LDFLAGS_SL) -Wl,-bnoentry
endif # PORTNAME == aix
else # PORTNAME == win
# WIN case
$(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
1999-01-17 07:20:06 +01:00
$(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
$(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(DLLINIT) $(DLLLIBS) $(SHLIB_LINK)
1999-01-17 07:20:06 +01:00
$(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
$(DLLINIT): $(DLLINIT:%.o=%.c)
$(MAKE) -C $(@D) $(@F)
endif # PORTNAME == win
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
endif # enable_shared
##
## INSTALL
##
.PHONY: install-lib install-lib-static install-lib-shared
install-lib: install-lib-static install-lib-shared
install-lib-static: lib$(NAME).a
2002-04-10 18:45:25 +02:00
$(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
ifeq ($(enable_shared), yes)
install-lib-shared: $(shlib)
$(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
1999-01-17 07:20:06 +01:00
ifneq ($(PORTNAME), win)
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
cd $(DESTDIR)$(libdir) && \
rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
1999-01-17 07:20:06 +01:00
endif
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
cd $(DESTDIR)$(libdir) && \
rm -f lib$(NAME)$(DLSUFFIX) && \
$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
endif
endif # not win
endif # enable_shared
##
## UNINSTALL
##
.PHONY: uninstall-lib
uninstall-lib:
rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
ifeq ($(enable_shared), yes)
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)
endif # enable_shared
##
## CLEAN
##
.PHONY: clean-lib
clean-lib:
rm -f lib$(NAME).a
ifeq ($(enable_shared), yes)
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
endif
ifeq ($(PORTNAME), win)
rm -rf $(NAME).def
endif