more
[automake.git] / automake.in
blob25f2e73eb8a8106eb90d462e08018da953805bd2
1 #! /bin/sh
2 # @configure_input@
4 # automake - create Makefile.in from Makefile.am
5 # Copyright (C) 1994 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 # Sample usage: automake Makefile lib/Makefile src/Makefile man/Makefile
22 # Written by David Mackenzie <djm@gnu.ai.mit.edu>.
24 # Caveat: must use all lowercase variables in this file. User
25 # Makefile.am can cause any uppercase variable to be set.
27 version=@VERSION@
29 # We need prefix because datadir might depend on it.
30 prefix=@prefix@
31 am_dir=@datadir@/automake
33 usage="Usage: automake [--help] [--version] [Makefile]..."
35 # These are commonly found files that we look for and automatically
36 # include in DIST_FILES. NOTE if you add something here, make sure
37 # you add it in the right place -- that is, so that the "--help" still
38 # lines up nicely.
39 common='THANKS TODO README NEWS COPYING COPYING.LIB INSTALL NLS ChangeLog configure configure.in config.guess config.sub mkinstalldirs install-sh texinfo.tex'
41 # NLS nuisances.
42 # Only set `LANG' and `LC_ALL' to "C" if already set.
43 # These must not be set unconditionally because not all systems understand
44 # e.g. LANG=C (notably SCO).
45 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
46 if test "${LANG+set}" = set; then LANG=C; export LANG; fi
48 mfiles=
49 while test $# -gt 0; do
50 case "$1" in
51 --help | --h* )
52 echo $usage
53 echo
54 echo "Files which are automatically distributed, if found:"
55 set $common
56 while test $# -gt 0; do
57 echo " $1 $2"
58 shift
59 shift
60 done
61 exit 0
64 --version | --v* )
65 echo "Automake version $version"
66 exit 0
69 -- ) # Stop option processing.
70 shift
71 break
74 -*)
75 # FIXME consider "-" meaning stdin as input?
76 echo "automake: unrecognized option -- \`$1'" 1>&2
77 echo "${usage}" 1>&2
78 exit 1
81 * )
82 mfiles="$mfiles $1"
84 esac
85 shift
86 done
88 test -n "$mfiles" || {
89 # Look around.
90 mfiles=`echo */Makefile.am`
91 if test "$mfiles" = '*/Makefile.am'; then
92 mfiles=
93 else
94 mfiles=`echo "$mfiles" | sed 's/\.am//g'`
97 if test -f Makefile.am; then
98 mfiles="Makefile $mfiles"
101 if test -n "$mfiles"; then
102 echo "automake: using $mfiles" 1>&2
103 else
104 echo "${usage}" 1>&2
105 exit 1
110 am_status=0
112 # Remove \newline.
113 am_rmnl=/tmp/am.sed1
114 cat > $am_rmnl <<\EOF
115 /\\$/{
116 s///
120 /[^\\]$/{
123 s/\n//g
125 s/.*//
130 # Turn Makefile target and variable assignments into shell variable
131 # assignments:
132 # * For targets, define the variable `target_NAME' to "explicit".
133 # * For variables whose names are uppercase, perform the actual assignment.
134 # We only do this for all-upper variables to avoid conflict with variables
135 # used in automake.
136 # * For other variables, define `var_NAME' to "explicit". Such variables
137 # can only be used as flags; any use of their values must be done
138 # later, in the generated Makefile.
139 am_ass=/tmp/am.sed2
140 cat > $am_ass <<\EOF
141 s/(/{/g
142 s/)/}/g
143 /^ *\([a-zA-Z_.][a-zA-Z0-9_.]*\):.*/{
144 s//target_\1=explicit/
145 s/\./_/g
148 s/^ *\([A-Z][A-Z0-9_]*\)[ ]*=[ ]*\(.*\)/\1='\2'/p
149 s/^ *\([A-Za-z][A-Za-z0-9_]*\)[ ]*=[ ]*\(.*\)/var_\1=explicit/p
152 for am_makefile in $mfiles; do
154 if test ! -f ${am_makefile}.am; then
155 echo "automake: ${am_makefile}.am: No such honkin' file" 1>&2
156 am_status=1
157 continue
160 echo creating ${am_makefile}.in
162 exec 4> ${am_makefile}.vars
163 exec 5> ${am_makefile}.rules
165 echo "# Makefile.in generated automatically by automake $version from Makefile.am." >&4
166 cat $am_dir/header-vars.am >&4
167 cat $am_dir/header.am >&5
169 DEFS= INCLUDES= CPPFLAGS= CFLAGS=
170 SOURCES= CONFIG_HEADER= SUBDIRS= PROGRAMS= LIBPROGRAMS= SCRIPTS= LIBSCRIPTS=
171 LIBRARIES= TEXINFOS= MANS= AM_PROGRAMS=
173 eval `sed -n -f $am_rmnl ${am_makefile}.am | sed -n -f $am_ass`
176 # If a variable is set at configure time, we still need to know the
177 # values it can assume (statically). This is done using the AM_
178 # forms in the Makefile.am. Handle it now.
180 test -n "$AM_PROGRAMS" && {
181 PROGRAMS=$AM_PROGRAMS
183 test -n "$AM_LIBPROGRAMS" && {
184 LIBPROGRAMS=$AM_LIBPROGRAMS
186 test -n "$AM_SCRIPTS" && {
187 SCRIPTS=$AM_SCRIPTS
189 test -n "$AM_LIBSCRIPTS" && {
190 LIBSCRIPTS=$AM_LIBSCRIPTS
192 test -n "$AM_LIBRARIES" && {
193 LIBRARIES=$AM_LIBRARIES
196 if grep @kr@ ${am_makefile}.am >/dev/null; then
197 kr='${kr}'
198 else
202 if test -n "$PROGRAMS$LIBPROGRAMS$LIBRARIES"; then
203 cat $am_dir/compile-vars.am >&4
204 cat $am_dir/compile.am >&5
205 grep @kr@ ${am_makefile}.am >/dev/null && cat $am_dir/compile-kr.am >&5
206 for am_file in $PROGRAMS $LIBPROGRAMS $LIBRARIES; do
207 if grep "^[ ]*${am_file}_SOURCES[ ]*=" ${am_makefile}.am >/dev/null; then
208 if grep "^[ ]*${am_file}_OBJECTS[ ]*=" ${am_makefile}.am >/dev/null; then
210 else
211 sed -n -f $am_rmnl ${am_makefile}.am |
212 sed -n "/^[ ]*${am_file}_SOURCES[ ]*=/{
213 s/SOURCES/OBJECTS/
214 s/@[^@]*@//g
215 s/\$([^)]*)//g
216 s/\${[^}]*}//g
217 s/\\.cc/.${kr}o/g
218 s/\\.\${kr}c/.${kr}o/g
219 s/\\.\$(kr)c/.${kr}o/g
220 s/\\.[cCmylfs]/.${kr}o/g
222 }" >&4
224 SOURCES="$SOURCES \${${am_file}_SOURCES}"
225 else
226 echo "${am_file}_SOURCES = ${am_file}.c
227 ${am_file}_OBJECTS = ${am_file}.${kr}o" >&4
228 SOURCES="$SOURCES ${am_file}.c"
230 if test -n "$CONFIG_HEADER"; then
231 echo "\$(${am_file}_OBJECTS): $CONFIG_HEADER" >&5
233 done
236 if test -n "$PROGRAMS$LIBPROGRAMS$SCRIPTS$LIBSCRIPTS"; then
237 if test -n "$PROGRAMS$SCRIPTS"; then
238 cat $am_dir/programs.am >&5
240 if test -n "$LIBPROGRAMS$LIBSCRIPTS"; then
241 cat $am_dir/libprograms.am >&5
243 if test -n "$PROGRAMS$LIBPROGRAMS"; then
244 for am_prog in $PROGRAMS $LIBPROGRAMS; do
245 # If `prog_LDADD' is explicitly defined, use it. Otherwise,
246 # use LDADD.
247 eval "test \"\$var_${am_prog}_LDADD\" = explicit" || {
248 # Not set, so set it.
249 echo "${am_prog}_LDADD = \${LDADD}" >&5
252 # Insert rule for this target, unless it is explicitly given
253 # in Makefile.am.
254 eval "test \"\$target_$am_prog\" != explicit" &&
255 sed "s/@PROGRAM@/$am_prog/g" $am_dir/program.am >&5
256 done
260 if test -n "$LIBRARIES"; then
261 echo "LIBFILES = " `echo "$LIBRARIES"|sed 's/\([a-zA-Z0-9_][a-zA-Z0-9_]*\)/lib\1.a/g'` >&4
262 cat $am_dir/libraries-vars.am >&4
263 cat $am_dir/libraries.am >&5
264 for am_lib in $LIBRARIES; do
265 sed "s/@LIBRARY@/$am_lib/g" $am_dir/library.am >&5
266 done
269 if test -n "$TEXINFOS"; then
270 cat $am_dir/texinfos-vars.am >&4
271 cat $am_dir/texinfos.am >&5
272 echo "$TEXINFOS" | sed 's/^/INFOS = /; s/\.texi/.info*/g' >&4
273 echo "$TEXINFOS" | sed 's/^/INFO_DEPS = /; s/\.texi/.info/g' >&4
274 echo "$TEXINFOS" | sed 's/^/DVIS = /; s/\.texi/.dvi/g' >&4
277 if test -n "$MANS"; then
278 cat $am_dir/mans-vars.am >&4
279 cat $am_dir/mans.am >&5
282 case "$SUBDIRS" in
283 "") if grep @kr@ ${am_makefile}.am >/dev/null; then
284 cat $am_dir/clean-kr.am >&5
285 else cat $am_dir/clean.am >&5
287 cat $am_dir/footer.am >&5 ;;
288 *) cat $am_dir/subdirs.am >&5 ;;
289 esac
291 case "$am_makefile" in
292 */*)
293 cat $am_dir/remake-subd.am >&5
296 test -f aclocal.m4 && echo "ACLOCAL = aclocal.m4" >&4
297 cat $am_dir/remake.am >&5
299 esac
301 case "$CONFIG_HEADER" in
302 "") ;;
303 */*) ;; # It's in some other directory, so don't remake it in this one.
305 test -f acconfig.h && echo "ACCONFIG = acconfig.h" >&4
306 test -f config.h.top && echo "CONFIG_TOP = config.h.top" >&4
307 test -f config.h.bot && echo "CONFIG_BOT = config.h.bot" >&4
308 cat $am_dir/remake-hdr.am >&5 ;;
309 esac
311 echo "SOURCES = $SOURCES" >&4
315 # Handle TAGS.
317 case "$am_makefile" in
318 */*)
319 if test -n "${SOURCES}${HEADERS}${ETAGS_ARGS}"; then
320 cat $am_dir/tags-subd.am >&5
324 if test -n "${SUBDIRS}"; then
325 cat $am_dir/tags.am >&5
326 else
327 if test -n "${SOURCES}${HEADERS}${ETAGS_ARGS}"; then
328 cat $am_dir/tags-subd.am >&5
332 esac
335 # Handle "dist" targets.
337 am_reldir=`echo "$am_makefile" | sed 's,//*[^/][^/]*$,,g'`
338 if test "$am_reldir" = "$am_makefile"; then
339 # Bogus.
340 am_reldir=.
342 # Look for certain common files and make sure they are included.
343 dlist=
344 for cfile in $common; do
345 if test -f $am_reldir/$cfile; then
346 dlist="$dlist $cfile"
348 done
349 echo "DIST_COMMON = $dlist" >&4
350 # Include "dist" boilerplate.
351 case "$am_makefile" in
352 */*)
353 cat $am_dir/dist-subd-vars.am >&4
354 echo "subdir = $am_reldir" >&5
355 cat $am_dir/dist-subd.am >&5
358 cat $am_dir/dist-vars.am >&4
359 if test -n "$SUBDIRS"; then
360 cat $am_dir/dist-subd-top.am >&5
361 else
362 cat $am_dir/dist.am >&5
365 esac
368 # Some final checks.
371 test -z "$TEXINFOS" || test -f $am_reldir/texinfo.tex || {
372 echo "automake: ${am_makefile}.am defines TEXINFOS, but" 1>&2
373 echo "automake: ${am_reldir}/texinfo.tex does not exist" 1>&2
377 sed '/^[^#=]*:/,$d' ${am_makefile}.am >&4
378 sed -n '/^[^#=]*:/,$p' ${am_makefile}.am >&5
379 cat ${am_makefile}.vars ${am_makefile}.rules > ${am_makefile}.in
380 rm -f ${am_makefile}.vars ${am_makefile}.rules
383 done
385 rm -f $am_rmnl $am_ass
387 exit $am_status