1#!/bin/csh -f
2set path = ($path .)
3######################################################################
4# HISTORY
5#  1-Dec-87  Michael Young (mwyoung) at Carnegie-Mellon University
6#	Added "-verbose" switch, so this script produces no output
7#	in the normal case.
8#
9# 10-Oct-87  Mike Accetta (mja) at Carnegie-Mellon University
10#	Flushed cmu_*.h and spin_locks.h
11#	[ V5.1(XF18) ]
12#
13#  6-Apr-87  Avadis Tevanian (avie) at Carnegie-Mellon University
14#	Use MASTER.local and MASTER.<machine>.local for generation of
15#	configuration files in addition to MASTER and MASTER.<machine>.
16#
17# 25-Mar-87  Mike Accetta (mja) at Carnegie-Mellon University
18#	Removed use of obsolete wb_*.h files when building the feature
19#	list;  modified to save the previous configuration file and
20#	display the differences between it and the new file.
21#	[ V5.1(F8) ]
22#
23# 25-Mar-87  Avadis Tevanian (avie) at Carnegie-Mellon University
24#	If there is no /etc/machine just print out a message telling
25#	user to use the -cpu option.  I thought this script was supposed
26#	to work even without a /etc/machine, but it doesn't... and this
27#	is the easiest way out.
28#
29# 13-Mar-87  Mike Accetta (mja) at Carnegie-Mellon University
30#	Added "romp_fpa.h" file to extra features for the RT.
31#	[ V5.1(F7) ]
32#
33# 11-Mar-87  Mike Accetta (mja) at Carnegie-Mellon University
34#	Updated to maintain the appropriate configuration features file
35#	in the "machine" directory whenever the corresponding
36#	configuration is generated.  This replaces the old mechanism of
37#	storing this directly in the <sys/features.h> file since it was
38#	machine dependent and also precluded building programs for more
39#	than one configuration from the same set of sources.
40#	[ V5.1(F6) ]
41#
42# 21-Feb-87  Mike Accetta (mja) at Carnegie-Mellon University
43#	Fixed to require wired-in cpu type names for only those
44#	machines where the kernel name differs from that provided by
45#	/etc/machine (i.e. IBMRT => ca and SUN => sun3);  updated to
46#	permit configuration descriptions in both machine indepedent
47#	and dependent master configuration files so that attributes can
48#	be grouped accordingly.
49#	[ V5.1(F3) ]
50#
51# 17-Jan-87  Mike Accetta (mja) at Carnegie-Mellon University
52#	Updated to work from any directory at the same level as
53#	"conf"; generate configuration from both MASTER and
54#	MASTER.<machine-type> files; added -cpu switch.
55#	[ V5.1(F1) ]
56#
57# 18-Aug-86  Mike Accetta (mja) at Carnegie-Mellon University
58#	Added -make switch and changed meaning of -config;  upgraded to
59#	allow multiple attributes per configuration and to define
60#	configurations in terms of these attributes within MASTER.
61#
62# 14-Apr-83  Mike Accetta (mja) at Carnegie-Mellon University
63#	Added -config switch to only run /etc/config without 
64#	"make depend" and "make".
65#
66######################################################################
67
68set prog=$0
69set prog=$prog:t
70set nonomatch
71set OBJDIR=../BUILD
72set CONFIG_DIR=$OBJROOT/SETUP/config
73
74unset domake
75unset doconfig
76unset beverbose
77unset MACHINE
78unset profile
79unset SOC_CONFIG
80
81while ($#argv >= 1)
82    if ("$argv[1]" =~ -*) then
83        switch ("$argv[1]")
84	case "-c":
85	case "-config":
86	    set doconfig
87	    breaksw
88	case "-m":
89	case "-make":
90	    set domake
91	    breaksw
92	case "-cpu":
93	    if ($#argv < 2) then
94		echo "${prog}: missing argument to ${argv[1]}"
95		exit 1
96	    endif
97	    set MACHINE="$argv[2]"
98	    shift
99	    breaksw
100	case "-soc":
101	    if ($#argv < 2) then
102		echo "${prog}: missing argument to ${argv[1]}"
103		exit 1
104	    endif
105	    set SOC_CONFIG="$argv[2]"
106	    shift
107	    breaksw
108	case "-d":
109	    if ($#argv < 2) then
110		echo "${prog}: missing argument to ${argv[1]}"
111		exit 1
112	    endif
113	    set OBJDIR="$argv[2]"
114	    shift
115	    breaksw
116	case "-verbose":
117	    set beverbose
118	    breaksw
119	case "-p":
120	case "-profile":
121	    set profile
122	    breaksw
123	default:
124	    echo "${prog}: ${argv[1]}: unknown switch"
125	    exit 1
126	    breaksw
127	endsw
128	shift
129    else
130	break
131    endif
132end
133
134if ($#argv == 0) set argv=(GENERIC)
135
136if (! $?MACHINE) then
137    if (-d /NextApps) then
138	set MACHINE=`hostinfo | awk '/MC680x0/ { printf("m68k") } /MC880x0/ { printf("m88k") }'`
139    endif
140endif
141
142if (! $?MACHINE) then
143    if (-f /etc/machine) then
144	    set MACHINE="`/etc/machine`"
145    else
146	    echo "${prog}: no /etc/machine, specify machine type with -cpu"
147	    echo "${prog}: e.g. ${prog} -cpu VAX CONFIGURATION"
148	    exit 1
149    endif
150endif
151
152set FEATURES_EXTRA=
153
154switch ("$MACHINE")
155    case IBMRT:
156	set cpu=ca
157	set ID=RT
158	set FEATURES_EXTRA="romp_dualcall.h romp_fpa.h"
159	breaksw
160    case SUN:
161	set cpu=sun3
162	set ID=SUN3
163	breaksw
164    default:
165	set cpu=`echo $MACHINE | tr A-Z a-z`
166	set ID=`echo $MACHINE | tr a-z A-Z`
167	breaksw
168endsw
169set FEATURES=../h/features.h
170set FEATURES_H=(cs_*.h mach_*.h net_*.h\
171	        cputypes.h cpus.h vice.h\
172	        $FEATURES_EXTRA)
173set MASTER_DIR=../conf
174set MASTER =   ${MASTER_DIR}/MASTER
175set MASTER_CPU=${MASTER}.${cpu}
176set MASTER_CPU_PER_SOC=${MASTER}.${cpu}.${SOC_CONFIG}
177if (-f $MASTER_CPU_PER_SOC) set MASTER_CPU = ${MASTER_CPU_PER_SOC}
178
179set MASTER_LOCAL = ${MASTER}.local
180set MASTER_CPU_LOCAL = ${MASTER_CPU}.local
181set MASTER_CPU_PER_SOC_LOCAL = ${MASTER_CPU_PER_SOC}.local
182if (! -f $MASTER_LOCAL) set MASTER_LOCAL = ""
183if (! -f $MASTER_CPU_LOCAL) set MASTER_CPU_LOCAL = ""
184if (-f $MASTER_CPU_PER_SOC_LOCAL) set MASTER_CPU_LOCAL = ${MASTER_CPU_PER_SOC_LOCAL}
185
186if (! -d $OBJDIR) then
187    if ($?beverbose) then
188        echo "[ creating $OBJDIR ]"
189    endif
190    mkdir -p $OBJDIR
191endif
192
193foreach SYS ($argv)
194    set SYSID=${SYS}_${ID}
195    set SYSCONF=$OBJDIR/config.$SYSID
196    set BLDDIR=$OBJDIR
197    if ($?beverbose) then
198	echo "[ generating $SYSID from $MASTER_DIR/MASTER{,.$cpu}{,.local} ]"
199    endif
200    echo +$SYS \
201    | \
202    cat $MASTER $MASTER_LOCAL $MASTER_CPU $MASTER_CPU_LOCAL - \
203        $MASTER $MASTER_LOCAL $MASTER_CPU $MASTER_CPU_LOCAL \
204    | \
205    sed -n \
206	-e "/^+/{" \
207	   -e "s;[-+];#&;gp" \
208	      -e 't loop' \
209	   -e ': loop' \
210           -e 'n' \
211	   -e '/^#/b loop' \
212	   -e '/^$/b loop' \
213	   -e 's;^\([^#]*\).*#[ 	]*<\(.*\)>[ 	]*$;\2#\1;' \
214	      -e 't not' \
215	   -e 's;\([^#]*\).*;#\1;' \
216	      -e 't not' \
217	   -e ': not' \
218	   -e 's;[ 	]*$;;' \
219	   -e 's;^\!\(.*\);\1#\!;' \
220	   -e 'p' \
221	      -e 't loop' \
222           -e 'b loop' \
223	-e '}' \
224	-e "/^[^#]/d" \
225	-e 's;	; ;g' \
226	-e "s;^# *\([^ ]*\)[ ]*=[ ]*\[\(.*\)\].*;\1#\2;p" \
227    | \
228    awk '-F#' '\
229part == 0 && $1 != "" {\
230	m[$1]=m[$1] " " $2;\
231	next;\
232}\
233part == 0 && $1 == "" {\
234	for (i=NF;i>1;i--){\
235		s=substr($i,2);\
236		c[++na]=substr($i,1,1);\
237		a[na]=s;\
238	}\
239	while (na > 0){\
240		s=a[na];\
241		d=c[na--];\
242		if (m[s] == "") {\
243			f[s]=d;\
244		} else {\
245			nx=split(m[s],x," ");\
246			for (j=nx;j>0;j--) {\
247				z=x[j];\
248				a[++na]=z;\
249				c[na]=d;\
250			}\
251		}\
252	}\
253	part=1;\
254	next;\
255}\
256part != 0 {\
257	if ($1 != "") {\
258		n=split($1,x,",");\
259		ok=0;\
260		for (i=1;i<=n;i++) {\
261			if (f[x[i]] == "+") {\
262				ok=1;\
263			}\
264		}\
265		if (NF > 2 && ok == 0 || NF <= 2 && ok != 0) {\
266			print $2; \
267		}\
268	} else { \
269		print $2; \
270	}\
271}\
272' >$SYSCONF.new
273    if (-z $SYSCONF.new) then
274	echo "${prog}: ${$SYSID}: no such configuration in $MASTER_DIR/MASTER{,.$cpu}"
275	rm -f $SYSCONF.new
276    endif
277    if (! -d $BLDDIR) then
278        if ($?beverbose) then
279	    echo "[ creating $BLDDIR ]"
280        endif
281	mkdir -p $BLDDIR
282    endif
283#
284# These paths are used by config.
285#
286# "builddir" is the name of the directory where kernel binaries
287# are put.  It is a single path element, never absolute, and is
288# always relative to "objectdir".  "builddir" is used by config
289# solely to determine where to put files created by "config" (e.g.
290# the created Makefile and *.h's.)
291#
292# "objectdir" is the name of the directory which will hold "builddir".
293# It is a path; if relative, it is relative to the current directory
294# where config is run.  It's sole use is to be prepended to "builddir"
295# to indicate where config-created files are to be placed (see above).
296#
297# "sourcedir" is the location of the sources used to build the kernel.
298# It is a path; if relative, it is relative to the directory specified
299# by the concatenation of "objectdir" and "builddir" (i.e. where the
300# kernel binaries are put).
301#
302    echo 'builddir	"."'			>> $SYSCONF.new
303    echo 'objectdir	"'$OBJDIR'"'		>> $SYSCONF.new
304    set SRCDIR=`dirname $SOURCE`
305    echo 'sourcedir	"'$SRCROOT'"'		>> $SYSCONF.new
306    if (-f $SYSCONF) then
307	diff $SYSCONF $SYSCONF.new
308	rm -f $SYSCONF.old
309	mv $SYSCONF $SYSCONF.old
310    endif
311    rm -f $SYSCONF
312    mv $SYSCONF.new $SYSCONF
313    if ($?doconfig) then
314        if ($?beverbose) then
315	    echo "[ configuring $SYSID ]"
316        endif
317	if ($?profile) then
318	    $CONFIG_DIR/config -c $MASTER_DIR -p $SYSCONF
319	else
320	    $CONFIG_DIR/config -c $MASTER_DIR $SYSCONF
321	endif
322    endif
323    if ($?domake) then
324        if ($?beverbose) then
325            echo "[ making $SYSID ]"
326        endif
327        (cd $BLDDIR; make)
328    endif
329end
330