do_subst.sh revision 1.4 1 # $NetBSD: do_subst.sh,v 1.4 2001/01/05 15:00:57 takemura 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 AWK=awk
32 if [ `uname` = SunOS ]; then
33 AWK=nawk
34 fi
35
36 STD_CPPDEF_LIST=''
37 STD_INCDIR_LIST=''
38 STD_LIBRARY_LIST=''
39
40 export NAME
41 export SRCFILE_LIST
42 export CPPDEF_LIST STD_CPPDEF_LIST
43 export INCDIR_LIST STD_INCDIR_LIST
44 export LIBDEP_LIST
45 export LIBRARY_LIST STD_LIBRARY_LIST
46
47 ${AWK} '
48 BEGIN {
49 NAME=ENVIRON["NAME"]
50
51 SRCFILES=""
52 sz = split(ENVIRON["SRCFILE_LIST"], a, "[ \t\n]+");
53 for (i = 1; i <= sz; i++) {
54 if (a[i] == "") {
55 continue
56 }
57 if (SRCFILES != "") {
58 SRCFILES=SRCFILES "\n"
59 }
60 SRCFILES=SRCFILES "# Begin Source File\n"
61 SRCFILES=SRCFILES "\n"
62 SRCFILES=SRCFILES "SOURCE=.\\" a[i] "\n"
63 SRCFILES=SRCFILES "# End Source File"
64 }
65
66 CPPDEFS=""
67 sz = split(ENVIRON["STD_CPPDEF_LIST"], a, "[ \t\n]+");
68 for (i = 1; i <= sz; i++) {
69 if (a[i] == "") {
70 continue
71 }
72 if (CPPDEFS != "") {
73 CPPDEFS=CPPDEFS " "
74 }
75 CPPDEFS=CPPDEFS "/D \"" a[i] "\""
76 }
77 sz = split(ENVIRON["CPPDEF_LIST"], a, "[ \t\n]+");
78 for (i = 1; i <= sz; i++) {
79 if (a[i] == "") {
80 continue
81 }
82 if (CPPDEFS != "") {
83 CPPDEFS=CPPDEFS " "
84 }
85 CPPDEFS=CPPDEFS "/D \"" a[i] "\""
86 }
87
88 INCDIRS=""
89 sz = split(ENVIRON["STD_INCDIR_LIST"], a, "[ \t\n]+");
90 for (i = 1; i <= sz; i++) {
91 if (a[i] == "") {
92 continue
93 }
94 if (INCDIRS != "") {
95 INCDIRS=INCDIRS " "
96 }
97 INCDIRS=INCDIRS "/I \"" a[i] "\""
98 }
99 sz = split(ENVIRON["INCDIR_LIST"], a, "[ \t\n]+");
100 for (i = 1; i <= sz; i++) {
101 if (a[i] == "") {
102 continue
103 }
104 if (INCDIRS != "") {
105 INCDIRS=INCDIRS " "
106 }
107 INCDIRS=INCDIRS "/I \"" a[i] "\""
108 }
109 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
110 for (i = 1; i <= sz; i++) {
111 if (a[i] == "") {
112 continue
113 }
114 if (INCDIRS != "") {
115 INCDIRS=INCDIRS " "
116 }
117 INCDIRS=INCDIRS "/I \"..\\" a[i] "\""
118 }
119
120 LIBRARIES=""
121 sz = split(ENVIRON["STD_LIBRARY_LIST"], a, "[ \t\n]+");
122 for (i = 1; i <= sz; i++) {
123 if (a[i] == "") {
124 continue
125 }
126 if (LIBRARIES != "") {
127 LIBRARIES=LIBRARIES " "
128 }
129 LIBRARIES=LIBRARIES a[i] ".lib"
130 }
131 sz = split(ENVIRON["LIBRARY_LIST"], a, "[ \t\n]+");
132 for (i = 1; i <= sz; i++) {
133 if (a[i] == "") {
134 continue
135 }
136 if (LIBRARIES != "") {
137 LIBRARIES=LIBRARIES " "
138 }
139 LIBRARIES=LIBRARIES a[i] ".lib"
140 }
141 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
142 for (i = 1; i <= sz; i++) {
143 if (a[i] == "") {
144 continue
145 }
146 if (LIBRARIES != "") {
147 LIBRARIES=LIBRARIES " "
148 }
149 LIBRARIES=LIBRARIES a[i] ".lib"
150 }
151
152 sz = split(ENVIRON["LIBDEP_LIST"], a, "[ \t\n]+");
153 DEBUG_LIBPATH=""
154 RELEASE_LIBPATH=""
155 for (i = 1; i <= sz; i++) {
156 if (a[i] == "") {
157 continue
158 }
159 if (i > 1) {
160 DEBUG_LIBPATH=DEBUG_LIBPATH " "
161 RELEASE_LIBPATH=RELEASE_LIBPATH " "
162 }
163 DEBUG_LIBPATH=DEBUG_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSDbg\""
164 RELEASE_LIBPATH=RELEASE_LIBPATH "/libpath:\"..\\" a[i] "\\WMIPSRel\""
165 }
166 }
167 {
168 gsub("%%% NAME %%%", NAME)
169 gsub("%%% SRCFILES %%%", SRCFILES)
170 gsub("%%% CPPDEFS %%%", CPPDEFS)
171 gsub("%%% INCDIRS %%%", INCDIRS)
172 gsub("%%% LIBRARIES %%%", LIBRARIES)
173 gsub("%%% DEBUG_LIBPATH %%%", DEBUG_LIBPATH)
174 gsub("%%% RELEASE_LIBPATH %%%", RELEASE_LIBPATH)
175 print $0
176 }
177 '
178