import os,re,glob #---------------------------------# # removefilespattern # #---------------------------------# def removefilespattern(dir,pat): for f in glob.glob(dir+'/'+pat): os.popen('rm '+f) return ################################### #---------------------------------# # parsedir # #---------------------------------# def parsedir(startDir): directories = [startDir] dir = [startDir] while len(directories)>0: directory = directories.pop() for name in os.listdir(directory): fullpath = os.path.join(directory,name) if os.path.isdir(fullpath): directories.append(fullpath) # It's a directory, store it. dir.append(fullpath) return dir ################################### #---------------------------------# # parsedirabs # #---------------------------------# def parsedirabs(startDir): directories = [startDir] dir = [os.path.abspath(startDir)] while len(directories)>0: directory = directories.pop() for name in os.listdir(directory): fullpath = os.path.join(directory,name) if os.path.isdir(fullpath): directories.append(fullpath) # It's a directory, store it. dir.append(os.path.abspath(fullpath)) return dir ################################### #---------------------------------# # dirdepth # #---------------------------------# def dirdepth(dir): p = re.compile('[a-z]+') print p.search(dir) return ################################### #---------------------------------# # parsefiles # #---------------------------------# def parsefiles(dir): file = [] for name in os.listdir(dir): fullpath = os.path.join(dir,name) if os.path.isfile(fullpath) == True and os.path.isdir(fullpath) == False: file.append(name) return file ################################### #---------------------------------# # parsedirpat # #---------------------------------# def parsedirpat(dir,pat): file = [] for name in glob.glob(dir+'/'+pat): file.append(name) return file ################################### #---------------------------------# # VARS # #---------------------------------# #Change if needed packagename = 'blaze' libfile = 'lib'+packagename+'.a' gdc = '/opt/gdc/bin/gdc' ar = '/usr/bin/ar' projecthome = '/home/fmanuel/projects/gamecraft/blaze/' projectsrc = projecthome+'/blaze' includedirs = [] librarydirs = [] #Absolute targetentrypoint = '' #Exclude dirs - Absolute #['aaa','bbb'] excludedirs = ['/home/fmanuel/projects/gamecraft/blaze/examples'] buildflags0 = ' -fversion=Posix ' buildflags1 = ' -funittest -fversion=Posix ' ################################### ################################### #---------------------------------# # cmd0 # #---------------------------------# def cmd0(inp,out): cmd = gdc+' -c '+inp+'.d -o '+out+'.o '+buildflags0+' -I '+projecthome os.popen(cmd) return cmd ################################### #---------------------------------# # cmd1 # #---------------------------------# def cmd1(inp): cmd = ar+' rcs '+libfile+' '+inp os.popen(cmd) return cmd ################################### #---------------------------------# # cmd2 # #---------------------------------# def cmd2(main,target,flags): cmd = gdc+' '+main+' -o '+target+' '+buildflags1+' -I '+projecthome+' -L '+projecthome+' -l'+packagename os.popen(cmd) return cmd ################################### #---------------------------------# # notinarray # #---------------------------------# def notinarray(ele,arr): for e in arr: if os.path.normpath(ele) == os.path.normpath(e): return False return True ################################### ################################### #---------------------------------# # notsubdir # #---------------------------------# def notsubdir(subdir,dir): return subdir.startswith(dir) ################################### #---------------------------------# # notsubdir2 # #---------------------------------# def notsubdir2(dir,arr): for e in arr: if notsubdir(dir,e) == True: return False return True ################################### removefilespattern(projecthome+"/",'*.a') # Build object files on every dir objfiles = [] for d in parsedirabs(projecthome): if (notinarray(d,excludedirs) == True) and (notsubdir2(d,excludedirs) == True): #removefilespattern(d,'*.o') #print "DIR: "+d files = parsedirpat(d,'*.d') for f in files: if f <> targetentrypoint: nf = os.path.splitext(f) if nf[0] <> '/home/fmanuel/projects/gamecraft/monster/monster/modules/threads': print cmd0(nf[0],nf[0]) objfiles.append(nf[0]+".o") str = ' ' objfiles_str = str.join(objfiles) str = ' -I ' includedirs_str = str.join(includedirs) str = ' -L ' librarydirs_str = str.join(librarydirs) print cmd1(objfiles_str) #print cmd2(targetentrypoint,'mvm',includedirs_str+' '+librarydirs_str) for d in parsedirabs(projecthome): if notinarray(d,excludedirs): removefilespattern(d,'*.o')