Support shared libperl on AIX
[p5sagit/p5-mst-13.2.git] / Makefile.SH
1 #! /bin/sh
2 case $CONFIG in
3 '')
4         if test -f config.sh; then TOP=.;
5         elif test -f ../config.sh; then TOP=..;
6         elif test -f ../../config.sh; then TOP=../..;
7         elif test -f ../../../config.sh; then TOP=../../..;
8         elif test -f ../../../../config.sh; then TOP=../../../..;
9         else
10                 echo "Can't find config.sh."; exit 1
11         fi
12         . $TOP/config.sh
13         ;;
14 esac
15 : This forces SH files to create target in same directory as SH file.
16 : This is so that make depend always knows where to find SH derivatives.
17 case "$0" in
18 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
19 esac
20
21 case "$d_dosuid" in
22 *define*) suidperl='suidperl' ;;
23 *) suidperl='';;
24 esac
25
26 linklibperl='$(LIBPERL)'
27 shrpldflags='$(LDDLFLAGS)'
28 case "$useshrplib" in
29 true)
30         pldlflags="$cccdlflags"
31         # NeXT-4 specific stuff.  Can't we do this in the hint file?
32         case "${osname}${osvers}" in
33         next4*)
34                 ld='libtool -dynamic -undefined warning -framework System \
35                 -compatibility_version 1 -current_version $(PATCHLEVEL) \
36                 -prebind -seg1addr 0x27000000 -install_name $(SHRPDIR)/$@'
37                 ;;
38         sunos*|freebsd[23]*|netbsd*)
39                 linklibperl="-lperl"
40                 ;;
41         aix*)
42                 shrpldflags="-H512 -T512 -bhalt:4 -bM:SRE -bE:perl.exp -b noentry -lc -lm -lbsd"
43                 aixinstdir=`pwd | sed 's/\/UU$//'`
44                 linklibperl="-L $archlibexp/CORE -L $aixinstdir -lperl"
45                 ;;
46         esac
47         ;;
48 *)      pldlflags=''
49         ;;
50 esac
51
52 : Prepare dependency lists for Makefile.
53 dynamic_list=' '
54 for f in $dynamic_ext; do
55     : the dependency named here will never exist
56       base=`echo "$f" | sed 's/.*\///'`
57     dynamic_list="$dynamic_list lib/auto/$f/$base.$dlext"
58 done
59
60 static_list=' '
61 for f in $static_ext; do
62         base=`echo "$f" | sed 's/.*\///'`
63         static_list="$static_list lib/auto/$f/$base\$(LIB_EXT)"
64 done
65
66 echo "Extracting Makefile (with variable substitutions)"
67 $spitshell >Makefile <<!GROK!THIS!
68 # Makefile.SH
69 # This file is derived from Makefile.SH.  Any changes made here will
70 # be lost the next time you run Configure.
71 #  Makefile is used to generate $firstmakefile.  The only difference
72 #  is that $firstmakefile has the dependencies filled in at the end.
73 #
74 #
75 # I now supply perly.c with the kits, so don't remake perly.c without byacc
76 BYACC = $byacc
77 CC = $cc
78 LD = $ld
79
80 LDFLAGS = $ldflags
81 CLDFLAGS = $ldflags
82
83 SMALL = $small
84 LARGE = $large $split
85 mallocsrc = $mallocsrc
86 mallocobj = $mallocobj
87 LNS = $lns
88 RMS = rm -f
89 ranlib = $ranlib
90
91 # The following are mentioned only to make metaconfig include the
92 # appropriate questions in Configure.  If you want to change these,
93 # edit config.sh instead, or specify --man1dir=/wherever on
94 # installman commandline.
95 bin = $installbin
96 scriptdir = $scriptdir
97 shrpdir = $archlibexp/CORE
98 privlib = $installprivlib
99 man1dir = $man1dir
100 man1ext = $man1ext
101 man3dir = $man3dir
102 man3ext = $man3ext
103
104 # The following are used to build and install shared libraries for
105 # dynamic loading.
106 LDDLFLAGS = $lddlflags
107 SHRPLDFLAGS = $shrpldflags
108 CCDLFLAGS = $ccdlflags
109 DLSUFFIX = .$dlext
110 PLDLFLAGS = $pldlflags
111 LIBPERL = $libperl
112 LLIBPERL= $linklibperl
113 SHRPENV = $shrpenv
114
115 dynamic_ext = $dynamic_list
116 static_ext = $static_list
117 ext = \$(dynamic_ext) \$(static_ext)
118 DYNALOADER = lib/auto/DynaLoader/DynaLoader\$(LIB_EXT)
119
120 libs = $libs $cryptlib
121
122 public = perl $suidperl utilities translators
123
124 shellflags = $shellflags
125
126 # This is set to  MAKE=$make if your $make command doesn't
127 # do it for you.
128 $make_set_make
129
130 # These variables will be used in a future version to make
131 # the make file more portable to non-unix systems.
132 AR = $ar
133 EXE_EXT = $exe_ext
134 LIB_EXT = $lib_ext
135 OBJ_EXT = $obj_ext
136 PATH_SEP = $path_sep
137
138 FIRSTMAKEFILE = $firstmakefile
139
140 # Any special object files needed by this architecture, e.g. os2/os2.obj
141 ARCHOBJS = $archobjs
142
143 .SUFFIXES: .c \$(OBJ_EXT)
144
145 # grrr
146 SHELL = $sh
147
148 !GROK!THIS!
149
150 ## In the following dollars and backticks do not need the extra backslash.
151 $spitshell >>Makefile <<'!NO!SUBS!'
152
153 CCCMD = `sh $(shellflags) cflags $(LIBPERL) $@`
154
155 private = preplibrary lib/ExtUtils/Miniperl.pm lib/Config.pm
156
157 # Files to be built with variable substitution before miniperl
158 # is available.
159 sh = Makefile.SH cflags.SH config_h.SH makeaperl.SH makedepend.SH \
160         makedir.SH perl_exp.SH writemain.SH
161
162 shextract = Makefile cflags config.h makeaperl makedepend \
163         makedir perl.exp writemain
164
165 # Files to be built with variable substitution after miniperl is
166 # available.  Dependencies handled manually below (for now).
167
168 pl = pod/pod2html.PL pod/pod2latex.PL pod/pod2man.PL pod/pod2text.PL
169
170 plextract = pod/pod2html pod/pod2latex pod/pod2man pod/pod2text
171
172 addedbyconf = UU $(shextract) $(plextract) pstruct
173
174 h1 = EXTERN.h INTERN.h XSUB.h av.h config.h cop.h cv.h dosish.h
175 h2 = embed.h form.h gv.h handy.h hv.h keywords.h mg.h op.h
176 h3 = opcode.h patchlevel.h perl.h perly.h pp.h proto.h regcomp.h
177 h4 = regexp.h scope.h sv.h unixish.h util.h perlio.h
178 h = $(h1) $(h2) $(h3) $(h4)
179
180 c1 = $(mallocsrc) av.c scope.c op.c doop.c doio.c dump.c hv.c mg.c
181 c2 = perl.c perly.c pp.c pp_hot.c pp_ctl.c pp_sys.c regcomp.c regexec.c
182 c3 = gv.c sv.c taint.c toke.c util.c deb.c run.c universal.c globals.c perlio.c
183
184 c = $(c1) $(c2) $(c3) miniperlmain.c perlmain.c
185
186 obj1 = $(mallocobj) gv$(OBJ_EXT) toke$(OBJ_EXT) perly$(OBJ_EXT) op$(OBJ_EXT) regcomp$(OBJ_EXT) dump$(OBJ_EXT) util$(OBJ_EXT) mg$(OBJ_EXT)
187 obj2 = hv$(OBJ_EXT) av$(OBJ_EXT) run$(OBJ_EXT) pp_hot$(OBJ_EXT) sv$(OBJ_EXT) pp$(OBJ_EXT) scope$(OBJ_EXT) pp_ctl$(OBJ_EXT) pp_sys$(OBJ_EXT)
188 obj3 = doop$(OBJ_EXT) doio$(OBJ_EXT) regexec$(OBJ_EXT) taint$(OBJ_EXT) deb$(OBJ_EXT) universal$(OBJ_EXT) globals$(OBJ_EXT) perlio$(OBJ_EXT)
189
190 obj = $(obj1) $(obj2) $(obj3) $(ARCHOBJS)
191
192 # Once perl has been Configure'd and built ok you build different
193 # perl variants (Debugging, Embedded, Multiplicity etc) by saying:
194 #       make clean; make LIBPERL=libperl<type>.a
195 # where <type> is some combination of 'd' and(or) 'e' or 'm'.
196 # See cflags to understand how this works.
197 #
198 # This mechanism is getting clunky and might not even work any more.
199 # EMBEDDING is on by default, and MULTIPLICITY doesn't work.
200 #
201
202 lintflags = -hbvxac
203
204 .c$(OBJ_EXT):
205         $(CCCMD) $(PLDLFLAGS) $*.c
206
207 all: $(FIRSTMAKEFILE) miniperl $(private) $(plextract) $(public) $(dynamic_ext)
208         @echo " "; echo "       Everything is up to date."
209
210 translators:    miniperl lib/Config.pm FORCE
211         @echo " "; echo "       Making x2p stuff"; cd x2p; $(MAKE) all
212
213 utilities:      miniperl lib/Config.pm FORCE
214         @echo " "; echo "       Making utilities"; cd utils; $(MAKE) all
215
216
217 # This is now done by installman only if you actually want the man pages.
218 #       @echo " "; echo "       Making docs"; cd pod; $(MAKE) all;
219
220 # Phony target to force checking subdirectories.
221 # Apparently some makes require an action for the FORCE target.
222 FORCE:
223         @sh -c true
224
225 miniperlmain$(OBJ_EXT): miniperlmain.c
226         $(CCCMD) $(PLDLFLAGS) $*.c
227
228 perlmain.c: miniperlmain.c config.sh $(FIRSTMAKEFILE)
229         sh writemain $(DYNALOADER) $(static_ext) > tmp
230         sh mv-if-diff tmp perlmain.c
231
232 perlmain$(OBJ_EXT): perlmain.c
233         $(CCCMD) $(PLDLFLAGS) $*.c
234
235 # The file ext.libs is a list of libraries that must be linked in
236 # for static extensions, e.g. -lm -lgdbm, etc.  The individual
237 # static extension Makefile's add to it.
238 ext.libs: $(static_ext)
239         -@test -f ext.libs || touch ext.libs
240
241 !NO!SUBS!
242
243 # How to build libperl.  This is still rather convoluted.
244 # Load up custom Makefile.SH fragment for shared loading and executables:
245 if test -r $osname/Makefile.SHs ; then
246         . $osname/Makefile.SHs
247         $spitshell >>Makefile <<!GROK!THIS!
248
249 Makefile: $osname/Makefile.SHs
250 !GROK!THIS!
251 else
252         $spitshell >>Makefile <<'!NO!SUBS!'
253 $(LIBPERL): $& perl$(OBJ_EXT) $(obj)
254 !NO!SUBS!
255         case "$useshrplib" in
256         true)
257                 $spitshell >>Makefile <<'!NO!SUBS!'
258         $(LD) $(SHRPLDFLAGS) -o $@ perl$(OBJ_EXT) $(obj)
259 !NO!SUBS!
260             case "$osname" in
261             aix)
262                     $spitshell >>Makefile <<'!NO!SUBS!'
263         mv $@ libperl$(OBJ_EXT)
264         $(AR) qv $(LIBPERL) libperl$(OBJ_EXT)
265 !NO!SUBS!
266                       ;;
267             *)
268                       ;;
269             esac
270                 ;;
271         *)
272                 $spitshell >>Makefile <<'!NO!SUBS!'
273         rm -f $(LIBPERL)
274         $(AR) rcu $(LIBPERL) perl$(OBJ_EXT) $(obj)
275         @$(ranlib) $(LIBPERL)
276 !NO!SUBS!
277                 ;;
278         esac
279         $spitshell >>Makefile <<'!NO!SUBS!'
280
281 # How to build executables.
282
283 # The $& notation tells Sequent machines that it can do a parallel make,
284 # and is harmless otherwise.
285 # The miniperl -w -MExporter line is a basic cheap test to catch errors
286 # before make goes on to run preplibrary and then MakeMaker on extensions.
287 # This is very handy because later errors are often caused by miniperl
288 # build problems but that's not obvious to the novice.
289 # The Module used here must not depend on Config or any extensions.
290
291 miniperl: $& miniperlmain$(OBJ_EXT) $(LIBPERL)
292         $(CC) $(LARGE) $(CLDFLAGS) -o miniperl miniperlmain$(OBJ_EXT) $(LLIBPERL) $(libs)
293         @./miniperl -w -Ilib -MExporter -e 0 || $(MAKE) minitest
294
295 perl: $& perlmain$(OBJ_EXT) $(LIBPERL) $(DYNALOADER) $(static_ext) ext.libs
296         $(SHRPENV) $(CC) $(LARGE) $(CLDFLAGS) $(CCDLFLAGS) -o perl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
297
298 pureperl: $& perlmain$(OBJ_EXT) $(LIBPERL) $(DYNALOADER) $(static_ext) ext.libs
299         purify $(CC) $(LARGE) $(CLDFLAGS) $(CCDLFLAGS) -o pureperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
300
301 purecovperl: $& perlmain$(OBJ_EXT) $(LIBPERL) $(DYNALOADER) $(static_ext) ext.libs
302         purecov $(CC) $(LARGE) $(CLDFLAGS) $(CCDLFLAGS) -o purecovperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
303
304 quantperl: $& perlmain$(OBJ_EXT) $(LIBPERL) $(DYNALOADER) $(static_ext) ext.libs
305         quantify $(CC) $(LARGE) $(CLDFLAGS) $(CCDLFLAGS) -o quantperl perlmain$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
306
307 # This version, if specified in Configure, does ONLY those scripts which need
308 # set-id emulation.  Suidperl must be setuid root.  It contains the "taint"
309 # checks as well as the special code to validate that the script in question
310 # has been invoked correctly.
311
312 suidperl: $& sperl$(OBJ_EXT) perlmain$(OBJ_EXT) $(LIBPERL) $(DYNALOADER) $(static_ext) ext.libs
313         $(CC) $(LARGE) $(CLDFLAGS) $(CCDLFLAGS) -o suidperl perlmain$(OBJ_EXT) sperl$(OBJ_EXT) $(DYNALOADER) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
314
315 !NO!SUBS!
316
317 fi
318
319 $spitshell >>Makefile <<'!NO!SUBS!'
320
321 sperl$(OBJ_EXT): perl.c perly.h patchlevel.h $(h)
322         $(RMS) sperl.c
323         $(LNS) perl.c sperl.c
324         $(CCCMD) -DIAMSUID sperl.c
325         $(RMS) sperl.c
326
327 # We have to call our ./makedir because Ultrix 4.3 make can't handle the line
328 #       test -d lib/auto || mkdir lib/auto
329 #
330 preplibrary: miniperl lib/Config.pm $(plextract)
331         @sh ./makedir lib/auto
332         @echo " AutoSplitting perl library"
333         @./miniperl -Ilib -e 'use AutoSplit; \
334                 autosplit_lib_modules(@ARGV)' lib/*.pm lib/*/*.pm
335
336 # Take care to avoid modifying lib/Config.pm without reason
337 lib/Config.pm: config.sh miniperl configpm
338         ./miniperl configpm tmp
339         sh mv-if-diff tmp lib/Config.pm
340
341 lib/ExtUtils/Miniperl.pm: miniperlmain.c miniperl minimod.pl lib/Config.pm
342         ./miniperl minimod.pl > tmp && mv tmp $@
343
344 $(plextract):   miniperl lib/Config.pm
345         ./miniperl -Ilib $@.PL
346
347 install: all install.perl install.man
348
349 install.perl:   all installperl
350         ./perl installperl
351
352 install.man:    all installman
353         ./perl installman
354
355 # Not implemented yet.
356 #install.html:  all installhtml
357 #       ./perl installhtml
358
359 # I now supply perly.c with the kits, so the following section is
360 # used only if you force byacc to run by saying
361 #       make run_byacc
362 # Since we patch up the byacc output, the perly.fixer script needs
363 # to run with precisely the same version of byacc as I use.  You
364 # normally shouldn't remake perly.[ch].
365
366 run_byacc:      FORCE
367         @ echo 'Expect' 113 shift/reduce and 1 reduce/reduce conflict
368         $(BYACC) -d perly.y
369         sh $(shellflags) ./perly.fixer y.tab.c perly.c
370         sed -e 's/fprintf *( *stderr *,/PerlIO_printf(Perl_debug_log,/g' \
371             -e 's/y\.tab/perly/g' perly.c >perly.tmp && mv perly.tmp perly.c
372         echo 'extern YYSTYPE yylval;' >>y.tab.h
373         cmp -s y.tab.h perly.h && rm -f y.tab.h || mv y.tab.h perly.h
374         - perl vms/vms_yfix.pl perly.c perly.h vms/perly_c.vms vms/perly_h.vms
375
376 # We don't want to regenerate perly.c and perly.h, but they might
377 # appear out-of-date after a patch is applied or a new distribution is
378 # made.
379 perly.c: perly.y
380         -@sh -c true
381
382 perly.h: perly.y
383         -@sh -c true
384
385 # The following three header files are generated automatically
386 #       keywords.h:     keywords.pl
387 #       opcode.h:       opcode.pl
388 #       embed.h:        embed.pl global.sym interp.sym
389 # The correct versions should be already supplied with the perl kit,
390 # in case you don't have perl available.
391 # To force them to run, type
392 #       make regen_headers
393 regen_headers:  FORCE
394         perl keywords.pl
395         perl opcode.pl
396         perl embed.pl
397
398 # Extensions:
399 # Names added to $(dynamic_ext) or $(static_ext) will automatically
400 # get built.  There should ordinarily be no need to change any of
401 # this part of makefile.
402 #
403 # The dummy dependency is a place holder in case $(dynamic_ext) or
404 # $(static_ext) is empty.
405 #
406 # DynaLoader may be needed for extensions that use Makefile.PL.
407
408 $(DYNALOADER):  miniperl preplibrary FORCE
409         @sh ext/util/make_ext static $@ LIBPERL_A=$(LIBPERL)
410
411 d_dummy $(dynamic_ext): miniperl preplibrary $(DYNALOADER) FORCE
412         @sh ext/util/make_ext dynamic $@ LIBPERL_A=$(LIBPERL)
413
414 s_dummy $(static_ext):  miniperl preplibrary $(DYNALOADER) FORCE
415         @sh ext/util/make_ext static $@ LIBPERL_A=$(LIBPERL)
416
417 clean:          _tidy _mopup
418
419 realclean:      _cleaner _mopup
420         @echo "Note that make realclean does not delete config.sh"
421
422 clobber:        _cleaner _mopup
423         rm -f config.sh cppstdin
424
425 distclean:      clobber
426
427 # Do not 'make _mopup' directly.
428 _mopup:
429         rm -f *$(OBJ_EXT) *$(LIB_EXT) all perlmain.c
430         rm -f perl.exp ext.libs
431         -rm -f perl.export perl.dll perl.libexp perl.map perl.def
432         rm -f perl suidperl miniperl $(LIBPERL)
433
434 # Do not 'make _tidy' directly.
435 _tidy:
436         -cd pod; $(MAKE) clean
437         -cd utils; $(MAKE) clean
438         -cd x2p; $(MAKE) clean
439         -@for x in $(DYNALOADER) $(dynamic_ext) $(static_ext) ; do \
440         sh ext/util/make_ext clean $$x ; \
441         done
442
443 # Do not 'make _cleaner' directly.
444 _cleaner:
445         -cd os2; rm -f Makefile
446         -cd pod; $(MAKE) realclean
447         -cd utils; $(MAKE) realclean
448         -cd x2p; $(MAKE) realclean
449         -@for x in $(DYNALOADER) $(dynamic_ext) $(static_ext) ; do \
450         sh ext/util/make_ext realclean $$x ; \
451         done
452         rm -f *.orig */*.orig *~ */*~ core t/core t/c t/perl
453         rm -rf $(addedbyconf)
454         rm -f $(FIRSTMAKEFILE) $(FIRSTMAKEFILE).old
455         rm -f $(private)
456         rm -rf lib/auto
457         rm -f lib/.exists
458         rm -f h2ph.man pstruct
459         rm -rf .config
460
461 # The following lint has practically everything turned on.  Unfortunately,
462 # you have to wade through a lot of mumbo jumbo that can't be suppressed.
463 # If the source file has a /*NOSTRICT*/ somewhere, ignore the lint message
464 # for that spot.
465
466 lint: perly.c $(c)
467         lint $(lintflags) $(defs) perly.c $(c) > perl.fuzz
468
469 # Need to unset during recursion to go out of loop
470
471 MAKEDEPEND = makedepend
472
473 $(FIRSTMAKEFILE):       Makefile $(MAKEDEPEND)
474         $(MAKE) depend MAKEDEPEND=
475
476 config.h: config_h.SH config.sh
477         $(SHELL) config_h.SH
478
479 perl.exp: perl_exp.SH config.sh
480         $(SHELL) perl_exp.SH
481
482 # When done, touch perlmain.c so that it doesn't get remade each time.
483 depend: makedepend
484         sh ./makedepend
485         - test -s perlmain.c && touch perlmain.c
486         cd x2p; $(MAKE) depend
487
488 # Cannot postpone this until $firstmakefile is ready ;-)
489 makedepend: makedepend.SH config.sh
490         sh ./makedepend.SH
491
492 check test: miniperl perl preplibrary $(dynamic_ext)
493         - cd t && (rm -f perl$(EXE_EXT); $(LNS) ../perl$(EXE_EXT) perl$(EXE_EXT)) && ./perl TEST </dev/tty
494
495 # Can't depend on lib/Config.pm because that might be where miniperl
496 # is crashing.
497 minitest: miniperl
498         @echo "You may see some irrelevant test failures if you have been unable"
499         @echo "to build lib/Config.pm."
500         - cd t && (rm -f perl$(EXE_EXT); $(LNS) ../miniperl$(EXE_EXT) perl$(EXE_EXT)) \
501                 && ./perl TEST base/*.t comp/*.t cmd/*.t io/*.t op/*.t pragma/*.t </dev/tty
502
503 clist:  $(c)
504         echo $(c) | tr ' ' '\012' >.clist
505
506 hlist:  $(h)
507         echo $(h) | tr ' ' '\012' >.hlist
508
509 shlist: $(sh)
510         echo $(sh) | tr ' ' '\012' >.shlist
511
512 pllist: $(pl)
513         echo $(pl) | tr ' ' '\012' >.pllist
514
515 Makefile: Makefile.SH ./config.sh
516         $(SHELL) Makefile.SH
517
518 distcheck: FORCE
519         perl '-MExtUtils::Manifest=&fullcheck' -e 'fullcheck()'
520
521 # AUTOMATICALLY GENERATED MAKE DEPENDENCIES--PUT NOTHING BELOW THIS LINE
522 # If this runs make out of memory, delete /usr/include lines.
523 !NO!SUBS!
524
525 $eunicefix Makefile
526 case `pwd` in
527 *SH)
528     $rm -f ../Makefile
529     $ln Makefile ../Makefile
530     ;;
531 esac
532 $rm -f $firstmakefile