2018-12-30 18:39:24 +00:00
import shutil , os , re , sys , zipfile
from distutils . dir_util import copy_tree
os . chdir ( os . path . dirname ( os . path . realpath ( sys . argv [ 0 ] ) ) + " /.. " )
import twlib
2015-05-18 19:17:20 +00:00
2018-12-30 18:39:24 +00:00
def unzip ( filename , where ) :
try :
z = zipfile . ZipFile ( filename , " r " )
except :
return False
for name in z . namelist ( ) :
z . extract ( name , where )
z . close ( )
return z . namelist ( ) [ 0 ]
2015-05-18 19:17:20 +00:00
2015-05-19 18:06:53 +00:00
def downloadAll ( arch , conf , targets ) :
2018-12-30 18:39:24 +00:00
url = " https://github.com/teeworlds/teeworlds-libs/archive/master.zip "
if arch == " x86_64 " :
_arch = " x64 "
else :
_arch = arch
builddir = " build/ " + arch + " / " + conf + " / "
# download and unzip
src_package_libs = twlib . fetch_file ( url )
if not src_package_libs :
print ( " couldn ' t download libs " )
sys . exit ( - 1 )
libs_dir = unzip ( src_package_libs , " . " )
if not libs_dir :
print ( " couldn ' t unzip libs " )
sys . exit ( - 1 )
libs_dir = " teeworlds-libs-master "
2015-05-19 18:06:53 +00:00
2018-12-30 18:39:24 +00:00
if " SDL2.dll " in targets :
shutil . copy ( libs_dir + " /sdl/windows/lib/ " + _arch + " /SDL2.dll " , builddir )
if " freetype.dll " in targets :
shutil . copy ( libs_dir + " /freetype/windows/lib/ " + _arch + " /freetype.dll " , builddir )
if " sdl " in targets :
copy_tree ( libs_dir + " /sdl/windows/ " , " other/sdl/ " )
if " freetype " in targets :
copy_tree ( libs_dir + " /freetype/windows/ " , " other/freetype/ " )
# cleanup
try :
shutil . rmtree ( libs_dir )
os . remove ( src_package_libs )
except : pass
2015-05-18 19:17:20 +00:00
def main ( ) :
2015-05-19 18:06:53 +00:00
import argparse
p = argparse . ArgumentParser ( description = " Download freetype and SDL library and header files for Windows. " )
p . add_argument ( " --arch " , default = " x86 " , choices = [ " x86 " , " x86_64 " ] , help = " Architecture for the downloaded libraries (Default: x86) " )
p . add_argument ( " --conf " , default = " debug " , choices = [ " debug " , " release " ] , help = " Build type (Default: debug) " )
2015-05-20 21:43:24 +00:00
p . add_argument ( " targets " , metavar = " TARGET " , nargs = ' + ' , choices = [ " SDL2.dll " , " freetype.dll " , " sdl " , " freetype " ] , help = ' Target to download. Valid choices are " SDL.dll " , " freetype.dll " , " sdl " and " freetype " ' )
2015-05-19 18:06:53 +00:00
args = p . parse_args ( )
2015-05-19 14:50:28 +00:00
2015-05-19 18:06:53 +00:00
downloadAll ( args . arch , args . conf , args . targets )
2015-05-18 19:17:20 +00:00
if __name__ == ' __main__ ' :
2015-05-19 14:50:28 +00:00
main ( )