MAKEDEV.awk revision 1.2 1 #!/usr/bin/awk -
2 #
3 # $NetBSD: MAKEDEV.awk,v 1.2 2003/10/15 19:43:00 jdolecek Exp $
4 #
5 # Copyright (c) 2003 The NetBSD Foundation, Inc.
6 # All rights reserved.
7 #
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Jaromir Dolecek.
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # 3. All advertising materials mentioning features or use of this software
20 # must display the following acknowledgement:
21 # This product includes software developed by the NetBSD
22 # Foundation, Inc. and its contributors.
23 # 4. Neither the name of The NetBSD Foundation nor the names of its
24 # contributors may be used to endorse or promote products derived
25 # from this software without specific prior written permission.
26 #
27 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 # POSSIBILITY OF SUCH DAMAGE.
38 #
39
40 # Script to generate platform MAKEDEV script from MI template, MD
41 # MAKEDEV.conf and MD/MI major lists
42 #
43 # Uses environment variables MACHINE/MACHINE_ARCH to select
44 # appropriate files, and NETBSDSRCDIR to get root of source tree.
45
46 BEGIN {
47 # top of source tree, used to find major number list in kernel
48 # sources
49 top = ENVIRON["NETBSDSRCDIR"]
50 if (!top)
51 top = ".."
52 top = top "/sys/"
53 if (system("test -d '" top "'") != 0) {
54 print "ERROR: didn't find top of kernel tree ('" top "' not a directory)" > "/dev/stderr"
55 exit 1
56 }
57
58 machine = ENVIRON["MACHINE"]
59 if (!machine)
60 machine = "i386" # XXX for testing
61 maarch = ENVIRON["MACHINE_ARCH"]
62
63 # file with major definitions
64 majors[0] = "conf/majors"
65 if (maarch == "arm32")
66 majors[1] = "arch/arm/conf/majors.arm32";
67 else if (machine == "evbsh5") {
68 majors[1] = "arch/evbsh5/conf/majors.evbsh5";
69 majors[2] = "arch/sh5/conf/majors.sh5";
70 } else
71 majors[1] = "arch/" machine "/conf/majors." machine;
72
73 # process all files with majors and fill the chr[] and blk[]
74 # arrays, used in template processing
75 for(m in majors) {
76 file = top majors[m]
77 while (getline < file) {
78 if ($1 == "device-major") {
79 if ($3 == "char") {
80 chr[$2] = $4
81 if ($5 == "block")
82 blk[$2] = $6
83 } else if ($3 == "block")
84 blk[$2] = $4
85 }
86 }
87 }
88
89 # read MD config file, and determine disk partitions
90 # and MD device list
91 cfgfile = "etc." machine "/MAKEDEV.conf"
92 MDDEV = 0 # MD device targets
93 MKDISK = "" # routine to create disk devices
94 while (getline < cfgfile) {
95 if ($1 ~ "^DISKPARTITIONS=") {
96 sub(".*=[ \t]*", "")
97 MKDISK = "makedisk_p" $0
98 } else if (MDDEV) {
99 if (MDDEV == 1)
100 MDDEV = $0
101 else
102 MDDEV = MDDEV "\n" $0
103 } else if ($1 ~ "^MD_DEVICES=")
104 MDDEV = 1
105 }
106
107 # initially no substitutions
108 devsubst = 0
109 deventry = ""
110 }
111
112 /%MI_DEVICES_BEGIN%/ {
113 devsubst = 1;
114 next
115 }
116
117 /%MI_DEVICES_END%/ {
118 devsubst = 0;
119 next
120 }
121
122 {
123 sub("^%MD_DEVICES%", MDDEV)
124 sub("%MKDISK%", MKDISK)
125
126 # if device substitutions are not active, do nothing more
127 if (!devsubst) {
128 print
129 next
130 }
131 }
132
133 # first line of device entry
134 /^[a-z].*\)$/ {
135 if (length(deventry) > 0) {
136 # We have a previous entry to print. Replace all known
137 # character and block devices. If no unknown character
138 # or block device definition remains within the entry,
139 # print it to output, otherwise scrap it.
140 for(c in chr)
141 gsub("%" c "_chr%", chr[c], deventry)
142 for(b in blk)
143 gsub("%" b "_blk%", blk[b], deventry)
144
145 if (deventry !~ "%[a-z]*_chr%" && deventry !~ "%[a-z]*_blk%")
146 print deventry
147 }
148 deventry = $0
149 next
150 }
151
152 # template line within device substitution section - just keep appending
153 # to the current entry
154 {
155 deventry = deventry "\n" $0
156 }
157