makepandacore.py 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. ########################################################################
  2. ##
  3. ## Caution: there are two separate, independent build systems:
  4. ## 'makepanda', and 'ppremake'. Use one or the other, do not attempt
  5. ## to use both. This file is part of the 'makepanda' system.
  6. ##
  7. ## This file, makepandacore, contains all the global state and
  8. ## global functions for the makepanda system.
  9. ##
  10. ########################################################################
  11. import sys,os,time,stat,string,re,getopt,cPickle,fnmatch,threading,Queue,signal,shutil,platform
  12. SUFFIX_INC=[".cxx",".c",".h",".I",".yxx",".lxx",".mm"]
  13. SUFFIX_DLL=[".dll",".dlo",".dle",".dli",".dlm",".mll",".exe"]
  14. SUFFIX_LIB=[".lib",".ilb"]
  15. STARTTIME=time.time()
  16. MAINTHREAD=threading.currentThread()
  17. ########################################################################
  18. ##
  19. ## Maya and Max Version List (with registry keys)
  20. ##
  21. ########################################################################
  22. MAYAVERSIONINFO=[("MAYA6", "6.0"),
  23. ("MAYA65", "6.5"),
  24. ("MAYA7", "7.0"),
  25. ("MAYA8", "8.0"),
  26. ("MAYA85", "8.5"),
  27. ("MAYA2008","2008"),
  28. ("MAYA2009","2009"),
  29. ]
  30. MAXVERSIONINFO = [("MAX6", "SOFTWARE\\Autodesk\\3DSMAX\\6.0", "installdir", "maxsdk\\cssdk\\include"),
  31. ("MAX7", "SOFTWARE\\Autodesk\\3DSMAX\\7.0", "Installdir", "maxsdk\\include\\CS"),
  32. ("MAX8", "SOFTWARE\\Autodesk\\3DSMAX\\8.0", "Installdir", "maxsdk\\include\\CS"),
  33. ("MAX9", "SOFTWARE\\Autodesk\\3DSMAX\\9.0", "Installdir", "maxsdk\\include\\CS"),
  34. ("MAX2009", "SOFTWARE\\Autodesk\\3DSMAX\\11.0", "Installdir", "maxsdk\\include\\CS"),
  35. ]
  36. MAYAVERSIONS=[]
  37. MAXVERSIONS=[]
  38. DXVERSIONS=["DX8","DX9"]
  39. for (ver,key) in MAYAVERSIONINFO:
  40. MAYAVERSIONS.append(ver)
  41. for (ver,key1,key2,subdir) in MAXVERSIONINFO:
  42. MAXVERSIONS.append(ver)
  43. ########################################################################
  44. ##
  45. ## The exit routine will normally
  46. ##
  47. ## - print a message
  48. ## - save the dependency cache
  49. ## - exit
  50. ##
  51. ## However, if it is invoked inside a thread, it instead:
  52. ##
  53. ## - prints a message
  54. ## - raises the "initiate-exit" exception
  55. ##
  56. ## If you create a thread, you must be prepared to catch this
  57. ## exception, save the dependency cache, and exit.
  58. ##
  59. ########################################################################
  60. WARNINGS=[]
  61. def PrettyTime(t):
  62. t = int(t)
  63. hours = t/3600
  64. t -= hours*3600
  65. minutes = t/60
  66. t -= minutes*60
  67. seconds = t
  68. if (hours): return str(hours)+" hours "+str(minutes)+" min"
  69. if (minutes): return str(minutes)+" min "+str(seconds)+" sec"
  70. return str(seconds)+" sec"
  71. def exit(msg):
  72. if (threading.currentThread() == MAINTHREAD):
  73. SaveDependencyCache()
  74. # Move any files we've moved away back.
  75. if os.path.isfile("dtool/src/dtoolutil/pandaVersion.h.moved"):
  76. os.rename("dtool/src/dtoolutil/pandaVersion.h.moved", "dtool/src/dtoolutil/pandaVersion.h")
  77. if os.path.isfile("dtool/src/dtoolutil/checkPandaVersion.h.moved"):
  78. os.rename("dtool/src/dtoolutil/checkPandaVersion.h.moved", "dtool/src/dtoolutil/checkPandaVersion.h")
  79. if os.path.isfile("dtool/src/dtoolutil/checkPandaVersion.cxx.moved"):
  80. os.rename("dtool/src/dtoolutil/checkPandaVersion.cxx.moved", "dtool/src/dtoolutil/checkPandaVersion.cxx")
  81. print "Elapsed Time: "+PrettyTime(time.time() - STARTTIME)
  82. print msg
  83. sys.stdout.flush()
  84. sys.stderr.flush()
  85. os._exit(1)
  86. else:
  87. print msg
  88. raise "initiate-exit"
  89. ########################################################################
  90. ##
  91. ## Run a command.
  92. ##
  93. ########################################################################
  94. def oscmd(cmd, ignoreError = False):
  95. print cmd
  96. sys.stdout.flush()
  97. if sys.platform == "win32":
  98. exe = cmd.split()[0]+".exe"
  99. if os.path.isfile(exe)==0:
  100. for i in os.environ["PATH"].split(";"):
  101. if os.path.isfile(os.path.join(i, exe)):
  102. exe = os.path.join(i, exe)
  103. break
  104. if os.path.isfile(exe)==0:
  105. exit("Cannot find "+exe+" on search path")
  106. res = os.spawnl(os.P_WAIT, exe, cmd)
  107. else:
  108. res = os.system(cmd)
  109. if res != 0 and not ignoreError:
  110. exit("")
  111. ########################################################################
  112. ##
  113. ## GetDirectoryContents
  114. ##
  115. ## At times, makepanda will use a function like "os.listdir" to process
  116. ## all the files in a directory. Unfortunately, that means that any
  117. ## accidental addition of a file to a directory could cause makepanda
  118. ## to misbehave without warning.
  119. ##
  120. ## To alleviate this weakness, we created GetDirectoryContents. This
  121. ## uses "os.listdir" to fetch the directory contents, but then it
  122. ## compares the results to the appropriate CVS/Entries to see if
  123. ## they match. If not, it prints a big warning message.
  124. ##
  125. ########################################################################
  126. def GetDirectoryContents(dir, filters="*", skip=[]):
  127. if (type(filters)==str):
  128. filters = [filters]
  129. actual = {}
  130. files = os.listdir(dir)
  131. for filter in filters:
  132. for file in fnmatch.filter(files, filter):
  133. if (skip.count(file)==0) and (os.path.isfile(dir + "/" + file)):
  134. actual[file] = 1
  135. if (os.path.isfile(dir + "/CVS/Entries")):
  136. cvs = {}
  137. srchandle = open(dir+"/CVS/Entries", "r")
  138. files = []
  139. for line in srchandle:
  140. if (line[0]=="/"):
  141. s = line.split("/",2)
  142. if (len(s)==3):
  143. files.append(s[1])
  144. srchandle.close()
  145. for filter in filters:
  146. for file in fnmatch.filter(files, filter):
  147. if (skip.count(file)==0):
  148. cvs[file] = 1
  149. for file in actual.keys():
  150. if (cvs.has_key(file)==0):
  151. msg = "WARNING: %s is in %s, but not in CVS"%(file, dir)
  152. print msg
  153. WARNINGS.append(msg)
  154. for file in cvs.keys():
  155. if (actual.has_key(file)==0):
  156. msg = "WARNING: %s is not in %s, but is in CVS"%(file, dir)
  157. print msg
  158. WARNINGS.append(msg)
  159. results = actual.keys()
  160. results.sort()
  161. return results
  162. ########################################################################
  163. ##
  164. ## The Timestamp Cache
  165. ##
  166. ## The make utility is constantly fetching the timestamps of files.
  167. ## This can represent the bulk of the file accesses during the make
  168. ## process. The timestamp cache eliminates redundant checks.
  169. ##
  170. ########################################################################
  171. TIMESTAMPCACHE = {}
  172. def GetTimestamp(path):
  173. if TIMESTAMPCACHE.has_key(path):
  174. return TIMESTAMPCACHE[path]
  175. try: date = os.path.getmtime(path)
  176. except: date = 0
  177. TIMESTAMPCACHE[path] = date
  178. return date
  179. def ClearTimestamp(path):
  180. del TIMESTAMPCACHE[path]
  181. ########################################################################
  182. ##
  183. ## The Dependency cache.
  184. ##
  185. ## Makepanda's strategy for file dependencies is different from most
  186. ## make-utilities. Whenever a file is built, makepanda records
  187. ## that the file was built, and it records what the input files were,
  188. ## and what their dates were. Whenever a file is about to be built,
  189. ## panda compares the current list of input files and their dates,
  190. ## to the previous list of input files and their dates. If they match,
  191. ## there is no need to build the file.
  192. ##
  193. ########################################################################
  194. BUILTFROMCACHE = {}
  195. def JustBuilt(files,others):
  196. dates = []
  197. for file in files:
  198. del TIMESTAMPCACHE[file]
  199. dates.append(GetTimestamp(file))
  200. for file in others:
  201. dates.append(GetTimestamp(file))
  202. key = tuple(files)
  203. BUILTFROMCACHE[key] = [others,dates]
  204. def NeedsBuild(files,others):
  205. dates = []
  206. for file in files:
  207. dates.append(GetTimestamp(file))
  208. for file in others:
  209. dates.append(GetTimestamp(file))
  210. key = tuple(files)
  211. if (BUILTFROMCACHE.has_key(key)):
  212. if (BUILTFROMCACHE[key] == [others,dates]):
  213. return 0
  214. else:
  215. oldothers = BUILTFROMCACHE[key][0]
  216. if (oldothers != others):
  217. print "CAUTION: file dependencies changed: "+str(files)
  218. return 1
  219. ########################################################################
  220. ##
  221. ## The CXX include cache:
  222. ##
  223. ## The following routine scans a CXX file and returns a list of
  224. ## the include-directives inside that file. It's not recursive:
  225. ## it just returns the includes that are textually inside the
  226. ## file. If you need recursive dependencies, you need the higher-level
  227. ## routine CxxCalcDependencies, defined elsewhere.
  228. ##
  229. ## Since scanning a CXX file is slow, we cache the result. It records
  230. ## the date of the source file and the list of includes that it
  231. ## contains. It assumes that if the file date hasn't changed, that
  232. ## the list of include-statements inside the file has not changed
  233. ## either. Once again, this particular routine does not return
  234. ## recursive dependencies --- it only returns an explicit list of
  235. ## include statements that are textually inside the file. That
  236. ## is what the cache stores, as well.
  237. ##
  238. ########################################################################
  239. CXXINCLUDECACHE = {}
  240. global CxxIncludeRegex
  241. CxxIncludeRegex = re.compile('^[ \t]*[#][ \t]*include[ \t]+"([^"]+)"[ \t\r\n]*$')
  242. def CxxGetIncludes(path):
  243. date = GetTimestamp(path)
  244. if (CXXINCLUDECACHE.has_key(path)):
  245. cached = CXXINCLUDECACHE[path]
  246. if (cached[0]==date): return cached[1]
  247. try: sfile = open(path, 'rb')
  248. except:
  249. exit("Cannot open source file \""+path+"\" for reading.")
  250. include = []
  251. for line in sfile:
  252. match = CxxIncludeRegex.match(line,0)
  253. if (match):
  254. incname = match.group(1)
  255. include.append(incname)
  256. sfile.close()
  257. CXXINCLUDECACHE[path] = [date, include]
  258. return include
  259. ########################################################################
  260. ##
  261. ## SaveDependencyCache / LoadDependencyCache
  262. ##
  263. ## This actually saves both the dependency and cxx-include caches.
  264. ##
  265. ########################################################################
  266. def SaveDependencyCache():
  267. try: icache = open("built/tmp/makepanda-dcache",'wb')
  268. except: icache = 0
  269. if (icache!=0):
  270. print "Storing dependency cache."
  271. cPickle.dump(CXXINCLUDECACHE, icache, 1)
  272. cPickle.dump(BUILTFROMCACHE, icache, 1)
  273. icache.close()
  274. def LoadDependencyCache():
  275. global CXXINCLUDECACHE
  276. global BUILTFROMCACHE
  277. try: icache = open("built/tmp/makepanda-dcache",'rb')
  278. except: icache = 0
  279. if (icache!=0):
  280. CXXINCLUDECACHE = cPickle.load(icache)
  281. BUILTFROMCACHE = cPickle.load(icache)
  282. icache.close()
  283. ########################################################################
  284. ##
  285. ## CxxFindSource: given a source file name and a directory list,
  286. ## searches the directory list for the given source file. Returns
  287. ## the full pathname of the located file.
  288. ##
  289. ## CxxFindHeader: given a source file, an include directive, and a
  290. ## directory list, searches the directory list for the given header
  291. ## file. Returns the full pathname of the located file.
  292. ##
  293. ## Of course, CxxFindSource and CxxFindHeader cannot find a source
  294. ## file that has not been created yet. This can cause dependency
  295. ## problems. So the function CreateStubHeader can be used to create
  296. ## a file that CxxFindSource or CxxFindHeader can subsequently find.
  297. ##
  298. ########################################################################
  299. def CxxFindSource(name, ipath):
  300. for dir in ipath:
  301. if (dir == "."): full = name
  302. else: full = dir + "/" + name
  303. if GetTimestamp(full) > 0: return full
  304. exit("Could not find source file: "+name)
  305. def CxxFindHeader(srcfile, incfile, ipath):
  306. if (incfile.startswith(".")):
  307. last = srcfile.rfind("/")
  308. if (last < 0): exit("CxxFindHeader cannot handle this case #1")
  309. srcdir = srcfile[:last+1]
  310. while (incfile[:1]=="."):
  311. if (incfile[:2]=="./"):
  312. incfile = incfile[2:]
  313. elif (incfile[:3]=="../"):
  314. incfile = incfile[3:]
  315. last = srcdir[:-1].rfind("/")
  316. if (last < 0): exit("CxxFindHeader cannot handle this case #2")
  317. srcdir = srcdir[:last+1]
  318. else: exit("CxxFindHeader cannot handle this case #3")
  319. full = srcdir + incfile
  320. if GetTimestamp(full) > 0: return full
  321. return 0
  322. else:
  323. for dir in ipath:
  324. full = dir + "/" + incfile
  325. if GetTimestamp(full) > 0: return full
  326. return 0
  327. ########################################################################
  328. ##
  329. ## CxxCalcDependencies(srcfile, ipath, ignore)
  330. ##
  331. ## Calculate the dependencies of a source file given a
  332. ## particular include-path. Any file in the list of files to
  333. ## ignore is not considered.
  334. ##
  335. ########################################################################
  336. global CxxIgnoreHeader
  337. global CxxDependencyCache
  338. CxxIgnoreHeader = {}
  339. CxxDependencyCache = {}
  340. def CxxCalcDependencies(srcfile, ipath, ignore):
  341. if (CxxDependencyCache.has_key(srcfile)):
  342. return CxxDependencyCache[srcfile]
  343. if (ignore.count(srcfile)): return []
  344. dep = {}
  345. dep[srcfile] = 1
  346. includes = CxxGetIncludes(srcfile)
  347. for include in includes:
  348. header = CxxFindHeader(srcfile, include, ipath)
  349. if (header!=0):
  350. if (ignore.count(header)==0):
  351. hdeps = CxxCalcDependencies(header, ipath, [srcfile]+ignore)
  352. for x in hdeps: dep[x] = 1
  353. result = dep.keys()
  354. CxxDependencyCache[srcfile] = result
  355. return result
  356. ########################################################################
  357. ##
  358. ## Registry Key Handling
  359. ##
  360. ## Of course, these routines will fail if you call them on a
  361. ## non win32 platform. If you use them on a win64 platform, they
  362. ## will look in the win32 private hive first, then look in the
  363. ## win64 hive.
  364. ##
  365. ########################################################################
  366. if sys.platform == "win32":
  367. import _winreg
  368. def TryRegistryKey(path):
  369. try:
  370. key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, path, 0, _winreg.KEY_READ)
  371. return key
  372. except: pass
  373. try:
  374. key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, path, 0, _winreg.KEY_READ | 256)
  375. return key
  376. except: pass
  377. return 0
  378. def ListRegistryKeys(path):
  379. result=[]
  380. index=0
  381. key = TryRegistryKey(path)
  382. if (key != 0):
  383. try:
  384. while (1):
  385. result.append(_winreg.EnumKey(key, index))
  386. index = index + 1
  387. except: pass
  388. _winreg.CloseKey(key)
  389. return result
  390. def GetRegistryKey(path, subkey):
  391. k1=0
  392. key = TryRegistryKey(path)
  393. if (key != 0):
  394. try:
  395. k1, k2 = _winreg.QueryValueEx(key, subkey)
  396. except: pass
  397. _winreg.CloseKey(key)
  398. return k1
  399. ########################################################################
  400. ##
  401. ## Parsing Compiler Option Lists
  402. ##
  403. ########################################################################
  404. def GetListOption(opts, prefix):
  405. res=[]
  406. for x in opts:
  407. if (x.startswith(prefix)):
  408. res.append(x[len(prefix):])
  409. return res
  410. def GetValueOption(opts, prefix):
  411. for x in opts:
  412. if (x.startswith(prefix)):
  413. return x[len(prefix):]
  414. return 0
  415. def GetOptimizeOption(opts,defval):
  416. val = GetValueOption(opts, "OPT:")
  417. if (val == 0):
  418. return defval
  419. return val
  420. ########################################################################
  421. ##
  422. ## General File Manipulation
  423. ##
  424. ########################################################################
  425. def MakeDirectory(path):
  426. if os.path.isdir(path): return 0
  427. os.mkdir(path)
  428. def ReadFile(wfile):
  429. try:
  430. srchandle = open(wfile, "rb")
  431. data = srchandle.read()
  432. srchandle.close()
  433. return data
  434. except: exit("Cannot read "+wfile)
  435. def WriteFile(wfile,data):
  436. try:
  437. dsthandle = open(wfile, "wb")
  438. dsthandle.write(data)
  439. dsthandle.close()
  440. except: exit("Cannot write "+wfile)
  441. def ConditionalWriteFile(dest,desiredcontents):
  442. try:
  443. rfile = open(dest, 'rb')
  444. contents = rfile.read(-1)
  445. rfile.close()
  446. except:
  447. contents=0
  448. if contents != desiredcontents:
  449. sys.stdout.flush()
  450. WriteFile(dest,desiredcontents)
  451. def DeleteCVS(dir):
  452. for entry in os.listdir(dir):
  453. if (entry != ".") and (entry != ".."):
  454. subdir = dir + "/" + entry
  455. if (os.path.isdir(subdir)):
  456. if (entry == "CVS"):
  457. shutil.rmtree(subdir)
  458. else:
  459. DeleteCVS(subdir)
  460. def CreateFile(file):
  461. if (os.path.exists(file)==0):
  462. WriteFile(file,"")
  463. ########################################################################
  464. #
  465. # Create the panda build tree.
  466. #
  467. ########################################################################
  468. def MakeBuildTree():
  469. MakeDirectory("built")
  470. MakeDirectory("built/bin")
  471. MakeDirectory("built/lib")
  472. MakeDirectory("built/tmp")
  473. MakeDirectory("built/etc")
  474. MakeDirectory("built/plugins")
  475. MakeDirectory("built/modelcache")
  476. MakeDirectory("built/include")
  477. MakeDirectory("built/include/parser-inc")
  478. MakeDirectory("built/include/parser-inc/openssl")
  479. MakeDirectory("built/include/parser-inc/netinet")
  480. MakeDirectory("built/include/parser-inc/Cg")
  481. MakeDirectory("built/include/openssl")
  482. MakeDirectory("built/models")
  483. MakeDirectory("built/models/audio")
  484. MakeDirectory("built/models/audio/sfx")
  485. MakeDirectory("built/models/icons")
  486. MakeDirectory("built/models/maps")
  487. MakeDirectory("built/models/misc")
  488. MakeDirectory("built/models/gui")
  489. MakeDirectory("built/direct")
  490. MakeDirectory("built/pandac")
  491. MakeDirectory("built/pandac/input")
  492. ########################################################################
  493. #
  494. # Make sure that you are in the root of the panda tree.
  495. #
  496. ########################################################################
  497. def CheckPandaSourceTree():
  498. dir = os.getcwd()
  499. if ((os.path.exists(os.path.join(dir, "makepanda/makepanda.py"))==0) or
  500. (os.path.exists(os.path.join(dir, "dtool","src","dtoolbase","dtoolbase.h"))==0) or
  501. (os.path.exists(os.path.join(dir, "panda","src","pandabase","pandabase.h"))==0)):
  502. exit("Current directory is not the root of the panda tree.")
  503. ########################################################################
  504. ##
  505. ## Visual Studio Manifest Manipulation.
  506. ##
  507. ########################################################################
  508. VC80CRTVERSIONRE=re.compile(" name=['\"]Microsoft.VC80.CRT['\"] version=['\"]([0-9.]+)['\"] ")
  509. def GetVC80CRTVersion(fn):
  510. manifest = ReadFile(fn)
  511. version = VC80CRTVERSIONRE.search(manifest)
  512. if (version == None):
  513. exit("Cannot locate version number in "+manifn)
  514. return version.group(1)
  515. def SetVC80CRTVersion(fn, ver):
  516. manifest = ReadFile(fn)
  517. subst = " name='Microsoft.VC80.CRT' version='"+ver+"' "
  518. manifest = VC80CRTVERSIONRE.sub(subst, manifest)
  519. WriteFile(fn, manifest)
  520. ########################################################################
  521. ##
  522. ## Package Selection
  523. ##
  524. ## This facility enables makepanda to keep a list of packages selected
  525. ## by the user for inclusion or omission.
  526. ##
  527. ########################################################################
  528. PKG_LIST_ALL=0
  529. PKG_LIST_OMIT=0
  530. def PkgListSet(pkgs):
  531. global PKG_LIST_ALL
  532. global PKG_LIST_OMIT
  533. PKG_LIST_ALL=pkgs
  534. PKG_LIST_OMIT={}
  535. PkgDisableAll()
  536. def PkgListGet():
  537. return PKG_LIST_ALL
  538. def PkgEnableAll():
  539. for x in PKG_LIST_ALL:
  540. PKG_LIST_OMIT[x] = 0
  541. def PkgDisableAll():
  542. for x in PKG_LIST_ALL:
  543. PKG_LIST_OMIT[x] = 1
  544. def PkgEnable(pkg):
  545. PKG_LIST_OMIT[pkg] = 0
  546. def PkgDisable(pkg):
  547. PKG_LIST_OMIT[pkg] = 1
  548. def PkgSkip(pkg):
  549. return PKG_LIST_OMIT[pkg]
  550. def PkgSelected(pkglist, pkg):
  551. if (pkglist.count(pkg)==0): return 0
  552. if (PKG_LIST_OMIT[pkg]): return 0
  553. return 1
  554. ########################################################################
  555. ##
  556. ## SDK Location
  557. ##
  558. ## This section is concerned with locating the install directories
  559. ## for various third-party packages. The results are stored in the
  560. ## SDK table.
  561. ##
  562. ## Microsoft keeps changing the &*#$*& registry key for the DirectX SDK.
  563. ## The only way to reliably find it is to search through the installer's
  564. ## uninstall-directories, look in each one, and see if it contains the
  565. ## relevant files.
  566. ##
  567. ########################################################################
  568. SDK = {}
  569. def SdkLocateDirectX():
  570. if (sys.platform != "win32"): return
  571. if (os.path.isdir("sdks/directx8")): SDK["DX8"]="sdks/directx8"
  572. if (os.path.isdir("sdks/directx9")): SDK["DX9"]="sdks/directx9"
  573. uninstaller = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
  574. for subdir in ListRegistryKeys(uninstaller):
  575. if (subdir[0]=="{"):
  576. dir = GetRegistryKey(uninstaller+"\\"+subdir, "InstallLocation")
  577. if (dir != 0):
  578. if ((SDK.has_key("DX8")==0) and
  579. (os.path.isfile(dir+"\\Include\\d3d8.h")) and
  580. (os.path.isfile(dir+"\\Include\\d3dx8.h")) and
  581. (os.path.isfile(dir+"\\Lib\\d3d8.lib")) and
  582. (os.path.isfile(dir+"\\Lib\\d3dx8.lib"))):
  583. SDK["DX8"] = dir.replace("\\", "/").rstrip("/")
  584. if ((SDK.has_key("DX9")==0) and
  585. (os.path.isfile(dir+"\\Include\\d3d9.h")) and
  586. (os.path.isfile(dir+"\\Include\\d3dx9.h")) and
  587. (os.path.isfile(dir+"\\Include\\dxsdkver.h")) and
  588. (os.path.isfile(dir+"\\Lib\\x86\\d3d9.lib")) and
  589. (os.path.isfile(dir+"\\Lib\\x86\\d3dx9.lib"))):
  590. SDK["DX9"] = dir.replace("\\", "/").rstrip("/")
  591. if (SDK.has_key("DX9")):
  592. SDK["DIRECTCAM"] = SDK["DX9"]
  593. def SdkLocateMaya():
  594. for (ver,key) in MAYAVERSIONINFO:
  595. if (PkgSkip(ver)==0 and SDK.has_key(ver)==0):
  596. if (sys.platform == "win32"):
  597. ddir = "sdks/"+ver.lower().replace("x","")
  598. if (os.path.isdir(ddir)):
  599. SDK[ver] = ddir
  600. else:
  601. for dev in ["Alias|Wavefront","Alias","Autodesk"]:
  602. fullkey="SOFTWARE\\"+dev+"\\Maya\\"+key+"\\Setup\\InstallPath"
  603. res = GetRegistryKey(fullkey, "MAYA_INSTALL_LOCATION")
  604. if (res != 0):
  605. res = res.replace("\\", "/").rstrip("/")
  606. SDK[ver] = res
  607. elif (sys.platform == "darwin"):
  608. ddir1 = "sdks/"+ver.lower().replace("x","")+"-osx"
  609. if os.environ.has_key("MAYA_LOCATION"): ddir2 = os.environ["MAYA_LOCATION"].rstrip("/")
  610. ddir3 = "/Applications/Autodesk/maya"+key+"/Maya.app/Contents"
  611. if (os.path.isdir(ddir1)):
  612. SDK[ver] = ddir1
  613. elif (os.environ.has_key("MAYA_LOCATION") and os.path.isdir(ddir2)):
  614. SDK[ver] = ddir2
  615. elif (os.path.isdir(ddir3)):
  616. SDK[ver] = ddir3
  617. else:
  618. ddir1 = "sdks/"+ver.lower().replace("x","")+"-linux"+platform.architecture()[0].replace("bit","")
  619. if os.environ.has_key("MAYA_LOCATION"): ddir2 = os.environ["MAYA_LOCATION"].rstrip("/")
  620. if (platform.architecture()[0] == "64bit"):
  621. ddir3 = "/usr/autodesk/maya"+key+"-x64"
  622. else:
  623. ddir3 = "/usr/autodesk/maya"+key
  624. if (os.path.isdir(ddir1)):
  625. SDK[ver] = ddir1
  626. elif (os.environ.has_key("MAYA_LOCATION") and os.path.isdir(ddir2) and
  627. ((ver.lower() in ddir2.lower()) or ("maya"+key in ddir2.lower()))):
  628. SDK[ver] = ddir2
  629. elif (os.path.isdir(ddir3)):
  630. SDK[ver] = ddir3
  631. def SdkLocateMax():
  632. if (sys.platform != "win32"): return
  633. for version,key1,key2,subdir in MAXVERSIONINFO:
  634. if (PkgSkip(version)==0):
  635. if (SDK.has_key(version)==0):
  636. ddir = "sdks/maxsdk"+version.lower()[3:]
  637. if (os.path.isdir(ddir)):
  638. SDK[version] = ddir
  639. SDK[version+"CS"] = ddir
  640. else:
  641. top = GetRegistryKey(key1,key2)
  642. if (top != 0):
  643. SDK[version] = top + "maxsdk"
  644. if (os.path.isdir(top + "\\" + subdir)!=0):
  645. SDK[version+"CS"] = top + subdir
  646. def SdkLocatePython():
  647. if (PkgSkip("PYTHON")==0):
  648. if (sys.platform == "win32"):
  649. SDK["PYTHON"]="thirdparty/win-python"
  650. SDK["PYTHONVERSION"]="python2.5"
  651. elif (sys.platform == "darwin"):
  652. if not SDK.has_key("MACOSX"): SdkLocateMacOSX()
  653. if (os.path.isdir("%s/System/Library/Frameworks/Python.framework" % SDK["MACOSX"])):
  654. os.system("readlink %s/System/Library/Frameworks/Python.framework/Versions/Current > built/tmp/pythonversion 2>&1" % SDK["MACOSX"])
  655. pv = ReadFile("built/tmp/pythonversion")
  656. SDK["PYTHON"] = SDK["MACOSX"]+"/System/Library/Frameworks/Python.framework/Headers"
  657. SDK["PYTHONVERSION"] = "python"+pv
  658. else:
  659. exit("Could not find the python framework!")
  660. else:
  661. os.system("python -V > built/tmp/pythonversion 2>&1")
  662. pv=ReadFile("built/tmp/pythonversion")
  663. if (pv.startswith("Python ")==0):
  664. exit("python -V did not produce the expected output")
  665. pv = pv[7:10]
  666. if (os.path.isdir("/usr/include/python"+pv)==0):
  667. exit("Python reports version "+pv+" but /usr/include/python"+pv+" is not installed.")
  668. SDK["PYTHON"]="/usr/include/python"+pv
  669. SDK["PYTHONVERSION"]="python"+pv
  670. def SdkLocateVisualStudio():
  671. if (sys.platform != "win32"): return
  672. vcdir = GetRegistryKey("SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7", "8.0")
  673. if (vcdir != 0) and (vcdir[-4:] == "\\VC\\"):
  674. vcdir = vcdir[:-3]
  675. SDK["VISUALSTUDIO"] = vcdir
  676. def SdkLocateMSPlatform():
  677. platsdk=GetRegistryKey("SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1", "Install Dir")
  678. if (platsdk == 0):
  679. platsdk=GetRegistryKey("SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v6.1","InstallationFolder")
  680. if (platsdk == 0 and os.path.isdir("C:\\Program Files\\Microsoft Visual Studio 8\\VC\\PlatformSDK")):
  681. platsdk = "C:\\Program Files\\Microsoft Visual Studio 8\\VC\\PlatformSDK\\"
  682. if (platsdk != 0):
  683. SDK["MSPLATFORM"] = platsdk
  684. def SdkLocateMacOSX():
  685. if (sys.platform != "darwin"): return
  686. if (os.path.exists("/Developer/SDKs/MacOSX10.5.sdk")):
  687. SDK["MACOSX"] = "/Developer/SDKs/MacOSX10.5.sdk"
  688. elif (os.path.exists("/Developer/SDKs/MacOSX10.4u.sdk")):
  689. SDK["MACOSX"] = "/Developer/SDKs/MacOSX10.4u.sdk"
  690. else:
  691. exit("Could not find any MacOSX SDK")
  692. ########################################################################
  693. ##
  694. ## SDK Auto-Disables
  695. ##
  696. ## Disable packages whose SDKs could not be found.
  697. ##
  698. ########################################################################
  699. def SdkAutoDisableDirectX():
  700. for ver in ["DX8","DX9","DIRECTCAM"]:
  701. if (PkgSkip(ver)==0):
  702. if (SDK.has_key(ver)==0):
  703. if (sys.platform == "win32"):
  704. WARNINGS.append("I cannot locate SDK for "+ver)
  705. else:
  706. WARNINGS.append(ver+" only supported on windows yet")
  707. WARNINGS.append("I have automatically added this command-line option: --no-"+ver.lower())
  708. PkgDisable(ver)
  709. else:
  710. WARNINGS.append("Using "+ver+" sdk: "+SDK[ver])
  711. def SdkAutoDisableMaya():
  712. for (ver,key) in MAYAVERSIONINFO:
  713. if (SDK.has_key(ver)==0) and (PkgSkip(ver)==0):
  714. if (sys.platform == "win32"):
  715. WARNINGS.append("The registry does not appear to contain a pointer to the "+ver+" SDK.")
  716. else:
  717. WARNINGS.append("I cannot locate SDK for "+ver)
  718. WARNINGS.append("I have automatically added this command-line option: --no-"+ver.lower())
  719. PkgDisable(ver)
  720. def SdkAutoDisableMax():
  721. for version,key1,key2,subdir in MAXVERSIONINFO:
  722. if (PkgSkip(version)==0) and ((SDK.has_key(version)==0) or (SDK.has_key(version+"CS")==0)):
  723. if (sys.platform == "win32"):
  724. if (SDK.has_key(version)):
  725. WARNINGS.append("Your copy of "+version+" does not include the character studio SDK")
  726. else:
  727. WARNINGS.append("The registry does not appear to contain a pointer to "+version)
  728. else:
  729. WARNINGS.append(version+" only supported on windows yet")
  730. WARNINGS.append("I have automatically added this command-line option: --no-"+version.lower())
  731. PkgDisable(version)
  732. ########################################################################
  733. ##
  734. ## Visual Studio comes with a script called VSVARS32.BAT, which
  735. ## you need to run before using visual studio command-line tools.
  736. ## The following python subroutine serves the same purpose.
  737. ##
  738. ########################################################################
  739. def AddToPathEnv(path,add):
  740. if (os.environ.has_key(path)):
  741. os.environ[path] = add + ";" + os.environ[path]
  742. else:
  743. os.environ[path] = add
  744. def SetupVisualStudioEnviron():
  745. if (SDK.has_key("VISUALSTUDIO")==0):
  746. exit("Could not find Visual Studio install directory")
  747. if (SDK.has_key("MSPLATFORM")==0):
  748. exit("Could not find the Microsoft Platform SDK")
  749. AddToPathEnv("PATH", SDK["VISUALSTUDIO"] + "VC\\bin")
  750. AddToPathEnv("PATH", SDK["VISUALSTUDIO"] + "Common7\\IDE")
  751. AddToPathEnv("INCLUDE", SDK["VISUALSTUDIO"] + "VC\\include")
  752. AddToPathEnv("LIB", SDK["VISUALSTUDIO"] + "VC\\lib")
  753. AddToPathEnv("INCLUDE", SDK["MSPLATFORM"] + "include")
  754. AddToPathEnv("INCLUDE", SDK["MSPLATFORM"] + "include\\atl")
  755. AddToPathEnv("LIB", SDK["MSPLATFORM"] + "lib")
  756. ########################################################################
  757. #
  758. # Include and Lib directories.
  759. #
  760. # These allow you to add include and lib directories to the
  761. # compiler search paths. These methods accept a "package"
  762. # parameter, which specifies which package the directory is
  763. # associated with. The include/lib directory is not used
  764. # if the package is not selected. The package can be 'ALWAYS'.
  765. #
  766. ########################################################################
  767. INCDIRECTORIES = []
  768. LIBDIRECTORIES = []
  769. LIBNAMES = []
  770. DEFSYMBOLS = []
  771. def IncDirectory(opt, dir):
  772. INCDIRECTORIES.append((opt, dir))
  773. def LibDirectory(opt, dir):
  774. LIBDIRECTORIES.append((opt, dir))
  775. def LibName(opt, name):
  776. LIBNAMES.append((opt, name))
  777. def DefSymbol(opt, sym, val):
  778. DEFSYMBOLS.append((opt, sym, val))
  779. ########################################################################
  780. #
  781. # On Linux, to run panda, the dynamic linker needs to know how to find
  782. # the shared libraries. This subroutine verifies that the dynamic
  783. # linker is properly configured. If not, it sets it up on a temporary
  784. # basis and issues a warning.
  785. #
  786. ########################################################################
  787. def CheckLinkerLibraryPath():
  788. if (sys.platform == "win32"): return
  789. builtlib = os.path.abspath("built/lib")
  790. try:
  791. ldpath = []
  792. f = file("/etc/ld.so.conf","r")
  793. for line in f: ldpath.append(line.rstrip())
  794. f.close()
  795. except: ldpath = []
  796. if (os.environ.has_key("LD_LIBRARY_PATH")):
  797. ldpath = ldpath + os.environ["LD_LIBRARY_PATH"].split(":")
  798. if (ldpath.count(builtlib)==0):
  799. WARNINGS.append("Caution: the built/lib directory is not in LD_LIBRARY_PATH")
  800. WARNINGS.append("or /etc/ld.so.conf. You must add it before using panda.")
  801. if (os.environ.has_key("LD_LIBRARY_PATH")):
  802. os.environ["LD_LIBRARY_PATH"] = builtlib + ":" + os.environ["LD_LIBRARY_PATH"]
  803. else:
  804. os.environ["LD_LIBRARY_PATH"] = builtlib
  805. ########################################################################
  806. ##
  807. ## Routines to copy files into the build tree
  808. ##
  809. ########################################################################
  810. def CopyFile(dstfile,srcfile):
  811. if (dstfile[-1]=='/'):
  812. dstdir = dstfile
  813. fnl = srcfile.rfind("/")
  814. if (fnl < 0): fn = srcfile
  815. else: fn = srcfile[fnl+1:]
  816. dstfile = dstdir + fn
  817. if (NeedsBuild([dstfile],[srcfile])):
  818. WriteFile(dstfile,ReadFile(srcfile))
  819. JustBuilt([dstfile], [srcfile])
  820. def CopyAllFiles(dstdir, srcdir, suffix=""):
  821. for x in GetDirectoryContents(srcdir, ["*"+suffix]):
  822. CopyFile(dstdir+x, srcdir+x)
  823. def CopyAllHeaders(dir, skip=[]):
  824. for filename in GetDirectoryContents(dir, ["*.h", "*.I", "*.T"], skip):
  825. srcfile = dir + "/" + filename
  826. dstfile = "built/include/" + filename
  827. if (NeedsBuild([dstfile],[srcfile])):
  828. WriteFile(dstfile,ReadFile(srcfile))
  829. JustBuilt([dstfile],[srcfile])
  830. def CopyTree(dstdir,srcdir):
  831. if (os.path.isdir(dstdir)): return 0
  832. if (sys.platform == "win32"):
  833. cmd = 'xcopy /I/Y/E/Q "' + srcdir + '" "' + dstdir + '"'
  834. else:
  835. cmd = 'cp -R -f ' + srcdir + ' ' + dstdir
  836. oscmd(cmd)
  837. ########################################################################
  838. ##
  839. ## Parse PandaVersion.pp to extract the version number.
  840. ##
  841. ########################################################################
  842. def ParsePandaVersion(fn):
  843. try:
  844. f = file(fn, "r")
  845. pattern = re.compile('^[ \t]*[#][ \t]*define[ \t]+PANDA_VERSION[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)')
  846. for line in f:
  847. match = pattern.match(line,0)
  848. if (match):
  849. version = match.group(1)+"."+match.group(2)+"."+match.group(3)
  850. break
  851. f.close()
  852. except: version="0.0.0"
  853. return version
  854. ########################################################################
  855. ##
  856. ## FindLocation
  857. ##
  858. ########################################################################
  859. ORIG_EXT={}
  860. def GetOrigExt(x):
  861. return ORIG_EXT[x]
  862. def CalcLocation(fn, ipath):
  863. if (fn.count("/")): return fn
  864. if (fn.endswith(".cxx")): return CxxFindSource(fn, ipath)
  865. if (fn.endswith(".I")): return CxxFindSource(fn, ipath)
  866. if (fn.endswith(".h")): return CxxFindSource(fn, ipath)
  867. if (fn.endswith(".c")): return CxxFindSource(fn, ipath)
  868. if (fn.endswith(".yxx")): return CxxFindSource(fn, ipath)
  869. if (fn.endswith(".lxx")): return CxxFindSource(fn, ipath)
  870. if (fn.endswith(".mll")): return "built/plugins/"+fn
  871. if (sys.platform == "win32"):
  872. if (fn.endswith(".def")): return CxxFindSource(fn, ipath)
  873. if (fn.endswith(".obj")): return "built/tmp/"+fn
  874. if (fn.endswith(".dll")): return "built/bin/"+fn
  875. if (fn.endswith(".dlo")): return "built/plugins/"+fn
  876. if (fn.endswith(".dli")): return "built/plugins/"+fn
  877. if (fn.endswith(".dle")): return "built/plugins/"+fn
  878. if (fn.endswith(".exe")): return "built/bin/"+fn
  879. if (fn.endswith(".lib")): return "built/lib/"+fn
  880. if (fn.endswith(".ilb")): return "built/tmp/"+fn[:-4]+".lib"
  881. if (fn.endswith(".dat")): return "built/tmp/"+fn
  882. if (fn.endswith(".in")): return "built/pandac/input/"+fn
  883. elif (sys.platform == "darwin"):
  884. if (fn.endswith(".mm")): return CxxFindSource(fn, ipath)
  885. if (fn.endswith(".obj")): return "built/tmp/"+fn[:-4]+".o"
  886. if (fn.endswith(".dll")): return "built/lib/"+fn[:-4]+".dylib"
  887. if (fn.endswith(".exe")): return "built/bin/"+fn[:-4]
  888. if (fn.endswith(".lib")): return "built/lib/"+fn[:-4]+".a"
  889. if (fn.endswith(".ilb")): return "built/tmp/"+fn[:-4]+".a"
  890. if (fn.endswith(".dat")): return "built/tmp/"+fn
  891. if (fn.endswith(".in")): return "built/pandac/input/"+fn
  892. else:
  893. if (fn.endswith(".obj")): return "built/tmp/"+fn[:-4]+".o"
  894. if (fn.endswith(".dll")): return "built/lib/"+fn[:-4]+".so"
  895. if (fn.endswith(".exe")): return "built/bin/"+fn[:-4]
  896. if (fn.endswith(".lib")): return "built/lib/"+fn[:-4]+".a"
  897. if (fn.endswith(".ilb")): return "built/tmp/"+fn[:-4]+".a"
  898. if (fn.endswith(".dat")): return "built/tmp/"+fn
  899. if (fn.endswith(".in")): return "built/pandac/input/"+fn
  900. return fn
  901. def FindLocation(fn, ipath):
  902. loc = CalcLocation(fn, ipath)
  903. (base,ext) = os.path.splitext(fn)
  904. ORIG_EXT[loc] = ext
  905. return loc
  906. ########################################################################
  907. ##
  908. ## TargetAdd
  909. ##
  910. ## Makepanda maintains a list of make-targets. Each target has
  911. ## these attributes:
  912. ##
  913. ## name - the name of the file being created.
  914. ## ext - the original file extension, prior to OS-specific translation
  915. ## inputs - the names of the input files to the compiler
  916. ## deps - other input files that the target also depends on
  917. ## opts - compiler options, a catch-all category
  918. ##
  919. ## TargetAdd will create the target if it does not exist. Then,
  920. ## depending on what options you pass, it will push data onto these
  921. ## various target attributes. This is cumulative: for example, if
  922. ## you use TargetAdd to add compiler options, then use TargetAdd
  923. ## again with more compiler options, both sets of options will be
  924. ## included.
  925. ##
  926. ## TargetAdd does some automatic dependency generation on C++ files.
  927. ## It will scan these files for include-files and automatically push
  928. ## the include files onto the list of dependencies. In order to do
  929. ## this, it needs an include-file search path. So if you supply
  930. ## any C++ input, you also need to supply compiler options containing
  931. ## include-directories, or alternately, a separate ipath parameter.
  932. ##
  933. ## The main body of 'makepanda' is a long list of TargetAdd
  934. ## directives building up a giant list of make targets. Then,
  935. ## finally, the targets are run and panda is built.
  936. ##
  937. ## Makepanda's dependency system does not understand multiple
  938. ## outputs from a single build step. When a build step generates
  939. ## a primary output file and a secondary output file, it is
  940. ## necessary to trick the dependency system. Insert a dummy
  941. ## build step that "generates" the secondary output file, using
  942. ## the primary output file as an input. There is a special
  943. ## compiler option DEPENDENCYONLY that creates such a dummy
  944. ## build-step. There are two cases where dummy build steps must
  945. ## be inserted: bison generates an OBJ and a secondary header
  946. ## file, interrogate generates an IN and a secondary IGATE.OBJ.
  947. ##
  948. ########################################################################
  949. class Target:
  950. pass
  951. TARGET_LIST=[]
  952. TARGET_TABLE={}
  953. def TargetAdd(target, dummy=0, opts=0, input=0, dep=0, ipath=0):
  954. if (dummy != 0):
  955. exit("Syntax error in TargetAdd "+target)
  956. if (ipath == 0): ipath = opts
  957. if (ipath == 0): ipath = []
  958. if (type(input) == str): input = [input]
  959. if (type(dep) == str): dep = [dep]
  960. full = FindLocation(target,["built/include"])
  961. if (TARGET_TABLE.has_key(full) == 0):
  962. t = Target()
  963. t.name = full
  964. t.inputs = []
  965. t.deps = {}
  966. t.opts = []
  967. TARGET_TABLE[full] = t
  968. TARGET_LIST.append(t)
  969. else:
  970. t = TARGET_TABLE[full]
  971. ipath = ["built/tmp"] + GetListOption(ipath, "DIR:") + ["built/include"]
  972. if (opts != 0):
  973. for x in opts:
  974. if (t.opts.count(x)==0):
  975. t.opts.append(x)
  976. if (input != 0):
  977. for x in input:
  978. fullinput = FindLocation(x, ipath)
  979. t.inputs.append(fullinput)
  980. t.deps[fullinput] = 1
  981. (base,suffix) = os.path.splitext(x)
  982. if (SUFFIX_INC.count(suffix)):
  983. for d in CxxCalcDependencies(fullinput, ipath, []):
  984. t.deps[d] = 1
  985. if (dep != 0):
  986. for x in dep:
  987. fulldep = FindLocation(x, ipath)
  988. t.deps[fulldep] = 1
  989. if (target.endswith(".in")):
  990. t.deps[FindLocation("interrogate.exe",[])] = 1
  991. t.deps[FindLocation("dtool_have_python.dat",[])] = 1