Only include depend.am if SOURCES not empty
[automake.git] / automake.in
blob0cfdd7009ad4f7aa9af4ccef74395c4741411113
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 # These are commonly found files that we look for and automatically
34 # include in DIST_FILES. NOTE if you add something here, make sure
35 # you add it in the right place -- that is, so that the "--help" still
36 # lines up nicely.
37 common='THANKS TODO README NEWS COPYING COPYING.LIB INSTALL NLS ChangeLog configure configure.in config.guess config.sub mkinstalldirs install-sh texinfo.tex acconfig.h config.h.top config.h.bot'
39 # NLS nuisances.
40 # Only set `LANG' and `LC_ALL' to "C" if already set.
41 # These must not be set unconditionally because not all systems understand
42 # e.g. LANG=C (notably SCO).
43 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
44 if test "${LANG+set}" = set; then LANG=C; export LANG; fi
46 mfiles=
47 am_usedeps=no
48 am_incdeps=no
49 while test $# -gt 0; do
50 case "$1" in
51 --help | --h* )
52 usage="Usage: automake [--help] [--version] [Makefile]..."
54 echo "Usage: automake [OPTION]... [Makefile]..."
55 echo "
56 --help print this help, then exit
57 --version print version number, then exit
58 --use-deps include code to auto-generate dependencies
59 --include-deps include generated dependencies in Makefile"
60 echo
61 echo "Files which are automatically distributed, if found:"
62 set $common
63 while test $# -gt 0; do
64 echo " $1 $2"
65 shift
66 # Ignore errors here, in case we have an odd number.
67 shift 2>/dev/null
68 done
69 exit 0
72 --version | --v* )
73 echo "Automake version $version"
74 exit 0
77 --use-deps)
78 am_usedeps=yes
81 --include-deps)
82 am_incdeps=yes
85 -- ) # Stop option processing.
86 break
89 -*)
90 # FIXME consider "-" meaning stdin as input?
91 echo "automake: unrecognized option -- \`$1'" 1>&2
92 exit 1
95 * )
96 mfiles="$mfiles $1"
98 esac
99 shift
100 done
102 if test "$am_usedeps" = yes && test "$am_incdeps" = yes; then
103 echo "automake: can't specify both --use-deps and --include-deps" 1>&2
104 exit 1
107 test -n "$mfiles" || {
108 # Look around.
109 mfiles=`echo */Makefile.am`
110 if test "$mfiles" = '*/Makefile.am'; then
111 mfiles=
112 else
113 mfiles=`echo "$mfiles" | sed 's/\.am//g'`
116 if test -f Makefile.am; then
117 mfiles="Makefile $mfiles"
120 if test -n "$mfiles"; then
121 echo "automake: using $mfiles" 1>&2
122 else
123 echo "automake: no \"Makefile.am\" found or specified" 1>&2
124 exit 1
129 am_status=0
131 # Some handy sed scripts.
132 am_rmnl=$am_dir/nl-remove.sed
133 am_ass=$am_dir/hack-make.sed
135 for am_makefile in $mfiles; do
137 if test ! -f ${am_makefile}.am; then
138 echo "automake: ${am_makefile}.am: No such honkin' file" 1>&2
139 am_status=1
140 continue
143 echo creating ${am_makefile}.in
145 exec 4> ${am_makefile}.vars
146 exec 5> ${am_makefile}.rules
148 echo "# Makefile.in generated automatically by automake $version from Makefile.am." >&4
149 cat $am_dir/header-vars.am >&4
150 cat $am_dir/header.am >&5
152 DEFS= INCLUDES= CPPFLAGS= CFLAGS=
153 SOURCES= CONFIG_HEADER= SUBDIRS= PROGRAMS= LIBPROGRAMS= SCRIPTS= LIBSCRIPTS=
154 LIBRARIES= TEXINFOS= MANS= AM_PROGRAMS=
155 am_suffixes=
157 eval `sed -n -f $am_rmnl ${am_makefile}.am | sed -n -f $am_ass`
160 # If a variable is set at configure time, we still need to know the
161 # values it can assume (statically). This is done using the AM_
162 # forms in the Makefile.am. Handle it now.
164 test -n "$AM_PROGRAMS" && {
165 PROGRAMS=$AM_PROGRAMS
167 test -n "$AM_LIBPROGRAMS" && {
168 LIBPROGRAMS=$AM_LIBPROGRAMS
170 test -n "$AM_SCRIPTS" && {
171 SCRIPTS=$AM_SCRIPTS
173 test -n "$AM_LIBSCRIPTS" && {
174 LIBSCRIPTS=$AM_LIBSCRIPTS
176 test -n "$AM_LIBRARIES" && {
177 LIBRARIES=$AM_LIBRARIES
180 if grep @kr@ ${am_makefile}.am >/dev/null; then
181 kr='${kr}'
182 else
186 if test -n "$PROGRAMS$LIBPROGRAMS$LIBRARIES"; then
187 cat $am_dir/compile-vars.am >&4
188 cat $am_dir/compile.am >&5
190 # Check for automatic de-ANSIfication.
191 if grep @kr@ ${am_makefile}.am >/dev/null; then
192 cat $am_dir/compile-kr.am >&5
193 am_suffixes=".krc .krh .kro $am_suffixes"
196 for am_file in $PROGRAMS $LIBPROGRAMS $LIBRARIES; do
197 if eval "test \"\$var_${am_file}_SOURCES\" = explicit"; then
198 if eval "test \"\$var_${am_file}_OBJECTS\" = explicit"; then
200 else
201 sed -n -f $am_rmnl ${am_makefile}.am |
202 sed -n "/^[ ]*${am_file}_SOURCES[ ]*=/{
203 s/SOURCES/OBJECTS/
204 s/@[^@]*@//g
205 s/\$([^)]*)//g
206 s/\${[^}]*}//g
207 s/\\.cc/.${kr}o/g
208 s/\\.\${kr}c/.${kr}o/g
209 s/\\.\$(kr)c/.${kr}o/g
210 s/\\.[cCmylfs]/.${kr}o/g
212 }" >&4
214 SOURCES="$SOURCES \${${am_file}_SOURCES}"
215 else
216 echo "${am_file}_SOURCES = ${am_file}.c" >&4
217 echo "${am_file}_OBJECTS = ${am_file}.${kr}o" >&4
218 SOURCES="$SOURCES ${am_file}.c"
220 if test -n "$CONFIG_HEADER"; then
221 echo "\$(${am_file}_OBJECTS): $CONFIG_HEADER" >&5
223 done
227 # Boilerplate for scripts or programs.
229 if test -n "$PROGRAMS"; then
230 cat $am_dir/programs.am >&5
232 if test -n "$SCRIPTS"; then
233 cat $am_dir/scripts.am >&5
235 if test -n "$LIBPROGRAMS$LIBSCRIPTS"; then
236 cat $am_dir/libprograms.am >&5
238 if test -n "$LIBSCRIPTS"; then
239 cat $am_dir/libscripts.am >&5
242 if test -n "$PROGRAMS$LIBPROGRAMS$SCRIPTS$LIBSCRIPTS"; then
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 am_suffixes=".texi .info .dvi $am_suffixes"
273 echo "$TEXINFOS" | sed 's/^/INFOS = /; s/\.texi/.info*/g' >&4
274 echo "$TEXINFOS" | sed 's/^/INFO_DEPS = /; s/\.texi/.info/g' >&4
275 echo "$TEXINFOS" | sed 's/^/DVIS = /; s/\.texi/.dvi/g' >&4
278 if test -n "$MANS"; then
279 cat $am_dir/mans-vars.am >&4
280 cat $am_dir/mans.am >&5
283 case "$SUBDIRS" in
284 "") if grep @kr@ ${am_makefile}.am >/dev/null; then
285 cat $am_dir/clean-kr.am >&5
286 else cat $am_dir/clean.am >&5
288 cat $am_dir/footer.am >&5 ;;
289 *) cat $am_dir/subdirs.am >&5 ;;
290 esac
292 case "$am_makefile" in
293 */*)
294 cat $am_dir/remake-subd.am >&5
297 test -f aclocal.m4 && echo "ACLOCAL = aclocal.m4" >&4
298 cat $am_dir/remake.am >&5
300 esac
302 case "$CONFIG_HEADER" in
303 "") ;;
304 */*) ;; # It's in some other directory, so don't remake it in this one.
306 test -f acconfig.h && echo "ACCONFIG = acconfig.h" >&4
307 test -f config.h.top && echo "CONFIG_TOP = config.h.top" >&4
308 test -f config.h.bot && echo "CONFIG_BOT = config.h.bot" >&4
309 cat $am_dir/remake-hdr.am >&5 ;;
310 esac
312 echo "SOURCES = $SOURCES" >&4
316 # Handle TAGS.
318 case "$am_makefile" in
319 */*)
320 if test -n "${SOURCES}${HEADERS}${ETAGS_ARGS}"; then
321 cat $am_dir/tags-subd.am >&5
325 if test -n "${SUBDIRS}"; then
326 cat $am_dir/tags.am >&5
327 else
328 if test -n "${SOURCES}${HEADERS}${ETAGS_ARGS}"; then
329 cat $am_dir/tags-subd.am >&5
333 esac
336 # Handle "dist" targets.
338 am_reldir=`echo "$am_makefile" | sed 's,//*[^/][^/]*$,,g'`
339 if test "$am_reldir" = "$am_makefile"; then
340 # Bogus.
341 am_reldir=.
343 # Look for certain common files and make sure they are included.
344 dlist=
345 for cfile in $common; do
346 if test -f $am_reldir/$cfile; then
347 dlist="$dlist $cfile"
349 done
350 echo "DIST_COMMON = $dlist" >&4
351 # Include "dist" boilerplate.
352 case "$am_makefile" in
353 */*)
354 cat $am_dir/dist-subd-vars.am >&4
355 echo "subdir = $am_reldir" >&5
356 cat $am_dir/dist-subd.am >&5
359 cat $am_dir/dist-vars.am >&4
360 if test -n "$SUBDIRS"; then
361 cat $am_dir/dist-subd-top.am >&5
362 else
363 cat $am_dir/dist.am >&5
366 esac
369 # Put .SUFFIXES way down at the bottom.
371 if test -n "$am_suffixes"; then
372 echo ".SUFFIXES:" >&5
373 echo ".SUFFIXES: $am_suffixes" >&5
374 echo >&5
379 # Handle auto-generating dependencies.
381 if test "$am_usedeps" = yes; then
382 if test -n "$SOURCES"; then
383 # Include code to auto-generate dependencies.
384 cat $am_dir/depend.am >&5
386 else
387 if test "$am_incdeps" = yes; then
388 # Include any already generated dependencies.
389 if test -d .deps && test -f .deps/empty.P; then
390 cat .deps/*.P >&5
397 # Some final checks.
399 test -z "$TEXINFOS" || test -f $am_reldir/texinfo.tex || {
400 echo "automake: ${am_makefile}.am defines TEXINFOS, but" 1>&2
401 echo "automake: ${am_reldir}/texinfo.tex does not exist" 1>&2
405 sed '/^[^#=]*:/,$d' ${am_makefile}.am >&4
406 sed -n '/^[^#=]*:/,$p' ${am_makefile}.am >&5
407 cat ${am_makefile}.vars ${am_makefile}.rules > ${am_makefile}.in
408 rm -f ${am_makefile}.vars ${am_makefile}.rules
411 done
413 exit $am_status