comparison setup.py @ 451:c034570ac785

Give a friendlier error message if pkg-config isn’t found.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 Aug 2013 20:04:39 +0200
parents 2a352118c55a
children 6864a38b2413
comparison
equal deleted inserted replaced
450:2a352118c55a 451:c034570ac785
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:
13 print('You don’t seem to have Cython installed. Please get a ' 13 print('You don’t seem to have Cython installed. Please get a '
14 'copy from www.cython.org and install it') 14 'copy from http://www.cython.org/ and install it.')
15 sys.exit(1) 15 sys.exit(1)
16 16
17 17
18 COMMAND = 'pkg-config' 18 COMMAND = 'pkg-config'
19 LIBRARIES = ['sdl2', 'SDL2_image', 'SDL2_mixer'] 19 SDL_LIBRARIES = ['sdl2', 'SDL2_image', 'SDL2_mixer']
20 20
21 packages = [] 21 packages = []
22 extension_names = [] 22 extension_names = []
23 extensions = [] 23 extensions = []
24
25
26 def get_arguments(arg, libraries):
27 try:
28 return check_output([COMMAND, arg] + libraries).split()
29 except OSError:
30 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'
32 'If you prefer to use it from somewhere else, just modify the '
33 'setup.py script.')
34 sys.exit(1)
24 35
25 36
26 for directory, _, files in os.walk('pytouhou'): 37 for directory, _, files in os.walk('pytouhou'):
27 package = directory.replace(os.path.sep, '.') 38 package = directory.replace(os.path.sep, '.')
28 packages.append(package) 39 packages.append(package)
29 for filename in files: 40 for filename in files:
30 if filename.endswith('.pyx') or filename.endswith('.py') and not filename == '__init__.py': 41 if filename.endswith('.pyx') or filename.endswith('.py') and not filename == '__init__.py':
31 extension_name = '%s.%s' % (package, os.path.splitext(filename)[0]) 42 extension_name = '%s.%s' % (package, os.path.splitext(filename)[0])
32 extension_names.append(extension_name) 43 extension_names.append(extension_name)
33 if extension_name == 'pytouhou.lib.sdl': 44 if extension_name == 'pytouhou.lib.sdl':
34 compile_args = check_output([COMMAND, '--cflags'] + LIBRARIES).split() 45 compile_args = get_arguments('--cflags', SDL_LIBRARIES)
35 link_args = check_output([COMMAND, '--libs'] + LIBRARIES).split() 46 link_args = get_arguments('--libs', SDL_LIBRARIES)
36 elif extension_name.startswith('pytouhou.ui.'): #XXX 47 elif extension_name.startswith('pytouhou.ui.'): #XXX
37 compile_args = check_output([COMMAND, '--cflags', 'gl']).split() 48 compile_args = get_arguments('--cflags', ['gl'])
38 link_args = check_output([COMMAND, '--libs', 'gl']).split() 49 link_args = get_arguments('--libs', ['gl'])
39 else: 50 else:
40 compile_args = None 51 compile_args = None
41 link_args = None 52 link_args = None
42 extensions.append(Extension(extension_name, 53 extensions.append(Extension(extension_name,
43 [os.path.join(directory, filename)], 54 [os.path.join(directory, filename)],