Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: dlsrc.U,v$ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1996-1998, Andy Dougherty | |
4 | ?RCS: | |
5 | ?RCS: You may distribute under the terms of either the GNU General Public | |
6 | ?RCS: License or the Artistic License, as specified in the README file. | |
7 | ?RCS: | |
8 | ?RCS: $Log: dlsrc.U,v $ | |
9 | ?RCS: | |
10 | ?X: hpux support thanks to Jeff Okamoto <okamoto@hpcc101.corp.hp.com> | |
11 | ?X: | |
12 | ?X: To create a shared library, you must compile ALL source files in the | |
13 | ?X: library with +z (or possibly +Z if the library is whopping huge), | |
14 | ?X: then link the library with -b. Example: | |
15 | ?X: cc -c +z module_a.c | |
16 | ?X: cc -c +z module_b.c | |
17 | ?X: ld -b module_a.o module_b.o -o module.sl | |
18 | ?X: | |
2cb64bf6 | 19 | ?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags: rm_try \ |
3c617870 TC |
20 | Getfile Myread test osname sed i_dld d_dlopen Findhdr Setvar src run \ |
21 | cc ccflags ldflags optimize ls gccversion cat rsrc i_stdlib i_unistd | |
959f3c4c JH |
22 | ?MAKE: -pick add $@ %< |
23 | ?Y:BOTTOM | |
24 | ?S:usedl: | |
edd6115f | 25 | ?S: This variable indicates if the system supports dynamic |
959f3c4c JH |
26 | ?S: loading of some sort. See also dlsrc and dlobj. |
27 | ?S:. | |
28 | ?S:ld: | |
29 | ?S: This variable indicates the program to be used to link | |
30 | ?S: libraries for dynamic loading. On some systems, it is 'ld'. | |
31 | ?S: On ELF systems, it should be $cc. Mostly, we'll try to respect | |
32 | ?S: the hint file setting. | |
33 | ?S:. | |
34 | ?S:dlsrc: | |
35 | ?S: This variable contains the name of the dynamic loading file that | |
36 | ?S: will be used with the package. | |
37 | ?S:. | |
38 | ?S:cccdlflags: | |
39 | ?S: This variable contains any special flags that might need to be | |
40 | ?S: passed with 'cc -c' to compile modules to be used to create a shared | |
41 | ?S: library that will be used for dynamic loading. For hpux, this | |
42 | ?S: should be +z. It is up to the makefile to use it. | |
43 | ?S:. | |
44 | ?S:lddlflags: | |
45 | ?S: This variable contains any special flags that might need to be | |
46 | ?S: passed to $ld to create a shared library suitable for dynamic | |
47 | ?S: loading. It is up to the makefile to use it. For hpux, it | |
48 | ?S: should be '-b'. For sunos 4.1, it is empty. | |
49 | ?S:. | |
50 | ?S:ccdlflags: | |
51 | ?S: This variable contains any special flags that might need to be | |
52 | ?S: passed to cc to link with a shared library for dynamic loading. | |
53 | ?S: It is up to the makefile to use it. For sunos 4.1, it should | |
54 | ?S: be empty. | |
55 | ?S:. | |
56 | ?C:USE_DYNAMIC_LOADING ~ %<: | |
57 | ?C: This symbol, if defined, indicates that dynamic loading of | |
58 | ?C: some sort is available. | |
59 | ?C:. | |
60 | ?H:?%<:#$usedl USE_DYNAMIC_LOADING /**/ | |
61 | ?H:. | |
62 | ?W:%<:dlopen | |
63 | ?T:dldir thisflag tdir | |
64 | : determine which dynamic loading, if any, to compile in | |
65 | echo " " | |
66 | dldir="ext/DynaLoader" | |
67 | case "$usedl" in | |
68 | $define|y|true) | |
69 | dflt='y' | |
70 | usedl="$define" | |
71 | ;; | |
72 | $undef|n|false) | |
73 | dflt='n' | |
74 | usedl="$undef" | |
75 | ;; | |
2cb64bf6 | 76 | *) |
959f3c4c JH |
77 | dflt='n' |
78 | case "$d_dlopen" in | |
79 | $define) dflt='y' ;; | |
80 | esac | |
81 | case "$i_dld" in | |
82 | $define) dflt='y' ;; | |
83 | esac | |
84 | : Does a dl_xxx.xs file exist for this operating system | |
85 | $test -f $rsrc/$dldir/dl_${osname}.xs && dflt='y' | |
86 | ;; | |
87 | esac | |
88 | rp="Do you wish to use dynamic loading?" | |
89 | . ./myread | |
90 | usedl="$ans" | |
91 | case "$ans" in | |
92 | y*) usedl="$define" | |
93 | case "$dlsrc" in | |
94 | '') | |
95 | if $test -f $rsrc/$dldir/dl_${osname}.xs ; then | |
96 | dflt="$dldir/dl_${osname}.xs" | |
97 | elif $test "$d_dlopen" = "$define" ; then | |
98 | dflt="$dldir/dl_dlopen.xs" | |
99 | elif $test "$i_dld" = "$define" ; then | |
100 | dflt="$dldir/dl_dld.xs" | |
101 | else | |
102 | dflt='' | |
103 | fi | |
104 | ;; | |
105 | *) dflt="$dldir/$dlsrc" | |
106 | ;; | |
107 | esac | |
108 | echo "The following dynamic loading files are available:" | |
109 | : Can not go over to $dldir because getfile has path hard-coded in. | |
3720fc47 | 110 | tdir=`pwd`; cd "$rsrc"; $ls -C $dldir/dl*.xs; cd "$tdir" |
959f3c4c JH |
111 | rp="Source file to use for dynamic loading" |
112 | fn="fne" | |
113 | gfpth="$src" | |
114 | . ./getfile | |
115 | usedl="$define" | |
116 | : emulate basename | |
70ffff07 | 117 | dlsrc=`echo $ans | $sed -e 's%.*/\([^/]*\)$%\1%'` |
959f3c4c JH |
118 | |
119 | $cat << EOM | |
120 | ||
121 | Some systems may require passing special flags to $cc -c to | |
122 | compile modules that will be used to create a shared library. | |
123 | To use no flags, say "none". | |
124 | ||
125 | EOM | |
126 | case "$cccdlflags" in | |
127 | '') case "$gccversion" in | |
128 | '') case "$osname" in | |
129 | hpux) dflt='+z' ;; | |
130 | next) dflt='none' ;; | |
131 | irix*) dflt='-KPIC' ;; | |
5bcf820f | 132 | svr4*|esix*|solaris|nonstopux) dflt='-KPIC' ;; |
959f3c4c JH |
133 | sunos) dflt='-pic' ;; |
134 | *) dflt='none' ;; | |
135 | esac | |
136 | ;; | |
137 | *) case "$osname" in | |
5e191ef7 | 138 | darwin) dflt='none' ;; |
4b3d7136 | 139 | linux*|svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;; |
959f3c4c JH |
140 | *) dflt='-fpic' ;; |
141 | esac ;; | |
142 | esac ;; | |
143 | ' ') dflt='none' ;; | |
144 | *) dflt="$cccdlflags" ;; | |
145 | esac | |
146 | rp="Any special flags to pass to $cc -c to compile shared library modules?" | |
147 | . ./myread | |
148 | case "$ans" in | |
149 | ?X: Use ' ' so that a subsequent Configure run preserves the old state. | |
150 | none) cccdlflags=' ' ;; | |
151 | *) cccdlflags="$ans" ;; | |
152 | esac | |
153 | ||
154 | cat << EOM | |
155 | ||
156 | Some systems use ld to create libraries that can be dynamically loaded, | |
157 | while other systems (such as those using ELF) use $cc. | |
158 | ||
159 | EOM | |
160 | case "$ld" in | |
1273bb5e | 161 | '') $cat >try.c <<EOM |
959f3c4c JH |
162 | /* Test for whether ELF binaries are produced */ |
163 | #include <fcntl.h> | |
1273bb5e JH |
164 | #$i_stdlib I_STDLIB |
165 | #ifdef I_STDLIB | |
959f3c4c | 166 | #include <stdlib.h> |
1273bb5e | 167 | #endif |
20376335 JH |
168 | #$i_unistd I_UNISTD |
169 | #ifdef I_UNISTD | |
170 | #include <unistd.h> | |
171 | #endif | |
959f3c4c JH |
172 | int main() { |
173 | char b[4]; | |
174 | int i = open("a.out",O_RDONLY); | |
2cb64bf6 | 175 | if(i == -1) |
959f3c4c JH |
176 | exit(1); /* fail */ |
177 | if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F') | |
178 | exit(0); /* succeed (yes, it's ELF) */ | |
179 | else | |
180 | exit(1); /* fail */ | |
181 | } | |
182 | EOM | |
0f00356b | 183 | if $cc $ccflags $ldflags try.c >/dev/null 2>&1 && $run ./a.out; then |
959f3c4c JH |
184 | cat <<EOM |
185 | You appear to have ELF support. I'll use $cc to build dynamic libraries. | |
186 | EOM | |
187 | dflt="$cc" | |
188 | else | |
189 | echo "I'll use ld to build dynamic libraries." | |
190 | dflt='ld' | |
191 | fi | |
2cb64bf6 | 192 | $rm_try |
959f3c4c JH |
193 | ;; |
194 | *) dflt="$ld" | |
195 | ;; | |
196 | esac | |
197 | ||
198 | rp="What command should be used to create dynamic libraries?" | |
199 | . ./myread | |
200 | ld="$ans" | |
201 | ||
202 | cat << EOM | |
203 | ||
204 | Some systems may require passing special flags to $ld to create a | |
205 | library that can be dynamically loaded. If your ld flags include | |
206 | -L/other/path options to locate libraries outside your loader's normal | |
207 | search path, you may need to specify those -L options here as well. To | |
208 | use no flags, say "none". | |
209 | ||
210 | EOM | |
211 | case "$lddlflags" in | |
212 | '') case "$osname" in | |
213 | beos) dflt='-nostart' ;; | |
8b424337 JH |
214 | hpux) dflt='-b'; |
215 | case "$gccversion" in | |
216 | '') dflt="$dflt +vnocompatwarnings" ;; | |
f27d6ab9 | 217 | esac |
2cb64bf6 | 218 | ;; |
3c617870 | 219 | linux|irix*|gnu*) dflt="-shared $optimize" ;; |
959f3c4c JH |
220 | next) dflt='none' ;; |
221 | solaris) dflt='-G' ;; | |
222 | sunos) dflt='-assert nodefinitions' ;; | |
5bcf820f | 223 | svr4*|esix*|nonstopux) dflt="-G $ldflags" ;; |
959f3c4c JH |
224 | *) dflt='none' ;; |
225 | esac | |
226 | ;; | |
227 | *) dflt="$lddlflags" ;; | |
228 | esac | |
229 | ||
230 | : Try to guess additional flags to pick up local libraries. | |
231 | : Be careful not to append to a plain 'none' | |
232 | case "$dflt" in | |
233 | none) dflt='' ;; | |
234 | esac | |
235 | for thisflag in $ldflags; do | |
236 | case "$thisflag" in | |
4d5de5cd | 237 | -L*|-R*|-Wl,-R*) |
959f3c4c JH |
238 | case " $dflt " in |
239 | *" $thisflag "*) ;; | |
240 | *) dflt="$dflt $thisflag" ;; | |
241 | esac | |
242 | ;; | |
243 | esac | |
244 | done | |
245 | ||
246 | case "$dflt" in | |
247 | ''|' ') dflt='none' ;; | |
248 | esac | |
249 | ||
250 | rp="Any special flags to pass to $ld to create a dynamically loaded library?" | |
251 | . ./myread | |
252 | case "$ans" in | |
253 | ?X: Use ' ' so that a subsequent Configure run preserves the old state. | |
254 | none) lddlflags=' ' ;; | |
255 | *) lddlflags="$ans" ;; | |
256 | esac | |
257 | ||
258 | cat <<EOM | |
259 | ||
260 | Some systems may require passing special flags to $cc to indicate that | |
261 | the resulting executable will use dynamic linking. To use no flags, | |
262 | say "none". | |
263 | ||
264 | EOM | |
265 | case "$ccdlflags" in | |
266 | '') case "$osname" in | |
76ba8ff9 | 267 | linux|hpux|gnu*) dflt='-Wl,-E' ;; |
2c3385d3 AH |
268 | next|sunos) dflt='none' ;; |
269 | *) dflt='none' ;; | |
959f3c4c JH |
270 | esac ;; |
271 | ' ') dflt='none' ;; | |
272 | *) dflt="$ccdlflags" ;; | |
273 | esac | |
ec0d834e | 274 | rp="Any special flags to pass to $cc to use dynamic linking?" |
959f3c4c JH |
275 | . ./myread |
276 | case "$ans" in | |
277 | ?X: Use ' ' so that a subsequent Configure run preserves the old state. | |
278 | none) ccdlflags=' ' ;; | |
279 | *) ccdlflags="$ans" ;; | |
280 | esac | |
281 | ;; | |
282 | ?X: End of usedl=y section | |
283 | *) usedl="$undef" | |
284 | ld='ld' | |
285 | dlsrc='dl_none.xs' | |
286 | lddlflags='' | |
287 | ccdlflags='' | |
288 | ;; | |
289 | esac | |
290 |