makepandacore.py 36 KB

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