"""Config on Windows"""# **** The search part is broken. For instance, the png Visual Studio project# places to dll in a directory not checked by this module.fromsetup_win_commonimportget_definitionsimportos,sysimportrefromglobimportglobfromdistutils.sysconfigimportget_python_inctry:raw_inputexceptNameError:raw_input=inputhuntpaths=['..','..\\..','..\\*','..\\..\\*']classDependency(object):inc_hunt=['include']lib_hunt=['VisualC\\SDL\\Release','VisualC\\Release','Release','lib']def__init__(self,name,wildcards,libs=None,required=0):iflibsisNone:libs=[]self.name=nameself.wildcards=wildcardsself.required=requiredself.paths=[]self.path=Noneself.inc_dir=Noneself.lib_dir=Noneself.libs=libsself.found=Falseself.cflags=''defhunt(self):parent=os.path.abspath('..')forpinhuntpaths:forwinself.wildcards:found=glob(os.path.join(p,w))found.sort()orfound.reverse()#reverse sortforfinfound:iff[:5]=='..'+os.sep+'..'and \
os.path.abspath(f)[:len(parent)]==parent:continueifos.path.isdir(f):self.paths.append(f)defchoosepath(self):ifnotself.paths:print("Path for %s not found."%self.name)ifself.required:print('Too bad that is a requirement! Hand-fix the "Setup"')eliflen(self.paths)==1:self.path=self.paths[0]print("Path for %s:' % self.name")else:print("Select path for %s:"%self.name)foriinrange(len(self.paths)):print(" %i=%s"%(i+1,self.paths[i]))print(" %i = <Nothing>"%0)choice=raw_input("Select 0-%i (1=default):"%len(self.paths))ifnotchoice:choice=1else:choice=int(choice)if(choice):self.path=self.paths[choice-1]deffindhunt(self,base,paths):forhinpaths:hh=os.path.join(base,h)ifos.path.isdir(hh):returnhh.replace('\\','/')returnbase.replace('\\','/')defconfigure(self):self.hunt()self.choosepath()ifself.path:self.found=Trueself.inc_dir=self.findhunt(self.path,Dependency.inc_hunt)self.lib_dir=self.findhunt(self.path,Dependency.lib_hunt)classDependencyPython(object):def__init__(self,name,module,header):self.name=nameself.lib_dir=''self.inc_dir=''self.libs=[]self.cflags=''self.found=Falseself.ver='0'self.module=moduleself.header=headerdefconfigure(self):self.found=Trueifself.module:try:self.ver=__import__(self.module).__version__exceptImportError:self.found=Falseifself.foundandself.header:fullpath=os.path.join(get_python_inc(0),self.header)ifnotos.path.isfile(fullpath):found=0else:self.inc_dir=os.path.split(fullpath)[0]ifself.found:print("%-8.8s: found %s"%(self.name,self.ver))else:print("%-8.8s: not found"%self.name)classDependencyDLL(Dependency):def__init__(self,dll_regex,lib=None,wildcards=None,libs=None,link=None):iflibisNone:lib=link.libs[0]Dependency.__init__(self,'COPYLIB_'+lib,wildcards,libs)self.lib_name=libself.test=re.compile(dll_regex,re.I).matchself.lib_dir='_'self.found=Trueself.link=linkdefconfigure(self):ifself.linkisNoneandself.wildcards:self.hunt()self.choosepath()else:self.path=self.link.pathifself.pathisnotNone:self.hunt_dll()defhunt_dll(self):fordirinself.lib_hunt:path=os.path.join(self.path,dir)try:entries=os.listdir(path)except:passelse:foreinentries:ifself.test(e)andos.path.isfile(os.path.join(path,e)):# Foundself.lib_dir=os.path.join(path,e).replace('\\','/')print("DLL for %s is %s"%(self.lib_name,self.lib_dir))returnprint("DLL for %s not found"%self.lib_name)classDependencyWin(object):def__init__(self,name,cflags):self.name=nameself.inc_dir=Noneself.lib_dir=Noneself.libs=[]self.found=Trueself.cflags=cflagsdefconfigure(self):passclassDependencyGroup(object):def__init__(self):self.dependencies=[]self.dlls=[]defadd(self,name,lib,wildcards,dll_regex,libs=None,required=0):iflibsisNone:libs=[]dep=Dependency(name,wildcards,[lib],required)self.dependencies.append(dep)self.dlls.append(DependencyDLL(dll_regex,link=dep,libs=libs))defadd_win(self,name,cflags):self.dependencies.append(DependencyWin(name,cflags))defadd_dll(self,dll_regex,lib=None,wildcards=None,libs=None,link_lib=None):link=Noneiflink_libisnotNone:name='COPYLIB_'+link_libfordinself.dlls:ifd.name==name:link=dbreakelse:raiseKeyError("Link lib %s not found"%link_lib)self.dlls.append(DependencyDLL(dll_regex,lib,wildcards,libs,link))defconfigure(self):fordinself:d.configure()def__iter__(self):fordinself.dependencies:yielddfordinself.dlls:yielddDEPS=DependencyGroup()DEPS.add('SDL','SDL',['SDL-[1-9].*'],r'(lib){0,1}SDL\.dll$',required=1)DEPS.add('FONT','SDL_ttf',['SDL_ttf-[2-9].*'],r'(lib){0,1}SDL_ttf\.dll$',['SDL','z'])DEPS.add('IMAGE','SDL_image',['SDL_image-[1-9].*'],r'(lib){0,1}SDL_image\.dll$',['SDL','jpeg','png','tiff'],0),DEPS.add('MIXER','SDL_mixer',['SDL_mixer-[1-9].*'],r'(lib){0,1}SDL_mixer\.dll$',['SDL','vorbisfile','smpeg'])DEPS.add('SMPEG','smpeg',['smpeg-[0-9].*','smpeg'],r'smpeg\.dll$',['SDL'])DEPS.add('PNG','png',['libpng-[1-9].*'],r'(png|libpng13)\.dll$',['z'])DEPS.add('JPEG','jpeg',['jpeg-[6-9]*'],r'(lib){0,1}jpeg\.dll$')DEPS.add('PORTMIDI','portmidi',['portmidi'],r'portmidi\.dll$')#DEPS.add('PORTTIME', 'porttime', ['porttime'], r'porttime\.dll$')DEPS.add_dll(r'(lib){0,1}tiff\.dll$','tiff',['tiff-[3-9].*'],['jpeg','z'])DEPS.add_dll(r'(z|zlib1)\.dll$','z',['zlib-[1-9].*'])DEPS.add_dll(r'(libvorbis-0|vorbis)\.dll$','vorbis',['libvorbis-[1-9].*'],['ogg'])DEPS.add_dll(r'(libvorbisfile-3|vorbisfile)\.dll$','vorbisfile',link_lib='vorbis',libs=['vorbis'])DEPS.add_dll(r'(libogg-0|ogg)\.dll$','ogg',['libogg-[1-9].*'])fordinget_definitions():DEPS.add_win(d.name,d.value)defsetup_prebuilt():setup=open('Setup','w')try:try:setup_win_in=open(os.path.join('prebuilt','Setup_Win.in'))exceptIOError:raiseIOError("prebuilt missing required Setup_Win.in")# Copy Setup.in to Setup, replacing the BeginConfig/EndConfig# block with prebuilt\Setup_Win.in .setup_in=open('Setup.in')try:do_copy=Trueforlineinsetup_in:ifline.startswith('#--StartConfig'):do_copy=Falsesetup.write(setup_win_in.read())try:setup_win_common_in=open('Setup_Win_Common.in')except:passelse:try:setup.write(setup_win_common_in.read())finally:setup_win_common_in.close()elifline.startswith('#--EndConfig'):do_copy=Trueelifdo_copy:setup.write(line)finally:setup_in.close()finally:setup.close()defmain():ifos.path.isdir('prebuilt'):reply=raw_input('\nUse the SDL libraries in "prebuilt"? [Y/n]')ifnotreplyorreply[0].lower()!='n':setup_prebuilt()raiseSystemExit()globalDEPSDEPS.configure()returnlist(DEPS)if__name__=='__main__':print("""This is the configuration subscript for Windows.Please run "config.py" for full configuration.""")