makepandacore.py 36 KB

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