xref: /onnv-gate/usr/src/cmd/perl/5.8.4/extract_makeext.sh (revision 4020:5fbe2f47bce2)
1#!/bin/ksh -p
2#
3# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
4# Use is subject to license terms.
5#
6#ident	"%Z%%M%	%I%	%E% SMI"
7#
8# The perl extension build mechanism works by generating a Makefile from a
9# template Makefile.PL file in the extension directory.  Unfortunately this
10# generated Makefile has a dependency against both the original Makefile.PL as
11# well as config.sh and config.h.  If triggered, the rule for this dependency
12# rebuilds the Makefile from Makefile.PL and exits the make by calling 'false'.
13# This behaviour is unacceptable in the context of ON, where the build must
14# succeed wherever possible.  This script generates a makefile that mimics
15# that generated by the Makefile.PL, so that we can ensure that the extension
16# make will always pass the relevant dependency checks, and will build
17# sucessfully.  The output of this script is a combination of parts of make_ext
18# and the dependencies from the various module Makefiles.  Note also that the
19# generated rules unset VERSION in the environment before calling make, to avoid
20# a clash between the Solaris and Perl uses of this variable.
21#
22
23if  [ -z "$1" -o ! -r "$1" ]; then
24	printf 'No config.sh file specified\n'
25	exit 1
26fi
27
28# Pull in config.sh.
29set -e
30. $1
31set +e
32
33printf '# This file was automatically generated from config.sh by %s\n\n' \
34    $(basename $0)
35
36# Boilerplate, mostly the same as distrib/Makefile.
37cat <<'EOF'
38include ../../../../Makefile.cmd
39include ../../Makefile.perlcfg
40
41PERL_MM_ARGS += INSTALLDIRS=perl LIBPERL_A=libperl.so
42
43EOF
44
45# Define some useful macros.
46printf 'PERL_STATIC_EXT = '
47for ext in $static_ext
48do
49	printf '%s ' $ext
50done
51printf '\n'
52
53printf 'PERL_DYNAMIC_EXT = '
54for ext in $dynamic_ext
55do
56	printf '%s ' $ext
57done
58printf '\n'
59
60printf 'PERL_NONXS_EXT = '
61for ext in $nonxs_ext
62do
63	printf '%s ' $ext
64done
65printf '\n'
66
67printf 'PERL_EXT = $(PERL_STATIC_EXT) $(PERL_DYNAMIC_EXT) $(PERL_NONXS_EXT)\n'
68printf 'PERL_EXT_MAKEFILES = $(PERL_EXT:%%=%%/Makefile)\n\n'
69
70# Define the all, clean and clobber rules
71cat <<'EOF'
72all: $(PERL_EXT)
73
74.PARALLEL: $(PERL_EXT_MAKEFILES) $(PERL_EXT)
75
76clean:
77	-@ $(PERL_MM_ENV); \
78	for ext in $(PERL_EXT); do \
79		( \
80		cd $$ext; pwd; \
81		[ -f Makefile.old ] && mf=Makefile.old; \
82		[ -f Makefile ] && mf=Makefile; \
83		[ ! -z "$$mf" ] && $(MAKE) -f $$mf clean; \
84		) \
85	done
86
87clobber:
88	-@ $(PERL_MM_ENV); \
89	for ext in $(PERL_EXT); do \
90		( \
91		cd $$ext; pwd; \
92		[ -f Makefile.old ] && mf=Makefile.old; \
93		[ -f Makefile ] && mf=Makefile; \
94		[ ! -z "$$mf" ] && $(MAKE) -f $$mf realclean; \
95		) \
96	done
97
98EOF
99
100# Generic Makefile.PL pattern matching rule.
101printf '%%/Makefile: %%/Makefile.PL $(PERL_CONFIGDEP)\n'
102printf '\t@ cd $(@D); pwd; '
103printf '$(PERL_MM_ENV); $(MINIPERL) $(<F) $(PERL_MM_ARGS) >/dev/null 2>&1\n\n'
104
105# Static extensions.
106for ext in $static_ext
107do
108	printf '%s: %s/Makefile FRC\n' $ext $ext
109	printf '\t@ cd $@; pwd; '
110	printf '$(PERL_MM_ENV); $(MAKE) LINKTYPE=static CCCDLFLAGS= all\n\n'
111done
112
113# Dynamic extensions.
114for ext in $dynamic_ext
115do
116	printf '%s: %s/Makefile FRC\n' $ext $ext
117	printf '\t@ cd $@; pwd; '
118	printf '$(PERL_MM_ENV); $(MAKE) LINKTYPE=dynamic all\n\n'
119done
120
121# Non-XS extensions.
122for ext in $nonxs_ext
123do
124	printf '%s: %s/Makefile FRC\n' $ext $ext
125	printf '\t@ cd $@; pwd; '
126	printf '$(PERL_MM_ENV); $(MAKE) all\n\n'
127done
128
129printf 'FRC:\n'
130