1 | n/a | #! /usr/bin/env python3 |
---|
2 | n/a | |
---|
3 | n/a | """Freeze a Python script into a binary. |
---|
4 | n/a | |
---|
5 | n/a | usage: freeze [options...] script [module]... |
---|
6 | n/a | |
---|
7 | n/a | Options: |
---|
8 | n/a | -p prefix: This is the prefix used when you ran ``make install'' |
---|
9 | n/a | in the Python build directory. |
---|
10 | n/a | (If you never ran this, freeze won't work.) |
---|
11 | n/a | The default is whatever sys.prefix evaluates to. |
---|
12 | n/a | It can also be the top directory of the Python source |
---|
13 | n/a | tree; then -P must point to the build tree. |
---|
14 | n/a | |
---|
15 | n/a | -P exec_prefix: Like -p but this is the 'exec_prefix', used to |
---|
16 | n/a | install objects etc. The default is whatever sys.exec_prefix |
---|
17 | n/a | evaluates to, or the -p argument if given. |
---|
18 | n/a | If -p points to the Python source tree, -P must point |
---|
19 | n/a | to the build tree, if different. |
---|
20 | n/a | |
---|
21 | n/a | -e extension: A directory containing additional .o files that |
---|
22 | n/a | may be used to resolve modules. This directory |
---|
23 | n/a | should also have a Setup file describing the .o files. |
---|
24 | n/a | On Windows, the name of a .INI file describing one |
---|
25 | n/a | or more extensions is passed. |
---|
26 | n/a | More than one -e option may be given. |
---|
27 | n/a | |
---|
28 | n/a | -o dir: Directory where the output files are created; default '.'. |
---|
29 | n/a | |
---|
30 | n/a | -m: Additional arguments are module names instead of filenames. |
---|
31 | n/a | |
---|
32 | n/a | -a package=dir: Additional directories to be added to the package's |
---|
33 | n/a | __path__. Used to simulate directories added by the |
---|
34 | n/a | package at runtime (eg, by OpenGL and win32com). |
---|
35 | n/a | More than one -a option may be given for each package. |
---|
36 | n/a | |
---|
37 | n/a | -l file: Pass the file to the linker (windows only) |
---|
38 | n/a | |
---|
39 | n/a | -d: Debugging mode for the module finder. |
---|
40 | n/a | |
---|
41 | n/a | -q: Make the module finder totally quiet. |
---|
42 | n/a | |
---|
43 | n/a | -h: Print this help message. |
---|
44 | n/a | |
---|
45 | n/a | -x module Exclude the specified module. It will still be imported |
---|
46 | n/a | by the frozen binary if it exists on the host system. |
---|
47 | n/a | |
---|
48 | n/a | -X module Like -x, except the module can never be imported by |
---|
49 | n/a | the frozen binary. |
---|
50 | n/a | |
---|
51 | n/a | -E: Freeze will fail if any modules can't be found (that |
---|
52 | n/a | were not excluded using -x or -X). |
---|
53 | n/a | |
---|
54 | n/a | -i filename: Include a file with additional command line options. Used |
---|
55 | n/a | to prevent command lines growing beyond the capabilities of |
---|
56 | n/a | the shell/OS. All arguments specified in filename |
---|
57 | n/a | are read and the -i option replaced with the parsed |
---|
58 | n/a | params (note - quoting args in this file is NOT supported) |
---|
59 | n/a | |
---|
60 | n/a | -s subsystem: Specify the subsystem (For Windows only.); |
---|
61 | n/a | 'console' (default), 'windows', 'service' or 'com_dll' |
---|
62 | n/a | |
---|
63 | n/a | -w: Toggle Windows (NT or 95) behavior. |
---|
64 | n/a | (For debugging only -- on a win32 platform, win32 behavior |
---|
65 | n/a | is automatic.) |
---|
66 | n/a | |
---|
67 | n/a | -r prefix=f: Replace path prefix. |
---|
68 | n/a | Replace prefix with f in the source path references |
---|
69 | n/a | contained in the resulting binary. |
---|
70 | n/a | |
---|
71 | n/a | Arguments: |
---|
72 | n/a | |
---|
73 | n/a | script: The Python script to be executed by the resulting binary. |
---|
74 | n/a | |
---|
75 | n/a | module ...: Additional Python modules (referenced by pathname) |
---|
76 | n/a | that will be included in the resulting binary. These |
---|
77 | n/a | may be .py or .pyc files. If -m is specified, these are |
---|
78 | n/a | module names that are search in the path instead. |
---|
79 | n/a | |
---|
80 | n/a | NOTES: |
---|
81 | n/a | |
---|
82 | n/a | In order to use freeze successfully, you must have built Python and |
---|
83 | n/a | installed it ("make install"). |
---|
84 | n/a | |
---|
85 | n/a | The script should not use modules provided only as shared libraries; |
---|
86 | n/a | if it does, the resulting binary is not self-contained. |
---|
87 | n/a | """ |
---|
88 | n/a | |
---|
89 | n/a | |
---|
90 | n/a | # Import standard modules |
---|
91 | n/a | |
---|
92 | n/a | import modulefinder |
---|
93 | n/a | import getopt |
---|
94 | n/a | import os |
---|
95 | n/a | import sys |
---|
96 | n/a | |
---|
97 | n/a | |
---|
98 | n/a | # Import the freeze-private modules |
---|
99 | n/a | |
---|
100 | n/a | import checkextensions |
---|
101 | n/a | import makeconfig |
---|
102 | n/a | import makefreeze |
---|
103 | n/a | import makemakefile |
---|
104 | n/a | import parsesetup |
---|
105 | n/a | import bkfile |
---|
106 | n/a | |
---|
107 | n/a | |
---|
108 | n/a | # Main program |
---|
109 | n/a | |
---|
110 | n/a | def main(): |
---|
111 | n/a | # overridable context |
---|
112 | n/a | prefix = None # settable with -p option |
---|
113 | n/a | exec_prefix = None # settable with -P option |
---|
114 | n/a | extensions = [] |
---|
115 | n/a | exclude = [] # settable with -x option |
---|
116 | n/a | addn_link = [] # settable with -l, but only honored under Windows. |
---|
117 | n/a | path = sys.path[:] |
---|
118 | n/a | modargs = 0 |
---|
119 | n/a | debug = 1 |
---|
120 | n/a | odir = '' |
---|
121 | n/a | win = sys.platform[:3] == 'win' |
---|
122 | n/a | replace_paths = [] # settable with -r option |
---|
123 | n/a | error_if_any_missing = 0 |
---|
124 | n/a | |
---|
125 | n/a | # default the exclude list for each platform |
---|
126 | n/a | if win: exclude = exclude + [ |
---|
127 | n/a | 'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', ] |
---|
128 | n/a | |
---|
129 | n/a | fail_import = exclude[:] |
---|
130 | n/a | |
---|
131 | n/a | # output files |
---|
132 | n/a | frozen_c = 'frozen.c' |
---|
133 | n/a | config_c = 'config.c' |
---|
134 | n/a | target = 'a.out' # normally derived from script name |
---|
135 | n/a | makefile = 'Makefile' |
---|
136 | n/a | subsystem = 'console' |
---|
137 | n/a | |
---|
138 | n/a | # parse command line by first replacing any "-i" options with the |
---|
139 | n/a | # file contents. |
---|
140 | n/a | pos = 1 |
---|
141 | n/a | while pos < len(sys.argv)-1: |
---|
142 | n/a | # last option can not be "-i", so this ensures "pos+1" is in range! |
---|
143 | n/a | if sys.argv[pos] == '-i': |
---|
144 | n/a | try: |
---|
145 | n/a | options = open(sys.argv[pos+1]).read().split() |
---|
146 | n/a | except IOError as why: |
---|
147 | n/a | usage("File name '%s' specified with the -i option " |
---|
148 | n/a | "can not be read - %s" % (sys.argv[pos+1], why) ) |
---|
149 | n/a | # Replace the '-i' and the filename with the read params. |
---|
150 | n/a | sys.argv[pos:pos+2] = options |
---|
151 | n/a | pos = pos + len(options) - 1 # Skip the name and the included args. |
---|
152 | n/a | pos = pos + 1 |
---|
153 | n/a | |
---|
154 | n/a | # Now parse the command line with the extras inserted. |
---|
155 | n/a | try: |
---|
156 | n/a | opts, args = getopt.getopt(sys.argv[1:], 'r:a:dEe:hmo:p:P:qs:wX:x:l:') |
---|
157 | n/a | except getopt.error as msg: |
---|
158 | n/a | usage('getopt error: ' + str(msg)) |
---|
159 | n/a | |
---|
160 | n/a | # process option arguments |
---|
161 | n/a | for o, a in opts: |
---|
162 | n/a | if o == '-h': |
---|
163 | n/a | print(__doc__) |
---|
164 | n/a | return |
---|
165 | n/a | if o == '-d': |
---|
166 | n/a | debug = debug + 1 |
---|
167 | n/a | if o == '-e': |
---|
168 | n/a | extensions.append(a) |
---|
169 | n/a | if o == '-m': |
---|
170 | n/a | modargs = 1 |
---|
171 | n/a | if o == '-o': |
---|
172 | n/a | odir = a |
---|
173 | n/a | if o == '-p': |
---|
174 | n/a | prefix = a |
---|
175 | n/a | if o == '-P': |
---|
176 | n/a | exec_prefix = a |
---|
177 | n/a | if o == '-q': |
---|
178 | n/a | debug = 0 |
---|
179 | n/a | if o == '-w': |
---|
180 | n/a | win = not win |
---|
181 | n/a | if o == '-s': |
---|
182 | n/a | if not win: |
---|
183 | n/a | usage("-s subsystem option only on Windows") |
---|
184 | n/a | subsystem = a |
---|
185 | n/a | if o == '-x': |
---|
186 | n/a | exclude.append(a) |
---|
187 | n/a | if o == '-X': |
---|
188 | n/a | exclude.append(a) |
---|
189 | n/a | fail_import.append(a) |
---|
190 | n/a | if o == '-E': |
---|
191 | n/a | error_if_any_missing = 1 |
---|
192 | n/a | if o == '-l': |
---|
193 | n/a | addn_link.append(a) |
---|
194 | n/a | if o == '-a': |
---|
195 | n/a | modulefinder.AddPackagePath(*a.split("=", 2)) |
---|
196 | n/a | if o == '-r': |
---|
197 | n/a | f,r = a.split("=", 2) |
---|
198 | n/a | replace_paths.append( (f,r) ) |
---|
199 | n/a | |
---|
200 | n/a | # modules that are imported by the Python runtime |
---|
201 | n/a | implicits = [] |
---|
202 | n/a | for module in ('site', 'warnings', 'encodings.utf_8', 'encodings.latin_1'): |
---|
203 | n/a | if module not in exclude: |
---|
204 | n/a | implicits.append(module) |
---|
205 | n/a | |
---|
206 | n/a | # default prefix and exec_prefix |
---|
207 | n/a | if not exec_prefix: |
---|
208 | n/a | if prefix: |
---|
209 | n/a | exec_prefix = prefix |
---|
210 | n/a | else: |
---|
211 | n/a | exec_prefix = sys.exec_prefix |
---|
212 | n/a | if not prefix: |
---|
213 | n/a | prefix = sys.prefix |
---|
214 | n/a | |
---|
215 | n/a | # determine whether -p points to the Python source tree |
---|
216 | n/a | ishome = os.path.exists(os.path.join(prefix, 'Python', 'ceval.c')) |
---|
217 | n/a | |
---|
218 | n/a | # locations derived from options |
---|
219 | n/a | version = '%d.%d' % sys.version_info[:2] |
---|
220 | n/a | flagged_version = version + sys.abiflags |
---|
221 | n/a | if win: |
---|
222 | n/a | extensions_c = 'frozen_extensions.c' |
---|
223 | n/a | if ishome: |
---|
224 | n/a | print("(Using Python source directory)") |
---|
225 | n/a | binlib = exec_prefix |
---|
226 | n/a | incldir = os.path.join(prefix, 'Include') |
---|
227 | n/a | config_h_dir = exec_prefix |
---|
228 | n/a | config_c_in = os.path.join(prefix, 'Modules', 'config.c.in') |
---|
229 | n/a | frozenmain_c = os.path.join(prefix, 'Python', 'frozenmain.c') |
---|
230 | n/a | makefile_in = os.path.join(exec_prefix, 'Makefile') |
---|
231 | n/a | if win: |
---|
232 | n/a | frozendllmain_c = os.path.join(exec_prefix, 'Pc\\frozen_dllmain.c') |
---|
233 | n/a | else: |
---|
234 | n/a | binlib = os.path.join(exec_prefix, |
---|
235 | n/a | 'lib', 'python%s' % version, |
---|
236 | n/a | 'config-%s' % flagged_version) |
---|
237 | n/a | incldir = os.path.join(prefix, 'include', 'python%s' % flagged_version) |
---|
238 | n/a | config_h_dir = os.path.join(exec_prefix, 'include', |
---|
239 | n/a | 'python%s' % flagged_version) |
---|
240 | n/a | config_c_in = os.path.join(binlib, 'config.c.in') |
---|
241 | n/a | frozenmain_c = os.path.join(binlib, 'frozenmain.c') |
---|
242 | n/a | makefile_in = os.path.join(binlib, 'Makefile') |
---|
243 | n/a | frozendllmain_c = os.path.join(binlib, 'frozen_dllmain.c') |
---|
244 | n/a | supp_sources = [] |
---|
245 | n/a | defines = [] |
---|
246 | n/a | includes = ['-I' + incldir, '-I' + config_h_dir] |
---|
247 | n/a | |
---|
248 | n/a | # sanity check of directories and files |
---|
249 | n/a | check_dirs = [prefix, exec_prefix, binlib, incldir] |
---|
250 | n/a | if not win: |
---|
251 | n/a | # These are not directories on Windows. |
---|
252 | n/a | check_dirs = check_dirs + extensions |
---|
253 | n/a | for dir in check_dirs: |
---|
254 | n/a | if not os.path.exists(dir): |
---|
255 | n/a | usage('needed directory %s not found' % dir) |
---|
256 | n/a | if not os.path.isdir(dir): |
---|
257 | n/a | usage('%s: not a directory' % dir) |
---|
258 | n/a | if win: |
---|
259 | n/a | files = supp_sources + extensions # extensions are files on Windows. |
---|
260 | n/a | else: |
---|
261 | n/a | files = [config_c_in, makefile_in] + supp_sources |
---|
262 | n/a | for file in supp_sources: |
---|
263 | n/a | if not os.path.exists(file): |
---|
264 | n/a | usage('needed file %s not found' % file) |
---|
265 | n/a | if not os.path.isfile(file): |
---|
266 | n/a | usage('%s: not a plain file' % file) |
---|
267 | n/a | if not win: |
---|
268 | n/a | for dir in extensions: |
---|
269 | n/a | setup = os.path.join(dir, 'Setup') |
---|
270 | n/a | if not os.path.exists(setup): |
---|
271 | n/a | usage('needed file %s not found' % setup) |
---|
272 | n/a | if not os.path.isfile(setup): |
---|
273 | n/a | usage('%s: not a plain file' % setup) |
---|
274 | n/a | |
---|
275 | n/a | # check that enough arguments are passed |
---|
276 | n/a | if not args: |
---|
277 | n/a | usage('at least one filename argument required') |
---|
278 | n/a | |
---|
279 | n/a | # check that file arguments exist |
---|
280 | n/a | for arg in args: |
---|
281 | n/a | if arg == '-m': |
---|
282 | n/a | break |
---|
283 | n/a | # if user specified -m on the command line before _any_ |
---|
284 | n/a | # file names, then nothing should be checked (as the |
---|
285 | n/a | # very first file should be a module name) |
---|
286 | n/a | if modargs: |
---|
287 | n/a | break |
---|
288 | n/a | if not os.path.exists(arg): |
---|
289 | n/a | usage('argument %s not found' % arg) |
---|
290 | n/a | if not os.path.isfile(arg): |
---|
291 | n/a | usage('%s: not a plain file' % arg) |
---|
292 | n/a | |
---|
293 | n/a | # process non-option arguments |
---|
294 | n/a | scriptfile = args[0] |
---|
295 | n/a | modules = args[1:] |
---|
296 | n/a | |
---|
297 | n/a | # derive target name from script name |
---|
298 | n/a | base = os.path.basename(scriptfile) |
---|
299 | n/a | base, ext = os.path.splitext(base) |
---|
300 | n/a | if base: |
---|
301 | n/a | if base != scriptfile: |
---|
302 | n/a | target = base |
---|
303 | n/a | else: |
---|
304 | n/a | target = base + '.bin' |
---|
305 | n/a | |
---|
306 | n/a | # handle -o option |
---|
307 | n/a | base_frozen_c = frozen_c |
---|
308 | n/a | base_config_c = config_c |
---|
309 | n/a | base_target = target |
---|
310 | n/a | if odir and not os.path.isdir(odir): |
---|
311 | n/a | try: |
---|
312 | n/a | os.mkdir(odir) |
---|
313 | n/a | print("Created output directory", odir) |
---|
314 | n/a | except OSError as msg: |
---|
315 | n/a | usage('%s: mkdir failed (%s)' % (odir, str(msg))) |
---|
316 | n/a | base = '' |
---|
317 | n/a | if odir: |
---|
318 | n/a | base = os.path.join(odir, '') |
---|
319 | n/a | frozen_c = os.path.join(odir, frozen_c) |
---|
320 | n/a | config_c = os.path.join(odir, config_c) |
---|
321 | n/a | target = os.path.join(odir, target) |
---|
322 | n/a | makefile = os.path.join(odir, makefile) |
---|
323 | n/a | if win: extensions_c = os.path.join(odir, extensions_c) |
---|
324 | n/a | |
---|
325 | n/a | # Handle special entry point requirements |
---|
326 | n/a | # (on Windows, some frozen programs do not use __main__, but |
---|
327 | n/a | # import the module directly. Eg, DLLs, Services, etc |
---|
328 | n/a | custom_entry_point = None # Currently only used on Windows |
---|
329 | n/a | python_entry_is_main = 1 # Is the entry point called __main__? |
---|
330 | n/a | # handle -s option on Windows |
---|
331 | n/a | if win: |
---|
332 | n/a | import winmakemakefile |
---|
333 | n/a | try: |
---|
334 | n/a | custom_entry_point, python_entry_is_main = \ |
---|
335 | n/a | winmakemakefile.get_custom_entry_point(subsystem) |
---|
336 | n/a | except ValueError as why: |
---|
337 | n/a | usage(why) |
---|
338 | n/a | |
---|
339 | n/a | |
---|
340 | n/a | # Actual work starts here... |
---|
341 | n/a | |
---|
342 | n/a | # collect all modules of the program |
---|
343 | n/a | dir = os.path.dirname(scriptfile) |
---|
344 | n/a | path[0] = dir |
---|
345 | n/a | mf = modulefinder.ModuleFinder(path, debug, exclude, replace_paths) |
---|
346 | n/a | |
---|
347 | n/a | if win and subsystem=='service': |
---|
348 | n/a | # If a Windows service, then add the "built-in" module. |
---|
349 | n/a | mod = mf.add_module("servicemanager") |
---|
350 | n/a | mod.__file__="dummy.pyd" # really built-in to the resulting EXE |
---|
351 | n/a | |
---|
352 | n/a | for mod in implicits: |
---|
353 | n/a | mf.import_hook(mod) |
---|
354 | n/a | for mod in modules: |
---|
355 | n/a | if mod == '-m': |
---|
356 | n/a | modargs = 1 |
---|
357 | n/a | continue |
---|
358 | n/a | if modargs: |
---|
359 | n/a | if mod[-2:] == '.*': |
---|
360 | n/a | mf.import_hook(mod[:-2], None, ["*"]) |
---|
361 | n/a | else: |
---|
362 | n/a | mf.import_hook(mod) |
---|
363 | n/a | else: |
---|
364 | n/a | mf.load_file(mod) |
---|
365 | n/a | |
---|
366 | n/a | # Alias "importlib._bootstrap" to "_frozen_importlib" so that the |
---|
367 | n/a | # import machinery can bootstrap. Do the same for |
---|
368 | n/a | # importlib._bootstrap_external. |
---|
369 | n/a | mf.modules["_frozen_importlib"] = mf.modules["importlib._bootstrap"] |
---|
370 | n/a | mf.modules["_frozen_importlib_external"] = mf.modules["importlib._bootstrap_external"] |
---|
371 | n/a | |
---|
372 | n/a | # Add the main script as either __main__, or the actual module name. |
---|
373 | n/a | if python_entry_is_main: |
---|
374 | n/a | mf.run_script(scriptfile) |
---|
375 | n/a | else: |
---|
376 | n/a | mf.load_file(scriptfile) |
---|
377 | n/a | |
---|
378 | n/a | if debug > 0: |
---|
379 | n/a | mf.report() |
---|
380 | n/a | print() |
---|
381 | n/a | dict = mf.modules |
---|
382 | n/a | |
---|
383 | n/a | if error_if_any_missing: |
---|
384 | n/a | missing = mf.any_missing() |
---|
385 | n/a | if missing: |
---|
386 | n/a | sys.exit("There are some missing modules: %r" % missing) |
---|
387 | n/a | |
---|
388 | n/a | # generate output for frozen modules |
---|
389 | n/a | files = makefreeze.makefreeze(base, dict, debug, custom_entry_point, |
---|
390 | n/a | fail_import) |
---|
391 | n/a | |
---|
392 | n/a | # look for unfrozen modules (builtin and of unknown origin) |
---|
393 | n/a | builtins = [] |
---|
394 | n/a | unknown = [] |
---|
395 | n/a | mods = sorted(dict.keys()) |
---|
396 | n/a | for mod in mods: |
---|
397 | n/a | if dict[mod].__code__: |
---|
398 | n/a | continue |
---|
399 | n/a | if not dict[mod].__file__: |
---|
400 | n/a | builtins.append(mod) |
---|
401 | n/a | else: |
---|
402 | n/a | unknown.append(mod) |
---|
403 | n/a | |
---|
404 | n/a | # search for unknown modules in extensions directories (not on Windows) |
---|
405 | n/a | addfiles = [] |
---|
406 | n/a | frozen_extensions = [] # Windows list of modules. |
---|
407 | n/a | if unknown or (not win and builtins): |
---|
408 | n/a | if not win: |
---|
409 | n/a | addfiles, addmods = \ |
---|
410 | n/a | checkextensions.checkextensions(unknown+builtins, |
---|
411 | n/a | extensions) |
---|
412 | n/a | for mod in addmods: |
---|
413 | n/a | if mod in unknown: |
---|
414 | n/a | unknown.remove(mod) |
---|
415 | n/a | builtins.append(mod) |
---|
416 | n/a | else: |
---|
417 | n/a | # Do the windows thang... |
---|
418 | n/a | import checkextensions_win32 |
---|
419 | n/a | # Get a list of CExtension instances, each describing a module |
---|
420 | n/a | # (including its source files) |
---|
421 | n/a | frozen_extensions = checkextensions_win32.checkextensions( |
---|
422 | n/a | unknown, extensions, prefix) |
---|
423 | n/a | for mod in frozen_extensions: |
---|
424 | n/a | unknown.remove(mod.name) |
---|
425 | n/a | |
---|
426 | n/a | # report unknown modules |
---|
427 | n/a | if unknown: |
---|
428 | n/a | sys.stderr.write('Warning: unknown modules remain: %s\n' % |
---|
429 | n/a | ' '.join(unknown)) |
---|
430 | n/a | |
---|
431 | n/a | # windows gets different treatment |
---|
432 | n/a | if win: |
---|
433 | n/a | # Taking a shortcut here... |
---|
434 | n/a | import winmakemakefile, checkextensions_win32 |
---|
435 | n/a | checkextensions_win32.write_extension_table(extensions_c, |
---|
436 | n/a | frozen_extensions) |
---|
437 | n/a | # Create a module definition for the bootstrap C code. |
---|
438 | n/a | xtras = [frozenmain_c, os.path.basename(frozen_c), |
---|
439 | n/a | frozendllmain_c, os.path.basename(extensions_c)] + files |
---|
440 | n/a | maindefn = checkextensions_win32.CExtension( '__main__', xtras ) |
---|
441 | n/a | frozen_extensions.append( maindefn ) |
---|
442 | n/a | with open(makefile, 'w') as outfp: |
---|
443 | n/a | winmakemakefile.makemakefile(outfp, |
---|
444 | n/a | locals(), |
---|
445 | n/a | frozen_extensions, |
---|
446 | n/a | os.path.basename(target)) |
---|
447 | n/a | return |
---|
448 | n/a | |
---|
449 | n/a | # generate config.c and Makefile |
---|
450 | n/a | builtins.sort() |
---|
451 | n/a | with open(config_c_in) as infp, bkfile.open(config_c, 'w') as outfp: |
---|
452 | n/a | makeconfig.makeconfig(infp, outfp, builtins) |
---|
453 | n/a | |
---|
454 | n/a | cflags = ['$(OPT)'] |
---|
455 | n/a | cppflags = defines + includes |
---|
456 | n/a | libs = [os.path.join(binlib, '$(LDLIBRARY)')] |
---|
457 | n/a | |
---|
458 | n/a | somevars = {} |
---|
459 | n/a | if os.path.exists(makefile_in): |
---|
460 | n/a | makevars = parsesetup.getmakevars(makefile_in) |
---|
461 | n/a | for key in makevars: |
---|
462 | n/a | somevars[key] = makevars[key] |
---|
463 | n/a | |
---|
464 | n/a | somevars['CFLAGS'] = ' '.join(cflags) # override |
---|
465 | n/a | somevars['CPPFLAGS'] = ' '.join(cppflags) # override |
---|
466 | n/a | files = [base_config_c, base_frozen_c] + \ |
---|
467 | n/a | files + supp_sources + addfiles + libs + \ |
---|
468 | n/a | ['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)'] |
---|
469 | n/a | |
---|
470 | n/a | with bkfile.open(makefile, 'w') as outfp: |
---|
471 | n/a | makemakefile.makemakefile(outfp, somevars, files, base_target) |
---|
472 | n/a | |
---|
473 | n/a | # Done! |
---|
474 | n/a | |
---|
475 | n/a | if odir: |
---|
476 | n/a | print('Now run "make" in', odir, end=' ') |
---|
477 | n/a | print('to build the target:', base_target) |
---|
478 | n/a | else: |
---|
479 | n/a | print('Now run "make" to build the target:', base_target) |
---|
480 | n/a | |
---|
481 | n/a | |
---|
482 | n/a | # Print usage message and exit |
---|
483 | n/a | |
---|
484 | n/a | def usage(msg): |
---|
485 | n/a | sys.stdout = sys.stderr |
---|
486 | n/a | print("Error:", msg) |
---|
487 | n/a | print("Use ``%s -h'' for help" % sys.argv[0]) |
---|
488 | n/a | sys.exit(2) |
---|
489 | n/a | |
---|
490 | n/a | |
---|
491 | n/a | main() |
---|