a45bf1f80039bad20e5bc85b125291ef3c6b7eb5
[mirror_edk2.git] / BaseTools / Conf / build_rule.template
1 # file extention : file type
2 FileTypeMapping = {
3 ".c" : "C-Code",
4 ".C" : "C-Code",
5 ".cpp" : "C-Code",
6 ".Cpp" : "C-Code",
7 ".CPP" : "C-Code",
8 ".h" : "C-Header",
9 ".H" : "C-Header",
10 ".inc" : "Masm-Header",
11 ".asm" : "Masm-Code",
12 ".Asm" : "Masm-Code",
13 ".ASM" : "Masm-Code",
14 ".asm16" : "Masm16-Code", #RealAsm16 Link Code
15 ".Asm16" : "Masm16-Code",
16 ".ASM16" : "Masm16-Code",
17 ".s" : "Iasm-Code", # IPF assembly code
18 ".S" : "Gasm-Code", # GNU assembly code
19 ".uni" : "Unicode-Text",
20 ".Uni" : "Unicode-Text",
21 ".UNI" : "Unicode-Text",
22 ".vfr" : "Visual-Form-Representation",
23 ".Vfr" : "Visual-Form-Representation",
24 ".VFR" : "Visual-Form-Representation",
25 ".dxs" : "Dependency-Expression",
26 ".Dxs" : "Dependency-Expression",
27 ".DXS" : "Dependency-Expression",
28 ".TXT" : "MicorCode-Text",
29 ".fv" : "FirmwareVolume",
30 ".Fv" : "FirmwareVolume",
31 ".FV" : "FirmwareVolume",
32 ".efi" : "Efi-Image",
33 ".Efi" : "Efi-Image",
34 ".EFI" : "Efi-Image",
35 ".SEC" : "Firmware-File-System",
36 ".PEI" : "Firmware-File-System",
37 ".DXE" : "Firmware-File-System",
38 ".APP" : "Firmware-File-System",
39 ".FYI" : "Firmware-File-System",
40 ".FFS" : "Firmware-File-System",
41 ".bmp" : "Bmp-Image",
42 ".i" : "Preprocessed-Code",
43 ".asl" : "Acpi-Source-Language",
44 ".Asl" : "Acpi-Source-Language",
45 ".ASL" : "Acpi-Source-Language",
46 ".aslc" : "Acpi-Table-Source",
47 ".obj" : "Object",
48 ".o" : "Object",
49 ".lib" : "Static-Library",
50 ".a" : "Static-Library",
51 ".dll" : "Dynamic-Library",
52 ".so" : "Dynamic-Library",
53 }
54
55 ObjectFileMapping = {
56 "C-Code" : ".obj",
57 # "C-Header" : ".gch",
58 "Masm-Code" : ".obj",
59 "Iasm-Code" : ".obj", # IPF assembly code
60 "Gasm-Code" : ".obj", # GNU assembly code
61 "Visual-Form-Representation" : ".obj",
62 "Preprocessed-Code" : ".obj",
63 "Object" : ".dll",
64 "Static-Library" : ".dll",
65 "Dynamic-Library" : ".efi",
66 "Dependency-Expression" : ".depex",
67 "Acpi-Source-Language" : ".aml",
68 "Acpi-Table-Source" : ".acpi",
69 "Masm16-Code" : ".com",
70 "MicorCode-Text" : ".bin",
71 }
72
73 DefaultToolCode = ["CC", "ASM", "SLINK", "DLINK", "PCH", "PP", "ASL", "ASMLINK"]
74
75 ToolCodeMapping = {
76 "C-Code" : ["CC"],
77 # "C-Header" : ["PCH"],
78 "Masm-Code" : ["PP", "ASM"],
79 "Iasm-Code" : ["PP", "ASM"], # IPF assembly code
80 "Gasm-Code" : ["ASM"], # GNU assembly code
81 "Visual-Form-Representation" : ["PP", "CC"],
82 "Preprocessed-Code" : ["CC"],
83 "Acpi-Source-Language" : ["ASL"],
84 "Object" : ["SLINK"],
85 "Static-Library" : ["DLINK"],
86 "Dependency-Expression" : ["PP"],
87 "Acpi-Source-Language" : ["PP", "ASL"],
88 "Acpi-Table-Source" : ["CC", "DLINK"],
89 "Masm16-Code" : ["ASM", "ASMLINK"],
90 }
91
92 ToolChainFamilyMapping = {
93 "C-Code" : ["MSFT", "INTEL", "GCC"],
94 "C-Header" : ["MSFT", "INTEL", "GCC"],
95 "Masm-Code" : ["MSFT", "INTEL"],
96 "Iasm-Code" : ["MSFT", "INTEL"], # IPF assembly code
97 "Gasm-Code" : ["GCC"], # GNU assembly code
98 "Unicode-Text" : ["MSFT", "INTEL", "GCC"],
99 "Visual-Form-Representation" : ["MSFT", "INTEL", "GCC"],
100 "Dependency-Expression" : ["MSFT", "INTEL", "GCC"],
101 "FirmwareVolume" : ["MSFT", "INTEL", "GCC"],
102 "Efi-Image" : ["MSFT", "INTEL", "GCC"],
103 "Firmware-File-System" : ["MSFT", "INTEL", "GCC"],
104 "Bmp-Image" : ["MSFT", "INTEL", "GCC"],
105 "Preprocessed-Code" : ["MSFT", "INTEL"],
106 "Acpi-Source-Language" : ["MSFT", "INTEL"],
107 "Acpi-Table-Source" : ["MSFT", "INTEL"],
108 "Masm16-Code" : ["MSFT"],
109 "MicorCode-Text" : ["MSFT", "INTEL"],
110 }
111
112 ## Build rules for makefile
113 # Placeholders for string substitution
114 # ${fpath} File path relative to $(WORKSPACE)
115 # ${fdir} File relative directory within a module
116 # ${fname} File full name without path
117 # ${fbase} File name without extension and path
118 # ${fext} File extension
119 # ${fdep} File dependencies
120 # ${_sep_} Directory separator
121 # ${_of_} Output flag
122 # ${_if_} Include flag
123 #
124 Makefile = {
125 # MSFT tool chain family
126 "MSFT" : {
127 "C-Code" : '''\
128 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
129 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
130 ${END}\t"$(CC)" /Fo$@ $(CC_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath}
131 ''',
132
133 "Masm-Code" : '''\
134 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
135 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
136 ${END}\t"$(PP)" $(PP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} > $(@D)${_sep_}${fbase}.i
137 \tTrim -s -c $(@D)${_sep_}${fbase}.i
138 \t"$(ASM)" /Fo$@ $(ASM_FLAGS) $(INC) $(@D)${_sep_}${fbase}.iii
139 ''',
140
141 "Iasm-Code" : '''\
142 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
143 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
144 ${END}\t"$(APP)" $(APP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} > $(@D)${_sep_}${fbase}.i
145 \t"$(ASM)" -o $@ $(ASM_FLAGS) $(@D)${_sep_}${fbase}.i
146 ''',
147
148 "Visual-Form-Representation" : '''\
149 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
150 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
151 ${END}\t"$(PP)" $(VFRPP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} > $(@D)${_sep_}${fbase}.i
152 \tTrim -v $(@D)${_sep_}${fbase}.i
153 \t-mkdir $(DEBUG_DIR)${_sep_}${fdir} > NUL 2>&1
154 \tVfrCompile -od $(DEBUG_DIR)${_sep_}${fdir} $(@D)${_sep_}${fbase}.iii
155 \t"$(CC)" /Fo$@ $(CC_FLAGS) $(INC) $(DEBUG_DIR)${_sep_}${fdir}${_sep_}${fbase}.c
156 ''',
157
158 "Acpi-Source-Language" :
159 '''
160 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.aml : $(COMMON_DEPS)
161 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.aml : $(WORKSPACE)${_sep_}${fdep}
162 ${END}\t"$(PP)" $(APP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} > $(@D)${_sep_}${fbase}.i
163 \t"$(ASL)" -p $@ $(@D)${_sep_}${fbase}.i
164 \t-copy $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.aml $(OUTPUT_DIR)${_sep_}${fbase}.aml /Y
165 ''',
166
167 "Acpi-Table-Source" :
168 '''
169 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.acpi : $(COMMON_DEPS)
170 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.acpi : $(WORKSPACE)${_sep_}${fdep}
171 ${END}\t"$(CC)" /Fo$(@D)${_sep_}${fbase}.obj $(CC_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath}
172 \t"$(DLINK)" $(@D)${_sep_}${fbase}.obj /out:$(@D)${_sep_}${fbase}.dll $(DLINK_FLAGS) $(DLINK_SPATH) $(LIBS)
173 \tGenFw -o $@ -c $(@D)${_sep_}${fbase}.dll
174 \t-copy $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.acpi $(OUTPUT_DIR)${_sep_}${fbase}.acpi /Y
175 ''',
176
177 "Masm16-Code" : '''\
178 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.com : $(COMMON_DEPS)
179 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.com : $(WORKSPACE)${_sep_}${fdep}
180 ${END}\tpushd .
181 \tcd $(OUTPUT_DIR)${_sep_}${fdir}
182 \t"$(ASM)" /nologo /omf $(WORKSPACE)${_sep_}${fpath} /Bl"$(ASMLINK)" $(ASMLINK_FLAGS)
183 \t-copy ${fbase}.com $(OUTPUT_DIR)${_sep_}${fbase}.com /Y & popd
184 ''',
185
186 "MicorCode-Text" : '''\
187 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.bin : $(COMMON_DEPS)
188 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.bin : $(WORKSPACE)${_sep_}${fdep}
189 ${END}\tGenFw -o $@ -m $(WORKSPACE)${_sep_}${fpath}
190 ''',
191 },
192
193 #
194 # INTEL tool chain family
195 #
196 "INTEL" : {
197 "C-Code" : '''\
198 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
199 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
200 ${END}\t"$(CC)" /Fo$@ $(CC_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath}
201 ''',
202
203 "Masm-Code" : '''\
204 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
205 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
206 ${END}\t"$(PP)" $(PP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} > $(@D)${_sep_}${fbase}.i
207 \tTrim -s -c $(@D)${_sep_}${fbase}.i
208 \t"$(ASM)" /Fo$@ $(ASM_FLAGS) $(INC) $(@D)${_sep_}${fbase}.iii
209 ''',
210
211 "Iasm-Code" : '''\
212 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
213 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
214 ${END}\t"$(APP)" $(APP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} > $(@D)${_sep_}${fbase}.i
215 \t"$(ASM)" -o $@ $(ASM_FLAGS) $(@D)${_sep_}${fbase}.i
216 ''',
217
218 "Visual-Form-Representation" : '''\
219 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
220 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
221 ${END}\t"$(PP)" $(VFRPP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} > $(@D)${_sep_}${fbase}.i
222 \tTrim -v $(@D)${_sep_}${fbase}.i
223 \t-mkdir $(DEBUG_DIR)${_sep_}${fdir} > NUL 2>&1
224 \tVfrCompile -od $(DEBUG_DIR)${_sep_}${fdir} $(@D)${_sep_}${fbase}.iii
225 \t"$(CC)" /Fo$@ $(CC_FLAGS) $(INC) $(DEBUG_DIR)${_sep_}${fdir}${_sep_}${fbase}.c
226 ''',
227
228 "Acpi-Source-Language" :
229 '''
230 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.aml : $(COMMON_DEPS)
231 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.aml : $(WORKSPACE)${_sep_}${fdep}
232 ${END}\t"$(PP)" $(APP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} > $(@D)${_sep_}${fbase}.i
233 \t"$(ASL)" -p $@ $(@D)${_sep_}${fbase}.i
234 \t-copy $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.aml $(OUTPUT_DIR)${_sep_}${fbase}.aml /Y
235 ''',
236
237 "Acpi-Table-Source" :
238 '''
239 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.acpi : $(COMMON_DEPS)
240 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.acpi : $(WORKSPACE)${_sep_}${fdep}
241 ${END}\t"$(CC)" /Fo$(@D)${_sep_}${fbase}.obj $(CC_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath}
242 \t"$(DLINK)" $(@D)${_sep_}${fbase}.obj /out:$(@D)${_sep_}${fbase}.dll $(DLINK_FLAGS) $(DLINK_SPATH) $(LIBS)
243 \tGenFw -o $@ -c $(@D)${_sep_}${fbase}.dll
244 \t-copy $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.acpi $(OUTPUT_DIR)${_sep_}${fbase}.acpi /Y
245 ''',
246 },
247
248 #
249 # GCC tool chain family
250 #
251 "GCC" : {
252
253 "C-Code" :
254 '''
255 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
256 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
257 ${END}\t"$(CC)" -o $@ $(CC_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath}
258 ''',
259
260 "Gasm-Code" :
261 '''
262 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
263 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
264 ${END}\t"$(ASM)" -o $@ $(ASM_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath}
265 ''',
266
267 "Visual-Form-Representation" :
268 '''
269 $(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(COMMON_DEPS)
270 ${BEGIN}$(OUTPUT_DIR)${_sep_}${fdir}${_sep_}${fbase}.obj : $(WORKSPACE)${_sep_}${fdep}
271 ${END}\t"$(PP)" $(VFRPP_FLAGS) $(INC) $(WORKSPACE)${_sep_}${fpath} -o $(@D)${_sep_}${fbase}.i
272 \tTrim -v $(@D)${_sep_}${fbase}.i
273 \t-mkdir $(DEBUG_DIR)${_sep_}${fdir} > NUL 2>&1
274 \tVfrCompile -od $(DEBUG_DIR)${_sep_}${fdir} $(@D)${_sep_}${fbase}.iii
275 \t"$(CC)" -o $@ $(CC_FLAGS) $(INC) $(DEBUG_DIR)${_sep_}${fdir}${_sep_}${fbase}.c
276 ''',
277 }
278 }
279
280 # This acts like the main() function for the script, unless it is 'import'ed into another
281 # script.
282 if __name__ == '__main__':
283 for ext in FileTypeMapping:
284 print ext,":",FileTypeMapping[ext]
285
286 for type in Makefile["nmake"]:
287 print "[",type,"]\n",Makefile["nmake"][type]
288 print
289
290 for type in Makefile["gmake"]:
291 print "[",type,"]\n",Makefile["gmake"][type]
292 print
293