xref: /xnu-8020.140.41/SETUP/config/doconf (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
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 SOURCEDIR=.
73set CONFIG_DIR=$OBJROOT/SETUP/config
74set MASTER_CONF_DIR=.
75
76unset doconfig
77unset beverbose
78unset MACHINE
79unset profile
80unset SOC_CONFIG
81unset PLATFORM
82
83while ($#argv >= 1)
84    if ("$argv[1]" =~ -*) then
85        switch ("$argv[1]")
86	case "-c":
87	case "-config":
88	    set doconfig
89	    breaksw
90	case "-cpu":
91	    if ($#argv < 2) then
92		echo "${prog}: missing argument to ${argv[1]}"
93		exit 1
94	    endif
95	    set MACHINE="$argv[2]"
96	    shift
97	    breaksw
98	case "-soc":
99	    if ($#argv < 2) then
100		echo "${prog}: missing argument to ${argv[1]}"
101		exit 1
102	    endif
103	    set SOC_CONFIG="$argv[2]"
104	    if (`echo $SOC_CONFIG | awk '{print substr($0,0,2)}'` == "vm") then
105	    set DEF_AVP="-DSOC_IS_VIRTUALIZED"
106	    else
107	    set DEF_AVP=""
108	    endif
109	    shift
110	    breaksw
111	case "-platform":
112	    if ($#argv < 2) then
113		echo "${prog}: missing argument to ${argv[1]}"
114		exit 1
115	    endif
116	    set PLATFORM="$argv[2]"
117	    shift
118	    breaksw
119	case "-d":
120	    if ($#argv < 2) then
121		echo "${prog}: missing argument to ${argv[1]}"
122		exit 1
123	    endif
124	    set OBJDIR="$argv[2]"
125	    shift
126	    breaksw
127	case "-m":
128	    if ($#argv < 2) then
129		echo "${prog}: missing argument to ${argv[1]}"
130		exit 1
131	    endif
132	    set MASTER_CONF_DIR="$argv[2]"
133	    shift
134	    breaksw
135	case "-s":
136	    if ($#argv < 2) then
137		echo "${prog}: missing argument to ${argv[1]}"
138		exit 1
139	    endif
140	    set SOURCEDIR="$argv[2]"
141	    shift
142	    breaksw
143	case "-verbose":
144	    set beverbose
145	    breaksw
146	case "-p":
147	case "-profile":
148	    set profile
149	    breaksw
150	default:
151	    echo "${prog}: ${argv[1]}: unknown switch"
152	    exit 1
153	    breaksw
154	endsw
155	shift
156    else
157	break
158    endif
159end
160
161if ($#argv == 0) set argv=(GENERIC)
162
163if (! $?MACHINE) then
164    echo "${prog}: MACHINE not set"
165    exit 1
166endif
167
168set cpu=`echo $MACHINE | tr A-Z a-z`
169set ID=`echo $MACHINE | tr a-z A-Z`
170set MASTER_DIR=${MASTER_CONF_DIR}
171set MASTER =   ${MASTER_DIR}/MASTER
172
173foreach master_file (${MASTER}.${cpu}.${SOC_CONFIG}.${PLATFORM} ${MASTER}.${cpu}.${SOC_CONFIG} ${MASTER}.${cpu}.${PLATFORM} ${MASTER}.${cpu})
174    if (-f $master_file) then
175        set MASTER_CPU = $master_file
176        break
177    endif
178end
179
180if ($?beverbose) then
181    echo MASTER_CPU=$MASTER_CPU
182endif
183
184foreach SYS ($argv)
185    set SYSID=${SYS}_${ID}
186    set SYSCONF=$OBJDIR/config.$SYSID
187    set BLDDIR=$OBJDIR
188    if ($?beverbose) then
189        echo "[ generating $SYSID from $MASTER_DIR/MASTER{,.$cpu}{,.local} ]"
190    endif
191    echo +$SYS \
192    | \
193    cat $MASTER $MASTER_CPU - \
194        $MASTER $MASTER_CPU \
195    | \
196    unifdef -t -DPLATFORM_${PLATFORM} -DCPU_$cpu -DSOC_CONFIG_${SOC_CONFIG} -DSYS_${SYS} $DEF_AVP - \
197    | \
198    sed -n \
199	-e "/^+/{" \
200	   -e "s;[-+];#&;gp" \
201	      -e 't loop' \
202	   -e ': loop' \
203           -e 'n' \
204	   -e '/^#/b loop' \
205	   -e '/^$/b loop' \
206	   -e 's;^\([^#]*\).*#[ 	]*<\(.*\)>[ 	]*$;\2#\1;' \
207	      -e 't not' \
208	   -e 's;\([^#]*\).*;#\1;' \
209	      -e 't not' \
210	   -e ': not' \
211	   -e 's;[ 	]*$;;' \
212	   -e 's;^\!\(.*\);\1#\!;' \
213	   -e 'p' \
214	      -e 't loop' \
215           -e 'b loop' \
216	-e '}' \
217	-e "/^[^#]/d" \
218	-e 's;	; ;g' \
219	-e "s;^# *\([^ ]*\)[ ]*=[ ]*\[\(.*\)\].*;\1#\2;p" \
220    | \
221    awk '-F#' '\
222part == 0 && $1 != "" {\
223	m[$1]=m[$1] " " $2;\
224	next;\
225}\
226part == 0 && $1 == "" {\
227	for (i=NF;i>1;i--){\
228		s=substr($i,2);\
229		c[++na]=substr($i,1,1);\
230		a[na]=s;\
231	}\
232	while (na > 0){\
233		s=a[na];\
234		d=c[na--];\
235		if (m[s] == "") {\
236			f[s]=d;\
237		} else {\
238			nx=split(m[s],x," ");\
239			for (j=nx;j>0;j--) {\
240				z=x[j];\
241				a[++na]=z;\
242				c[na]=d;\
243			}\
244		}\
245	}\
246	part=1;\
247	next;\
248}\
249part != 0 {\
250	if ($1 != "") {\
251		n=split($1,x,",");\
252		ok=0;\
253		for (i=1;i<=n;i++) {\
254			if (f[x[i]] == "+") {\
255				ok=1;\
256			}\
257		}\
258		if (NF > 2 && ok == 0 || NF <= 2 && ok != 0) {\
259			print $2; \
260		}\
261	} else { \
262		print $2; \
263	}\
264}\
265' >$SYSCONF.new
266    if (-z $SYSCONF.new) then
267	echo "${prog}: ${$SYSID}: no such configuration in $MASTER_DIR/MASTER{,.$cpu}"
268	rm -f $SYSCONF.new
269    endif
270#
271# These paths are used by config.
272#
273# "builddir" is the name of the directory where kernel binaries
274# are put.  It is a single path element, never absolute, and is
275# always relative to "objectdir".  "builddir" is used by config
276# solely to determine where to put files created by "config" (e.g.
277# the created Makefile and *.h's.)
278#
279# "objectdir" is the name of the directory which will hold "builddir".
280# It is a path; if relative, it is relative to the current directory
281# where config is run.  It's sole use is to be prepended to "builddir"
282# to indicate where config-created files are to be placed (see above).
283#
284# "sourcedir" is the location of the sources used to build the kernel.
285# It is a path; if relative, it is relative to the directory specified
286# by the concatenation of "objectdir" and "builddir" (i.e. where the
287# kernel binaries are put).
288#
289    echo 'builddir	"."'			>> $SYSCONF.new
290    echo 'objectdir	"'$OBJDIR'"'		>> $SYSCONF.new
291    set SRCDIR=`dirname $SOURCE`
292    echo 'sourcedir	"'$SRCROOT'"'		>> $SYSCONF.new
293    if (-f $SYSCONF) then
294	diff $SYSCONF $SYSCONF.new
295	rm -f $SYSCONF.old
296	mv $SYSCONF $SYSCONF.old
297    endif
298    rm -f $SYSCONF
299    mv $SYSCONF.new $SYSCONF
300    if ($?doconfig) then
301        if ($?beverbose) then
302	    echo "[ configuring $SYSID ]"
303        endif
304	if ($?profile) then
305	    $CONFIG_DIR/config -c $SOURCEDIR -p $SYSCONF
306	else
307	    $CONFIG_DIR/config -c $SOURCEDIR $SYSCONF
308	endif
309    endif
310end
311