root/mpich2/branches/dev/kumudb/confdb/aclocal_shl.m4 @ 4870

Revision 4870, 11.3 KB (checked in by kumudb, 5 months ago)

Merge from trunk to kumudb r4748:r4869

Line 
1dnl
2dnl Definitions for creating shared libraries
3dnl
4dnl The purpose of these definitions is to provide common support for
5dnl shared libraries, with *or without* the use of the GNU Libtool package.
6dnl For many of our important platforms, the Libtool approach is overkill,
7dnl and can be particularly painful for developers.
8dnl
9dnl To use libtool, you need macros that are defined by libtool for libtool
10dnl Don't even think about the consequences of this for updating and for
11dnl using user-versions of libtool :(
12dnl
13dnl !!!!!!!!!!!!!!!!!!!!!
14dnl libtool requires ac 2.50 !!!!!!!!!!!!!!!!!
15dnl
16dnl builtin(include,libtool.m4)
17dnl
18dnl/*D
19dnl PAC_ARG_SHAREDLIBS - Add --enable-sharedlibs=kind to configure.
20dnl
21dnl Synopsis:
22dnl PAC_ARG_SHAREDLIBS
23dnl
24dnl Output effects:
25dnl Adds '--enable-sharedlibs=kind' to the command line.  If this is enabled,
26dnl then based on the value of 'kind', programs are selected for the
27dnl names 'CC_SHL' and 'CC_LINK_SHL' that configure will substitute for in
28dnl 'Makefile.in's.  These symbols are generated by 'simplemake' when
29dnl shared library support is selected.
30dnl The variable 'C_LINKPATH_SHL' is set to the option to specify the
31dnl path to search at runtime for libraries (-rpath in gcc/GNU ld).
32dnl The variable 'SHLIB_EXT' is set to the extension used by shared
33dnl libraries; under most forms of Unix, this is 'so'; under Mac OS/X, this
34dnl is 'dylib', and under Windows (including cygwin), this is 'dll'.
35dnl
36dnl Supported values of 'kind' include \:
37dnl+    gcc - Use gcc to create both shared objects and libraries
38dnl.    osx-gcc - Use gcc on Mac OS/X to create both shared objects and
39dnl               libraries
40dnl.    solaris-cc - Use native Solaris cc to create shared objects and
41dnl               libraries
42dnl.    cygwin-gcc - Use gcc on Cygwin to create shared objects and libraries
43dnl-    none - The same as '--disable-sharedlibs'
44dnl
45dnl Others will be added as experience dictates.  Likely names are
46dnl + libtool - For general GNU libtool
47dnl - linux-pgcc - For Portland group under Linux
48dnl
49dnl Notes:
50dnl Shared libraries are only partially implemented.  Additional symbols
51dnl will probably be defined, including symbols to specify how shared library
52dnl search paths are specified and how shared library names are set.
53dnl D*/
54AC_DEFUN([PAC_ARG_SHAREDLIBS],[
55AC_ARG_ENABLE(sharedlibs,
56[--enable-sharedlibs=kind - Enable shared libraries.  kind may be
57    gcc     - Standard gcc and GNU ld options for creating shared libraries
58    osx-gcc - Special options for gcc needed only on OS/X
59    solaris-cc - Solaris native (SPARC) compilers for 32 bit systems
60    cygwin-gcc - Special options for gcc needed only for cygwin
61    none    - same as --disable-sharedlibs
62Only gcc, osx-gcc, and solaris-cc are currently supported],
63,enable_sharedlibs=none;enable_shared=no)
64dnl
65CC_SHL=true
66C_LINK_SHL=true
67SHLIB_EXT=unknown
68SHLIB_FROM_LO=no
69SHLIB_INSTALL='$(INSTALL_PROGRAM)'
70case "$enable_sharedlibs" in
71    no|none)
72    ;;
73    gcc-osx|osx-gcc)
74    AC_MSG_RESULT([Creating shared libraries using GNU for Mac OSX])
75    C_LINK_SHL='${CC} -dynamiclib -undefined suppress -single_module -flat_namespace'
76    CC_SHL='${CC} -fPIC'
77    # No way in osx to specify the location of the shared libraries at link
78    # time (see the code in createshlib in mpich2/src/util)
79    C_LINKPATH_SHL=""
80    SHLIB_EXT="dylib"
81    enable_sharedlibs="osx-gcc"
82    ;;
83    gcc)
84    AC_MSG_RESULT([Creating shared libraries using GNU])
85    # Not quite right yet.  See mpich/util/makesharedlib
86    # Use syntax that works in both Make and the shell
87    #C_LINK_SHL='${CC} -shared -Wl,-r'
88    C_LINK_SHL='${CC} -shared'
89    # For example, include the libname as ${LIBNAME_SHL}
90    #C_LINK_SHL='${CC} -shared -Wl,-h,<finallibname>'
91    # May need -fPIC
92    CC_SHL='${CC} -fpic'
93    #C_LINKPATH_SHL="-Wl,-rpath -Wl,"
94    # More recent versions allow multiple args, separated by commas
95    C_LINKPATH_SHL="-Wl,-rpath,"
96    SHLIB_EXT=so
97    # We need to test that this isn't osx.  The following is a
98    # simple hack
99    osname=`uname -s`
100    case $osname in
101        *Darwin*|*darwin*)
102        AC_MSG_ERROR([You must specify --enable-sharedlibs=osx-gcc for Mac OS/X])
103        ;;     
104        *CYGWIN*|*cygwin*)
105        AC_MSG_ERROR([You must specify --enable-sharedlibs=cygwin-gcc for Cygwin])
106        ;;
107        *SunOS*)
108        AC_MSG_ERROR([You must specify --enable-sharedlibs=solaris-gcc for Solaris with gcc])
109        ;;
110    esac
111    ;;
112
113    cygwin|cygwin-gcc|gcc-cygwin)
114    AC_MSG_RESULT([Creating shared libraries using GNU under CYGWIN])
115    C_LINK_SHL='${CC} -shared'
116    CC_SHL='${CC}'
117    # DLL Libraries need to be in the user's path (!)
118    C_LINKPATH_SHL=""
119    SHLIB_EXT="dll"
120    enable_sharedlibs="cygwin-gcc"
121    ;; 
122
123    libtool)
124    AC_MSG_ERROR([Creating shared libraries using libtool not yet supported])
125dnl     dnl Using libtool requires a heavy-weight process to test for
126dnl     dnl various stuff that libtool needs.  Without this, you'll get a
127dnl     dnl bizarre error message about libtool being unable to find
128dnl     dnl configure.in or configure.ac (!)
129dnl     AC_PROG_LIBTOOL
130dnl     # Likely to be
131dnl     # either CC or CC_SHL is libtool $cc
132dnl     CC_SHL='${LIBTOOL} --mode=compile ${CC}'
133dnl     # CC_LINK_SHL includes the final installation path
134dnl     # For many systems, the link may need to include *all* libraries
135dnl     # (since many systems don't allow any unsatisfied dependencies)
136dnl     # We need to give libtool the .lo file, not the .o files
137dnl     SHLIB_FROM_LO=yes
138dnl     # We also need to add -no-undefined when the compiler is gcc and
139dnl     # we are building under cygwin
140dnl     sysname=`uname -s | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
141dnl     isCygwin=no
142dnl     case "$sysname" in
143dnl     *CYGWIN*) isCygwin=yes;;
144dnl     esac
145dnl     if test "$isCygwin" = yes ; then
146dnl         C_LINK_SHL='${LIBTOOL} --mode=link ${CC} -no-undefined -rpath ${libdir}'
147dnl     else
148dnl         C_LINK_SHL='${LIBTOOL} --mode=link ${CC} -rpath ${libdir}'
149dnl     fi
150dnl     C_LINKPATH_SHL="-rpath "
151dnl     # We also need a special install process with libtool.  Note that this
152dnl     # will also install the static libraries
153dnl     SHLIB_INSTALL='$(LIBTOOL) --mode=install $(INSTALL_PROGRAM)'
154dnl     # Note we may still need to add
155dnl     #'$(LIBTOOL) --mode=finish $(libdir)'
156    ;;
157dnl
158dnl Other, such as solaris-cc
159    solaris|solaris-cc)
160    AC_MSG_RESULT([Creating shared libraries using Solaris])
161    # pic32 is appropriate for both 32 and 64 bit Solaris
162    C_LINK_SHL='${CC} -G -xcode=pic32'
163    CC_SHL='${CC} -xcode=pic32'
164    C_LINKPATH_SHL="-R"
165    SHLIB_EXT=so
166    enable_sharedlibs="solaris-cc"
167    ;;
168
169    solaris-gcc)
170    # This is the same as gcc, except for the C_LINKPATH_SHL
171    AC_MSG_RESULT([Creating shared libraries using Solaris with gcc])
172    C_LINK_SHL='${CC} -shared'
173    CC_SHL='${CC} -fPIC'
174    C_LINKPATH_SHL="-R"
175    SHLIB_EXT=so
176    enable_sharedlibs="solaris-gcc"
177    ;;
178
179    linuxppc-xlc)
180    # This is only the beginning of xlc support, thanks to andy@vpac.org
181    CC_SHL='${CC} -qmkshrobj'
182    # More recent versions allow multiple args, separated by commas
183    C_LINKPATH_SHL="-Wl,-rpath,"
184    #C_LINKPATH_SHL="-Wl,-rpath -Wl,"
185    C_LINK_SHL='${CC} -shared -qmkshrobj'
186    SHLIB_EXT=so
187    # Note that the full line should be more like
188    # $CLINKER -shared -qmkshrobj -Wl,-h,$libbase.$slsuffix -o ../shared/$libbase.$slsuffix *.o $OtherLibs
189    # for the appropriate values of $libbase and $slsuffix
190    # The -h name sets the name of the object; this is necessary to
191    # ensure that the dynamic linker can find the proper shared library.
192    ;;
193
194    *)
195    AC_MSG_ERROR([Unknown value $enable_sharedlibs for enable-sharedlibs.  Values should be gcc or osx-gcc])
196    enable_sharedlibs=no
197    ;; 
198esac
199# Check for the shared-library extension
200PAC_CC_SHLIB_EXT
201dnl
202AC_SUBST(CC_SHL)
203AC_SUBST(C_LINK_SHL)
204AC_SUBST(C_LINKPATH_SHL)
205AC_SUBST(SHLIB_EXT)
206AC_SUBST(SHLIB_FROM_LO)
207AC_SUBST(SHLIB_INSTALL)
208])
209
210dnl /*D
211dnl PAC_xx_SHAREDLIBS - Get compiler and linker for shared libraries
212dnl These routines may be used to determine the compiler and the
213dnl linker to be used in creating shared libraries
214dnl Rather than set predefined variable names, they set an argument
215dnl (if provided)
216dnl
217dnl Synopsis
218dnl PAC_CC_SHAREDLIBS(type,CCvar,CLINKvar)
219dnl D*/
220AC_DEFUN([PAC_CC_SHAREDLIBS],
221[
222pac_kinds=$1
223ifelse($1,,[
224    pac_prog=""
225    AC_CHECK_PROG(pac_prog,gcc,yes,no)
226    # If we are gcc but OS X, set the special type
227    # We need a similar setting for cygwin
228    if test "$pac_prog" = yes ; then
229        osname=`uname -s`
230        case $osname in
231             *Darwin*|*darwin*) pac_kinds=gcc-osx
232             ;;                         
233             *) pac_kinds=gcc
234             ;;
235        esac
236    fi
237    pac_prog=""
238    AC_CHECK_PROG(pac_prog,libtool,yes,no)
239    if test "$pac_prog" = yes ; then pac_kinds="$pac_kinds libtool" ; fi
240])
241for pac_arg in $pac_kinds ; do
242    case $pac_arg in
243    gcc)
244    # For example, include the libname as ${LIBNAME_SHL}
245    #C_LINK_SHL='${CC} -shared -Wl,-h,<finallibname>'
246    pac_cc_sharedlibs='gcc -shared -fpic'
247    pac_clink_sharedlibs='gcc -shared'
248    pac_type_sharedlibs=gcc
249    ;;
250    gcc-osx|osx-gcc)
251    pac_clink_sharedlibs='${CC} -dynamiclib -undefined suppress -single_module -flat_namespace'
252    pac_cc_sharedlibs='${CC} -fPIC'
253    pac_type_sharedlibs=gcc-osx
254    ;;
255    libtool)
256    AC_CHECK_PROGS(LIBTOOL,libtool,false)
257    if test "$LIBTOOL" = "false" ; then
258        AC_MSG_WARN([Could not find libtool])
259    else
260        # Likely to be
261        # either CC or CC_SHL is libtool $cc
262        pac_cc_sharedlibs'${LIBTOOL} -mode=compile ${CC}'
263        pac_clink_sharedlibs='${LIBTOOL} -mode=link ${CC} -rpath ${libdir}'
264        pac_type_sharedlibs=libtool
265    fi
266    ;;
267    *)
268    ;;
269    esac
270    if test -n "$pac_cc_sharedlibs" ; then break ; fi
271done
272if test -z "$pac_cc_sharedlibs" ; then pac_cc_sharedlibs=true ; fi
273if test -z "$pac_clink_sharedlibs" ; then pac_clink_sharedlibs=true ; fi
274ifelse($2,,CC_SHL=$pac_cc_sharedlibs,$2=$pac_cc_sharedlibs)
275ifelse($3,,C_LINK_SHL=$pac_clink_sharedlibs,$3=$pac_clink_sharedlibs)
276ifelse($4,,SHAREDLIB_TYPE=$pac_type_sharedlibs,$4=$pac_type_sharedlibs)
277])
278dnl
279dnl
280dnl This macro ensures that all of the necessary substitutions are
281dnl made by any subdirectory configure (which may simply SUBST the
282dnl necessary values rather than trying to determine them from scratch)
283dnl This is a more robust (and, in the case of libtool, only
284dnl managable) method.
285AC_DEFUN([PAC_CC_SUBDIR_SHLIBS],[
286        AC_SUBST(CC_SHL)
287        AC_SUBST(C_LINK_SHL)
288        AC_SUBST(LIBTOOL)
289        AC_SUBST(ENABLE_SHLIB)
290        AC_SUBST(SHLIB_EXT)
291        if test "$ENABLE_SHLIB" = "libtool" ; then
292            if test -z "$LIBTOOL" ; then
293                AC_MSG_WARN([libtool selected for shared library support but LIBTOOL is not defined])
294            fi
295        fi
296])
297dnl
298dnl
299dnl PAC_CC_SHLIB_EXT - get the extension for shared libraries
300dnl Set the variable SHLIB_EXT if it is other than unknown.
301dnl
302AC_DEFUN([PAC_CC_SHLIB_EXT],[
303# Not all systems use .so as the extension for shared libraries (cygwin
304# and OSX are two important examples).  If we did not set the SHLIB_EXT,
305# then try and determine it.  We need this to properly implement
306# clean steps that look for libfoo.$SHLIB_EXT .
307if test "$SHLIB_EXT" = "unknown" ; then
308    osname=`uname -s`
309    case $osname in
310        *Darwin*|*darwin*) SHLIB_EXT=dylib
311        ;;     
312        *CYGWIN*|*cygwin*) SHLIB_EXT=dll
313        ;;
314        *Linux*|*LINUX*|*SunOS*) SHLIB_EXT=so
315        ;;
316   esac
317fi
318])
Note: See TracBrowser for help on using the browser.