Mercurial > pygame
annotate config.py @ 3182:0c07af110477 docs-changes
Ignore Sphinx-generated files
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 22:35:43 +0000 |
| parents | 55a175eb7c7b |
| children |
| rev | line source |
|---|---|
| 26 | 1 #!/usr/bin/env python |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
2 # For MinGW build requires Python 2.4 or better and win32api. |
| 26 | 3 |
| 4 """Quick tool to help setup the needed paths and flags | |
| 5 in your Setup file. This will call the appropriate sub-config | |
| 6 scripts automatically. | |
| 50 | 7 |
| 8 each platform config file only needs a "main" routine | |
| 9 that returns a list of instances. the instances must | |
| 10 contain the following variables. | |
| 11 name: name of the dependency, as references in Setup (SDL, FONT, etc) | |
| 12 inc_dir: path to include | |
| 13 lib_dir: library directory | |
| 14 lib: name of library to be linked to | |
| 15 found: true if the dep is available | |
| 16 cflags: extra compile flags | |
| 26 | 17 """ |
| 18 | |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
19 import msysio |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
20 import mingwcfg |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1453
diff
changeset
|
21 import sys, os, shutil |
| 50 | 22 |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
23 def print_(*args, **kwds): |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
24 """Simular to the Python 3.0 print function""" |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
25 # This not only supports MSYS but is also a head start on the move to |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
26 # Python 3.0. Also, this function can be overridden for testing. |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
27 msysio.print_(*args, **kwds) |
| 26 | 28 |
| 29 def confirm(message): | |
| 50 | 30 "ask a yes/no question, return result" |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
31 reply = msysio.raw_input_("\n%s [Y/n]:" % message) |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1453
diff
changeset
|
32 if reply and reply[0].lower() == 'n': |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1453
diff
changeset
|
33 return False |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1453
diff
changeset
|
34 return True |
| 26 | 35 |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
36 def is_msys_mingw(): |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
37 """Return true if this in an MinGW/MSYS build |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
38 |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
39 The user may prompted for confirmation so only call this function |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
40 once. |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
41 """ |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
42 if msysio.is_msys(): |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
43 return 1 |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
44 if ('MINGW_ROOT_DIRECTORY' in os.environ or |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
45 os.path.isfile(mingwcfg.path)): |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
46 return confirm("Is this an mingw/msys build") |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
47 return 0 |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
48 |
| 50 | 49 def prepdep(dep, basepath): |
| 50 "add some vars to a dep" | |
|
807
3b0f4ccf23c4
Patches from Marcus for scrap. This gets windows bitmap support working.
Rene Dudfield <renesd@gmail.com>
parents:
585
diff
changeset
|
51 if dep.libs: |
|
3b0f4ccf23c4
Patches from Marcus for scrap. This gets windows bitmap support working.
Rene Dudfield <renesd@gmail.com>
parents:
585
diff
changeset
|
52 dep.line = dep.name + ' =' |
|
3b0f4ccf23c4
Patches from Marcus for scrap. This gets windows bitmap support working.
Rene Dudfield <renesd@gmail.com>
parents:
585
diff
changeset
|
53 for lib in dep.libs: |
|
3b0f4ccf23c4
Patches from Marcus for scrap. This gets windows bitmap support working.
Rene Dudfield <renesd@gmail.com>
parents:
585
diff
changeset
|
54 dep.line += ' -l' + lib |
| 356 | 55 else: |
| 56 dep.line = dep.name + ' = -I.' | |
| 57 | |
| 56 | 58 dep.varname = '$('+dep.name+')' |
| 59 | |
| 50 | 60 if not dep.found: |
| 61 if dep.name == 'SDL': #fudge if this is unfound SDL | |
| 62 dep.line = 'SDL = -I/NEED_INC_PATH_FIX -L/NEED_LIB_PATH_FIX -lSDL' | |
| 63 dep.varname = '$('+dep.name+')' | |
| 64 dep.found = 1 | |
| 65 return | |
| 66 | |
| 67 inc = lid = lib = "" | |
| 68 if basepath: | |
| 69 if dep.inc_dir: inc = ' -I$(BASE)'+dep.inc_dir[len(basepath):] | |
| 70 if dep.lib_dir: lid = ' -L$(BASE)'+dep.lib_dir[len(basepath):] | |
| 71 else: | |
| 72 if dep.inc_dir: inc = ' -I' + dep.inc_dir | |
| 73 if dep.lib_dir: lid = ' -L' + dep.lib_dir | |
|
807
3b0f4ccf23c4
Patches from Marcus for scrap. This gets windows bitmap support working.
Rene Dudfield <renesd@gmail.com>
parents:
585
diff
changeset
|
74 libs = '' |
|
3b0f4ccf23c4
Patches from Marcus for scrap. This gets windows bitmap support working.
Rene Dudfield <renesd@gmail.com>
parents:
585
diff
changeset
|
75 for lib in dep.libs: |
|
3b0f4ccf23c4
Patches from Marcus for scrap. This gets windows bitmap support working.
Rene Dudfield <renesd@gmail.com>
parents:
585
diff
changeset
|
76 libs += ' -l' + lib |
|
907
2d530d8fe54f
In build process merged Setup.in and Setup_win.in
Lenard Lindstrom <len-l@telus.net>
parents:
896
diff
changeset
|
77 |
|
2d530d8fe54f
In build process merged Setup.in and Setup_win.in
Lenard Lindstrom <len-l@telus.net>
parents:
896
diff
changeset
|
78 if dep.name.startswith('COPYLIB_'): |
|
2d530d8fe54f
In build process merged Setup.in and Setup_win.in
Lenard Lindstrom <len-l@telus.net>
parents:
896
diff
changeset
|
79 dep.line = dep.name + libs + lid |
|
2d530d8fe54f
In build process merged Setup.in and Setup_win.in
Lenard Lindstrom <len-l@telus.net>
parents:
896
diff
changeset
|
80 else: |
|
2d530d8fe54f
In build process merged Setup.in and Setup_win.in
Lenard Lindstrom <len-l@telus.net>
parents:
896
diff
changeset
|
81 dep.line = dep.name+' =' + inc + lid + ' ' + dep.cflags + libs |
| 50 | 82 |
| 1453 | 83 def writesetupfile(deps, basepath, additional_lines): |
| 50 | 84 "create a modified copy of Setup.in" |
| 85 origsetup = open('Setup.in', 'r') | |
| 86 newsetup = open('Setup', 'w') | |
| 87 line = '' | |
| 88 while line.find('#--StartConfig') == -1: | |
| 89 newsetup.write(line) | |
| 90 line = origsetup.readline() | |
| 91 while line.find('#--EndConfig') == -1: | |
| 92 line = origsetup.readline() | |
| 93 | |
| 94 if basepath: | |
| 95 newsetup.write('BASE = ' + basepath + '\n') | |
| 96 for d in deps: | |
| 97 newsetup.write(d.line + '\n') | |
| 98 | |
| 1453 | 99 lines = origsetup.readlines() |
|
1981
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
100 |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
101 # overwrite lines which already exist with new ones. |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
102 new_lines = [] |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
103 for l in lines: |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
104 addit = 1 |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
105 parts = l.split() |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
106 for al in additional_lines: |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
107 aparts = al.split() |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
108 if aparts and parts: |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
109 if aparts[0] == parts[0]: |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
110 #print ('the same!' + repr(aparts) + repr(parts)) |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
111 #the same, we should not add the old one. |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
112 #It will be overwritten by the new one. |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
113 addit = 0 |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
114 if addit: |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
115 new_lines.append(l) |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
116 |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
117 new_lines.extend(additional_lines) |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
118 lines = new_lines |
|
07cbe94f9ece
Config from platform specific overwrites original if first word is the same.
Rene Dudfield <renesd@gmail.com>
parents:
1907
diff
changeset
|
119 |
| 1453 | 120 for line in lines: |
| 50 | 121 useit = 1 |
| 59 | 122 if not line.startswith('COPYLIB'): |
| 123 for d in deps: | |
| 124 if line.find(d.varname)!=-1 and not d.found: | |
| 125 useit = 0 | |
| 126 newsetup.write('#'+line) | |
| 127 break | |
| 487 | 128 if useit: |
| 1453 | 129 newsetup.write(line) |
| 50 | 130 |
| 26 | 131 def main(): |
| 1453 | 132 additional_platform_setup = [] |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1453
diff
changeset
|
133 if (sys.platform == 'win32' and |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1453
diff
changeset
|
134 # Note that msys builds supported for 2.6 and greater. Use prebuilt. |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1453
diff
changeset
|
135 (sys.version_info >= (2, 6) or not is_msys_mingw())): |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
136 print_('Using WINDOWS configuration...\n') |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
137 import config_win as CFG |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
138 elif sys.platform == 'win32': |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
139 print_('Using WINDOWS mingw/msys configuration...\n') |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
140 import config_msys as CFG |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
141 elif sys.platform == 'darwin': |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
142 print_('Using Darwin configuration...\n') |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
143 import config_darwin as CFG |
|
1907
b8387770f9f6
python3.1 support for OSX.
Rene Dudfield <renesd@gmail.com>
parents:
1553
diff
changeset
|
144 additional_platform_setup = open("Setup_Darwin.in", "r").readlines() |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
145 else: |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
146 print_('Using UNIX configuration...\n') |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
147 import config_unix as CFG |
|
2124
55a175eb7c7b
reenable the camera module for linux
Nirav Patel <nrp@eclecti.cc>
parents:
1981
diff
changeset
|
148 additional_platform_setup = open("Setup_Unix.in", "r").readlines() |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
149 |
| 26 | 150 if os.path.isfile('Setup'): |
| 542 | 151 if "-auto" in sys.argv or confirm('Backup existing "Setup" file'): |
| 26 | 152 shutil.copyfile('Setup', 'Setup.bak') |
| 542 | 153 if not "-auto" in sys.argv and os.path.isdir('build'): |
| 26 | 154 if confirm('Remove old build directory (force recompile)'): |
| 155 shutil.rmtree('build', 0) | |
| 156 | |
| 50 | 157 deps = CFG.main() |
| 158 if deps: | |
| 122 | 159 basepath = None |
| 50 | 160 for d in deps: |
| 161 prepdep(d, basepath) | |
| 1453 | 162 writesetupfile(deps, basepath, additional_platform_setup) |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
163 print_("""\nIf you get compiler errors during install, doublecheck |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
164 the compiler flags in the "Setup" file.\n""") |
| 50 | 165 else: |
|
916
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
166 print_("""\nThere was an error creating the Setup file, check for errors |
|
8a7d9b2de067
MinGW/MSYS build process more automated and DLLs Win32 GUI by default
Lenard Lindstrom <len-l@telus.net>
parents:
907
diff
changeset
|
167 or make a copy of "Setup.in" and edit by hand.""") |
| 359 | 168 |
| 26 | 169 if __name__ == '__main__': main() |
