do_subst.awk revision 1.3 1 # $NetBSD: do_subst.awk,v 1.3 2001/03/13 16:31:31 uch Exp $
2 #
3 # Copyright (c) 1999, 2000 Christopher G. Demetriou. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # 3. All advertising materials mentioning features or use of this software
14 # must display the following acknowledgement:
15 # This product includes software developed by Christopher G. Demetriou
16 # for the NetBSD Project.
17 # 4. The name of the author may not be used to endorse or promote products
18 # derived from this software without specific prior written permission
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 function setup_md_files (arch, env, srclist) {
32 srclist=""
33 asm_tmpl="dspgen/asm_build." arch
34 prop_tmpl="dspgen/property." arch
35
36 sz = split(ENVIRON[env], a, "[ \t\n]+");
37 for (i = 1; i <= sz; i++) {
38 if (a[i] == "") {
39 continue
40 }
41 if (srclist != "") {
42 srclist=srclist "\n"
43 }
44 srclist=srclist "# Begin Source File\n"
45 srclist=srclist "\n"
46 srclist=srclist "SOURCE=.\\" a[i] "\n"
47 base = index (a[i], ".asm")
48 if (base != 0) {
49 basename = substr (a[i], 0, base - 1)
50 while (getline < asm_tmpl > 0) {
51 gsub ("%%% ASM_BASENAME %%%", basename)
52 srclist=srclist $0 "\n"
53 }
54 close (asm_tmpl)
55 } else {
56 while (getline < prop_tmpl > 0)
57 srclist=srclist $0 "\n"
58 close (prop_tmpl)
59 }
60 srclist=srclist "# End Source File"
61 }
62 return srclist
63 }
64
65 BEGIN {
66 NAME=ENVIRON["NAME"]
67
68 SRCFILES=""
69 sz = split(ENVIRON["SRCFILE_LIST"], a, "[ \t\n]+");
70 for (i = 1; i <= sz; i++) {
71 if (a[i] == "") {
72 continue
73 }
74 if (SRCFILES != "") {
75 SRCFILES=SRCFILES "\n"
76 }
77 SRCFILES=SRCFILES "# Begin Source File\n"
78 SRCFILES=SRCFILES "\n"
79 SRCFILES=SRCFILES "SOURCE=.\\" a[i] "\n"
80 SRCFILES=SRCFILES "# End Source File"
81 }
82
83 SRCFILES_ARM = setup_md_files("ARM", "SRCFILE_LIST_ARM", SRCFILES_ARM)
84 SRCFILES_SH3 = setup_md_files("SH3", "SRCFILE_LIST_SH3", SRCFILES_SH3)
85 SRCFILES_SH4 = setup_md_files("SH4", "SRCFILE_LIST_SH3", SRCFILES_SH3)
86 SRCFILES_SH = setup_md_files("SH", "SRCFILE_LIST_SH3", SRCFILES_SH3)
87 SRCFILES_MIPS = setup_md_files("MIPS", "SRCFILE_LIST_MIPS",
88 SRCFILES_MIPS)
89
90 CPPDEFS=""
91 sz = split(ENVIRON["STD_CPPDEF_LIST"], a, "[ \t\n]+");
92 for (i = 1; i <= sz; i++) {
93 if (a[i] == "") {
94 continue
95 }
96 if (CPPDEFS != "") {
97 CPPDEFS=CPPDEFS " "
98 }
99 CPPDEFS=CPPDEFS "/D \"" a[i] "\""
100 }
101 sz = split(ENVIRON["CPPDEF_LIST"], a, "[ \t\n]+");
102 for (i = 1; i <= sz; i++) {
103 if (a[i] == "") {
104 continue
105 }
106 if (CPPDEFS != "") {
107 CPPDEFS=CPPDEFS " "
108 }
109 CPPDEFS=CPPDEFS "/D \"" a[i] "\""
110 }
111
112 INCDIRS=""
113 sz = split(ENVIRON["STD_INCDIR_LIST"], a, "[ \t\n]+");
114 for (i = 1; i <= sz; i++) {
115 if (a[i] == "") {
116 continue
117 }
118 if (INCDIRS != "") {
119 INCDIRS=INCDIRS " "
120 }
121 INCDIRS=INCDIRS "/I \"" a[i] "\""
122 }
123 sz = split(ENVIRON["INCDIR_LIST"], a, "[ \t\n]+");
124 for (i = 1; i <= sz; i++) {
125 if (a[i] == "") {
126 continue
127 }
128 if (INCDIRS != "") {
129 INCDIRS=INCDIRS " "
130 }
131 INCDIRS=INCDIRS "/I \"" a[i] "\""
132 }
133 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
134 for (i = 1; i <= sz; i++) {
135 if (a[i] == "") {
136 continue
137 }
138 if (INCDIRS != "") {
139 INCDIRS=INCDIRS " "
140 }
141 INCDIRS=INCDIRS "/I \"..\\" a[i] "\""
142 }
143
144 LIBRARIES=""
145 sz = split(ENVIRON["STD_LIBRARY_LIST"], a, "[ \t\n]+");
146 for (i = 1; i <= sz; i++) {
147 if (a[i] == "") {
148 continue
149 }
150 if (LIBRARIES != "") {
151 LIBRARIES=LIBRARIES " "
152 }
153 LIBRARIES=LIBRARIES a[i] ".lib"
154 }
155 sz = split(ENVIRON["LIBRARY_LIST"], a, "[ \t\n]+");
156 for (i = 1; i <= sz; i++) {
157 if (a[i] == "") {
158 continue
159 }
160 if (LIBRARIES != "") {
161 LIBRARIES=LIBRARIES " "
162 }
163 LIBRARIES=LIBRARIES a[i] ".lib"
164 }
165 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
166 for (i = 1; i <= sz; i++) {
167 if (a[i] == "") {
168 continue
169 }
170 if (LIBRARIES != "") {
171 LIBRARIES=LIBRARIES " "
172 }
173 LIBRARIES=LIBRARIES a[i] ".lib"
174 }
175
176 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
177 DEBUG_LIBPATH=""
178 RELEASE_LIBPATH=""
179 for (i = 1; i <= sz; i++) {
180 if (a[i] == "") {
181 continue
182 }
183 if (i > 1) {
184 DEBUG_LIBPATH=DEBUG_LIBPATH " "
185 RELEASE_LIBPATH=RELEASE_LIBPATH " "
186 }
187 DEBUG_LIBPATH=DEBUG_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSDbg\""
188 RELEASE_LIBPATH=RELEASE_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSRel\""
189 }
190 }
191 {
192 gsub("%%% SRCFILES %%%", SRCFILES)
193 gsub("%%% SRCFILES_ARM %%%", SRCFILES_ARM)
194 gsub("%%% SRCFILES_SH3 %%%", SRCFILES_SH3)
195 gsub("%%% SRCFILES_SH4 %%%", SRCFILES_SH4)
196 gsub("%%% SRCFILES_SH %%%", SRCFILES_SH)
197 gsub("%%% SRCFILES_MIPS %%%", SRCFILES_MIPS)
198 gsub("%%% CPPDEFS %%%", CPPDEFS)
199 gsub("%%% INCDIRS %%%", INCDIRS)
200 gsub("%%% LIBRARIES %%%", LIBRARIES)
201 gsub("%%% DEBUG_LIBPATH %%%", DEBUG_LIBPATH)
202 gsub("%%% RELEASE_LIBPATH %%%", RELEASE_LIBPATH)
203 gsub("%%% NAME %%%", NAME)
204 print $0
205 }
206