]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/RunMakefile.py
ArmPlatformPkg/MemoryInitPeiLib: don't reserve primary FV in memory
[mirror_edk2.git] / BaseTools / Scripts / RunMakefile.py
1 ## @file
2 # Run a makefile as part of a PREBUILD or POSTBUILD action.
3 #
4 # Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 '''
15 RunMakefile.py
16 '''
17
18 import os
19 import sys
20 import argparse
21 import subprocess
22
23 #
24 # Globals for help information
25 #
26 __prog__ = 'RunMakefile'
27 __version__ = '%s Version %s' % (__prog__, '1.0')
28 __copyright__ = 'Copyright (c) 2017, Intel Corporation. All rights reserved.'
29 __description__ = 'Run a makefile as part of a PREBUILD or POSTBUILD action.\n'
30
31 #
32 # Globals
33 #
34 gArgs = None
35
36 def Log(Message):
37 if not gArgs.Verbose:
38 return
39 sys.stdout.write (__prog__ + ': ' + Message + '\n')
40
41 def Error(Message, ExitValue=1):
42 sys.stderr.write (__prog__ + ': ERROR: ' + Message + '\n')
43 sys.exit (ExitValue)
44
45 def RelativePath(target):
46 return os.path.relpath (target, gWorkspace)
47
48 def NormalizePath(target):
49 if isinstance(target, tuple):
50 return os.path.normpath (os.path.join (*target))
51 else:
52 return os.path.normpath (target)
53
54 if __name__ == '__main__':
55 #
56 # Create command line argument parser object
57 #
58 parser = argparse.ArgumentParser (
59 prog = __prog__,
60 version = __version__,
61 description = __description__ + __copyright__,
62 conflict_handler = 'resolve'
63 )
64 parser.add_argument (
65 '-a', '--arch', dest = 'Arch', nargs = '+', action = 'append',
66 required = True,
67 help = '''ARCHS is one of list: IA32, X64, IPF, ARM, AARCH64 or EBC,
68 which overrides target.txt's TARGET_ARCH definition. To
69 specify more archs, please repeat this option.'''
70 )
71 parser.add_argument (
72 '-t', '--tagname', dest = 'ToolChain', required = True,
73 help = '''Using the Tool Chain Tagname to build the platform,
74 overriding target.txt's TOOL_CHAIN_TAG definition.'''
75 )
76 parser.add_argument (
77 '-p', '--platform', dest = 'PlatformFile', required = True,
78 help = '''Build the platform specified by the DSC file name argument,
79 overriding target.txt's ACTIVE_PLATFORM definition.'''
80 )
81 parser.add_argument (
82 '-b', '--buildtarget', dest = 'BuildTarget', required = True,
83 help = '''Using the TARGET to build the platform, overriding
84 target.txt's TARGET definition.'''
85 )
86 parser.add_argument (
87 '--conf=', dest = 'ConfDirectory', required = True,
88 help = '''Specify the customized Conf directory.'''
89 )
90 parser.add_argument (
91 '-D', '--define', dest = 'Define', nargs='*', action = 'append',
92 help = '''Macro: "Name [= Value]".'''
93 )
94 parser.add_argument (
95 '--makefile', dest = 'Makefile', required = True,
96 help = '''Makefile to run passing in arguments as makefile defines.'''
97 )
98 parser.add_argument (
99 '-v', '--verbose', dest = 'Verbose', action = 'store_true',
100 help = '''Turn on verbose output with informational messages printed'''
101 )
102
103 #
104 # Parse command line arguments
105 #
106 gArgs, remaining = parser.parse_known_args()
107 gArgs.BuildType = 'all'
108 for BuildType in ['all', 'fds', 'genc', 'genmake', 'clean', 'cleanall', 'modules', 'libraries', 'run']:
109 if BuildType in remaining:
110 gArgs.BuildType = BuildType
111 remaining.remove(BuildType)
112 break
113 gArgs.Remaining = ' '.join(remaining)
114
115 #
116 # Start
117 #
118 Log ('Start')
119
120 #
121 # Find makefile in WORKSPACE or PACKAGES_PATH
122 #
123 PathList = ['']
124 try:
125 PathList.append(os.environ['WORKSPACE'])
126 except:
127 Error ('WORKSPACE environment variable not set')
128 try:
129 PathList += os.environ['PACKAGES_PATH'].split(os.pathsep)
130 except:
131 pass
132 for Path in PathList:
133 Makefile = NormalizePath((Path, gArgs.Makefile))
134 if os.path.exists (Makefile):
135 break
136 if not os.path.exists(Makefile):
137 Error ('makefile %s not found' % (gArgs.Makefile))
138
139 #
140 # Build command line arguments converting build arguments to makefile defines
141 #
142 CommandLine = [Makefile]
143 CommandLine.append('TARGET_ARCH="%s"' % (' '.join([Item[0] for Item in gArgs.Arch])))
144 CommandLine.append('TOOL_CHAIN_TAG="%s"' % (gArgs.ToolChain))
145 CommandLine.append('TARGET="%s"' % (gArgs.BuildTarget))
146 CommandLine.append('ACTIVE_PLATFORM="%s"' % (gArgs.PlatformFile))
147 CommandLine.append('CONF_DIRECTORY="%s"' % (gArgs.ConfDirectory))
148 if gArgs.Define:
149 for Item in gArgs.Define:
150 if '=' not in Item[0]:
151 continue
152 Item = Item[0].split('=',1)
153 CommandLine.append('%s="%s"' % (Item[0], Item[1]))
154 CommandLine.append('EXTRA_FLAGS="%s"' % (gArgs.Remaining))
155 CommandLine.append(gArgs.BuildType)
156 if sys.platform == "win32":
157 CommandLine = 'nmake /f %s' % (' '.join(CommandLine))
158 else:
159 CommandLine = 'make -f %s' % (' '.join(CommandLine))
160
161 #
162 # Run the makefile
163 #
164 try:
165 Process = subprocess.Popen(CommandLine, shell=True)
166 except:
167 Error ('make command not available. Please verify PATH')
168 Process.communicate()
169
170 #
171 # Done
172 #
173 Log ('Done')
174
175 #
176 # Return status from running the makefile
177 #
178 sys.exit(Process.returncode)