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