comparison setup.py @ 513:5e3e0b09a531

Move the OpenGL backend to its own package.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 05 Dec 2013 02:16:31 +0100
parents b39ad30c6620
children b3193b43a86c
comparison
equal deleted inserted replaced
512:b39ad30c6620 513:5e3e0b09a531
2 2
3 import os 3 import os
4 import sys 4 import sys
5 from distutils.core import setup 5 from distutils.core import setup
6 from distutils.extension import Extension 6 from distutils.extension import Extension
7 from subprocess import check_output 7 from subprocess import check_output, CalledProcessError
8 8
9 # Cython is needed 9 # Cython is needed
10 try: 10 try:
11 from Cython.Build import cythonize 11 from Cython.Build import cythonize
12 except ImportError: 12 except ImportError:
15 sys.exit(1) 15 sys.exit(1)
16 16
17 17
18 COMMAND = 'pkg-config' 18 COMMAND = 'pkg-config'
19 SDL_LIBRARIES = ['sdl2', 'SDL2_image', 'SDL2_mixer', 'SDL2_ttf'] 19 SDL_LIBRARIES = ['sdl2', 'SDL2_image', 'SDL2_mixer', 'SDL2_ttf']
20 GL_LIBRARIES = ['gl']
20 21
21 packages = [] 22 packages = []
22 extension_names = [] 23 extension_names = []
23 extensions = [] 24 extensions = []
24 25
25 26
27 # Check for gl.pc, and don’t compile the OpenGL backend if it isn’t present.
28 try:
29 check_output([COMMAND] + GL_LIBRARIES)
30 except CalledProcessError:
31 use_opengl = False
32 else:
33 use_opengl = True
34
35
26 def get_arguments(arg, libraries): 36 def get_arguments(arg, libraries):
27 try: 37 try:
28 return check_output([COMMAND, arg] + libraries).split() 38 return check_output([COMMAND, arg] + libraries).split()
39 except CalledProcessError:
40 # The error has already been displayed, just exit.
41 sys.exit(1)
29 except OSError: 42 except OSError:
30 print('You don’t seem to have pkg-config installed. Please get a copy ' 43 print('You don’t seem to have pkg-config installed. Please get a copy '
31 'from http://pkg-config.freedesktop.org/ and install it.\n' 44 'from http://pkg-config.freedesktop.org/ and install it.\n'
32 'If you prefer to use it from somewhere else, just modify the ' 45 'If you prefer to use it from somewhere else, just modify the '
33 'setup.py script.') 46 'setup.py script.')
34 sys.exit(1) 47 sys.exit(1)
35 48
36 49
50 try:
51 sdl_args = {'extra_compile_args': get_arguments('--cflags', SDL_LIBRARIES),
52 'extra_link_args': get_arguments('--libs', SDL_LIBRARIES)}
53
54 if use_opengl:
55 opengl_args = {'extra_compile_args': get_arguments('--cflags', GL_LIBRARIES + SDL_LIBRARIES),
56 'extra_link_args': get_arguments('--libs', GL_LIBRARIES + SDL_LIBRARIES)}
57 except CalledProcessError:
58 # The error has already been displayed, just exit.
59 sys.exit(1)
60 except OSError:
61 # pkg-config is needed too.
62 print('You don’t seem to have pkg-config installed. Please get a copy '
63 'from http://pkg-config.freedesktop.org/ and install it.\n'
64 'If you prefer to use it from somewhere else, just modify the '
65 'setup.py script.')
66 sys.exit(1)
67
68
37 for directory, _, files in os.walk('pytouhou'): 69 for directory, _, files in os.walk('pytouhou'):
38 package = directory.replace(os.path.sep, '.') 70 package = directory.replace(os.path.sep, '.')
39 packages.append(package) 71 packages.append(package)
40 if package not in ('pytouhou.game', 'pytouhou.lib', 'pytouhou.ui', 'pytouhou.utils', 'pytouhou.ui.sdl'): 72 if package not in ('pytouhou.game', 'pytouhou.lib', 'pytouhou.utils') and not package.startswith('pytouhou.ui'):
41 continue 73 continue
42 if package == 'pytouhou.ui': 74 if package == 'pytouhou.ui' or package == 'pytouhou.ui.sdl':
43 compile_args = get_arguments('--cflags', ['gl'] + SDL_LIBRARIES) 75 package_args = sdl_args
44 link_args = get_arguments('--libs', ['gl'] + SDL_LIBRARIES) 76 elif package == 'pytouhou.ui.opengl':
45 elif package == 'pytouhou.ui.sdl': 77 package_args = opengl_args
46 compile_args = get_arguments('--cflags', SDL_LIBRARIES)
47 link_args = get_arguments('--libs', SDL_LIBRARIES)
48 else: 78 else:
49 compile_args = None 79 package_args = {}
50 link_args = None
51 for filename in files: 80 for filename in files:
52 if (filename.endswith('.pyx') or filename.endswith('.py') and 81 if (filename.endswith('.pyx') or filename.endswith('.py') and
53 not filename == '__init__.py'): 82 not filename == '__init__.py'):
54 extension_name = '%s.%s' % (package, os.path.splitext(filename)[0]) 83 extension_name = '%s.%s' % (package, os.path.splitext(filename)[0])
55 extension_names.append(extension_name) 84 extension_names.append(extension_name)
56 if extension_name == 'pytouhou.lib.sdl': 85 if extension_name == 'pytouhou.lib.sdl':
57 compile_args = get_arguments('--cflags', SDL_LIBRARIES) 86 compile_args = sdl_args
58 link_args = get_arguments('--libs', SDL_LIBRARIES) 87 elif extension_name == 'pytouhou.ui.window' and use_opengl:
88 compile_args = opengl_args
89 else:
90 compile_args = package_args
59 extensions.append(Extension(extension_name, 91 extensions.append(Extension(extension_name,
60 [os.path.join(directory, filename)], 92 [os.path.join(directory, filename)],
61 extra_compile_args=compile_args, 93 **compile_args))
62 extra_link_args=link_args))
63 94
64 95
65 # TODO: find a less-intrusive, cleaner way to do this... 96 # TODO: find a less-intrusive, cleaner way to do this...
66 try: 97 try:
67 from cx_Freeze import setup, Executable 98 from cx_Freeze import setup, Executable
85 compiler_directives={'infer_types': True, 116 compiler_directives={'infer_types': True,
86 'infer_types.verbose': True}, 117 'infer_types.verbose': True},
87 compile_time_env={'MAX_TEXTURES': 1024, 118 compile_time_env={'MAX_TEXTURES': 1024,
88 'MAX_ELEMENTS': 640 * 4 * 3, 119 'MAX_ELEMENTS': 640 * 4 * 3,
89 'MAX_CHANNELS': 26, 120 'MAX_CHANNELS': 26,
121 'USE_OPENGL': use_opengl,
90 'USE_GLEW': is_windows}), 122 'USE_GLEW': is_windows}),
91 scripts=['eosd', 'anmviewer'], 123 scripts=['eosd', 'anmviewer'],
92 **extra) 124 **extra)