| 1 | n/a | import sys, os |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | # Template used then the program is a GUI program |
|---|
| 4 | n/a | WINMAINTEMPLATE = """ |
|---|
| 5 | n/a | #include <windows.h> |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | int WINAPI WinMain( |
|---|
| 8 | n/a | HINSTANCE hInstance, // handle to current instance |
|---|
| 9 | n/a | HINSTANCE hPrevInstance, // handle to previous instance |
|---|
| 10 | n/a | LPSTR lpCmdLine, // pointer to command line |
|---|
| 11 | n/a | int nCmdShow // show state of window |
|---|
| 12 | n/a | ) |
|---|
| 13 | n/a | { |
|---|
| 14 | n/a | extern int Py_FrozenMain(int, char **); |
|---|
| 15 | n/a | PyImport_FrozenModules = _PyImport_FrozenModules; |
|---|
| 16 | n/a | return Py_FrozenMain(__argc, __argv); |
|---|
| 17 | n/a | } |
|---|
| 18 | n/a | """ |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | SERVICETEMPLATE = """ |
|---|
| 21 | n/a | extern int PythonService_main(int, char **); |
|---|
| 22 | n/a | |
|---|
| 23 | n/a | int main( int argc, char **argv) |
|---|
| 24 | n/a | { |
|---|
| 25 | n/a | PyImport_FrozenModules = _PyImport_FrozenModules; |
|---|
| 26 | n/a | return PythonService_main(argc, argv); |
|---|
| 27 | n/a | } |
|---|
| 28 | n/a | """ |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | subsystem_details = { |
|---|
| 31 | n/a | # -s flag : (C entry point template), (is it __main__?), (is it a DLL?) |
|---|
| 32 | n/a | 'console' : (None, 1, 0), |
|---|
| 33 | n/a | 'windows' : (WINMAINTEMPLATE, 1, 0), |
|---|
| 34 | n/a | 'service' : (SERVICETEMPLATE, 0, 0), |
|---|
| 35 | n/a | 'com_dll' : ("", 0, 1), |
|---|
| 36 | n/a | } |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | def get_custom_entry_point(subsystem): |
|---|
| 39 | n/a | try: |
|---|
| 40 | n/a | return subsystem_details[subsystem][:2] |
|---|
| 41 | n/a | except KeyError: |
|---|
| 42 | n/a | raise ValueError("The subsystem %s is not known" % subsystem) |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | def makemakefile(outfp, vars, files, target): |
|---|
| 46 | n/a | save = sys.stdout |
|---|
| 47 | n/a | try: |
|---|
| 48 | n/a | sys.stdout = outfp |
|---|
| 49 | n/a | realwork(vars, files, target) |
|---|
| 50 | n/a | finally: |
|---|
| 51 | n/a | sys.stdout = save |
|---|
| 52 | n/a | |
|---|
| 53 | n/a | def realwork(vars, moddefns, target): |
|---|
| 54 | n/a | version_suffix = "%r%r" % sys.version_info[:2] |
|---|
| 55 | n/a | print("# Makefile for Microsoft Visual C++ generated by freeze.py script") |
|---|
| 56 | n/a | print() |
|---|
| 57 | n/a | print('target = %s' % target) |
|---|
| 58 | n/a | print('pythonhome = %s' % vars['prefix']) |
|---|
| 59 | n/a | print() |
|---|
| 60 | n/a | print('DEBUG=0 # Set to 1 to use the _d versions of Python.') |
|---|
| 61 | n/a | print('!IF $(DEBUG)') |
|---|
| 62 | n/a | print('debug_suffix=_d') |
|---|
| 63 | n/a | print('c_debug=/Zi /Od /DDEBUG /D_DEBUG') |
|---|
| 64 | n/a | print('l_debug=/DEBUG') |
|---|
| 65 | n/a | print('temp_dir=Build\\Debug') |
|---|
| 66 | n/a | print('!ELSE') |
|---|
| 67 | n/a | print('debug_suffix=') |
|---|
| 68 | n/a | print('c_debug=/Ox') |
|---|
| 69 | n/a | print('l_debug=') |
|---|
| 70 | n/a | print('temp_dir=Build\\Release') |
|---|
| 71 | n/a | print('!ENDIF') |
|---|
| 72 | n/a | print() |
|---|
| 73 | n/a | |
|---|
| 74 | n/a | print('# The following line assumes you have built Python using the standard instructions') |
|---|
| 75 | n/a | print('# Otherwise fix the following line to point to the library.') |
|---|
| 76 | n/a | print('pythonlib = "$(pythonhome)/pcbuild/python%s$(debug_suffix).lib"' % version_suffix) |
|---|
| 77 | n/a | print() |
|---|
| 78 | n/a | |
|---|
| 79 | n/a | # We only ever write one "entry point" symbol - either |
|---|
| 80 | n/a | # "main" or "WinMain". Therefore, there is no need to |
|---|
| 81 | n/a | # pass a subsystem switch to the linker as it works it |
|---|
| 82 | n/a | # out all by itself. However, the subsystem _does_ determine |
|---|
| 83 | n/a | # the file extension and additional linker flags. |
|---|
| 84 | n/a | target_link_flags = "" |
|---|
| 85 | n/a | target_ext = ".exe" |
|---|
| 86 | n/a | if subsystem_details[vars['subsystem']][2]: |
|---|
| 87 | n/a | target_link_flags = "-dll" |
|---|
| 88 | n/a | target_ext = ".dll" |
|---|
| 89 | n/a | |
|---|
| 90 | n/a | |
|---|
| 91 | n/a | print("# As the target uses Python%s.dll, we must use this compiler option!" % version_suffix) |
|---|
| 92 | n/a | print("cdl = /MD") |
|---|
| 93 | n/a | print() |
|---|
| 94 | n/a | print("all: $(target)$(debug_suffix)%s" % (target_ext)) |
|---|
| 95 | n/a | print() |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | print('$(temp_dir):') |
|---|
| 98 | n/a | print(r' if not exist $(temp_dir)\. mkdir $(temp_dir)') |
|---|
| 99 | n/a | print() |
|---|
| 100 | n/a | |
|---|
| 101 | n/a | objects = [] |
|---|
| 102 | n/a | libs = ["shell32.lib", "comdlg32.lib", "wsock32.lib", "user32.lib", "oleaut32.lib"] |
|---|
| 103 | n/a | for moddefn in moddefns: |
|---|
| 104 | n/a | print("# Module", moddefn.name) |
|---|
| 105 | n/a | for file in moddefn.sourceFiles: |
|---|
| 106 | n/a | base = os.path.basename(file) |
|---|
| 107 | n/a | base, ext = os.path.splitext(base) |
|---|
| 108 | n/a | objects.append(base + ".obj") |
|---|
| 109 | n/a | print(r'$(temp_dir)\%s.obj: "%s"' % (base, file)) |
|---|
| 110 | n/a | print("\t@$(CC) -c -nologo /Fo$* $(cdl) $(c_debug) /D BUILD_FREEZE", end=' ') |
|---|
| 111 | n/a | print('"-I$(pythonhome)/Include" "-I$(pythonhome)/PC" \\') |
|---|
| 112 | n/a | print("\t\t$(cflags) $(cdebug) $(cinclude) \\") |
|---|
| 113 | n/a | extra = moddefn.GetCompilerOptions() |
|---|
| 114 | n/a | if extra: |
|---|
| 115 | n/a | print("\t\t%s \\" % (' '.join(extra),)) |
|---|
| 116 | n/a | print('\t\t"%s"' % file) |
|---|
| 117 | n/a | print() |
|---|
| 118 | n/a | |
|---|
| 119 | n/a | # Add .lib files this module needs |
|---|
| 120 | n/a | for modlib in moddefn.GetLinkerLibs(): |
|---|
| 121 | n/a | if modlib not in libs: |
|---|
| 122 | n/a | libs.append(modlib) |
|---|
| 123 | n/a | |
|---|
| 124 | n/a | print("ADDN_LINK_FILES=", end=' ') |
|---|
| 125 | n/a | for addn in vars['addn_link']: print('"%s"' % (addn), end=' ') |
|---|
| 126 | n/a | print() ; print() |
|---|
| 127 | n/a | |
|---|
| 128 | n/a | print("OBJS=", end=' ') |
|---|
| 129 | n/a | for obj in objects: print(r'"$(temp_dir)\%s"' % (obj), end=' ') |
|---|
| 130 | n/a | print() ; print() |
|---|
| 131 | n/a | |
|---|
| 132 | n/a | print("LIBS=", end=' ') |
|---|
| 133 | n/a | for lib in libs: print('"%s"' % (lib), end=' ') |
|---|
| 134 | n/a | print() ; print() |
|---|
| 135 | n/a | |
|---|
| 136 | n/a | print("$(target)$(debug_suffix)%s: $(temp_dir) $(OBJS)" % (target_ext)) |
|---|
| 137 | n/a | print("\tlink -out:$(target)$(debug_suffix)%s %s" % |
|---|
| 138 | n/a | (target_ext, target_link_flags), "@<<") |
|---|
| 139 | n/a | print("\t$(OBJS)") |
|---|
| 140 | n/a | print("\t$(LIBS)") |
|---|
| 141 | n/a | print("\t$(ADDN_LINK_FILES)") |
|---|
| 142 | n/a | print("\t$(pythonlib) $(lcustom) $(l_debug)") |
|---|
| 143 | n/a | print("\t$(resources)") |
|---|
| 144 | n/a | print("<<") |
|---|
| 145 | n/a | print() |
|---|
| 146 | n/a | print("clean:") |
|---|
| 147 | n/a | print("\t-del /f *.obj") |
|---|
| 148 | n/a | print("\t-del /f $(target).exe") |
|---|