xref: /xnu-12377.1.9/SETUP/config/doconf (revision f6217f891ac0bb64f3d375211650a4c1ff8ca1ea)
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	default:
161	    echo "${prog}: ${argv[1]}: unknown switch"
162	    exit 1
163	    breaksw
164	endsw
165	shift
166    else
167	break
168    endif
169end
170
171if ($#argv == 0) set argv=(GENERIC)
172
173if (! $?MACHINE) then
174    echo "${prog}: MACHINE not set"
175    exit 1
176endif
177
178set cpu=`echo $MACHINE | tr A-Z a-z`
179set ID=`echo $MACHINE | tr a-z A-Z`
180set MASTER_DIR=${MASTER_CONF_DIR}
181set MASTER =   ${MASTER_DIR}/MASTER
182
183foreach master_file (${MASTER}.${cpu}.${SOC_CONFIG}.${PLATFORM} ${MASTER}.${cpu}.${SOC_CONFIG} ${MASTER}.${cpu}.${PLATFORM} ${MASTER}.${cpu})
184    if (-f $master_file) then
185        set MASTER_CPU = $master_file
186        break
187    endif
188end
189
190if ($?beverbose) then
191    echo MASTER_CPU=$MASTER_CPU
192endif
193
194foreach SYS ($argv)
195    set SYSID=${SYS}_${ID}
196    set SYSCONF=$OBJDIR/config.$SYSID
197    set BLDDIR=$OBJDIR
198    if ($?beverbose) then
199        echo "[ generating $SYSID from $MASTER_DIR/MASTER{,.$cpu}{,.local} ]"
200    endif
201    echo +$SYS \
202    | \
203    cat $MASTER $MASTER_CPU - \
204        $MASTER $MASTER_CPU \
205    | \
206    unifdef -t -DPLATFORM_${PLATFORM} -DCPU_$cpu -DSOC_CONFIG_${SOC_CONFIG} -DSYS_${SYS} $DEF_AVP $DEF_SEED $DEF_EXCLAVES $DEF_SPTM $DEF_BUILD $DEF_TAG - \
207    | \
208    sed -n \
209	-e "/^+/{" \
210	   -e "s;[-+];#&;gp" \
211	      -e 't loop' \
212	   -e ': loop' \
213           -e 'n' \
214	   -e '/^#/b loop' \
215	   -e '/^$/b loop' \
216	   -e 's;^\([^#]*\).*#[ 	]*<\(.*\)>[ 	]*$;\2#\1;' \
217	      -e 't not' \
218	   -e 's;\([^#]*\).*;#\1;' \
219	      -e 't not' \
220	   -e ': not' \
221	   -e 's;[ 	]*$;;' \
222	   -e 's;^\!\(.*\);\1#\!;' \
223	   -e 'p' \
224	      -e 't loop' \
225           -e 'b loop' \
226	-e '}' \
227	-e "/^[^#]/d" \
228	-e 's;	; ;g' \
229	-e "s;^# *\([^ ]*\)[ ]*=[ ]*\[\(.*\)\].*;\1#\2;p" \
230    | \
231    awk '-F#' '\
232part == 0 && $1 != "" {\
233	m[$1]=m[$1] " " $2;\
234	next;\
235}\
236part == 0 && $1 == "" {\
237	for (i=NF;i>1;i--){\
238		s=substr($i,2);\
239		c[++na]=substr($i,1,1);\
240		a[na]=s;\
241	}\
242	while (na > 0){\
243		s=a[na];\
244		d=c[na--];\
245		if (m[s] == "") {\
246			f[s]=d;\
247		} else {\
248			nx=split(m[s],x," ");\
249			for (j=nx;j>0;j--) {\
250				z=x[j];\
251				a[++na]=z;\
252				c[na]=d;\
253			}\
254		}\
255	}\
256	part=1;\
257	next;\
258}\
259part != 0 {\
260	if ($1 != "") {\
261		n=split($1,x,",");\
262		ok=0;\
263		for (i=1;i<=n;i++) {\
264			if (f[x[i]] == "+") {\
265				ok=1;\
266			}\
267		}\
268		if (NF > 2 && ok == 0 || NF <= 2 && ok != 0) {\
269			print $2; \
270		}\
271	} else { \
272		print $2; \
273	}\
274}\
275' >$SYSCONF.new
276    if (-z $SYSCONF.new) then
277	echo "${prog}: ${$SYSID}: no such configuration in $MASTER_DIR/MASTER{,.$cpu}"
278	rm -f $SYSCONF.new
279    endif
280#
281# These paths are used by config.
282#
283# "builddir" is the name of the directory where kernel binaries
284# are put.  It is a single path element, never absolute, and is
285# always relative to "objectdir".  "builddir" is used by config
286# solely to determine where to put files created by "config" (e.g.
287# the created Makefile and *.h's.)
288#
289# "objectdir" is the name of the directory which will hold "builddir".
290# It is a path; if relative, it is relative to the current directory
291# where config is run.  It's sole use is to be prepended to "builddir"
292# to indicate where config-created files are to be placed (see above).
293#
294# "sourcedir" is the location of the sources used to build the kernel.
295# It is a path; if relative, it is relative to the directory specified
296# by the concatenation of "objectdir" and "builddir" (i.e. where the
297# kernel binaries are put).
298#
299    echo 'builddir	"."'			>> $SYSCONF.new
300    echo 'objectdir	"'$OBJDIR'"'		>> $SYSCONF.new
301    set SRCDIR=`dirname $SOURCE`
302    echo 'sourcedir	"'$SRCROOT'"'		>> $SYSCONF.new
303    if (-f $SYSCONF) then
304	diff $SYSCONF $SYSCONF.new
305	rm -f $SYSCONF.old
306	mv $SYSCONF $SYSCONF.old
307    endif
308    rm -f $SYSCONF
309    mv $SYSCONF.new $SYSCONF
310    if ($?doconfig) then
311        if ($?beverbose) then
312	    echo "[ configuring $SYSID ]"
313        endif
314	if ($?profile) then
315	    $CONFIG_DIR/config -c $SOURCEDIR -p $SYSCONF
316	else
317	    $CONFIG_DIR/config -c $SOURCEDIR $SYSCONF
318	endif
319    endif
320end
321