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