makepandacore.py 43 KB

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