|
| 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.1 1998/10/19 00:00:40 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), bsd) |
| 60 | + ifdef BSD_SHLIB |
| 61 | + install-shlib-dep := install-shlib |
| 62 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 63 | + LDFLAGS_SL := -x -Bshareable -Bforcearchive |
| 64 | + CFLAGS += $(CFLAGS_SL) |
| 65 | + endif |
| 66 | +endif |
| 67 | + |
| 68 | +ifeq ($(PORTNAME), bsdi) |
| 69 | + ifdef BSD_SHLIB |
| 70 | + ifeq ($(DLSUFFIX), .so) |
| 71 | + install-shlib-dep := install-shlib |
| 72 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 73 | + LDFLAGS_SL += -shared |
| 74 | + CFLAGS += $(CFLAGS_SL) |
| 75 | + endif |
| 76 | + ifeq ($(DLSUFFIX), .o) |
| 77 | + install-shlib-dep := install-shlib |
| 78 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 79 | + LD := shlicc |
| 80 | + LDFLAGS_SL += -O -r |
| 81 | + CFLAGS += $(CFLAGS_SL) |
| 82 | + endif |
| 83 | + endif |
| 84 | +endif |
| 85 | + |
| 86 | +ifeq ($(PORTNAME), hpux) |
| 87 | + install-shlib-dep := install-shlib |
| 88 | +# HPUX doesn't believe in version numbers for shlibs |
| 89 | + shlib := lib$(NAME)$(DLSUFFIX) |
| 90 | + LDFLAGS_SL := -b |
| 91 | + CFLAGS += $(CFLAGS_SL) |
| 92 | +endif |
| 93 | + |
| 94 | +ifeq ($(PORTNAME), linux) |
| 95 | + install-shlib-dep := install-shlib |
| 96 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 97 | + LDFLAGS_SL := -shared -soname $(shlib) |
| 98 | + CFLAGS += $(CFLAGS_SL) |
| 99 | +endif |
| 100 | + |
| 101 | +ifeq ($(PORTNAME), solaris_i386) |
| 102 | + install-shlib-dep := install-shlib |
| 103 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 104 | + LDFLAGS_SL := -G |
| 105 | + CFLAGS += $(CFLAGS_SL) |
| 106 | +endif |
| 107 | + |
| 108 | +ifeq ($(PORTNAME), solaris_sparc) |
| 109 | + install-shlib-dep := install-shlib |
| 110 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 111 | + LDFLAGS_SL := -G |
| 112 | + CFLAGS += $(CFLAGS_SL) |
| 113 | +endif |
| 114 | + |
| 115 | +ifeq ($(PORTNAME), svr4) |
| 116 | + install-shlib-dep := install-shlib |
| 117 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 118 | + LDFLAGS_SL := -G |
| 119 | + CFLAGS += $(CFLAGS_SL) |
| 120 | +endif |
| 121 | + |
| 122 | +ifeq ($(PORTNAME), univel) |
| 123 | + install-shlib-dep := install-shlib |
| 124 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 125 | + LDFLAGS_SL := -G -z text |
| 126 | + CFLAGS += $(CFLAGS_SL) |
| 127 | + ifeq ($(CXX), CC) |
| 128 | + CXXFLAGS += -Xw |
| 129 | + COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c |
| 130 | + endif |
| 131 | +endif |
| 132 | + |
| 133 | +ifeq ($(PORTNAME), unixware) |
| 134 | + install-shlib-dep := install-shlib |
| 135 | + shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) |
| 136 | + LDFLAGS_SL := -G -z text |
| 137 | + CFLAGS += $(CFLAGS_SL) |
| 138 | + ifeq ($(CXX), CC) |
| 139 | + CXXFLAGS += -Xw |
| 140 | + COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c |
| 141 | + endif |
| 142 | +endif |
| 143 | + |
| 144 | + |
| 145 | +# Default target definition. Note shlib is empty if not building a shlib. |
| 146 | + |
| 147 | +all: lib$(NAME).a $(shlib) |
| 148 | + |
| 149 | +# Rules to build regular and shared libraries |
| 150 | + |
| 151 | +lib$(NAME).a: $(OBJS) |
| 152 | +ifdef MK_NO_LORDER |
| 153 | + $(AR) $(AROPT) $@ $(OBJS) |
| 154 | +else |
| 155 | + $(AR) $(AROPT) $@ `lorder $(OBJS) | tsort` |
| 156 | +endif |
| 157 | + $(RANLIB) $@ |
| 158 | + |
| 159 | +$(shlib): $(OBJS) |
| 160 | + $(LD) $(LDFLAGS_SL) -o $@ $(OBJS) $(SHLIB_LINK) |
| 161 | + |
| 162 | +# Rules to install regular and shared libraries |
| 163 | + |
| 164 | +.PHONY: all install-lib install-shlib |
| 165 | + |
| 166 | +install-lib: lib$(NAME).a |
| 167 | + $(INSTALL) $(INSTL_LIB_OPTS) lib$(NAME).a $(LIBDIR)/lib$(NAME).a |
| 168 | + |
| 169 | +install-shlib: $(shlib) |
| 170 | + $(INSTALL) $(INSTL_SHLIB_OPTS) $(shlib) $(LIBDIR)/$(shlib) |
| 171 | + if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)" ]; then \ |
| 172 | + cd $(LIBDIR); \ |
| 173 | + rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \ |
| 174 | + $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \ |
| 175 | + fi |
| 176 | + if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX)" ]; then \ |
| 177 | + cd $(LIBDIR); \ |
| 178 | + rm -f lib$(NAME)$(DLSUFFIX); \ |
| 179 | + $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX); \ |
| 180 | + fi |
0 commit comments