4040input_c = Extension ('evdev._input' , sources = ['evdev/input.c' ], extra_compile_args = cflags )
4141uinput_c = Extension ('evdev._uinput' , sources = ['evdev/uinput.c' ], extra_compile_args = cflags )
4242ecodes_c = Extension ('evdev._ecodes' , sources = ['evdev/ecodes.c' ], extra_compile_args = cflags )
43+ iprops_c = Extension ('evdev.iprops' , sources = ['evdev/iprops.c' ], extra_compile_args = cflags )
4344
4445#-----------------------------------------------------------------------------
4546kw = {
5758 'classifiers' : classifiers ,
5859
5960 'packages' : ['evdev' ],
60- 'ext_modules' : [input_c , uinput_c , ecodes_c ],
61+ 'ext_modules' : [input_c , uinput_c , ecodes_c , iprops_c ],
6162 'include_package_data' : False ,
6263 'zip_safe' : True ,
6364 'cmdclass' : {},
@@ -106,6 +107,48 @@ def create_ecodes(headers=None):
106107 check_call (cmd , cwd = "%s/evdev" % here , shell = True )
107108
108109
110+ #-----------------------------------------------------------------------------
111+ def create_iprops (headers = None ):
112+ if not headers :
113+ headers = [
114+ '/usr/include/linux/input.h' ,
115+ '/usr/include/linux/input-event-codes.h' ,
116+ '/usr/include/linux/uinput.h' ,
117+ ]
118+
119+ headers = [header for header in headers if os .path .isfile (header )]
120+ if not headers :
121+ msg = '''\
122+ The 'linux/input.h' and 'linux/input-event-codes.h' include files
123+ are missing. You will have to install the kernel header files in
124+ order to continue:
125+
126+ yum install kernel-headers-$(uname -r)
127+ apt-get install linux-headers-$(uname -r)
128+ emerge sys-kernel/linux-headers
129+ pacman -S kernel-headers
130+
131+ In case they are installed in a non-standard location, you may use
132+ the '--evdev-headers' option to specify one or more colon-separated
133+ paths. For example:
134+
135+ python setup.py \\
136+ build \\
137+ build_iprops --evdev-headers path/input.h:path/input-event-codes.h \\
138+ build_ext --include-dirs path/ \\
139+ install
140+ '''
141+
142+ sys .stderr .write (textwrap .dedent (msg ))
143+ sys .exit (1 )
144+
145+ from subprocess import check_call
146+
147+ print ('writing iprops.c (using %s)' % ' ' .join (headers ))
148+ cmd = '%s geniprops.py %s > iprops.c' % (sys .executable , ' ' .join (headers ))
149+ check_call (cmd , cwd = "%s/evdev" % here , shell = True )
150+
151+
109152#-----------------------------------------------------------------------------
110153class build_ecodes (Command ):
111154 description = 'generate ecodes.c'
@@ -125,6 +168,24 @@ def run(self):
125168 create_ecodes (self .evdev_headers )
126169
127170
171+ class build_iprops (Command ):
172+ description = 'generate iprops.c'
173+
174+ user_options = [
175+ ('evdev-headers=' , None , 'colon-separated paths to input subsystem headers' ),
176+ ]
177+
178+ def initialize_options (self ):
179+ self .evdev_headers = None
180+
181+ def finalize_options (self ):
182+ if self .evdev_headers :
183+ self .evdev_headers = self .evdev_headers .split (':' )
184+
185+ def run (self ):
186+ create_iprops (self .evdev_headers )
187+
188+
128189class build_ext (_build_ext .build_ext ):
129190 def has_ecodes (self ):
130191 ecodes_path = os .path .join (here , 'evdev/ecodes.c' )
@@ -133,17 +194,25 @@ def has_ecodes(self):
133194 print ('ecodes.c already exists ... skipping build_ecodes' )
134195 return not res
135196
197+ def has_iprops (self ):
198+ iprops_path = os .path .join (here , 'evdev/iprops.c' )
199+ res = os .path .exists (iprops_path )
200+ if res :
201+ print ('iprops.c already exists ... skipping build_iprops' )
202+ return not res
203+
136204 def run (self ):
137205 for cmd_name in self .get_sub_commands ():
138206 self .run_command (cmd_name )
139207 _build_ext .build_ext .run (self )
140208
141- sub_commands = [('build_ecodes' , has_ecodes )] + _build_ext .build_ext .sub_commands
209+ sub_commands = [('build_ecodes' , has_ecodes ), ( 'build_iprops' , has_iprops ) ] + _build_ext .build_ext .sub_commands
142210
143211
144212#-----------------------------------------------------------------------------
145213kw ['cmdclass' ]['build_ext' ] = build_ext
146214kw ['cmdclass' ]['build_ecodes' ] = build_ecodes
215+ kw ['cmdclass' ]['build_iprops' ] = build_iprops
147216
148217
149218#-----------------------------------------------------------------------------
0 commit comments