makepandacore.py 37 KB

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