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 | |
7 | # ext/util/make_ext dynamic $@ | |
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 | |
14 | passthru="$*" # allow extra macro=value to be passed through | |
15 | echo "" | |
a0d0e21e LW |
16 | |
17 | case $CONFIG in | |
18 | '') | |
19 | if test -f config.sh; then TOP=.; | |
20 | elif test -f ../config.sh; then TOP=..; | |
21 | elif test -f ../../config.sh; then TOP=../..; | |
22 | elif test -f ../../../config.sh; then TOP=../../..; | |
23 | elif test -f ../../../../config.sh; then TOP=../../../..; | |
24 | else | |
25 | echo "Can't find config.sh generated by Configure"; exit 1 | |
26 | fi | |
27 | . $TOP/config.sh | |
28 | ;; | |
29 | esac | |
30 | ||
31 | if test "X$extspec" = X; then | |
32 | echo "make_ext: no extension specified" | |
33 | exit 1; | |
34 | fi | |
35 | ||
75f92628 | 36 | # The Perl Makefile.SH will expand all extensions to |
2698564b | 37 | # lib/auto/X/X.a (or lib/auto/X/Y/Y.a if nested) |
75f92628 | 38 | # A user wishing to run make_ext might use |
2698564b | 39 | # X (or X/Y or X::Y if nested) |
75f92628 AD |
40 | |
41 | # canonise into X/Y form (pname) | |
42 | case "$extspec" in | |
43 | lib*) # Remove lib/auto prefix and /*.* suffix | |
44 | pname=`echo "$extspec" | sed -e 's:^lib/auto/::' -e 's:/[^/]*\.[^/]*$::' ` ;; | |
45 | *::*) # Convert :: to / | |
46 | pname=`echo "$extspec" | sed -e 's/::/\//g' ` ;; | |
47 | *) pname="$extspec" ;; | |
48 | esac | |
49 | # echo "Converted $extspec to $pname" | |
a0d0e21e | 50 | |
e1666bf5 | 51 | mname=`echo "$pname" | sed -e 's!/!::!g'` |
a0d0e21e | 52 | depth=`echo "$pname" | sed -e 's![^/][^/]*!..!g'` |
75f92628 | 53 | makefile=Makefile |
42793c05 | 54 | makeargs='' |
75f92628 | 55 | makeopts='' |
a0d0e21e LW |
56 | |
57 | if test ! -d "ext/$pname"; then | |
42793c05 TB |
58 | echo " Skipping $extspec (directory does not exist)" |
59 | exit 0 # not an error ? | |
a0d0e21e LW |
60 | fi |
61 | ||
a0d0e21e | 62 | |
42793c05 | 63 | echo " Making $mname ($target)" |
a0d0e21e LW |
64 | |
65 | cd ext/$pname | |
66 | ||
42793c05 TB |
67 | # check link type and do any preliminaries |
68 | case "$target" in | |
75f92628 AD |
69 | # convert 'static' or 'dynamic' into 'all LINKTYPE=XXX' |
70 | static) makeargs="LINKTYPE=static CCCDLFLAGS=" | |
71 | target=all | |
72 | ;; | |
73 | dynamic) makeargs="LINKTYPE=dynamic"; | |
74 | target=all | |
75 | ;; | |
76 | ||
77 | *clean) # If Makefile has been moved to Makefile.old by a make clean | |
78 | # then use Makefile.old for realclean rather than rebuild it | |
79 | if test ! -f $makefile -a -f Makefile.old; then | |
80 | makefile=Makefile.old | |
81 | makeopts="-f $makefile" | |
82 | echo "Note: Using Makefile.old" | |
83 | fi | |
84 | ;; | |
85 | ||
42793c05 | 86 | *) # for the time being we are strict about what make_ext is used for |
75f92628 AD |
87 | echo "make_ext: unknown make target '$target'"; exit 1 |
88 | ;; | |
89 | '') echo "make_ext: no make target specified (eg static or dynamic)"; exit 1 | |
90 | ;; | |
42793c05 TB |
91 | esac |
92 | ||
75f92628 | 93 | if test ! -f $makefile ; then |
76c7ba2e | 94 | test -f Makefile.PL && ../$depth/miniperl -I../$depth/lib Makefile.PL INSTALLDIRS=perl $passthru |
a0d0e21e | 95 | fi |
75f92628 AD |
96 | if test ! -f $makefile ; then |
97 | if test -f Makefile.SH; then | |
98 | echo "Warning: Writing $makefile from old-style Makefile.SH!" | |
99 | sh Makefile.SH | |
100 | else | |
101 | echo "Warning: No Makefile!" | |
102 | fi | |
a0d0e21e LW |
103 | fi |
104 | ||
42793c05 TB |
105 | case "$target" in |
106 | clean) ;; | |
107 | realclean) ;; | |
75f92628 AD |
108 | *) # Give makefile an opportunity to rewrite itself. |
109 | # reassure users that life goes on... | |
110 | $make config $passthru || echo "$make config failed, continuing anyway..." | |
111 | ;; | |
42793c05 | 112 | esac |
a0d0e21e | 113 | |
75f92628 | 114 | $make $makeopts $target $makeargs $passthru || exit |
a0d0e21e LW |
115 | |
116 | exit $? |