works on fileutils
[platform/upstream/automake.git] / automake.in
1 #!/bin/sh
2 # automake - create Makefile.in from Makefile.am
3 # Copyright (C) 1994 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # Sample usage: automake Makefile lib/Makefile src/Makefile man/Makefile
20 # Written by David Mackenzie <djm@gnu.ai.mit.edu>.
21
22 if test $# -eq 0; then
23   echo "Usage: automake Makefile..." >&2
24   exit 1
25 fi
26
27 am_status=0
28 AM_DIR=`echo $0|sed s%automake%%`
29
30 # Remove \newline.
31 am_rmnl=/tmp/am.sed1
32 cat > $am_rmnl <<\EOF
33 /\\$/{
34   s///
35   H
36   d
37 }
38 /[^\\]$/{
39   H
40   x
41   s/\n//g
42   p
43   s/.*//
44   h
45 }
46 EOF
47
48 # Turn Makefile target and variable assignments
49 # into shell variable assignments.
50 am_ass=/tmp/am.sed2
51 cat > $am_ass <<\EOF
52 s/(/{/g
53 s/)/}/g
54 /^ *\([a-zA-Z_.][a-zA-Z0-9_.]*\):.*/{
55 s//target_\1=explicit/
56 s/\./_/g
57 p
58 }
59 s/^ *\([A-Z][A-Z0-9_]*\)[        ]*=[    ]*\(.*\)/\1='\2'/p
60 EOF
61
62 for am_makefile
63 do
64   if test ! -f ${am_makefile}.am; then
65     echo "automake: ${am_makefile}.am: No such honkin' file"
66     am_status=1
67     continue
68   fi
69
70   echo creating ${am_makefile}.in
71
72   exec 4> ${am_makefile}.vars
73   exec 5> ${am_makefile}.rules
74
75   cat $AM_DIR/header-vars.am >&4
76   cat $AM_DIR/header.am >&5
77
78   target_distname=default
79   DEFS= INCLUDES= CPPFLAGS= CFLAGS=
80   SOURCES= CONFIG_HEADER= SUBDIRS= PROGRAMS= LIBRARIES= TEXINFOS= MANS=
81
82   eval `sed -n -f $am_rmnl ${am_makefile}.am | sed -n -f $am_ass`
83
84   if test -n "$PROGRAMS" || test -n "$LIBRARIES"; then
85     cat $AM_DIR/compile-vars.am >&4
86     cat $AM_DIR/compile.am >&5
87     for am_file in $PROGRAMS $LIBRARIES; do
88       if grep "^[        ]*${am_file}_SOURCES[   ]*=" ${am_makefile}.am >/dev/null; then
89         sed -n -f $am_rmnl ${am_makefile}.am |
90         sed -n "/^[      ]*${am_file}_SOURCES[   ]*=/{
91 s/SOURCES/OBJECTS/
92 s/@[^@]*@//g
93 s/\$([^)]*)//g
94 s/\${[^}]*}//g
95 s/\\.cc/.o/g
96 s/\\.\${kr}c/.o/g
97 s/\\.\$(kr)c/.o/g
98 s/\\.[cCmylfs]/.o/g
99 p
100 }" >&4
101         SOURCES="$SOURCES \${${am_file}_SOURCES}"
102       else
103         echo "${am_file}_SOURCES = ${am_file}.c
104 ${am_file}_OBJECTS = ${am_file}.o" >&4
105         SOURCES="$SOURCES ${am_file}.c"
106       fi
107       if test -n "$CONFIG_HEADER"; then
108         echo "\$(${am_file}_OBJECTS): $CONFIG_HEADER" >&4
109       fi
110     done
111   fi
112
113   if test -n "$PROGRAMS"; then
114     cat $AM_DIR/programs-vars.am >&4
115     cat $AM_DIR/programs.am >&5
116     for am_prog in $PROGRAMS; do
117       sed "s/@PROGRAM@/$am_prog/g" $AM_DIR/program.am >&5
118     done
119   fi
120
121   if test -n "$LIBRARIES"; then
122     echo "LIBFILES = " `echo "$LIBRARIES"|sed 's/\([a-zA-Z0-9_][a-zA-Z0-9_]*\)/lib\1.a/g'` >&4
123     cat $AM_DIR/libraries-vars.am >&4
124     cat $AM_DIR/libraries.am >&5
125     for am_lib in $LIBRARIES; do
126       sed "s/@LIBRARY@/$am_lib/g" $AM_DIR/library.am >&5
127     done
128   fi
129
130   if test -n "$TEXINFOS"; then
131     cat $AM_DIR/texinfos-vars.am >&4
132     cat $AM_DIR/texinfos.am >&5
133     echo "$TEXINFOS" | sed 's/^/INFOS = /; s/\.texi/.info/g' >&4
134     echo "$TEXINFOS" | sed 's/^/DVIS = /; s/\.texi/.dvi/g' >&4
135   fi
136
137   if test -n "$MANS"; then
138     cat $AM_DIR/mans-vars.am >&4
139     cat $AM_DIR/mans.am >&5
140   fi
141
142   case "$SUBDIRS" in
143   "") cat $AM_DIR/clean.am >&5 ;;
144   *) cat $AM_DIR/subdirs.am >&5 ;;
145   esac
146
147   case "$am_makefile" in
148   */*) cat $AM_DIR/remake-subd.am >&5 ;;
149   *) test -f aclocal.m4 && echo "ACLOCAL = aclocal.m4" >&4
150   cat $AM_DIR/remake.am >&5 ;;
151   esac
152
153   case "$CONFIG_HEADER" in
154   "") ;;
155   */*) ;; # It's in some other directory, so don't remake it in this one.
156   *)
157     test -f acconfig.h && echo "ACCONFIG = acconfig.h" >&4
158     test -f config.h.top && echo "CONFIG_TOP = config.h.top" >&4
159     test -f config.h.bot && echo "CONFIG_BOT = config.h.bot" >&4
160     cat $AM_DIR/remake-hdr.am >&5 ;;
161   esac
162
163   echo "SOURCES = $SOURCES" >&4
164
165   case "$am_makefile" in
166   */*) 
167      cat $AM_DIR/dist-subd-vars.am >&4
168      cat $AM_DIR/dist-subd.am >&5 ;;
169   *) test "$target_distname" != explicit && cat $AM_DIR/distname.am >&5
170      cat $AM_DIR/dist-vars.am >&4
171      cat $AM_DIR/dist.am >&5 ;;
172   esac
173
174   cat $AM_DIR/footer.am >&5
175
176 #  if test -n "$SOURCES"; then
177 #    echo "# Dependencies generated automatically by mkdep:" >&5
178 #    mkdep -a -f ${am_makefile}.in $DEFS $INCLUDES $CPPFLAGS $CFLAGS $SOURCES
179 #  fi
180
181   sed '/^ *\([a-zA-Z_.][a-zA-Z0-9_.]*\):.*/,$d' ${am_makefile}.am >> ${am_makefile}.vars
182   sed -n '/^ *\([a-zA-Z_.][a-zA-Z0-9_.]*\):.*/,$p' ${am_makefile}.am >> ${am_makefile}.rules
183   cat ${am_makefile}.vars ${am_makefile}.rules > ${am_makefile}.in
184   rm -f ${am_makefile}.vars ${am_makefile}.rules
185
186 done
187
188 exit $am_status