"""Config on Unix"""importos,sys,stringfromglobimportglobfromdistutils.sysconfigimportget_python_incconfigcommand=os.environ.get('SDL_CONFIG','sdl-config',)configcommand=configcommand+' --version --cflags --libs'localbase=os.environ.get('LOCALBASE','')#these get prefixes with '/usr' and '/usr/local' or the $LOCALBASEorigincdirs=['/include','/include/SDL','/include/SDL','/include/smpeg']origlibdirs=['/lib','/lib64','/X11R6/lib']defconfirm(message):"ask a yes/no question, return result"reply=raw_input('\n'+message+' [Y/n]:')ifreplyandstring.lower(reply[0])=='n':return0return1classDependencyProg:def__init__(self,name,envname,exename,minver,defaultlibs):self.name=namecommand=os.environ.get(envname,exename)self.lib_dir=''self.inc_dir=''self.libs=[]self.cflags=''try:config=os.popen(command+' --version --cflags --libs').readlines()flags=string.split(string.join(config[1:],' '))# remove this GNU_SOURCE if there... since python has it already,# it causes a warning.if'-D_GNU_SOURCE=1'inflags:flags.remove('-D_GNU_SOURCE=1')self.ver=string.strip(config[0])ifminverandself.ver<minver:err='WARNING: requires %s version %s (%s found)'%(self.name,self.ver,minver)raiseValueError,errself.found=1self.cflags=''forfinflags:iff[:2]in('-l','-D','-I','-L'):self.cflags+=f+' 'eliff[:3]=='-Wl':self.cflags+='-Xlinker '+f+' 'ifself.name=='SDL':inc='-I'+'/usr/X11R6/include'self.cflags=inc+' '+self.cflagsexcept:print'WARNING: "%s" failed!'%commandself.found=0self.ver='0'self.libs=defaultlibsdefconfigure(self,incdirs,libdir):ifself.found:printself.name+' '[len(self.name):]+': found '+self.verself.found=1else:printself.name+' '[len(self.name):]+': not found'classDependency:def__init__(self,name,checkhead,checklib,libs):self.name=nameself.inc_dir=Noneself.lib_dir=Noneself.libs=libsself.found=0self.checklib=checklibself.checkhead=checkheadself.cflags=''defconfigure(self,incdirs,libdirs):incname=self.checkheadlibnames=self.checklib,string.lower(self.name)ifincname:fordirinincdirs:path=os.path.join(dir,incname)ifos.path.isfile(path):self.inc_dir=dirfordirinlibdirs:fornameinlibnames:path=os.path.join(dir,name)iffilter(os.path.isfile,glob(path+'*')):self.lib_dir=dirif(incnameandself.lib_dirandself.inc_dir)or(notincnameandself.lib_dir):printself.name+' '[len(self.name):]+': found'self.found=1else:printself.name+' '[len(self.name):]+': not found'classDependencyPython:def__init__(self,name,module,header):self.name=nameself.lib_dir=''self.inc_dir=''self.libs=[]self.cflags=''self.found=0self.ver='0'self.module=moduleself.header=headerdefconfigure(self,incdirs,libdirs):self.found=1ifself.module:try:self.ver=__import__(self.module).__version__exceptImportError:self.found=0ifself.foundandself.header:fullpath=os.path.join(get_python_inc(0),self.header)ifnotos.path.isfile(fullpath):self.found=0else:self.inc_dir=os.path.split(fullpath)[0]ifself.found:printself.name+' '[len(self.name):]+': found',self.verelse:printself.name+' '[len(self.name):]+': not found'sdl_lib_name='SDL'defmain():print'\nHunting dependencies...'DEPS=[DependencyProg('SDL','SDL_CONFIG','sdl-config','1.2',['sdl']),Dependency('FONT','SDL_ttf.h','libSDL_ttf.so',['SDL_ttf']),Dependency('IMAGE','SDL_image.h','libSDL_image.so',['SDL_image']),Dependency('MIXER','SDL_mixer.h','libSDL_mixer.so',['SDL_mixer']),DependencyProg('SMPEG','SMPEG_CONFIG','smpeg-config','0.4.3',['smpeg']),Dependency('PNG','png.h','libpng',['png']),Dependency('JPEG','jpeglib.h','libjpeg',['jpeg']),Dependency('SCRAP','','libX11',['X11']),]ifnotDEPS[0].found:print'Unable to run "sdl-config". Please make sure a development version of SDL is installed.'raiseSystemExitiflocalbase:incdirs=[localbase+dfordinorigincdirs]libdirs=[localbase+dfordinoriglibdirs]else:incdirs=[]libdirs=[]incdirs+=["/usr"+dfordinorigincdirs]libdirs+=["/usr"+dfordinoriglibdirs]incdirs+=["/usr/local"+dfordinorigincdirs]libdirs+=["/usr/local"+dfordinoriglibdirs]forarginstring.split(DEPS[0].cflags):ifarg[:2]=='-I':incdirs.append(arg[2:])elifarg[:2]=='-L':libdirs.append(arg[2:])fordinDEPS:d.configure(incdirs,libdirs)fordinDEPS[1:]:ifnotd.found:ifnotconfirm("""Warning, some of the pygame dependencies were not found. Pygame can stillcompile and install, but games that depend on those missing dependencieswill not run. Would you like to continue the configuration?"""):raiseSystemExitbreakreturnDEPSif__name__=='__main__':print"""This is the configuration subscript for Unix.Please run "config.py" for full configuration."""