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