]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/RunMakefile.py
0e0a0114f9c7f6c4e0302679e4d74eea5f2be4cd
2 # Run a makefile as part of a PREBUILD or POSTBUILD action.
4 # Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
18 # Globals for help information
20 __prog__
= 'RunMakefile'
21 __version__
= '%s Version %s' % (__prog__
, '1.0')
22 __copyright__
= 'Copyright (c) 2017, Intel Corporation. All rights reserved.'
23 __description__
= 'Run a makefile as part of a PREBUILD or POSTBUILD action.\n'
33 sys
.stdout
.write (__prog__
+ ': ' + Message
+ '\n')
35 def Error(Message
, ExitValue
=1):
36 sys
.stderr
.write (__prog__
+ ': ERROR: ' + Message
+ '\n')
39 def RelativePath(target
):
40 return os
.path
.relpath (target
, gWorkspace
)
42 def NormalizePath(target
):
43 if isinstance(target
, tuple):
44 return os
.path
.normpath (os
.path
.join (*target
))
46 return os
.path
.normpath (target
)
48 if __name__
== '__main__':
50 # Create command line argument parser object
52 parser
= argparse
.ArgumentParser (
54 version
= __version__
,
55 description
= __description__
+ __copyright__
,
56 conflict_handler
= 'resolve'
59 '-a', '--arch', dest
= 'Arch', nargs
= '+', action
= 'append',
61 help = '''ARCHS is one of list: IA32, X64, IPF, ARM, AARCH64 or EBC,
62 which overrides target.txt's TARGET_ARCH definition. To
63 specify more archs, please repeat this option.'''
66 '-t', '--tagname', dest
= 'ToolChain', required
= True,
67 help = '''Using the Tool Chain Tagname to build the platform,
68 overriding target.txt's TOOL_CHAIN_TAG definition.'''
71 '-p', '--platform', dest
= 'PlatformFile', required
= True,
72 help = '''Build the platform specified by the DSC file name argument,
73 overriding target.txt's ACTIVE_PLATFORM definition.'''
76 '-b', '--buildtarget', dest
= 'BuildTarget', required
= True,
77 help = '''Using the TARGET to build the platform, overriding
78 target.txt's TARGET definition.'''
81 '--conf=', dest
= 'ConfDirectory', required
= True,
82 help = '''Specify the customized Conf directory.'''
85 '-D', '--define', dest
= 'Define', nargs
='*', action
= 'append',
86 help = '''Macro: "Name [= Value]".'''
89 '--makefile', dest
= 'Makefile', required
= True,
90 help = '''Makefile to run passing in arguments as makefile defines.'''
93 '-v', '--verbose', dest
= 'Verbose', action
= 'store_true',
94 help = '''Turn on verbose output with informational messages printed'''
98 # Parse command line arguments
100 gArgs
, remaining
= parser
.parse_known_args()
101 gArgs
.BuildType
= 'all'
102 for BuildType
in ['all', 'fds', 'genc', 'genmake', 'clean', 'cleanall', 'modules', 'libraries', 'run']:
103 if BuildType
in remaining
:
104 gArgs
.BuildType
= BuildType
105 remaining
.remove(BuildType
)
107 gArgs
.Remaining
= ' '.join(remaining
)
115 # Find makefile in WORKSPACE or PACKAGES_PATH
119 PathList
.append(os
.environ
['WORKSPACE'])
121 Error ('WORKSPACE environment variable not set')
123 PathList
+= os
.environ
['PACKAGES_PATH'].split(os
.pathsep
)
126 for Path
in PathList
:
127 Makefile
= NormalizePath((Path
, gArgs
.Makefile
))
128 if os
.path
.exists (Makefile
):
130 if not os
.path
.exists(Makefile
):
131 Error ('makefile %s not found' % (gArgs
.Makefile
))
134 # Build command line arguments converting build arguments to makefile defines
136 CommandLine
= [Makefile
]
137 CommandLine
.append('TARGET_ARCH="%s"' % (' '.join([Item
[0] for Item
in gArgs
.Arch
])))
138 CommandLine
.append('TOOL_CHAIN_TAG="%s"' % (gArgs
.ToolChain
))
139 CommandLine
.append('TARGET="%s"' % (gArgs
.BuildTarget
))
140 CommandLine
.append('ACTIVE_PLATFORM="%s"' % (gArgs
.PlatformFile
))
141 CommandLine
.append('CONF_DIRECTORY="%s"' % (gArgs
.ConfDirectory
))
143 for Item
in gArgs
.Define
:
144 if '=' not in Item
[0]:
146 Item
= Item
[0].split('=', 1)
147 CommandLine
.append('%s="%s"' % (Item
[0], Item
[1]))
148 CommandLine
.append('EXTRA_FLAGS="%s"' % (gArgs
.Remaining
))
149 CommandLine
.append(gArgs
.BuildType
)
150 if sys
.platform
== "win32":
151 CommandLine
= 'nmake /f %s' % (' '.join(CommandLine
))
153 CommandLine
= 'make -f %s' % (' '.join(CommandLine
))
159 Process
= subprocess
.Popen(CommandLine
, shell
=True)
161 Error ('make command not available. Please verify PATH')
162 Process
.communicate()
170 # Return status from running the makefile
172 sys
.exit(Process
.returncode
)