do_subst.awk revision 1.2 1 # $NetBSD: do_subst.awk,v 1.2 2001/03/04 16:51:05 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_SH = setup_md_files("SH", "SRCFILE_LIST_SH3", SRCFILES_SH3)
86 SRCFILES_MIPS = setup_md_files("MIPS", "SRCFILE_LIST_MIPS",
87 SRCFILES_MIPS)
88
89 CPPDEFS=""
90 sz = split(ENVIRON["STD_CPPDEF_LIST"], a, "[ \t\n]+");
91 for (i = 1; i <= sz; i++) {
92 if (a[i] == "") {
93 continue
94 }
95 if (CPPDEFS != "") {
96 CPPDEFS=CPPDEFS " "
97 }
98 CPPDEFS=CPPDEFS "/D \"" a[i] "\""
99 }
100 sz = split(ENVIRON["CPPDEF_LIST"], a, "[ \t\n]+");
101 for (i = 1; i <= sz; i++) {
102 if (a[i] == "") {
103 continue
104 }
105 if (CPPDEFS != "") {
106 CPPDEFS=CPPDEFS " "
107 }
108 CPPDEFS=CPPDEFS "/D \"" a[i] "\""
109 }
110
111 INCDIRS=""
112 sz = split(ENVIRON["STD_INCDIR_LIST"], a, "[ \t\n]+");
113 for (i = 1; i <= sz; i++) {
114 if (a[i] == "") {
115 continue
116 }
117 if (INCDIRS != "") {
118 INCDIRS=INCDIRS " "
119 }
120 INCDIRS=INCDIRS "/I \"" a[i] "\""
121 }
122 sz = split(ENVIRON["INCDIR_LIST"], a, "[ \t\n]+");
123 for (i = 1; i <= sz; i++) {
124 if (a[i] == "") {
125 continue
126 }
127 if (INCDIRS != "") {
128 INCDIRS=INCDIRS " "
129 }
130 INCDIRS=INCDIRS "/I \"" a[i] "\""
131 }
132 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
133 for (i = 1; i <= sz; i++) {
134 if (a[i] == "") {
135 continue
136 }
137 if (INCDIRS != "") {
138 INCDIRS=INCDIRS " "
139 }
140 INCDIRS=INCDIRS "/I \"..\\" a[i] "\""
141 }
142
143 LIBRARIES=""
144 sz = split(ENVIRON["STD_LIBRARY_LIST"], a, "[ \t\n]+");
145 for (i = 1; i <= sz; i++) {
146 if (a[i] == "") {
147 continue
148 }
149 if (LIBRARIES != "") {
150 LIBRARIES=LIBRARIES " "
151 }
152 LIBRARIES=LIBRARIES a[i] ".lib"
153 }
154 sz = split(ENVIRON["LIBRARY_LIST"], a, "[ \t\n]+");
155 for (i = 1; i <= sz; i++) {
156 if (a[i] == "") {
157 continue
158 }
159 if (LIBRARIES != "") {
160 LIBRARIES=LIBRARIES " "
161 }
162 LIBRARIES=LIBRARIES a[i] ".lib"
163 }
164 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
165 for (i = 1; i <= sz; i++) {
166 if (a[i] == "") {
167 continue
168 }
169 if (LIBRARIES != "") {
170 LIBRARIES=LIBRARIES " "
171 }
172 LIBRARIES=LIBRARIES a[i] ".lib"
173 }
174
175 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
176 DEBUG_LIBPATH=""
177 RELEASE_LIBPATH=""
178 for (i = 1; i <= sz; i++) {
179 if (a[i] == "") {
180 continue
181 }
182 if (i > 1) {
183 DEBUG_LIBPATH=DEBUG_LIBPATH " "
184 RELEASE_LIBPATH=RELEASE_LIBPATH " "
185 }
186 DEBUG_LIBPATH=DEBUG_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSDbg\""
187 RELEASE_LIBPATH=RELEASE_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSRel\""
188 }
189 }
190 {
191 gsub("%%% SRCFILES %%%", SRCFILES)
192 gsub("%%% SRCFILES_ARM %%%", SRCFILES_ARM)
193 gsub("%%% SRCFILES_SH3 %%%", SRCFILES_SH3)
194 gsub("%%% SRCFILES_SH %%%", SRCFILES_SH)
195 gsub("%%% SRCFILES_MIPS %%%", SRCFILES_MIPS)
196 gsub("%%% CPPDEFS %%%", CPPDEFS)
197 gsub("%%% INCDIRS %%%", INCDIRS)
198 gsub("%%% LIBRARIES %%%", LIBRARIES)
199 gsub("%%% DEBUG_LIBPATH %%%", DEBUG_LIBPATH)
200 gsub("%%% RELEASE_LIBPATH %%%", RELEASE_LIBPATH)
201 gsub("%%% NAME %%%", NAME)
202 print $0
203 }
204