comparison aclocal.m4 @ 388:aabb7f5b1c81 r21-2-9

Import from CVS: tag r21-2-9
author cvs
date Mon, 13 Aug 2007 11:09:42 +0200
parents 8efd647ea9ca
children 74fd4e045ea6
comparison
equal deleted inserted replaced
387:f892a9d0bb8d 388:aabb7f5b1c81
1 dnl aclocal.m4 --- Dynamically linked library support for XEmacs 1 dnl aclocal.m4 --- Dynamically linked library support for XEmacs
2 dnl Copyright (C) 1998 Free Software Foundation, Inc. 2 dnl Copyright (C) 1998, 1999 J. Kean Johnston.
3 dnl Author: William Perry <wmperry@aventail.com> 3 dnl Author: J. Kean Johnston <jkj@sco.com>, based on work in libtool.
4 dnl This file is part of XEmacs 4 dnl This file is part of XEmacs.
5 5
6 AC_DEFUN(XE_MAKE_SHAREDLIB, [ 6 dnl
7 dll_ld="ld" 7 dnl There are several things we care about here. First, we need to find
8 dll_lflags="-shared" 8 dnl out how we create an executable that has its symbols exported, so
9 dll_cflags="-r" 9 dnl that dynamically loaded modules have access to the internal XEmacs
10 dll_oflags="-o " 10 dnl symbols. This is stored in ``ld_dynamic_link_flags'' and is used
11 11 dnl in the main Makefile.
12 AC_MSG_CHECKING(how to build a shared library) 12 dnl Next, we need to know how we compile actual shared libraries, and
13 case `uname -rs` in 13 dnl the objects in them. For these purposes, we need to determine the
14 UNIX_SV*|UNIX_System_V*) 14 dnl C compiler flags used to produce shared objects (``dll_cflags''),
15 dll_lflags="-G" 15 dnl what linker to use to create the final shared object that will be
16 dll_cflags=-Kpic 16 dnl loaded (``dll_ld'') and the flags to pass to that linker
17 dll_ld="ld" 17 dnl (``dll_ldflags''). This information is used by ellcc to build up
18 ;; 18 dnl the command line when compiling modules. We build up two other commands
19 BSD/OS*) 19 dnl for extremely weird systems where special things need to be done.
20 dll_cflags= 20 dnl The first is ``dll_ldo'', which is the flag used to specify the output
21 dll_lflags="-r" 21 dnl file name, and the second is ``dll_post'' which is inserted after the
22 dll_ld="shlicc2" 22 dnl list of objects.
23 ;; 23 dnl After all of this, we should be able to:
24 FreeBSD*2*) 24 dnl $(CC) $(CFLAGS) $(dll_cflags) -c module.c
25 dll_lflags="-Bshareable" 25 dnl to produce a single shared object
26 dll_cflags="-fPIC -DPIC" 26 dnl And then:
27 dll_ld=ld 27 dnl $(dll_ld) $(dll_ldflags) $(dll_ldo) module.ell module.o $(dll_post)
28 ;; 28 dnl to create the loadable shared library.
29 SunOS*4.*) 29 dnl
30 dll_cflags="-P" 30 dnl NOTE: In the code below, where I have modified things to work with
31 dll_lflags="-dp -assert pure-text -assert nodefinitions" 31 dnl XEmacs, we use $canonical instead of libtool's $host, and we use
32 ;; 32 dnl $internal_configuration instead of $host_alias. To make typing
33 SunOS*5.*) 33 dnl shorter we assign these to $xehost and $xealias
34 dll_ld="cc" 34
35 dll_cflags="-KPIC" 35 AC_DEFUN(XE_SHLIB_STUFF,[
36 dll_lflags="-G" 36 dll_ld=
37 dll_oflags="-W0,-y-o -W0,-y" 37 dll_ldflags=
38 ;; 38 dll_cflags=
39 IRIX*5.*|IRIX*6.*) 39 dll_post=
40 dll_cflags="-KPIC" 40 dll_ldo="-o"
41 ;; 41 ld_dynamic_link_flags=
42 OSF1*) 42 xehost=$canonical
43 ;; 43 xealias=$internal_configuration
44 HP-UX*) 44
45 dll_ld="ld" 45 AC_CHECKING([how to build dynamic libraries for ${xehost}])
46 dll_lflags="-b" 46 # Transform *-*-linux* to *-*-linux-gnu*, to support old configure scripts.
47 dll_cflags="+z" 47 case "$xehost" in
48 ;; 48 *-*-linux-gnu*) ;;
49 SCO_SV*) 49 *-*-linux*) xehost=`echo $xehost | sed 's/^\(.*-.*-linux\)\(.*\)$/\1-gnu\2/'`
50 dll_ld="ld" 50 esac
51 dll_lflags="-G" 51
52 dll_cflags="-Kpic" 52 changequote(<<, >>)dnl
53 ;; 53 xehost_cpu=`echo $xehost | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
54 AIX*) 54 xehost_vendor=`echo $xehost | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
55 dll_lflags="-H512 -T512 -bhalt:4 -bM:SRE -bE:\${@:.ell=.exp} -b noentry -lc" 55 xehost_os=`echo $xehost | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
56 dll_ld="ld" 56 changequote([, ])dnl
57 ;; 57
58 *) 58 case "$xehost_os" in
59 ;; 59 aix3*)
60 esac 60 # AIX sometimes has problems with the GCC collect2 program. For some
61 61 # reason, if we set the COLLECT_NAMES environment variable, the problems
62 if test "$GCC" = "yes" ; then 62 # vanish in a puff of smoke.
63 dll_cflags="-fPIC" 63 if test "${COLLECT_NAMES+set}" != set; then
64 case `uname -rs` in 64 COLLECT_NAMES=
65 SunOS*5.*) 65 export COLLECT_NAMES
66 dll_ld="ld" 66 fi
67 dll_oflags="-o " 67 ;;
68 dll_lflags="-G" 68 esac
69 ;; 69
70 SCO_SV*) 70 # Now see if the compiler is really GCC.
71 dll_ld="ld" 71 if test "$GCC" = "yes"; then
72 dll_lflags="-G" 72 XEGCC=yes
73 dll_cflags="-b elf" 73 else
74 ;; 74 AC_MSG_CHECKING(checking whether we are using GNU C)
75 FreeBSD*) 75 AC_EGREP_CPP(yes,[
76 dll_cflags="-DDLSYM_NEEDS_UNDERSCORE -DPIC -fPIC" 76 #ifdef __GNUC__
77 dll_lflags="-Bshareable" 77 yes;
78 dll_ld=ld 78 #endif
79 ;; 79 ],XEGCC=yes, XEGCC=no)
80 BSD/OS*) 80 AC_MSG_RESULT([${XEGCC}])
81 dll_cflags= 81 fi
82 dll_lflags="-r" 82
83 dll_ld="shlicc2" 83 AC_MSG_CHECKING(how to produce PIC code)
84 ;; 84 wl=
85 UNIX_SV*) 85
86 dll_cflags="-fPIC" 86 can_build_shared=yes
87 ;; 87 if test "$XEGCC" = yes; then
88 *) 88 wl='-Wl,'
89 dll_ld="$CC" 89
90 dll_lflags="-shared" 90 case "$xehost_os" in
91 esac 91 aix3* | aix4* | irix5* | irix6* | osf3* | osf4*)
92 fi 92 # PIC is the default for these OSes.
93 93 ;;
94 AC_MSG_RESULT("lflags: $dll_lflags cflags: $dll_cflags") 94
95 os2*)
96 # We can build DLLs from non-PIC.
97 ;;
98 amigaos*)
99 # FIXME: we need at least 68020 code to build shared libraries, but
100 # adding the `-m68020' flag to GCC prevents building anything better,
101 # like `-m68040'.
102 dll_cflags='-m68020 -resident32 -malways-restore-a4'
103 ;;
104 *)
105 dll_cflags='-fPIC'
106 ;;
107 esac
108 else
109 # PORTME Check for PIC flags for the system compiler.
110 case "$xehost_os" in
111 hpux9* | hpux10*)
112 # Is there a better link_static_flag that works with the bundled CC?
113 wl='-Wl,'
114 dll_cflags='+Z'
115 ;;
116
117 irix5* | irix6*)
118 wl='-Wl,'
119 # PIC (with -KPIC) is the default.
120 ;;
121
122 os2*)
123 # We can build DLLs from non-PIC.
124 ;;
125
126 osf3* | osf4*)
127 # All OSF/1 code is PIC.
128 wl='-Wl,'
129 ;;
130
131 sco3.2v5*)
132 dll_cflags='-belf -Kpic'
133 wl='-Wl,'
134 ;;
135
136 unixware*)
137 dll_cflags="-KPIC"
138 wl="-Wl,"
139 ;;
140
141 sysv4*)
142 dll_cflags="-KPIC"
143 wl="-Wl,"
144 ;;
145
146 sysv5*)
147 dll_cflags="-KPIC"
148 wl="-Wl,"
149 ;;
150
151 solaris2*)
152 dll_cflags='-KPIC'
153 wl='-Wl,'
154 ;;
155
156 sunos4*)
157 dll_cflags='-PIC'
158 wl='-Qoption ld '
159 ;;
160
161 uts4*)
162 dll_cflags='-pic'
163 ;;
164
165 *)
166 can_build_shared=no
167 ;;
168 esac
169 fi
170
171 if test -n "$dll_cflags"; then
172 AC_MSG_RESULT([${dll_cflags}])
173
174 # Check to make sure the dll_cflags actually works.
175 AC_MSG_CHECKING([if PIC flag ${dll_cflags} really works])
176 save_CFLAGS="$CFLAGS"
177 CFLAGS="$CFLAGS $dll_cflags -DPIC"
178 AC_TRY_COMPILE(,[int x=0;],[
179 # On HP-UX, the stripped-down bundled CC doesn't accept +Z, but also
180 # reports no error. So, we need to grep stderr for (Bundled).
181 if grep '(Bundled)' config.log >/dev/null; then
182 AC_MSG_RESULT(no)
183 can_build_shared=no
184 dll_cflags=
185 else
186 AC_MSG_RESULT(yes)
187 fi], [AC_MSG_RESULT(no)
188 can_build_shared=no
189 dll_cflags=])
190 CFLAGS="$save_CFLAGS"
191 else
192 AC_MSG_RESULT(none)
193 fi
194
195 dnl
196 dnl Now comes the LD trickery. We do things differently to libtool here.
197 dnl I believe that libtool is incorrect in trying to drive the linker
198 dnl directly. This can cause considerable problems if the module you are
199 dnl compiling has C++ or other static initializers. If we use ld directly,
200 dnl we dont end up with the crt stuff being linked in, and we dont end up
201 dnl with any .init or .fini sections (or the moral equivalent thereof).
202 dnl gcc takes great care to do this propperly when invoked in -shared
203 dnl mode, and we really do want this behaviour. Perhaps the libtool folks
204 dnl are not aware that any SVR4 based dynamic loader will automatically
205 dnl execute code in the .init section before dlopen() returns. This is
206 dnl vital, as the module may have been compiled to rely on that behaviour.
207 dnl
208 dnl So, having said all of that, we diverge from libtool significantly
209 dnl here. We want to try and use the C compiler as much as possible. Only
210 dnl if the C compiler itself cannot create shared libraries to we try to
211 dnl find the linker.
212 dnl
213 dnl The other advantage to my scheme is that it removes the dependancy
214 dnl on a given compiler version remaining static with relation to the
215 dnl version of XEmacs. With the libtool way, it picks up the linker that
216 dnl gcc uses, which can be the internal collect2 that comes with gcc.
217 dnl If the user ever changes their compiler version, the paths will no
218 dnl longer be correct, and ellcc will break. This is clearly unacceptable.
219 dnl By using the compiler driver on the path, we dont have this problem.
220 dnl If that is not clear, consider that gcc -print-prog-name=ld can
221 dnl produce something along the lines of:
222 dnl /usr/local/lib/gcc-lib/OS-NAME/GCC-VERSION/ld
223 dnl If you ever change GCC versions, then that path no longer exists.
224 dnl
225 dnl So, we change the check order here. We first check to see if we are
226 dnl using GCC, and if so, we see if -shared works. If it does, great.
227 dnl If we are not using gcc, but the system C compiler can produce
228 dnl shared objects, we try that. Only if all of that fails do we revert
229 dnl back to the libtool ld trickery.
230 dnl
231 dnl We dont do ANY of this if we can't produce shared objects.
232 dnl
233 if test "$can_build_shared" = "yes"; then
234 cc_produces_so=no
235 xldf=
236 xcldf=
237 AC_MSG_CHECKING(if C compiler can produce shared libraries)
238 if test "$XEGCC" = yes; then
239 xcldf="-shared"
240 xldf="-shared"
241 else # Not using GCC
242 case "$xehost_os" in
243 aix3* | aix4*)
244 xldf="-bE:ELLSONAME.exp -H512 -T512 -bhalt:4 -bM:SRE -bnoentry -lc"
245 xcldf="${wl}-bE:ELLSONAME.exp ${wl}-H512 ${wl}-T512 ${wl}-bhalt:4 ${wl}-bM:SRE ${wl}-bnoentry ${wl}-lc"
246 ;;
247
248 freebsd2* | netbsd* | openbsd*)
249 xldf="-Bshareable"
250 xcldf="${wl}-Bshareable"
251 ;;
252
253 freebsd3*)
254 xcldf="-shared"
255 ;;
256
257 hpux*)
258 xldf="-b +s"
259 xcldf="${wl}-b ${wl}+s"
260 ;;
261
262 irix5* | irix6* | osf3* | osf4*)
263 xcldf="${wl}-shared"
264 xldf="-shared"
265 ;;
266
267 sco3.2v5* | unixware* | sysv5* | sysv4* | solaris2* | solaris7* | uts4*)
268 xcldf="-G"
269 xldf="-G"
270 ;;
271
272 sunos4*)
273 xcldf="${wl}-assert ${wl}pure-text ${wl}-Bstatic"
274 xldf="-assert pure-text -Bstatic"
275 ;;
276 esac
277 fi # End if if we are using gcc
278
279 if test -n "$xcldf"; then
280 save_LDFLAGS=$LDFLAGS
281 save_LIBS=$LIBS
282 save_xe_libs=$xe_libs
283 LDFLAGS="$xcldf $LDFLAGS"
284 LIBS=
285 xe_libs=
286 ac_link='${CC-cc} -o conftest $CFLAGS '"$xe_cppflags $xe_ldflags"' conftest.$ac_ext '"$xe_libs"' 1>&AC_FD_CC'
287 AC_TRY_LINK(,[int x=0;],cc_produces_so=yes,cc_produces_so=no)
288 LDFLAGS=$save_LDFLAGS
289 LIBS=$save_LIBS
290 xe_libs=$save_xe_libs
291 ac_link='${CC-cc} -o conftest $CFLAGS '"$xe_cppflags $xe_ldflags"' conftest.$ac_ext '"$xe_libs"' 1>&AC_FD_CC'
292 else
293 cc_produces_so=no
294 fi
295 AC_MSG_RESULT([${cc_produces_so}])
296
297 LTLD=$LD
298 if test -z "$LTLD"; then
299 ac_prog=ld
300 if test "$XEGCC" = yes; then
301 # Check if gcc -print-prog-name=ld gives a path.
302 AC_MSG_CHECKING(for ld used by GCC)
303 ac_prog=`($CC -print-prog-name=ld) 2>&5`
304 case "$ac_prog" in
305 # Accept absolute paths.
306 /*)
307 if test -z "$LTLD"; then
308 case "$ac_prog" in
309 *gcc-lib*) LTLD="$CC"
310 ;;
311 *) LTLD="$ac_prog"
312 ;;
313 esac
314 fi
315 ;;
316 "")
317 # If it fails, then pretend we aren't using GCC.
318 ac_prog=ld
319 ;;
320 *)
321 # If it is relative, then search for the first ld in PATH.
322 with_gnu_ld=unknown
323 ;;
324 esac
325 else
326 AC_MSG_CHECKING(for GNU ld)
327 fi
328
329 if test -z "$LTLD"; then
330 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
331 for ac_dir in $PATH; do
332 test -z "$ac_dir" && ac_dir=.
333 if test -f "$ac_dir/$ac_prog"; then
334 LTLD="$ac_dir/$ac_prog"
335 # Check to see if the program is GNU ld. I'd rather use --version,
336 # but apparently some GNU ld's only accept -v.
337 # Break only if it was the GNU/non-GNU ld that we prefer.
338 if "$LTLD" -v 2>&1 < /dev/null | egrep '(GNU|with BFD)' > /dev/null; then
339 xe_gnu_ld=yes
340 else
341 xe_gnu_ld=no
342 fi
343 fi
344 done
345 IFS="$ac_save_ifs"
346 fi
347
348 if test -n "$LTLD"; then
349 AC_MSG_RESULT([${LTLD}])
350 else
351 AC_MSG_RESULT(no)
352 fi
353
354 if test -z "$LTLD" -a "$cc_produces_so" = no; then
355 AC_MSG_ERROR(no acceptable linker found in \$PATH)
356 exit 1
357 fi
358 fi
359
360 dnl
361 dnl Order of the tests changed somewhat to prevent repetition
362 dnl
363 ld_dynamic_link_flags=
364
365 # Check to see if it really is or isn't GNU ld.
366 AC_MSG_CHECKING(if the linker is GNU ld)
367 # I'd rather use --version here, but apparently some GNU ld's only accept -v.
368 if $LTLD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
369 xe_gnu_ld=yes
370 else
371 xe_gnu_ld=no
372 fi
373 AC_MSG_RESULT([${xe_gnu_ld}])
374
375 case "$xehost_os" in
376 amigaos* | sunos4*)
377 # On these operating systems, we should treat GNU ld like the system ld.
378 gnu_ld_acts_native=yes
379 ;;
380 *)
381 gnu_ld_acts_native=no
382 ;;
383 esac
384
385 if test "$cc_produces_so" = "yes"; then
386 dll_ld=$CC
387 dll_ldflags=$xcldf
388 can_build_shared=yes
389 else
390 # OK - only NOW do we futz about with ld.
391 # See if the linker supports building shared libraries.
392 AC_MSG_CHECKING(whether the linker supports shared libraries)
393 dll_ld=$CC
394 dll_ldflags=$LDFLAGS
395 ld_shlibs=yes
396 can_build_shared=yes
397 if test "$xe_gnu_ld" = yes && test "$gnu_ld_acts_native" != yes; then
398 # See if GNU ld supports shared libraries.
399 if $LTLD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
400 dll_ld=$CC
401 dll_ldflags="-shared"
402 ld_shlibs=yes
403 else
404 ld_shlibs=no
405 fi
406 else
407 # PORTME fill in a description of your system's linker (not GNU ld)
408 case "$xehost_os" in
409 aix3*)
410 dll_ld=$LTLD
411 dll_ldflags=$xldf
412 ;;
413
414 aix4*)
415 dll_ldflags=$xcldf
416 ;;
417
418 # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
419 # support. Future versions do this automatically, but an explicit c++rt0.o
420 # doesn't break anything, and helps significantly (at the cost of a little
421 # extra space).
422 freebsd2.2*)
423 dll_ld=$LTLD
424 dll_ldflags=$xldf
425 dll_post="/usr/lib/c++rt0.o"
426 ;;
427
428 # Unfortunately, older versions of FreeBSD 2 don't have this feature.
429 freebsd2*)
430 dll_ld=$LTLD
431 dll_ldflags="-Bshareable"
432 ;;
433
434 # FreeBSD 3, at last, uses gcc -shared to do shared libraries.
435 freebsd3*)
436 dll_ldflags="-shared"
437 ;;
438
439 hpux*)
440 dll_ld=$LTLD
441 dll_ldflags=$xldf
442 ;;
443
444 irix5* | irix6*)
445 dll_ld=$LTLD
446 dll_ldflags=$xldf
447 ;;
448
449 netbsd*)
450 # Tested with NetBSD 1.2 ld
451 dll_ld=$LTLD
452 dll_ldflags=$xldf
453 ;;
454
455 openbsd*)
456 dll_ld=$LTLD
457 dll_ldflags=$xldf
458 ;;
459
460 osf3* | osf4*)
461 dll_ld=$LTLD
462 dll_ldflags=$xldf
463 ;;
464
465 # For both SCO and Solaris we MAY want to have LDFLAGS include -z text
466 sco3.2v5* | unixware* | sysv5* | sysv4* | solaris2* | solaris7*)
467 dll_ld=$LTLD
468 case "$dll_ld" in
469 *gcc*) dll_ldflags="-shared"
470 dll_ld=$CC
471 ;;
472 *) dll_ldflags="-G"
473 ;;
474 esac
475 ;;
476
477 sunos4*)
478 if test "$XEGCC" = yes; then
479 dll_ld=$CC
480 else
481 dll_ld=$LTLD
482 fi
483 dll_ldflags=$xldf
484 ;;
485
486 uts4*)
487 dll_ld=$LTLD
488 dll_ldflags="-G"
489 ;;
490
491 bsdi*)
492 dll_ldflags="-r"
493 dll_ld="shlicc2"
494 ;;
495
496 *)
497 ld_shlibs=no
498 can_build_shared=no
499 ;;
500 esac
501 fi
502 AC_MSG_RESULT([${ld_shlibs}])
503 if test "$ld_shlibs" = "no"; then
504 can_build_shared=no
505 fi
506 fi # End of if cc_produces_so = no
507
508 dnl
509 dnl Last thing, check how to get a linked executable to have its symbols
510 dnl exported, so that the modules have access to them.
511 dnl
512 dnl XEmacs FIXME - we need to set ld_dynamic_link_flags propperly for
513 dnl most of these systems, which was missing from libtool. I know they
514 dnl all have a way of doing this, but someone needs to look at this
515 dnl for each OS and make sure it is correct. Remember that the arguments
516 dnl are passed when temacs is linked, this is NOT for modules. The sole
517 dnl purpose of the argument is to get the internal XEmacs symbols exposed
518 dnl for modules to use. This means that the COMPILER (and NOT the linker)
519 dnl is most often used to create temacs, so arguments to the linker will
520 dnl usually need to be prefix with ${wl} or some other such thing.
521 dnl
522
523 if test "$xe_gnu_ld" = yes; then
524 if test "$ld_shlibs" = yes; then
525 ld_dynamic_link_flags="${wl}-export-dynamic"
526 fi
527 fi
528
529 if test -z "$ld_dynamic_link_flags"; then
530 case "$xehost_os" in
531 aix3*)
532 ld_dynamic_link_flags=
533 ;;
534
535 aix4*)
536 ld_dynamic_link_flags=
537 ;;
538
539 freebsd2.2*)
540 ld_dynamic_link_flags=
541 ;;
542
543 freebsd2*)
544 ld_dynamic_link_flags=
545 ;;
546
547 freebsd3*)
548 ld_dynamic_link_flags=
549 ;;
550
551 hpux*)
552 ld_dynamic_link_flags="${wl}-E"
553 ;;
554
555 irix5* | irix6*)
556 ld_dynamic_link_flags=
557 ;;
558
559 netbsd*)
560 ld_dynamic_link_flags=
561 ;;
562
563 openbsd*)
564 ld_dynamic_link_flags=
565 ;;
566
567 osf3* | osf4*)
568 ld_dynamic_link_flags=
569 ;;
570
571 sco3.2v5* | unixware* | sysv5* | sysv4* | solaris2* | solaris7*)
572 ld_dynamic_link_flags="${wl}-Bexport"
573 ;;
574
575 sunos4*)
576 ld_dynamic_link_flags=
577 ;;
578
579 uts4*)
580 ld_dynamic_link_flags=
581 ;;
582
583 bsdi*)
584 ld_dynamic_link_flags=
585 ;;
586
587 esac
588 fi # End of if -z ld_dynamic_link_flags
589 fi # End of if test "$can_build_shared" = "yes"
590
95 AC_SUBST(dll_ld) 591 AC_SUBST(dll_ld)
96 AC_SUBST(dll_cflags) 592 AC_SUBST(dll_cflags)
97 AC_SUBST(dll_oflags) 593 AC_SUBST(dll_ldflags)
98 AC_SUBST(dll_lflags) 594 AC_SUBST(dll_post)
595 AC_SUBST(dll_ldo)
596 AC_SUBST(ld_dynamic_link_flags)
99 ])dnl 597 ])dnl
598