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