comparison setup.py @ 541:8895ede4e51e

Fix Windows and OSX build by making pkg-config optional and assuming every dependency is available.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 06 May 2014 20:04:10 +0200
parents 7c3c90468996
children a09f6990eab4
comparison
equal deleted inserted replaced
540:53fa73932e9a 541:8895ede4e51e
23 extension_names = [] 23 extension_names = []
24 extensions = [] 24 extensions = []
25 25
26 debug = False # True to generate HTML annotations and display infered types. 26 debug = False # True to generate HTML annotations and display infered types.
27 anmviewer = False # It’s currently broken anyway. 27 anmviewer = False # It’s currently broken anyway.
28 use_opengl = True # Compile the OpenGL backend if True
29 nthreads = 4 # How many processes to use for Cython compilation.
30
31 default_libs = {
32 'sdl2': '-lSDL2',
33 'SDL2_image': '-lSDL2_image',
34 'SDL2_mixer': '-lSDL2_mixer',
35 'SDL2_ttf': '-lSDL2_ttf',
36 'gl': '-lGL'
37 }
28 38
29 39
30 # Check for gl.pc, and don’t compile the OpenGL backend if it isn’t present. 40 # Check for gl.pc, and don’t compile the OpenGL backend if it isn’t present.
31 try: 41 try:
32 check_output([COMMAND] + GL_LIBRARIES) 42 check_output([COMMAND] + GL_LIBRARIES)
33 except CalledProcessError: 43 except CalledProcessError:
34 use_opengl = False 44 use_opengl = False
35 else: 45 except OSError:
36 use_opengl = True 46 # Assume GL is here if we can’t use pkg-config, but display a warning.
47 print('You don’t seem to have pkg-config installed. Please get a copy '
48 'from http://pkg-config.freedesktop.org/ and install it.\n'
49 'Continuing without it, assuming every dependency is available.')
37 50
38 51
39 def get_arguments(arg, libraries): 52 def get_arguments(arg, libraries):
40 try: 53 try:
41 return check_output([COMMAND, arg] + libraries).split() 54 return check_output([COMMAND, arg] + libraries).split()
42 except CalledProcessError: 55 except CalledProcessError:
43 # The error has already been displayed, just exit. 56 # The error has already been displayed, just exit.
44 sys.exit(1) 57 sys.exit(1)
45 except OSError: 58 except OSError:
46 print('You don’t seem to have pkg-config installed. Please get a copy ' 59 # We already said to the user pkg-config was suggested.
47 'from http://pkg-config.freedesktop.org/ and install it.\n' 60 if arg == '--cflags':
48 'If you prefer to use it from somewhere else, just modify the ' 61 return []
49 'setup.py script.') 62 return [default_libs[library] for library in libraries]
50 sys.exit(1)
51 63
52 64
53 try: 65 sdl_args = {'extra_compile_args': get_arguments('--cflags', SDL_LIBRARIES),
54 sdl_args = {'extra_compile_args': get_arguments('--cflags', SDL_LIBRARIES), 66 'extra_link_args': get_arguments('--libs', SDL_LIBRARIES)}
55 'extra_link_args': get_arguments('--libs', SDL_LIBRARIES)}
56 67
57 if use_opengl: 68 if use_opengl:
58 opengl_args = {'extra_compile_args': get_arguments('--cflags', GL_LIBRARIES + SDL_LIBRARIES), 69 opengl_args = {'extra_compile_args': get_arguments('--cflags', GL_LIBRARIES + SDL_LIBRARIES),
59 'extra_link_args': get_arguments('--libs', GL_LIBRARIES + SDL_LIBRARIES)} 70 'extra_link_args': get_arguments('--libs', GL_LIBRARIES + SDL_LIBRARIES)}
60 except CalledProcessError:
61 # The error has already been displayed, just exit.
62 sys.exit(1)
63 except OSError:
64 # pkg-config is needed too.
65 print('You don’t seem to have pkg-config installed. Please get a copy '
66 'from http://pkg-config.freedesktop.org/ and install it.\n'
67 'If you prefer to use it from somewhere else, just modify the '
68 'setup.py script.')
69 sys.exit(1)
70 71
71 72
72 for directory, _, files in os.walk('pytouhou'): 73 for directory, _, files in os.walk('pytouhou'):
73 package = directory.replace(os.path.sep, '.') 74 package = directory.replace(os.path.sep, '.')
75 if not use_opengl and package in ('pytouhou.ui.opengl', 'pytouhou.ui.opengl.shaders'):
76 continue
74 packages.append(package) 77 packages.append(package)
75 if package not in ('pytouhou.formats', 'pytouhou.game', 'pytouhou.lib', 'pytouhou.utils') and not package.startswith('pytouhou.ui'): 78 if package not in ('pytouhou.formats', 'pytouhou.game', 'pytouhou.lib',
79 'pytouhou.utils', 'pytouhou.ui', 'pytouhou.ui.opengl',
80 'pytouhou.ui.sdl'):
76 continue 81 continue
77 if package == 'pytouhou.ui' or package == 'pytouhou.ui.sdl': 82 if package in ('pytouhou.ui', 'pytouhou.ui.sdl'):
78 package_args = sdl_args 83 package_args = sdl_args
79 elif package == 'pytouhou.ui.opengl': 84 elif package == 'pytouhou.ui.opengl':
80 package_args = opengl_args 85 package_args = opengl_args
81 else: 86 else:
82 package_args = {} 87 package_args = {}
88 if extension_name == 'pytouhou.lib.sdl': 93 if extension_name == 'pytouhou.lib.sdl':
89 compile_args = sdl_args 94 compile_args = sdl_args
90 elif extension_name == 'pytouhou.ui.window' and use_opengl: 95 elif extension_name == 'pytouhou.ui.window' and use_opengl:
91 compile_args = opengl_args 96 compile_args = opengl_args
92 elif extension_name == 'pytouhou.ui.anmrenderer' and not anmviewer: 97 elif extension_name == 'pytouhou.ui.anmrenderer' and not anmviewer:
98 extension_names.pop()
93 continue 99 continue
94 elif package == 'pytouhou.formats' and extension_name != 'pytouhou.formats.anm0': 100 elif package == 'pytouhou.formats' and extension_name != 'pytouhou.formats.anm0':
95 continue 101 continue
96 else: 102 else:
97 compile_args = package_args 103 compile_args = package_args
98 extensions.append(Extension(extension_name, 104 extensions.append(Extension(extension_name,
99 [os.path.join(directory, filename)], 105 [os.path.join(directory, filename)],
100 **compile_args)) 106 **compile_args))
101 107
102 108
103 # TODO: find a less-intrusive, cleaner way to do this... 109 # OS-specific setuptools options.
104 try: 110 try:
105 from cx_Freeze import setup, Executable 111 from cx_Freeze import setup, Executable
106 except ImportError: 112 except ImportError:
107 is_windows = False 113 is_windows = False
108 extra = {} 114 extra = {}
109 else: 115 else:
110 is_windows = True 116 is_windows = True
111 extra = {'options': {'build_exe': {'includes': extension_names}}, 117 nthreads = None # It seems Windows can’t compile in parallel.
112 'executables': [Executable(script='eosd', base='Win32GUI')]} 118 base = 'Win32GUI' if sys.platform == 'win32' else None
119 extra = {'options': {'build_exe': {'includes': extension_names + ['glob', 'socket', 'select']}},
120 'executables': [Executable(script='eosd', base=base)]}
113 121
114 122
115 setup(name='PyTouhou', 123 setup(name='PyTouhou',
116 version='0.1', 124 version='0.1',
117 author='Thibaut Girka', 125 author='Thibaut Girka',
118 author_email='thib@sitedethib.com', 126 author_email='thib@sitedethib.com',
119 url='http://pytouhou.linkmauve.fr/', 127 url='http://pytouhou.linkmauve.fr/',
120 license='GPLv3', 128 license='GPLv3',
121 packages=packages, 129 packages=packages,
122 ext_modules=cythonize(extensions, nthreads=4, annotate=debug, 130 ext_modules=cythonize(extensions, nthreads=nthreads, annotate=debug,
123 compiler_directives={'infer_types': True, 131 compiler_directives={'infer_types': True,
124 'infer_types.verbose': debug, 132 'infer_types.verbose': debug,
125 'profile': debug}, 133 'profile': debug},
126 compile_time_env={'MAX_TEXTURES': 128, 134 compile_time_env={'MAX_TEXTURES': 128,
127 'MAX_ELEMENTS': 640 * 4 * 3, 135 'MAX_ELEMENTS': 640 * 4 * 3,