Commit | Line | Data |
---|---|---|
75f92628 AD |
1 | #!/bin/sh |
2 | ||
a0d0e21e LW |
3 | # This script acts as a simple interface for building extensions. |
4 | # It primarily used by the perl Makefile: | |
5 | # | |
6 | # d_dummy $(dynamic_ext): miniperl preplibrary FORCE | |
fb73857a | 7 | # @sh ext/util/make_ext dynamic $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) |
a0d0e21e LW |
8 | # |
9 | # It may be deleted in a later release of perl so try to | |
10 | # avoid using it for other purposes. | |
11 | ||
42793c05 TB |
12 | target=$1; shift |
13 | extspec=$1; shift | |
fb73857a | 14 | makecmd=$1; shift # Should be something like MAKE=make |
42793c05 TB |
15 | passthru="$*" # allow extra macro=value to be passed through |
16 | echo "" | |
a0d0e21e | 17 | |
fb73857a | 18 | # Previously, $make was taken from config.sh. However, the user might |
19 | # instead be running a possibly incompatible make. This might happen if | |
20 | # the user types "gmake" instead of a plain "make", for example. The | |
21 | # correct current value of MAKE will come through from the main perl | |
22 | # makefile as MAKE=/whatever/make in $makecmd. We'll be cautious in | |
23 | # case third party users of this script (are there any?) don't have the | |
24 | # MAKE=$(MAKE) argument, which was added after 5.004_03. | |
25 | case "$makecmd" in | |
26 | MAKE=*) | |
27 | eval $makecmd | |
28 | ;; | |
29 | *) echo 'ext/util/make_ext: WARNING: Please include MAKE=$(MAKE)' | |
30 | echo ' in your call to make_ext. See ext/util/make_ext for details.' | |
31 | exit 1 | |
32 | ;; | |
33 | esac | |
34 | ||
35 | ||
a0d0e21e LW |
36 | case $CONFIG in |
37 | '') | |
38 | if test -f config.sh; then TOP=.; | |
39 | elif test -f ../config.sh; then TOP=..; | |
40 | elif test -f ../../config.sh; then TOP=../..; | |
41 | elif test -f ../../../config.sh; then TOP=../../..; | |
42 | elif test -f ../../../../config.sh; then TOP=../../../..; | |
43 | else | |
44 | echo "Can't find config.sh generated by Configure"; exit 1 | |
45 | fi | |
46 | . $TOP/config.sh | |
47 | ;; | |
48 | esac | |
49 | ||
50 | if test "X$extspec" = X; then | |
51 | echo "make_ext: no extension specified" | |
52 | exit 1; | |
53 | fi | |
54 | ||
75f92628 | 55 | # The Perl Makefile.SH will expand all extensions to |
2698564b | 56 | # lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested) |
75f92628 | 57 | # A user wishing to run make_ext might use |
2698564b | 58 | # X (or X/Y or X::Y if nested) |
75f92628 AD |
59 | |
60 | # canonise into X/Y form (pname) | |
61 | case "$extspec" in | |
62 | lib*) # Remove lib/auto prefix and /*.* suffix | |
63 | pname=`echo "$extspec" | sed -e 's:^lib/auto/::' -e 's:/[^/]*\.[^/]*$::' ` ;; | |
4318d5a0 GB |
64 | ext*) # Remove ext/ prefix and /pm_to_blib suffix |
65 | pname=`echo "$extspec" | sed -e 's:^ext/::' -e 's:/pm_to_blib$::' ` ;; | |
75f92628 AD |
66 | *::*) # Convert :: to / |
67 | pname=`echo "$extspec" | sed -e 's/::/\//g' ` ;; | |
e37e15af | 68 | *.*o) pname=`echo "$extspec" | sed -e 's/\..*o//'` ;; |
75f92628 AD |
69 | *) pname="$extspec" ;; |
70 | esac | |
71 | # echo "Converted $extspec to $pname" | |
a0d0e21e | 72 | |
e1666bf5 | 73 | mname=`echo "$pname" | sed -e 's!/!::!g'` |
a0d0e21e | 74 | depth=`echo "$pname" | sed -e 's![^/][^/]*!..!g'` |
75f92628 | 75 | makefile=Makefile |
42793c05 | 76 | makeargs='' |
75f92628 | 77 | makeopts='' |
a0d0e21e | 78 | |
3b5ca523 | 79 | if test ! -d "ext/$pname"; then |
42793c05 TB |
80 | echo " Skipping $extspec (directory does not exist)" |
81 | exit 0 # not an error ? | |
a0d0e21e LW |
82 | fi |
83 | ||
9c12f1e5 | 84 | case "$osname" in |
6d4b7d88 | 85 | catamount) # Snowball's chance of building extensions. |
9c12f1e5 RGS |
86 | echo "This is $osname, not building $mname, sorry." |
87 | exit 0 | |
88 | ;; | |
89 | esac | |
90 | ||
42793c05 | 91 | echo " Making $mname ($target)" |
a0d0e21e LW |
92 | |
93 | cd ext/$pname | |
94 | ||
94c41b70 AD |
95 | # check link type and do any preliminaries. Valid link types are |
96 | # 'dynamic', 'static', and 'static_pic' (the last one respects | |
97 | # CCCDLFLAGS such as -fPIC -- see static_target in the main Makefile.SH) | |
42793c05 | 98 | case "$target" in |
94c41b70 AD |
99 | dynamic) makeargs="LINKTYPE=dynamic"; |
100 | target=all | |
101 | ;; | |
75f92628 AD |
102 | static) makeargs="LINKTYPE=static CCCDLFLAGS=" |
103 | target=all | |
104 | ;; | |
94c41b70 | 105 | static_pic) makeargs="LINKTYPE=static" |
75f92628 AD |
106 | target=all |
107 | ;; | |
4318d5a0 GB |
108 | nonxs) makeargs=""; |
109 | target=all | |
110 | ;; | |
111 | ||
75f92628 AD |
112 | *clean) # If Makefile has been moved to Makefile.old by a make clean |
113 | # then use Makefile.old for realclean rather than rebuild it | |
114 | if test ! -f $makefile -a -f Makefile.old; then | |
115 | makefile=Makefile.old | |
116 | makeopts="-f $makefile" | |
117 | echo "Note: Using Makefile.old" | |
118 | fi | |
119 | ;; | |
120 | ||
42793c05 | 121 | *) # for the time being we are strict about what make_ext is used for |
75f92628 AD |
122 | echo "make_ext: unknown make target '$target'"; exit 1 |
123 | ;; | |
124 | '') echo "make_ext: no make target specified (eg static or dynamic)"; exit 1 | |
125 | ;; | |
42793c05 TB |
126 | esac |
127 | ||
75f92628 | 128 | if test ! -f $makefile ; then |
83fdb6ac | 129 | test -f Makefile.PL && $run ../$depth/miniperl -I../$depth/lib Makefile.PL INSTALLDIRS=perl INSTALLMAN3DIR=none PERL_CORE=1 $passthru |
a0d0e21e | 130 | fi |
4b4bd025 GA |
131 | if test ! -f $makefile ; then |
132 | echo "Warning: No Makefile!" | |
133 | fi | |
a0d0e21e | 134 | |
42793c05 TB |
135 | case "$target" in |
136 | clean) ;; | |
137 | realclean) ;; | |
75f92628 AD |
138 | *) # Give makefile an opportunity to rewrite itself. |
139 | # reassure users that life goes on... | |
1c8b6db8 | 140 | $MAKE config MAKE=$MAKE $passthru || echo "$MAKE config failed, continuing anyway..." |
75f92628 | 141 | ;; |
42793c05 | 142 | esac |
a0d0e21e | 143 | |
1c8b6db8 | 144 | $MAKE $makeopts $target MAKE=$MAKE $makeargs $passthru || exit |
a0d0e21e LW |
145 | |
146 | exit $? |