]> git.saurik.com Git - apple/xnu.git/blob - libkern/conf/tools/doconf/doconf.csh
xnu-1504.15.3.tar.gz
[apple/xnu.git] / libkern / conf / tools / doconf / doconf.csh
1 #!/bin/csh -f
2 set 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
68 set prog=$0
69 set prog=$prog:t
70 set nonomatch
71 set OBJDIR=../BUILD
72 if ("`/usr/bin/uname`" == "Rhapsody" ) then
73 set CONFIG_DIR=/usr/local/bin
74 else
75 set CONFIG_DIR=/usr/bin
76 endif
77
78 unset domake
79 unset doconfig
80 unset beverbose
81 unset MACHINE
82 unset profile
83
84 while ($#argv >= 1)
85 if ("$argv[1]" =~ -*) then
86 switch ("$argv[1]")
87 case "-c":
88 case "-config":
89 set doconfig
90 breaksw
91 case "-m":
92 case "-make":
93 set domake
94 breaksw
95 case "-cpu":
96 if ($#argv < 2) then
97 echo "${prog}: missing argument to ${argv[1]}"
98 exit 1
99 endif
100 set MACHINE="$argv[2]"
101 shift
102 breaksw
103 case "-d":
104 if ($#argv < 2) then
105 echo "${prog}: missing argument to ${argv[1]}"
106 exit 1
107 endif
108 set OBJDIR="$argv[2]"
109 shift
110 breaksw
111 case "-verbose":
112 set beverbose
113 breaksw
114 case "-p":
115 case "-profile":
116 set profile
117 breaksw
118 default:
119 echo "${prog}: ${argv[1]}: unknown switch"
120 exit 1
121 breaksw
122 endsw
123 shift
124 else
125 break
126 endif
127 end
128
129 if ($#argv == 0) set argv=(GENERIC)
130
131 if (! $?MACHINE) then
132 if (-d /NextApps) then
133 set MACHINE=`hostinfo | awk '/MC680x0/ { printf("m68k") } /MC880x0/ { printf("m88k") }'`
134 endif
135 endif
136
137 if (! $?MACHINE) then
138 if (-f /etc/machine) then
139 set MACHINE="`/etc/machine`"
140 else
141 echo "${prog}: no /etc/machine, specify machine type with -cpu"
142 echo "${prog}: e.g. ${prog} -cpu VAX CONFIGURATION"
143 exit 1
144 endif
145 endif
146
147 set FEATURES_EXTRA=
148
149 switch ("$MACHINE")
150 case IBMRT:
151 set cpu=ca
152 set ID=RT
153 set FEATURES_EXTRA="romp_dualcall.h romp_fpa.h"
154 breaksw
155 case SUN:
156 set cpu=sun3
157 set ID=SUN3
158 breaksw
159 default:
160 set cpu=`echo $MACHINE | tr A-Z a-z`
161 set ID=`echo $MACHINE | tr a-z A-Z`
162 breaksw
163 endsw
164 set FEATURES=../h/features.h
165 set FEATURES_H=(cs_*.h mach_*.h net_*.h\
166 cputypes.h cpus.h vice.h\
167 $FEATURES_EXTRA)
168 set MASTER_DIR=../conf
169 set MASTER = ${MASTER_DIR}/MASTER
170 set MASTER_CPU=${MASTER}.${cpu}
171
172 set MASTER_LOCAL = ${MASTER}.local
173 set MASTER_CPU_LOCAL = ${MASTER_CPU}.local
174 if (! -f $MASTER_LOCAL) set MASTER_LOCAL = ""
175 if (! -f $MASTER_CPU_LOCAL) set MASTER_CPU_LOCAL = ""
176
177 if (! -d $OBJDIR) then
178 if ($?beverbose) then
179 echo "[ creating $OBJDIR ]"
180 endif
181 mkdir -p $OBJDIR
182 endif
183
184 foreach 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_LOCAL $MASTER_CPU $MASTER_CPU_LOCAL - \
194 $MASTER $MASTER_LOCAL $MASTER_CPU $MASTER_CPU_LOCAL \
195 | \
196 sed -n \
197 -e "/^+/{" \
198 -e "s;[-+];#&;gp" \
199 -e 't loop' \
200 -e ': loop' \
201 -e 'n' \
202 -e '/^#/b loop' \
203 -e '/^$/b loop' \
204 -e 's;^\([^#]*\).*#[ ]*<\(.*\)>[ ]*$;\2#\1;' \
205 -e 't not' \
206 -e 's;\([^#]*\).*;#\1;' \
207 -e 't not' \
208 -e ': not' \
209 -e 's;[ ]*$;;' \
210 -e 's;^\!\(.*\);\1#\!;' \
211 -e 'p' \
212 -e 't loop' \
213 -e 'b loop' \
214 -e '}' \
215 -e "/^[^#]/d" \
216 -e 's; ; ;g' \
217 -e "s;^# *\([^ ]*\)[ ]*=[ ]*\[\(.*\)\].*;\1#\2;p" \
218 | \
219 awk '-F#' '\
220 part == 0 && $1 != "" {\
221 m[$1]=m[$1] " " $2;\
222 next;\
223 }\
224 part == 0 && $1 == "" {\
225 for (i=NF;i>1;i--){\
226 s=substr($i,2);\
227 c[++na]=substr($i,1,1);\
228 a[na]=s;\
229 }\
230 while (na > 0){\
231 s=a[na];\
232 d=c[na--];\
233 if (m[s] == "") {\
234 f[s]=d;\
235 } else {\
236 nx=split(m[s],x," ");\
237 for (j=nx;j>0;j--) {\
238 z=x[j];\
239 a[++na]=z;\
240 c[na]=d;\
241 }\
242 }\
243 }\
244 part=1;\
245 next;\
246 }\
247 part != 0 {\
248 if ($1 != "") {\
249 n=split($1,x,",");\
250 ok=0;\
251 for (i=1;i<=n;i++) {\
252 if (f[x[i]] == "+") {\
253 ok=1;\
254 }\
255 }\
256 if (NF > 2 && ok == 0 || NF <= 2 && ok != 0) {\
257 print $2; \
258 }\
259 } else { \
260 print $2; \
261 }\
262 }\
263 ' >$SYSCONF.new
264 if (-z $SYSCONF.new) then
265 echo "${prog}: ${$SYSID}: no such configuration in $MASTER_DIR/MASTER{,.$cpu}"
266 rm -f $SYSCONF.new
267 endif
268 if (! -d $BLDDIR) then
269 if ($?beverbose) then
270 echo "[ creating $BLDDIR ]"
271 endif
272 mkdir -p $BLDDIR
273 endif
274 #
275 # These paths are used by config.
276 #
277 # "builddir" is the name of the directory where kernel binaries
278 # are put. It is a single path element, never absolute, and is
279 # always relative to "objectdir". "builddir" is used by config
280 # solely to determine where to put files created by "config" (e.g.
281 # the created Makefile and *.h's.)
282 #
283 # "objectdir" is the name of the directory which will hold "builddir".
284 # It is a path; if relative, it is relative to the current directory
285 # where config is run. It's sole use is to be prepended to "builddir"
286 # to indicate where config-created files are to be placed (see above).
287 #
288 # "sourcedir" is the location of the sources used to build the kernel.
289 # It is a path; if relative, it is relative to the directory specified
290 # by the concatenation of "objectdir" and "builddir" (i.e. where the
291 # kernel binaries are put).
292 #
293 echo 'builddir "."' >> $SYSCONF.new
294 set OBJRELDIR=`$RELPATH $OBJROOT $OBJDIR`
295 echo 'objectdir "'$OBJROOT'/'$OBJRELDIR'"' >> $SYSCONF.new
296 set SRCDIR=`dirname $SOURCE`
297 echo 'sourcedir "'$SRCROOT'"' >> $SYSCONF.new
298 if (-f $SYSCONF) then
299 diff $SYSCONF $SYSCONF.new
300 rm -f $SYSCONF.old
301 mv $SYSCONF $SYSCONF.old
302 endif
303 rm -f $SYSCONF
304 mv $SYSCONF.new $SYSCONF
305 if ($?doconfig) then
306 if ($?beverbose) then
307 echo "[ configuring $SYSID ]"
308 endif
309 if ($?profile) then
310 $CONFIG_DIR/config -c $MASTER_DIR -p $SYSCONF
311 else
312 $CONFIG_DIR/config -c $MASTER_DIR $SYSCONF
313 endif
314 endif
315 if ($?domake) then
316 if ($?beverbose) then
317 echo "[ making $SYSID ]"
318 endif
319 (cd $BLDDIR; make)
320 endif
321 end