tizen 2.3.1 release
[external/curl.git] / m4 / xc-am-iface.m4
1 #---------------------------------------------------------------------------
2 #
3 # xc-am-iface.m4
4 #
5 # Copyright (c) 2013 Daniel Stenberg <daniel@haxx.se>
6 #
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #
19 #---------------------------------------------------------------------------
20
21 # serial 1
22
23
24 dnl _XC_AUTOMAKE_BODY
25 dnl -------------------------------------------------
26 dnl Private macro.
27 dnl
28 dnl This macro performs embedding of automake initialization
29 dnl code into configure script. When automake version 1.14 or
30 dnl newer is used at configure script generation time, this
31 dnl results in 'subdir-objects' automake option being used.
32 dnl When using automake versions older than 1.14 this option
33 dnl is not used when generating configure script.
34 dnl
35 dnl Existence of automake _AM_PROG_CC_C_O m4 private macro
36 dnl is used to differentiate automake version 1.14 from older
37 dnl ones which lack this macro.
38
39 m4_define([_XC_AUTOMAKE_BODY],
40 [dnl
41 ## --------------------------------------- ##
42 ##  Start of automake initialization code  ##
43 ## --------------------------------------- ##
44 m4_ifdef([_AM_PROG_CC_C_O],
45 [
46 AM_INIT_AUTOMAKE([subdir-objects])
47 ],[
48 AM_INIT_AUTOMAKE
49 ])dnl
50 ## ------------------------------------- ##
51 ##  End of automake initialization code  ##
52 ## ------------------------------------- ##
53 dnl
54 m4_define([$0], [])[]dnl
55 ])
56
57
58 dnl XC_AUTOMAKE
59 dnl -------------------------------------------------
60 dnl Public macro.
61 dnl
62 dnl This macro embeds automake machinery into configure
63 dnl script regardless of automake version used in order
64 dnl to generate configure script.
65 dnl
66 dnl When using automake version 1.14 or newer, automake
67 dnl initialization option 'subdir-objects' is used to
68 dnl generate the configure script, otherwise this option
69 dnl is not used.
70
71 AC_DEFUN([XC_AUTOMAKE],
72 [dnl
73 AC_PREREQ([2.50])dnl
74 dnl
75 AC_BEFORE([$0],[AM_INIT_AUTOMAKE])dnl
76 dnl
77 _XC_AUTOMAKE_BODY
78 dnl
79 m4_ifdef([AM_INIT_AUTOMAKE],
80   [m4_undefine([AM_INIT_AUTOMAKE])])dnl
81 dnl
82 m4_define([$0], [])[]dnl
83 ])
84
85
86 dnl _XC_AMEND_DISTCLEAN_BODY ([LIST-OF-SUBDIRS])
87 dnl -------------------------------------------------
88 dnl Private macro.
89 dnl
90 dnl This macro performs shell code embedding into
91 dnl configure script in order to modify distclean
92 dnl and maintainer-clean targets of makefiles which
93 dnl are located in given list of subdirs.
94 dnl
95 dnl See XC_AMEND_DISTCLEAN comments for details.
96
97 m4_define([_XC_AMEND_DISTCLEAN_BODY],
98 [dnl
99 ## ---------------------------------- ##
100 ##  Start of distclean amending code  ##
101 ## ---------------------------------- ##
102
103 for xc_subdir in [$1]
104 do
105
106 if test ! -f "$xc_subdir/Makefile"; then
107   echo "$xc_msg_err $xc_subdir/Makefile file not found. $xc_msg_abrt" >&2
108   exit 1
109 fi
110
111 # Fetch dependency tracking file list from Makefile include lines.
112
113 xc_inc_lines=`grep '^include .*(DEPDIR)' "$xc_subdir/Makefile" 2>/dev/null`
114 xc_cnt_words=`echo "$xc_inc_lines" | wc -w | tr -d "$xc_space$xc_tab"`
115
116 # --disable-dependency-tracking might have been used, consequently
117 # there is nothing to amend without a dependency tracking file list.
118
119 if test $xc_cnt_words -gt 0; then
120
121 AC_MSG_NOTICE([amending $xc_subdir/Makefile])
122
123 # Build Makefile specific patch hunk.
124
125 xc_p="$xc_subdir/xc_patch.tmp"
126
127 xc_rm_depfiles=`echo "$xc_inc_lines" \
128   | $SED 's%include%    -rm -f%' 2>/dev/null`
129
130 xc_dep_subdirs=`echo "$xc_inc_lines" \
131   | $SED 's%include[[ ]][[ ]]*%%' 2>/dev/null \
132   | $SED 's%(DEPDIR)/.*%(DEPDIR)%' 2>/dev/null \
133   | sort | uniq`
134
135 echo "$xc_rm_depfiles" >$xc_p
136
137 for xc_dep_dir in $xc_dep_subdirs; do
138   echo "${xc_tab}@xm_dep_cnt=\`ls $xc_dep_dir | wc -l 2>/dev/null\`; \\"            >>$xc_p
139   echo "${xc_tab}if test \$\$xm_dep_cnt -eq 0 && test -d $xc_dep_dir; then \\"      >>$xc_p
140   echo "${xc_tab}  rm -rf $xc_dep_dir; \\"                                          >>$xc_p
141   echo "${xc_tab}fi"                                                                >>$xc_p
142 done
143
144 # Build Makefile patching sed scripts.
145
146 xc_s1="$xc_subdir/xc_script_1.tmp"
147 xc_s2="$xc_subdir/xc_script_2.tmp"
148 xc_s3="$xc_subdir/xc_script_3.tmp"
149
150 cat >$xc_s1 <<\_EOT
151 /^distclean[[ ]]*:/,/^[[^       ]][[^   ]]*:/{
152   s/^.*(DEPDIR)/___xc_depdir_line___/
153 }
154 /^maintainer-clean[[ ]]*:/,/^[[^        ]][[^   ]]*:/{
155   s/^.*(DEPDIR)/___xc_depdir_line___/
156 }
157 _EOT
158
159 cat >$xc_s2 <<\_EOT
160 /___xc_depdir_line___$/{
161   N
162   /___xc_depdir_line___$/D
163 }
164 _EOT
165
166 cat >$xc_s3 <<_EOT
167 /^___xc_depdir_line___/{
168   r $xc_p
169   d
170 }
171 _EOT
172
173 # Apply patch to Makefile and cleanup.
174
175 $SED -f "$xc_s1" "$xc_subdir/Makefile"      >"$xc_subdir/Makefile.tmp1"
176 $SED -f "$xc_s2" "$xc_subdir/Makefile.tmp1" >"$xc_subdir/Makefile.tmp2"
177 $SED -f "$xc_s3" "$xc_subdir/Makefile.tmp2" >"$xc_subdir/Makefile.tmp3"
178
179 if test -f "$xc_subdir/Makefile.tmp3"; then
180   mv -f "$xc_subdir/Makefile.tmp3" "$xc_subdir/Makefile"
181 fi
182
183 test -f "$xc_subdir/Makefile.tmp1" && rm -f "$xc_subdir/Makefile.tmp1"
184 test -f "$xc_subdir/Makefile.tmp2" && rm -f "$xc_subdir/Makefile.tmp2"
185 test -f "$xc_subdir/Makefile.tmp3" && rm -f "$xc_subdir/Makefile.tmp3"
186
187 test -f "$xc_p"  && rm -f "$xc_p"
188 test -f "$xc_s1" && rm -f "$xc_s1"
189 test -f "$xc_s2" && rm -f "$xc_s2"
190 test -f "$xc_s3" && rm -f "$xc_s3"
191
192 fi
193
194 done
195
196 ## -------------------------------- ##
197 ##  End of distclean amending code  ##
198 ## -------------------------------- ##
199 dnl
200 m4_define([$0], [])[]dnl
201 ])
202
203
204 dnl XC_AMEND_DISTCLEAN ([LIST-OF-SUBDIRS])
205 dnl -------------------------------------------------
206 dnl Public macro.
207 dnl
208 dnl This macro embeds shell code into configure script
209 dnl that amends, at configure runtime, the distclean
210 dnl and maintainer-clean targets of Makefiles located
211 dnl in all subdirs given in the mandatory white-space
212 dnl separated list argument.
213 dnl
214 dnl Embedding only takes place when using automake 1.14
215 dnl or newer, otherwise amending code is not included
216 dnl in generated configure script.
217 dnl
218 dnl distclean and maintainer-clean targets are modified
219 dnl to avoid unconditional removal of dependency subdirs
220 dnl which triggers distclean and maintainer-clean errors
221 dnl when using automake 'subdir-objects' option along
222 dnl with per-target objects and source files existing in
223 dnl multiple subdirs used for different build targets.
224 dnl
225 dnl New behavior first removes each dependency tracking
226 dnl file independently, and only removes each dependency
227 dnl subdir when it finds out that it no longer holds any
228 dnl dependency tracking file.
229 dnl
230 dnl When configure option --disable-dependency-tracking
231 dnl is used no amending takes place given that there are
232 dnl no dependency tracking files.
233
234 AC_DEFUN([XC_AMEND_DISTCLEAN],
235 [dnl
236 AC_PREREQ([2.50])dnl
237 dnl
238 m4_ifdef([_AC_OUTPUT_MAIN_LOOP],
239   [m4_provide_if([_AC_OUTPUT_MAIN_LOOP], [],
240     [m4_fatal([call to AC_OUTPUT needed before $0])])])dnl
241 dnl
242 m4_if([$#], [1], [], [m4_fatal([$0: wrong number of arguments])])dnl
243 m4_if([$1], [], [m4_fatal([$0: missing argument])])dnl
244 dnl
245 AC_REQUIRE([XC_CONFIGURE_PREAMBLE])dnl
246 dnl
247 m4_ifdef([_AM_PROG_CC_C_O],
248 [
249 _XC_AMEND_DISTCLEAN_BODY([$1])
250 ])dnl
251 m4_define([$0], [])[]dnl
252 ])
253