makepandacore.py 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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. elif (os.path.exists("/Developer/SDKs/MacOSX10.4.0.sdk")):
  764. SDK["MACOSX"] = "/Developer/SDKs/MacOSX10.4.0.sdk"
  765. else:
  766. exit("Could not find any MacOSX SDK")
  767. ########################################################################
  768. ##
  769. ## SDK Auto-Disables
  770. ##
  771. ## Disable packages whose SDKs could not be found.
  772. ##
  773. ########################################################################
  774. def SdkAutoDisableDirectX():
  775. for ver in ["DX8","DX9","DIRECTCAM"]:
  776. if (PkgSkip(ver)==0):
  777. if (SDK.has_key(ver)==0):
  778. if (sys.platform == "win32"):
  779. WARNINGS.append("I cannot locate SDK for "+ver)
  780. else:
  781. WARNINGS.append(ver+" only supported on windows yet")
  782. WARNINGS.append("I have automatically added this command-line option: --no-"+ver.lower())
  783. PkgDisable(ver)
  784. else:
  785. WARNINGS.append("Using "+ver+" sdk: "+SDK[ver])
  786. def SdkAutoDisableMaya():
  787. for (ver,key) in MAYAVERSIONINFO:
  788. if (SDK.has_key(ver)==0) and (PkgSkip(ver)==0):
  789. if (sys.platform == "win32"):
  790. WARNINGS.append("The registry does not appear to contain a pointer to the "+ver+" SDK.")
  791. else:
  792. WARNINGS.append("I cannot locate SDK for "+ver)
  793. WARNINGS.append("I have automatically added this command-line option: --no-"+ver.lower())
  794. PkgDisable(ver)
  795. def SdkAutoDisableMax():
  796. for version,key1,key2,subdir in MAXVERSIONINFO:
  797. if (PkgSkip(version)==0) and ((SDK.has_key(version)==0) or (SDK.has_key(version+"CS")==0)):
  798. if (sys.platform == "win32"):
  799. if (SDK.has_key(version)):
  800. WARNINGS.append("Your copy of "+version+" does not include the character studio SDK")
  801. else:
  802. WARNINGS.append("The registry does not appear to contain a pointer to "+version)
  803. else:
  804. WARNINGS.append(version+" only supported on windows yet")
  805. WARNINGS.append("I have automatically added this command-line option: --no-"+version.lower())
  806. PkgDisable(version)
  807. ########################################################################
  808. ##
  809. ## Visual Studio comes with a script called VSVARS32.BAT, which
  810. ## you need to run before using visual studio command-line tools.
  811. ## The following python subroutine serves the same purpose.
  812. ##
  813. ########################################################################
  814. def AddToPathEnv(path,add):
  815. if (os.environ.has_key(path)):
  816. os.environ[path] = add + ";" + os.environ[path]
  817. else:
  818. os.environ[path] = add
  819. def SetupVisualStudioEnviron():
  820. if (SDK.has_key("VISUALSTUDIO")==0):
  821. exit("Could not find Visual Studio install directory")
  822. if (SDK.has_key("MSPLATFORM")==0):
  823. exit("Could not find the Microsoft Platform SDK")
  824. AddToPathEnv("PATH", SDK["VISUALSTUDIO"] + "VC\\bin")
  825. AddToPathEnv("PATH", SDK["VISUALSTUDIO"] + "Common7\\IDE")
  826. AddToPathEnv("INCLUDE", SDK["VISUALSTUDIO"] + "VC\\include")
  827. AddToPathEnv("LIB", SDK["VISUALSTUDIO"] + "VC\\lib")
  828. AddToPathEnv("INCLUDE", SDK["MSPLATFORM"] + "include")
  829. AddToPathEnv("INCLUDE", SDK["MSPLATFORM"] + "include\\atl")
  830. AddToPathEnv("LIB", SDK["MSPLATFORM"] + "lib")
  831. ########################################################################
  832. #
  833. # Include and Lib directories.
  834. #
  835. # These allow you to add include and lib directories to the
  836. # compiler search paths. These methods accept a "package"
  837. # parameter, which specifies which package the directory is
  838. # associated with. The include/lib directory is not used
  839. # if the package is not selected. The package can be 'ALWAYS'.
  840. #
  841. ########################################################################
  842. INCDIRECTORIES = []
  843. LIBDIRECTORIES = []
  844. LIBNAMES = []
  845. DEFSYMBOLS = []
  846. def IncDirectory(opt, dir):
  847. INCDIRECTORIES.append((opt, dir))
  848. def LibDirectory(opt, dir):
  849. LIBDIRECTORIES.append((opt, dir))
  850. def LibName(opt, name):
  851. LIBNAMES.append((opt, name))
  852. def DefSymbol(opt, sym, val):
  853. DEFSYMBOLS.append((opt, sym, val))
  854. ########################################################################
  855. #
  856. # On Linux, to run panda, the dynamic linker needs to know how to find
  857. # the shared libraries. This subroutine verifies that the dynamic
  858. # linker is properly configured. If not, it sets it up on a temporary
  859. # basis and issues a warning.
  860. #
  861. ########################################################################
  862. def CheckLinkerLibraryPath():
  863. if (sys.platform == "win32"): return
  864. builtlib = os.path.abspath("built/lib")
  865. try:
  866. ldpath = []
  867. f = file("/etc/ld.so.conf","r")
  868. for line in f: ldpath.append(line.rstrip())
  869. f.close()
  870. except: ldpath = []
  871. if (os.environ.has_key("LD_LIBRARY_PATH")):
  872. ldpath = ldpath + os.environ["LD_LIBRARY_PATH"].split(":")
  873. if (ldpath.count(builtlib)==0):
  874. WARNINGS.append("Caution: the built/lib directory is not in LD_LIBRARY_PATH")
  875. WARNINGS.append("or /etc/ld.so.conf. You must add it before using panda.")
  876. if (os.environ.has_key("LD_LIBRARY_PATH")):
  877. os.environ["LD_LIBRARY_PATH"] = builtlib + ":" + os.environ["LD_LIBRARY_PATH"]
  878. else:
  879. os.environ["LD_LIBRARY_PATH"] = builtlib
  880. ########################################################################
  881. ##
  882. ## Routines to copy files into the build tree
  883. ##
  884. ########################################################################
  885. def CopyFile(dstfile,srcfile):
  886. if (dstfile[-1]=='/'):
  887. dstdir = dstfile
  888. fnl = srcfile.rfind("/")
  889. if (fnl < 0): fn = srcfile
  890. else: fn = srcfile[fnl+1:]
  891. dstfile = dstdir + fn
  892. if (NeedsBuild([dstfile],[srcfile])):
  893. WriteFile(dstfile,ReadFile(srcfile))
  894. JustBuilt([dstfile], [srcfile])
  895. def CopyAllFiles(dstdir, srcdir, suffix=""):
  896. for x in GetDirectoryContents(srcdir, ["*"+suffix]):
  897. CopyFile(dstdir+x, srcdir+x)
  898. def CopyAllHeaders(dir, skip=[]):
  899. for filename in GetDirectoryContents(dir, ["*.h", "*.I", "*.T"], skip):
  900. srcfile = dir + "/" + filename
  901. dstfile = "built/include/" + filename
  902. if (NeedsBuild([dstfile],[srcfile])):
  903. WriteFile(dstfile,ReadFile(srcfile))
  904. JustBuilt([dstfile],[srcfile])
  905. def CopyTree(dstdir,srcdir):
  906. if (os.path.isdir(dstdir)): return 0
  907. if (sys.platform == "win32"):
  908. cmd = 'xcopy /I/Y/E/Q "' + srcdir + '" "' + dstdir + '"'
  909. else:
  910. cmd = 'cp -R -f ' + srcdir + ' ' + dstdir
  911. oscmd(cmd)
  912. ########################################################################
  913. ##
  914. ## Parse PandaVersion.pp to extract the version number.
  915. ##
  916. ########################################################################
  917. def ParsePandaVersion(fn):
  918. try:
  919. f = file(fn, "r")
  920. pattern = re.compile('^[ \t]*[#][ \t]*define[ \t]+PANDA_VERSION[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)')
  921. for line in f:
  922. match = pattern.match(line,0)
  923. if (match):
  924. version = match.group(1)+"."+match.group(2)+"."+match.group(3)
  925. break
  926. f.close()
  927. except: version="0.0.0"
  928. return version
  929. ########################################################################
  930. ##
  931. ## FindLocation
  932. ##
  933. ########################################################################
  934. ORIG_EXT={}
  935. def GetOrigExt(x):
  936. return ORIG_EXT[x]
  937. def CalcLocation(fn, ipath):
  938. if (fn.count("/")): return fn
  939. if (fn.endswith(".cxx")): return CxxFindSource(fn, ipath)
  940. if (fn.endswith(".I")): return CxxFindSource(fn, ipath)
  941. if (fn.endswith(".h")): return CxxFindSource(fn, ipath)
  942. if (fn.endswith(".c")): return CxxFindSource(fn, ipath)
  943. if (fn.endswith(".yxx")): return CxxFindSource(fn, ipath)
  944. if (fn.endswith(".lxx")): return CxxFindSource(fn, ipath)
  945. if (fn.endswith(".mll")): return "built/plugins/"+fn
  946. if (sys.platform == "win32"):
  947. if (fn.endswith(".def")): return CxxFindSource(fn, ipath)
  948. if (fn.endswith(".obj")): return "built/tmp/"+fn
  949. if (fn.endswith(".dll")): return "built/bin/"+fn
  950. if (fn.endswith(".dlo")): return "built/plugins/"+fn
  951. if (fn.endswith(".dli")): return "built/plugins/"+fn
  952. if (fn.endswith(".dle")): return "built/plugins/"+fn
  953. if (fn.endswith(".exe")): return "built/bin/"+fn
  954. if (fn.endswith(".lib")): return "built/lib/"+fn
  955. if (fn.endswith(".ilb")): return "built/tmp/"+fn[:-4]+".lib"
  956. if (fn.endswith(".dat")): return "built/tmp/"+fn
  957. if (fn.endswith(".in")): return "built/pandac/input/"+fn
  958. elif (sys.platform == "darwin"):
  959. if (fn.endswith(".mm")): return CxxFindSource(fn, ipath)
  960. if (fn.endswith(".obj")): return "built/tmp/"+fn[:-4]+".o"
  961. if (fn.endswith(".dll")): return "built/lib/"+fn[:-4]+".dylib"
  962. if (fn.endswith(".exe")): return "built/bin/"+fn[:-4]
  963. if (fn.endswith(".lib")): return "built/lib/"+fn[:-4]+".a"
  964. if (fn.endswith(".ilb")): return "built/tmp/"+fn[:-4]+".a"
  965. if (fn.endswith(".dat")): return "built/tmp/"+fn
  966. if (fn.endswith(".in")): return "built/pandac/input/"+fn
  967. else:
  968. if (fn.endswith(".obj")): return "built/tmp/"+fn[:-4]+".o"
  969. if (fn.endswith(".dll")): return "built/lib/"+fn[:-4]+".so"
  970. if (fn.endswith(".exe")): return "built/bin/"+fn[:-4]
  971. if (fn.endswith(".lib")): return "built/lib/"+fn[:-4]+".a"
  972. if (fn.endswith(".ilb")): return "built/tmp/"+fn[:-4]+".a"
  973. if (fn.endswith(".dat")): return "built/tmp/"+fn
  974. if (fn.endswith(".in")): return "built/pandac/input/"+fn
  975. return fn
  976. def FindLocation(fn, ipath):
  977. loc = CalcLocation(fn, ipath)
  978. (base,ext) = os.path.splitext(fn)
  979. ORIG_EXT[loc] = ext
  980. return loc
  981. ########################################################################
  982. ##
  983. ## TargetAdd
  984. ##
  985. ## Makepanda maintains a list of make-targets. Each target has
  986. ## these attributes:
  987. ##
  988. ## name - the name of the file being created.
  989. ## ext - the original file extension, prior to OS-specific translation
  990. ## inputs - the names of the input files to the compiler
  991. ## deps - other input files that the target also depends on
  992. ## opts - compiler options, a catch-all category
  993. ##
  994. ## TargetAdd will create the target if it does not exist. Then,
  995. ## depending on what options you pass, it will push data onto these
  996. ## various target attributes. This is cumulative: for example, if
  997. ## you use TargetAdd to add compiler options, then use TargetAdd
  998. ## again with more compiler options, both sets of options will be
  999. ## included.
  1000. ##
  1001. ## TargetAdd does some automatic dependency generation on C++ files.
  1002. ## It will scan these files for include-files and automatically push
  1003. ## the include files onto the list of dependencies. In order to do
  1004. ## this, it needs an include-file search path. So if you supply
  1005. ## any C++ input, you also need to supply compiler options containing
  1006. ## include-directories, or alternately, a separate ipath parameter.
  1007. ##
  1008. ## The main body of 'makepanda' is a long list of TargetAdd
  1009. ## directives building up a giant list of make targets. Then,
  1010. ## finally, the targets are run and panda is built.
  1011. ##
  1012. ## Makepanda's dependency system does not understand multiple
  1013. ## outputs from a single build step. When a build step generates
  1014. ## a primary output file and a secondary output file, it is
  1015. ## necessary to trick the dependency system. Insert a dummy
  1016. ## build step that "generates" the secondary output file, using
  1017. ## the primary output file as an input. There is a special
  1018. ## compiler option DEPENDENCYONLY that creates such a dummy
  1019. ## build-step. There are two cases where dummy build steps must
  1020. ## be inserted: bison generates an OBJ and a secondary header
  1021. ## file, interrogate generates an IN and a secondary IGATE.OBJ.
  1022. ##
  1023. ########################################################################
  1024. class Target:
  1025. pass
  1026. TARGET_LIST=[]
  1027. TARGET_TABLE={}
  1028. def TargetAdd(target, dummy=0, opts=0, input=0, dep=0, ipath=0):
  1029. if (dummy != 0):
  1030. exit("Syntax error in TargetAdd "+target)
  1031. if (ipath == 0): ipath = opts
  1032. if (ipath == 0): ipath = []
  1033. if (type(input) == str): input = [input]
  1034. if (type(dep) == str): dep = [dep]
  1035. full = FindLocation(target,["built/include"])
  1036. if (TARGET_TABLE.has_key(full) == 0):
  1037. t = Target()
  1038. t.name = full
  1039. t.inputs = []
  1040. t.deps = {}
  1041. t.opts = []
  1042. TARGET_TABLE[full] = t
  1043. TARGET_LIST.append(t)
  1044. else:
  1045. t = TARGET_TABLE[full]
  1046. ipath = ["built/tmp"] + GetListOption(ipath, "DIR:") + ["built/include"]
  1047. if (opts != 0):
  1048. for x in opts:
  1049. if (t.opts.count(x)==0):
  1050. t.opts.append(x)
  1051. if (input != 0):
  1052. for x in input:
  1053. fullinput = FindLocation(x, ipath)
  1054. t.inputs.append(fullinput)
  1055. t.deps[fullinput] = 1
  1056. (base,suffix) = os.path.splitext(x)
  1057. if (SUFFIX_INC.count(suffix)):
  1058. for d in CxxCalcDependencies(fullinput, ipath, []):
  1059. t.deps[d] = 1
  1060. if (dep != 0):
  1061. for x in dep:
  1062. fulldep = FindLocation(x, ipath)
  1063. t.deps[fulldep] = 1
  1064. if (target.endswith(".in")):
  1065. t.deps[FindLocation("interrogate.exe",[])] = 1
  1066. t.deps[FindLocation("dtool_have_python.dat",[])] = 1