]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/RunMakefile.py
2 # Run a makefile as part of a PREBUILD or POSTBUILD action.
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
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.
24 # Globals for help information
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'
39 sys
.stdout
.write (__prog__
+ ': ' + Message
+ '\n')
41 def Error(Message
, ExitValue
=1):
42 sys
.stderr
.write (__prog__
+ ': ERROR: ' + Message
+ '\n')
45 def RelativePath(target
):
46 return os
.path
.relpath (target
, gWorkspace
)
48 def NormalizePath(target
):
49 if isinstance(target
, tuple):
50 return os
.path
.normpath (os
.path
.join (*target
))
52 return os
.path
.normpath (target
)
54 if __name__
== '__main__':
56 # Create command line argument parser object
58 parser
= argparse
.ArgumentParser (
60 version
= __version__
,
61 description
= __description__
+ __copyright__
,
62 conflict_handler
= 'resolve'
65 '-a', '--arch', dest
= 'Arch', nargs
= '+', action
= 'append',
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.'''
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.'''
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.'''
82 '-b', '--buildtarget', dest
= 'BuildTarget', required
= True,
83 help = '''Using the TARGET to build the platform, overriding
84 target.txt's TARGET definition.'''
87 '--conf=', dest
= 'ConfDirectory', required
= True,
88 help = '''Specify the customized Conf directory.'''
91 '-D', '--define', dest
= 'Define', nargs
='*', action
= 'append',
92 help = '''Macro: "Name [= Value]".'''
95 '--makefile', dest
= 'Makefile', required
= True,
96 help = '''Makefile to run passing in arguments as makefile defines.'''
99 '-v', '--verbose', dest
= 'Verbose', action
= 'store_true',
100 help = '''Turn on verbose output with informational messages printed'''
104 # Parse command line arguments
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
)
113 gArgs
.Remaining
= ' '.join(remaining
)
121 # Find makefile in WORKSPACE or PACKAGES_PATH
125 PathList
.append(os
.environ
['WORKSPACE'])
127 Error ('WORKSPACE environment variable not set')
129 PathList
+= os
.environ
['PACKAGES_PATH'].split(os
.pathsep
)
132 for Path
in PathList
:
133 Makefile
= NormalizePath((Path
, gArgs
.Makefile
))
134 if os
.path
.exists (Makefile
):
136 if not os
.path
.exists(Makefile
):
137 Error ('makefile %s not found' % (gArgs
.Makefile
))
140 # Build command line arguments converting build arguments to makefile defines
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
))
149 for Item
in gArgs
.Define
:
150 if '=' not in Item
[0]:
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
))
159 CommandLine
= 'make -f %s' % (' '.join(CommandLine
))
165 Process
= subprocess
.Popen(CommandLine
, shell
=True)
167 Error ('make command not available. Please verify PATH')
168 Process
.communicate()
176 # Return status from running the makefile
178 sys
.exit(Process
.returncode
)