makepackage.py 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. #!/usr/bin/env python
  2. from makepandacore import *
  3. from installpanda import *
  4. import sys
  5. import os
  6. import shutil
  7. INSTALLER_DEB_FILE = """
  8. Package: panda3dMAJOR
  9. Version: VERSION
  10. Section: libdevel
  11. Priority: optional
  12. Architecture: ARCH
  13. Essential: no
  14. Depends: DEPENDS
  15. Recommends: RECOMMENDS
  16. Provides: PROVIDES
  17. Conflicts: PROVIDES
  18. Replaces: PROVIDES
  19. Maintainer: rdb <[email protected]>
  20. Installed-Size: INSTSIZE
  21. Description: Panda3D free 3D engine SDK
  22. Panda3D is a game engine which includes graphics, audio, I/O, collision detection, and other abilities relevant to the creation of 3D games. Panda3D is open source and free software under the revised BSD license, and can be used for both free and commercial game development at no financial cost.
  23. Panda3D's intended game-development language is Python. The engine itself is written in C++, and utilizes an automatic wrapper-generator to expose the complete functionality of the engine in a Python interface.
  24. .
  25. This package contains the SDK for development with Panda3D.
  26. """
  27. RUNTIME_INSTALLER_DEB_FILE = """
  28. Package: panda3d-runtime
  29. Version: VERSION
  30. Section: web
  31. Priority: optional
  32. Architecture: ARCH
  33. Essential: no
  34. Depends: DEPENDS
  35. Provides: panda3d-runtime
  36. Maintainer: rdb <[email protected]>
  37. Installed-Size: INSTSIZE
  38. Description: Runtime binary and browser plugin for the Panda3D Game Engine
  39. This package contains the runtime distribution and browser plugin of the Panda3D engine. It allows you view webpages that contain Panda3D content and to run games created with Panda3D that are packaged as .p3d file.
  40. """
  41. # We're not putting "python" in the "Requires" field,
  42. # since the rpm-based distros don't have a common
  43. # naming for the Python package.
  44. INSTALLER_SPEC_FILE = """
  45. Summary: The Panda3D free 3D engine SDK
  46. Name: panda3d
  47. Version: VERSION
  48. Release: RPMRELEASE
  49. License: BSD License
  50. Group: Development/Libraries
  51. BuildRoot: PANDASOURCE/targetroot
  52. %description
  53. Panda3D is a game engine which includes graphics, audio, I/O, collision detection, and other abilities relevant to the creation of 3D games. Panda3D is open source and free software under the revised BSD license, and can be used for both free and commercial game development at no financial cost.
  54. Panda3D's intended game-development language is Python. The engine itself is written in C++, and utilizes an automatic wrapper-generator to expose the complete functionality of the engine in a Python interface.
  55. This package contains the SDK for development with Panda3D, install panda3d-runtime for the runtime files.
  56. %post
  57. /sbin/ldconfig
  58. %postun
  59. /sbin/ldconfig
  60. %files
  61. %defattr(-,root,root)
  62. /etc/Confauto.prc
  63. /etc/Config.prc
  64. /usr/share/panda3d
  65. /etc/ld.so.conf.d/panda3d.conf
  66. /usr/%_lib/panda3d
  67. /usr/include/panda3d
  68. """
  69. INSTALLER_SPEC_FILE_PVIEW = \
  70. """/usr/share/applications/pview.desktop
  71. /usr/share/mime-info/panda3d.mime
  72. /usr/share/mime-info/panda3d.keys
  73. /usr/share/mime/packages/panda3d.xml
  74. /usr/share/application-registry/panda3d.applications
  75. """
  76. RUNTIME_INSTALLER_SPEC_FILE = """
  77. Summary: Runtime binary and browser plugin for the Panda3D Game Engine
  78. Name: panda3d-runtime
  79. Version: VERSION
  80. Release: RPMRELEASE
  81. License: BSD License
  82. Group: Productivity/Graphics/Other
  83. BuildRoot: PANDASOURCE/targetroot
  84. %description
  85. This package contains the runtime distribution and browser plugin of the Panda3D engine. It allows you view webpages that contain Panda3D content and to run games created with Panda3D that are packaged as .p3d file.
  86. %files
  87. %defattr(-,root,root)
  88. /usr/bin/panda3d
  89. /usr/%_lib/nppanda3d.so
  90. /usr/%_lib/mozilla/plugins/nppanda3d.so
  91. /usr/%_lib/mozilla-firefox/plugins/nppanda3d.so
  92. /usr/%_lib/xulrunner-addons/plugins/nppanda3d.so
  93. /usr/share/mime-info/panda3d-runtime.mime
  94. /usr/share/mime-info/panda3d-runtime.keys
  95. /usr/share/mime/packages/panda3d-runtime.xml
  96. /usr/share/application-registry/panda3d-runtime.applications
  97. /usr/share/applications/*.desktop
  98. """
  99. # plist file for Mac OSX
  100. Info_plist = """<?xml version="1.0" encoding="UTF-8"?>
  101. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  102. <plist version="1.0">
  103. <dict>
  104. <key>CFBundleIdentifier</key>
  105. <string>{package_id}</string>
  106. <key>CFBundleShortVersionString</key>
  107. <string>{version}</string>
  108. <key>IFPkgFlagRelocatable</key>
  109. <false/>
  110. <key>IFPkgFlagAuthorizationAction</key>
  111. <string>RootAuthorization</string>
  112. <key>IFPkgFlagAllowBackRev</key>
  113. <true/>
  114. </dict>
  115. </plist>
  116. """
  117. # FreeBSD pkg-descr
  118. INSTALLER_PKG_DESCR_FILE = """
  119. Panda3D is a game engine which includes graphics, audio, I/O, collision detection, and other abilities relevant to the creation of 3D games. Panda3D is open source and free software under the revised BSD license, and can be used for both free and commercial game development at no financial cost.
  120. Panda3D's intended game-development language is Python. The engine itself is written in C++, and utilizes an automatic wrapper-generator to expose the complete functionality of the engine in a Python interface.
  121. This package contains the SDK for development with Panda3D, install panda3d-runtime for the runtime files.
  122. WWW: https://www.panda3d.org/
  123. """
  124. # FreeBSD pkg-descr
  125. RUNTIME_INSTALLER_PKG_DESCR_FILE = """
  126. Runtime binary and browser plugin for the Panda3D Game Engine
  127. This package contains the runtime distribution and browser plugin of the Panda3D engine. It allows you view webpages that contain Panda3D content and to run games created with Panda3D that are packaged as .p3d file.
  128. WWW: https://www.panda3d.org/
  129. """
  130. # FreeBSD PKG Manifest template file
  131. INSTALLER_PKG_MANIFEST_FILE = """
  132. name: NAME
  133. version: VERSION
  134. arch: ARCH
  135. origin: ORIGIN
  136. comment: "Panda3D free 3D engine SDK"
  137. www: https://www.panda3d.org
  138. maintainer: rdb <[email protected]>
  139. prefix: /usr/local
  140. flatsize: INSTSIZEMB
  141. deps: {DEPENDS}
  142. """
  143. def MakeInstallerNSIS(version, file, title, installdir, runtime=False, compressor="lzma", **kwargs):
  144. outputdir = GetOutputDir()
  145. if os.path.isfile(file):
  146. os.remove(file)
  147. elif os.path.isdir(file):
  148. shutil.rmtree(file)
  149. if GetTargetArch() == 'x64':
  150. regview = '64'
  151. else:
  152. regview = '32'
  153. if runtime:
  154. # Invoke the make_installer script.
  155. AddToPathEnv("PATH", outputdir + "\\bin")
  156. AddToPathEnv("PATH", outputdir + "\\plugins")
  157. cmd = sys.executable + " -B -u " + os.path.join("direct", "src", "plugin_installer", "make_installer.py")
  158. cmd += " --version %s --regview %s" % (version, regview)
  159. if GetTargetArch() == 'x64':
  160. cmd += " --install \"$PROGRAMFILES64\\Panda3D\" "
  161. else:
  162. cmd += " --install \"$PROGRAMFILES32\\Panda3D\" "
  163. oscmd(cmd)
  164. shutil.move(os.path.join("direct", "src", "plugin_installer", "p3d-setup.exe"), file)
  165. return
  166. print("Building "+title+" installer at %s" % (file))
  167. if compressor != "lzma":
  168. print("Note: you are using zlib, which is faster, but lzma gives better compression.")
  169. if os.path.exists("nsis-output.exe"):
  170. os.remove("nsis-output.exe")
  171. WriteFile(outputdir+"/tmp/__init__.py", "")
  172. nsis_defs = {
  173. 'COMPRESSOR': compressor,
  174. 'TITLE' : title,
  175. 'INSTALLDIR': installdir,
  176. 'OUTFILE' : '..\\' + file,
  177. 'BUILT' : '..\\' + outputdir,
  178. 'SOURCE' : '..',
  179. 'REGVIEW' : regview,
  180. }
  181. # Are we shipping a version of Python?
  182. if os.path.isfile(os.path.join(outputdir, "python", "python.exe")):
  183. py_dlls = glob.glob(os.path.join(outputdir, "python", "python[0-9][0-9].dll")) \
  184. + glob.glob(os.path.join(outputdir, "python", "python[0-9][0-9]_d.dll"))
  185. assert py_dlls
  186. py_dll = os.path.basename(py_dlls[0])
  187. pyver = py_dll[6] + "." + py_dll[7]
  188. if GetTargetArch() != 'x64':
  189. pyver += '-32'
  190. nsis_defs['INCLUDE_PYVER'] = pyver
  191. if GetHost() == 'windows':
  192. cmd = os.path.join(GetThirdpartyBase(), 'win-nsis', 'makensis') + ' /V2'
  193. for item in nsis_defs.items():
  194. cmd += ' /D%s="%s"' % item
  195. else:
  196. cmd = 'makensis -V2'
  197. for item in nsis_defs.items():
  198. cmd += ' -D%s="%s"' % item
  199. cmd += ' "makepanda\\installer.nsi"'
  200. oscmd(cmd)
  201. def MakeDebugSymbolArchive(zipname, dirname):
  202. outputdir = GetOutputDir()
  203. import zipfile
  204. zip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
  205. for fn in glob.glob(os.path.join(outputdir, 'bin', '*.pdb')):
  206. zip.write(fn, dirname + '/bin/' + os.path.basename(fn))
  207. for fn in glob.glob(os.path.join(outputdir, 'panda3d', '*.pdb')):
  208. zip.write(fn, dirname + '/panda3d/' + os.path.basename(fn))
  209. for fn in glob.glob(os.path.join(outputdir, 'plugins', '*.pdb')):
  210. zip.write(fn, dirname + '/plugins/' + os.path.basename(fn))
  211. for fn in glob.glob(os.path.join(outputdir, 'python', '*.pdb')):
  212. zip.write(fn, dirname + '/python/' + os.path.basename(fn))
  213. for fn in glob.glob(os.path.join(outputdir, 'python', 'DLLs', '*.pdb')):
  214. zip.write(fn, dirname + '/python/DLLs/' + os.path.basename(fn))
  215. zip.close()
  216. def MakeInstallerLinux(version, debversion=None, rpmrelease=1, runtime=False,
  217. python_versions=[], **kwargs):
  218. outputdir = GetOutputDir()
  219. # We pack Python 2 and Python 3, if we built with support for it.
  220. python2_ver = None
  221. python3_ver = None
  222. install_python_versions = []
  223. if not runtime:
  224. # What's the system version of Python 3?
  225. oscmd('python3 -V > "%s/tmp/python3_version.txt"' % (outputdir))
  226. sys_python3_ver = '.'.join(ReadFile(outputdir + "/tmp/python3_version.txt").strip().split(' ')[1].split('.')[:2])
  227. # Check that we built with support for these.
  228. for version_info in python_versions:
  229. if version_info["version"] == "2.7":
  230. python2_ver = "2.7"
  231. install_python_versions.append(version_info)
  232. elif version_info["version"] == sys_python3_ver:
  233. python3_ver = sys_python3_ver
  234. install_python_versions.append(version_info)
  235. major_version = '.'.join(version.split('.')[:2])
  236. if not debversion:
  237. debversion = version
  238. # Clean and set up a directory to install Panda3D into
  239. oscmd("rm -rf targetroot data.tar.gz control.tar.gz panda3d.spec")
  240. oscmd("mkdir -m 0755 targetroot")
  241. dpkg_present = False
  242. if os.path.exists("/usr/bin/dpkg-architecture") and os.path.exists("/usr/bin/dpkg-deb"):
  243. dpkg_present = True
  244. rpmbuild_present = False
  245. if os.path.exists("/usr/bin/rpmbuild"):
  246. rpmbuild_present = True
  247. if dpkg_present and rpmbuild_present:
  248. Warn("both dpkg and rpmbuild present.")
  249. if dpkg_present:
  250. # Invoke installpanda.py to install it into a temporary dir
  251. lib_dir = GetDebLibDir()
  252. if runtime:
  253. InstallRuntime(destdir="targetroot", prefix="/usr",
  254. outputdir=outputdir, libdir=lib_dir)
  255. else:
  256. InstallPanda(destdir="targetroot", prefix="/usr",
  257. outputdir=outputdir, libdir=lib_dir,
  258. python_versions=install_python_versions)
  259. oscmd("chmod -R 755 targetroot/usr/share/panda3d")
  260. oscmd("mkdir -m 0755 -p targetroot/usr/share/man/man1")
  261. oscmd("install -m 0644 doc/man/*.1 targetroot/usr/share/man/man1/")
  262. oscmd("dpkg --print-architecture > "+outputdir+"/tmp/architecture.txt")
  263. pkg_arch = ReadFile(outputdir+"/tmp/architecture.txt").strip()
  264. if runtime:
  265. txt = RUNTIME_INSTALLER_DEB_FILE[1:]
  266. else:
  267. txt = INSTALLER_DEB_FILE[1:]
  268. txt = txt.replace("VERSION", debversion).replace("ARCH", pkg_arch).replace("MAJOR", major_version)
  269. txt = txt.replace("INSTSIZE", str(GetDirectorySize("targetroot") // 1024))
  270. oscmd("mkdir -m 0755 -p targetroot/DEBIAN")
  271. oscmd("cd targetroot && (find usr -type f -exec md5sum {} ;) > DEBIAN/md5sums")
  272. if not runtime:
  273. oscmd("cd targetroot && (find etc -type f -exec md5sum {} ;) >> DEBIAN/md5sums")
  274. WriteFile("targetroot/DEBIAN/conffiles","/etc/Config.prc\n")
  275. WriteFile("targetroot/DEBIAN/postinst","#!/bin/sh\necho running ldconfig\nldconfig\n")
  276. oscmd("cp targetroot/DEBIAN/postinst targetroot/DEBIAN/postrm")
  277. # Determine the package name and the locations that
  278. # dpkg-shlibdeps should look in for executables.
  279. pkg_version = debversion
  280. if runtime:
  281. pkg_name = "panda3d-runtime"
  282. lib_pattern = "debian/%s/usr/%s/*.so" % (pkg_name, lib_dir)
  283. else:
  284. pkg_name = "panda3d" + major_version
  285. lib_pattern = "debian/%s/usr/%s/panda3d/*.so*" % (pkg_name, lib_dir)
  286. bin_pattern = "debian/%s/usr/bin/*" % (pkg_name)
  287. # dpkg-shlibdeps looks in the debian/{pkg_name}/DEBIAN/shlibs directory
  288. # and also expects a debian/control file, so we create this dummy set-up.
  289. oscmd("mkdir targetroot/debian")
  290. oscmd("ln -s .. targetroot/debian/" + pkg_name)
  291. WriteFile("targetroot/debian/control", "")
  292. dpkg_shlibdeps = "dpkg-shlibdeps"
  293. if GetVerbose():
  294. dpkg_shlibdeps += " -v"
  295. if runtime:
  296. # The runtime doesn't export any useful symbols, so just query the dependencies.
  297. oscmd("cd targetroot && %(dpkg_shlibdeps)s -x%(pkg_name)s %(lib_pattern)s %(bin_pattern)s*" % locals())
  298. depends = ReadFile("targetroot/debian/substvars").replace("shlibs:Depends=", "").strip()
  299. recommends = ""
  300. provides = "panda3d-runtime"
  301. else:
  302. pkg_name = "panda3d" + major_version
  303. pkg_dir = "debian/panda3d" + major_version
  304. # Generate a symbols file so that other packages can know which symbols we export.
  305. oscmd("cd targetroot && dpkg-gensymbols -q -ODEBIAN/symbols -v%(pkg_version)s -p%(pkg_name)s -e%(lib_pattern)s" % locals())
  306. # Library dependencies are required, binary dependencies are recommended.
  307. # We explicitly exclude libphysx-extras since we don't want to depend on PhysX.
  308. oscmd("cd targetroot && LD_LIBRARY_PATH=usr/%(lib_dir)s/panda3d %(dpkg_shlibdeps)s -Tdebian/substvars_dep --ignore-missing-info -x%(pkg_name)s -xlibphysx-extras %(lib_pattern)s" % locals())
  309. oscmd("cd targetroot && LD_LIBRARY_PATH=usr/%(lib_dir)s/panda3d %(dpkg_shlibdeps)s -Tdebian/substvars_rec --ignore-missing-info -x%(pkg_name)s %(bin_pattern)s" % locals())
  310. # Parse the substvars files generated by dpkg-shlibdeps.
  311. depends = ReadFile("targetroot/debian/substvars_dep").replace("shlibs:Depends=", "").strip()
  312. recommends = ReadFile("targetroot/debian/substvars_rec").replace("shlibs:Depends=", "").strip()
  313. provides = "panda3d"
  314. if python2_ver or python3_ver:
  315. recommends += ", python-pmw"
  316. if python2_ver:
  317. depends += ", python%s" % (python2_ver)
  318. recommends += ", python-wxversion"
  319. recommends += ", python-tk (>= %s)" % (python2_ver)
  320. provides += ", python2-panda3d"
  321. if python3_ver:
  322. depends += ", python%s" % (python3_ver)
  323. recommends += ", python3-tk (>= %s)" % (python3_ver)
  324. provides += ", python3-panda3d"
  325. if not PkgSkip("NVIDIACG"):
  326. depends += ", nvidia-cg-toolkit"
  327. # Write back the dependencies, and delete the dummy set-up.
  328. txt = txt.replace("DEPENDS", depends.strip(', '))
  329. txt = txt.replace("RECOMMENDS", recommends.strip(', '))
  330. txt = txt.replace("PROVIDES", provides.strip(', '))
  331. WriteFile("targetroot/DEBIAN/control", txt)
  332. oscmd("rm -rf targetroot/debian")
  333. # Package it all up into a .deb file.
  334. oscmd("chmod -R 755 targetroot/DEBIAN")
  335. oscmd("chmod 644 targetroot/DEBIAN/control targetroot/DEBIAN/md5sums")
  336. if not runtime:
  337. oscmd("chmod 644 targetroot/DEBIAN/conffiles targetroot/DEBIAN/symbols")
  338. oscmd("fakeroot dpkg-deb -b targetroot %s_%s_%s.deb" % (pkg_name, pkg_version, pkg_arch))
  339. elif rpmbuild_present:
  340. # Invoke installpanda.py to install it into a temporary dir
  341. if runtime:
  342. InstallRuntime(destdir="targetroot", prefix="/usr", outputdir=outputdir, libdir=GetRPMLibDir())
  343. else:
  344. InstallPanda(destdir="targetroot", prefix="/usr",
  345. outputdir=outputdir, libdir=GetRPMLibDir(),
  346. python_versions=install_python_versions)
  347. oscmd("chmod -R 755 targetroot/usr/share/panda3d")
  348. oscmd("rpm -E '%_target_cpu' > "+outputdir+"/tmp/architecture.txt")
  349. arch = ReadFile(outputdir+"/tmp/architecture.txt").strip()
  350. pandasource = os.path.abspath(os.getcwd())
  351. if runtime:
  352. txt = RUNTIME_INSTALLER_SPEC_FILE[1:]
  353. else:
  354. txt = INSTALLER_SPEC_FILE[1:]
  355. # Add the MIME associations if we have pview
  356. if not PkgSkip("PVIEW"):
  357. txt += INSTALLER_SPEC_FILE_PVIEW
  358. # Add the platform-specific Python directories.
  359. dirs = set()
  360. for version_info in install_python_versions:
  361. dirs.add(version_info["platlib"])
  362. dirs.add(version_info["purelib"])
  363. for dir in dirs:
  364. txt += dir + "\n"
  365. # Add the binaries in /usr/bin explicitly to the spec file
  366. for base in os.listdir(outputdir + "/bin"):
  367. txt += "/usr/bin/%s\n" % (base)
  368. # Write out the spec file.
  369. txt = txt.replace("VERSION", version)
  370. txt = txt.replace("RPMRELEASE", str(rpmrelease))
  371. txt = txt.replace("PANDASOURCE", pandasource)
  372. WriteFile("panda3d.spec", txt)
  373. oscmd("fakeroot rpmbuild --define '_rpmdir "+pandasource+"' --buildroot '"+os.path.abspath("targetroot")+"' -bb panda3d.spec")
  374. if runtime:
  375. oscmd("mv "+arch+"/panda3d-runtime-"+version+"-"+rpmrelease+"."+arch+".rpm .")
  376. else:
  377. oscmd("mv "+arch+"/panda3d-"+version+"-"+rpmrelease+"."+arch+".rpm .")
  378. oscmd("rm -rf "+arch, True)
  379. else:
  380. exit("To build an installer, either rpmbuild or dpkg-deb must be present on your system!")
  381. def MakeInstallerOSX(version, runtime=False, python_versions=[], **kwargs):
  382. outputdir = GetOutputDir()
  383. if runtime:
  384. # Invoke the make_installer script.
  385. AddToPathEnv("DYLD_LIBRARY_PATH", outputdir + "/plugins")
  386. cmdstr = sys.executable + " "
  387. if sys.version_info >= (2, 6):
  388. cmdstr += "-B "
  389. cmdstr += "direct/src/plugin_installer/make_installer.py --version %s" % version
  390. oscmd(cmdstr)
  391. return
  392. dmg_name = "Panda3D-" + version
  393. if len(python_versions) == 1 and not python_versions[0]["version"].startswith("2."):
  394. dmg_name += "-py" + pyver
  395. dmg_name += ".dmg"
  396. if (os.path.isfile(dmg_name)): oscmd("rm -f %s" % dmg_name)
  397. if (os.path.exists("dstroot")): oscmd("rm -rf dstroot")
  398. if (os.path.exists("Panda3D-rw.dmg")): oscmd('rm -f Panda3D-rw.dmg')
  399. oscmd("mkdir -p dstroot/base/Developer/Panda3D/lib")
  400. oscmd("mkdir -p dstroot/base/Developer/Panda3D/etc")
  401. oscmd("cp %s/etc/Config.prc dstroot/base/Developer/Panda3D/etc/Config.prc" % outputdir)
  402. oscmd("cp %s/etc/Confauto.prc dstroot/base/Developer/Panda3D/etc/Confauto.prc" % outputdir)
  403. oscmd("cp -R %s/models dstroot/base/Developer/Panda3D/models" % outputdir)
  404. oscmd("cp -R doc/LICENSE dstroot/base/Developer/Panda3D/LICENSE")
  405. oscmd("cp -R doc/ReleaseNotes dstroot/base/Developer/Panda3D/ReleaseNotes")
  406. oscmd("cp -R %s/Frameworks dstroot/base/Developer/Panda3D/Frameworks" % outputdir)
  407. if os.path.isdir(outputdir+"/plugins"):
  408. oscmd("cp -R %s/plugins dstroot/base/Developer/Panda3D/plugins" % outputdir)
  409. # Libraries that shouldn't be in base, but are instead in other modules.
  410. no_base_libs = ['libp3ffmpeg', 'libp3fmod_audio', 'libfmodex', 'libfmodexL']
  411. for base in os.listdir(outputdir+"/lib"):
  412. if not base.endswith(".a") and base.split('.')[0] not in no_base_libs:
  413. libname = "dstroot/base/Developer/Panda3D/lib/" + base
  414. # We really need to specify -R in order not to follow symlinks
  415. # On OSX, just specifying -P is not enough to do that.
  416. oscmd("cp -R -P " + outputdir + "/lib/" + base + " " + libname)
  417. oscmd("mkdir -p dstroot/tools/Developer/Panda3D/bin")
  418. oscmd("mkdir -p dstroot/tools/Developer/Tools")
  419. oscmd("ln -s ../Panda3D/bin dstroot/tools/Developer/Tools/Panda3D")
  420. oscmd("mkdir -p dstroot/tools/etc/paths.d")
  421. # Trailing newline is important, works around a bug in OSX
  422. WriteFile("dstroot/tools/etc/paths.d/Panda3D", "/Developer/Panda3D/bin\n")
  423. oscmd("mkdir -m 0755 -p dstroot/tools/usr/local/share/man/man1")
  424. oscmd("install -m 0644 doc/man/*.1 dstroot/tools/usr/local/share/man/man1/")
  425. for base in os.listdir(outputdir+"/bin"):
  426. if not base.startswith("deploy-stub"):
  427. binname = "dstroot/tools/Developer/Panda3D/bin/" + base
  428. # OSX needs the -R argument to copy symbolic links correctly, it doesn't have -d. How weird.
  429. oscmd("cp -R " + outputdir + "/bin/" + base + " " + binname)
  430. if python_versions:
  431. # Let's only write a ppython link if there is only one Python version.
  432. if len(python_versions) == 1:
  433. oscmd("mkdir -p dstroot/pythoncode/usr/local/bin")
  434. oscmd("ln -s %s dstroot/pythoncode/usr/local/bin/ppython" % (python_versions[0]["executable"]))
  435. oscmd("mkdir -p dstroot/pythoncode/Developer/Panda3D/panda3d")
  436. oscmd("cp -R %s/pandac dstroot/pythoncode/Developer/Panda3D/pandac" % outputdir)
  437. oscmd("cp -R %s/direct dstroot/pythoncode/Developer/Panda3D/direct" % outputdir)
  438. oscmd("cp -R %s/*.so dstroot/pythoncode/Developer/Panda3D/" % outputdir, True)
  439. oscmd("cp -R %s/*.py dstroot/pythoncode/Developer/Panda3D/" % outputdir, True)
  440. if os.path.isdir(outputdir+"/Pmw"):
  441. oscmd("cp -R %s/Pmw dstroot/pythoncode/Developer/Panda3D/Pmw" % outputdir)
  442. for base in os.listdir(outputdir+"/panda3d"):
  443. if base.endswith('.py'):
  444. libname = "dstroot/pythoncode/Developer/Panda3D/panda3d/" + base
  445. oscmd("cp -R " + outputdir + "/panda3d/" + base + " " + libname)
  446. for version_info in python_versions:
  447. pyver = version_info["version"]
  448. oscmd("mkdir -p dstroot/pybindings%s/Library/Python/%s/site-packages" % (pyver, pyver))
  449. oscmd("mkdir -p dstroot/pybindings%s/Developer/Panda3D/panda3d" % (pyver))
  450. # Copy over extension modules.
  451. suffix = version_info["ext_suffix"]
  452. for base in os.listdir(outputdir+"/panda3d"):
  453. if base.endswith(suffix) and '.' not in base[:-len(suffix)]:
  454. libname = "dstroot/pybindings%s/Developer/Panda3D/panda3d/%s" % (pyver, base)
  455. # We really need to specify -R in order not to follow symlinks
  456. # On OSX, just specifying -P is not enough to do that.
  457. oscmd("cp -R -P " + outputdir + "/panda3d/" + base + " " + libname)
  458. # Write a .pth file.
  459. oscmd("mkdir -p dstroot/pybindings%s/Library/Python/%s/site-packages" % (pyver, pyver))
  460. WriteFile("dstroot/pybindings%s/Library/Python/%s/site-packages/Panda3D.pth" % (pyver, pyver), "/Developer/Panda3D")
  461. # Copy over panda3d.dist-info directory.
  462. if os.path.isdir(outputdir + "/panda3d.dist-info"):
  463. oscmd("cp -R %s/panda3d.dist-info dstroot/pybindings%s/Library/Python/%s/site-packages/" % (outputdir, pyver, pyver))
  464. if not PkgSkip("FFMPEG"):
  465. oscmd("mkdir -p dstroot/ffmpeg/Developer/Panda3D/lib")
  466. oscmd("cp -R %s/lib/libp3ffmpeg.* dstroot/ffmpeg/Developer/Panda3D/lib/" % outputdir)
  467. #if not PkgSkip("OPENAL"):
  468. # oscmd("mkdir -p dstroot/openal/Developer/Panda3D/lib")
  469. # oscmd("cp -R %s/lib/libp3openal_audio.* dstroot/openal/Developer/Panda3D/lib/" % outputdir)
  470. if not PkgSkip("FMODEX"):
  471. oscmd("mkdir -p dstroot/fmodex/Developer/Panda3D/lib")
  472. oscmd("cp -R %s/lib/libp3fmod_audio.* dstroot/fmodex/Developer/Panda3D/lib/" % outputdir)
  473. oscmd("cp -R %s/lib/libfmodex* dstroot/fmodex/Developer/Panda3D/lib/" % outputdir)
  474. oscmd("mkdir -p dstroot/headers/Developer/Panda3D/lib")
  475. oscmd("cp -R %s/include dstroot/headers/Developer/Panda3D/include" % outputdir)
  476. if os.path.isfile(outputdir + "/lib/libp3pystub.a"):
  477. oscmd("cp -R -P %s/lib/libp3pystub.a dstroot/headers/Developer/Panda3D/lib/" % outputdir)
  478. if os.path.isdir("samples"):
  479. oscmd("mkdir -p dstroot/samples/Developer/Examples/Panda3D")
  480. oscmd("cp -R samples/* dstroot/samples/Developer/Examples/Panda3D/")
  481. DeleteVCS("dstroot")
  482. DeleteBuildFiles("dstroot")
  483. # Compile Python files. Do this *after* the DeleteVCS step, above, which
  484. # deletes __pycache__ directories.
  485. for version_info in python_versions:
  486. if os.path.isdir("dstroot/pythoncode/Developer/Panda3D/Pmw"):
  487. oscmd("%s -m compileall -q -f -d /Developer/Panda3D/Pmw dstroot/pythoncode/Developer/Panda3D/Pmw" % (version_info["executable"]), True)
  488. oscmd("%s -m compileall -q -f -d /Developer/Panda3D/direct dstroot/pythoncode/Developer/Panda3D/direct" % (version_info["executable"]))
  489. oscmd("%s -m compileall -q -f -d /Developer/Panda3D/pandac dstroot/pythoncode/Developer/Panda3D/pandac" % (version_info["executable"]))
  490. oscmd("%s -m compileall -q -f -d /Developer/Panda3D/panda3d dstroot/pythoncode/Developer/Panda3D/panda3d" % (version_info["executable"]))
  491. oscmd("chmod -R 0775 dstroot/*")
  492. # We need to be root to perform a chown. Bleh.
  493. # Fortunately PackageMaker does it for us, on 10.5 and above.
  494. #oscmd("chown -R root:admin dstroot/*", True)
  495. oscmd("mkdir -p dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/")
  496. oscmd("mkdir -p dstroot/Panda3D/Panda3D.mpkg/Contents/Resources/en.lproj/")
  497. pkgs = ["base", "tools", "headers"]
  498. if python_versions:
  499. pkgs.append("pythoncode")
  500. for version_info in python_versions:
  501. pkgs.append("pybindings" + version_info["version"])
  502. if not PkgSkip("FFMPEG"): pkgs.append("ffmpeg")
  503. #if not PkgSkip("OPENAL"): pkgs.append("openal")
  504. if not PkgSkip("FMODEX"): pkgs.append("fmodex")
  505. if os.path.isdir("samples"): pkgs.append("samples")
  506. for pkg in pkgs:
  507. identifier = "org.panda3d.panda3d.%s.pkg" % pkg
  508. plist = open("/tmp/Info_plist", "w")
  509. plist.write(Info_plist.format(package_id=identifier, version=version))
  510. plist.close()
  511. if not os.path.isdir("dstroot/" + pkg):
  512. os.makedirs("dstroot/" + pkg)
  513. if os.path.exists("/usr/bin/pkgbuild"):
  514. # This new package builder is used in Lion and above.
  515. cmd = '/usr/bin/pkgbuild --identifier ' + identifier + ' --version ' + version + ' --root dstroot/' + pkg + '/ dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg'
  516. # In older versions, we use PackageMaker. Apple keeps changing its location.
  517. elif os.path.exists("/Developer/usr/bin/packagemaker"):
  518. cmd = '/Developer/usr/bin/packagemaker --info /tmp/Info_plist --version ' + version + ' --out dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg ' + target + ' --domain system --root dstroot/' + pkg + '/ --no-relocate'
  519. elif os.path.exists("/Applications/Xcode.app/Contents/Applications/PackageMaker.app/Contents/MacOS/PackageMaker"):
  520. cmd = '/Applications/Xcode.app/Contents/Applications/PackageMaker.app/Contents/MacOS/PackageMaker --info /tmp/Info_plist --version ' + version + ' --out dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg ' + target + ' --domain system --root dstroot/' + pkg + '/ --no-relocate'
  521. elif os.path.exists("/Developer/Tools/PackageMaker.app/Contents/MacOS/PackageMaker"):
  522. cmd = '/Developer/Tools/PackageMaker.app/Contents/MacOS/PackageMaker --info /tmp/Info_plist --version ' + version + ' --out dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg ' + target + ' --domain system --root dstroot/' + pkg + '/ --no-relocate'
  523. elif os.path.exists("/Developer/Tools/packagemaker"):
  524. cmd = '/Developer/Tools/packagemaker -build -f dstroot/' + pkg + '/ -p dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg -i /tmp/Info_plist'
  525. elif os.path.exists("/Applications/PackageMaker.app/Contents/MacOS/PackageMaker"):
  526. cmd = '/Applications/PackageMaker.app/Contents/MacOS/PackageMaker --info /tmp/Info_plist --version ' + version + ' --out dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg ' + target + ' --domain system --root dstroot/' + pkg + '/ --no-relocate'
  527. else:
  528. exit("Neither pkgbuild nor PackageMaker could be found!")
  529. oscmd(cmd)
  530. if os.path.isfile("/tmp/Info_plist"):
  531. oscmd("rm -f /tmp/Info_plist")
  532. # Now that we've built all of the individual packages, build the metapackage.
  533. dist = open("dstroot/Panda3D/Panda3D.mpkg/Contents/distribution.dist", "w")
  534. dist.write('<?xml version="1.0" encoding="utf-8"?>\n')
  535. dist.write('<installer-script minSpecVersion="1.000000" authoringTool="com.apple.PackageMaker" authoringToolVersion="3.0.3" authoringToolBuild="174">\n')
  536. dist.write(' <title>Panda3D SDK %s</title>\n' % (version))
  537. dist.write(' <options customize="always" allow-external-scripts="no" rootVolumeOnly="false"/>\n')
  538. dist.write(' <license language="en" mime-type="text/plain">%s</license>\n' % ReadFile("doc/LICENSE"))
  539. dist.write(' <script>\n')
  540. dist.write(' function isPythonVersionInstalled(version) {\n')
  541. dist.write(' return system.files.fileExistsAtPath("/usr/bin/python" + version)\n')
  542. dist.write(' || system.files.fileExistsAtPath("/usr/local/bin/python" + version)\n')
  543. dist.write(' || system.files.fileExistsAtPath("/opt/local/bin/python" + version)\n')
  544. dist.write(' || system.files.fileExistsAtPath("/sw/bin/python" + version)\n')
  545. dist.write(' || system.files.fileExistsAtPath("/System/Library/Frameworks/Python.framework/Versions/" + version + "/bin/python")\n')
  546. dist.write(' || system.files.fileExistsAtPath("/Library/Frameworks/Python.framework/Versions/" + version + "/bin/python");\n')
  547. dist.write(' }\n')
  548. dist.write(' </script>\n')
  549. dist.write(' <choices-outline>\n')
  550. dist.write(' <line choice="base"/>\n')
  551. if python_versions:
  552. dist.write(' <line choice="pythoncode">\n')
  553. for version_info in sorted(python_versions, key=lambda info:info["version"], reverse=True):
  554. dist.write(' <line choice="pybindings%s"/>\n' % (version_info["version"]))
  555. dist.write(' </line>\n')
  556. dist.write(' <line choice="tools"/>\n')
  557. if os.path.isdir("samples"):
  558. dist.write(' <line choice="samples"/>\n')
  559. if not PkgSkip("FFMPEG"):
  560. dist.write(' <line choice="ffmpeg"/>\n')
  561. if not PkgSkip("FMODEX"):
  562. dist.write(' <line choice="fmodex"/>\n')
  563. dist.write(' <line choice="headers"/>\n')
  564. dist.write(' </choices-outline>\n')
  565. dist.write(' <choice id="base" title="Panda3D Base Installation" description="This package contains the Panda3D libraries, configuration files and models/textures that are needed to use Panda3D.&#10;&#10;Location: /Developer/Panda3D/" start_enabled="false">\n')
  566. dist.write(' <pkg-ref id="org.panda3d.panda3d.base.pkg"/>\n')
  567. dist.write(' </choice>\n')
  568. dist.write(' <choice id="tools" title="Tools" tooltip="Useful tools and model converters to help with Panda3D development" description="This package contains the various utilities that ship with Panda3D, including packaging tools, model converters, and many more.&#10;&#10;Location: /Developer/Panda3D/bin/">\n')
  569. dist.write(' <pkg-ref id="org.panda3d.panda3d.tools.pkg"/>\n')
  570. dist.write(' </choice>\n')
  571. if python_versions:
  572. dist.write(' <choice id="pythoncode" title="Python Support" tooltip="Python bindings for the Panda3D libraries" description="This package contains the \'direct\', \'pandac\' and \'panda3d\' python packages that are needed to do Python development with Panda3D.&#10;&#10;Location: /Developer/Panda3D/">\n')
  573. dist.write(' <pkg-ref id="org.panda3d.panda3d.pythoncode.pkg"/>\n')
  574. dist.write(' </choice>\n')
  575. for version_info in python_versions:
  576. pyver = version_info["version"]
  577. if pyver == "2.7":
  578. # Always install Python 2.7 by default; it's included on macOS.
  579. cond = "true"
  580. else:
  581. cond = "isPythonVersionInstalled('%s')" % (pyver)
  582. dist.write(' <choice id="pybindings%s" start_selected="%s" title="Python %s Bindings" tooltip="Python bindings for the Panda3D libraries" description="Support for Python %s.">\n' % (pyver, cond, pyver, pyver))
  583. dist.write(' <pkg-ref id="org.panda3d.panda3d.pybindings%s.pkg"/>\n' % (pyver))
  584. dist.write(' </choice>\n')
  585. if not PkgSkip("FFMPEG"):
  586. dist.write(' <choice id="ffmpeg" title="FFMpeg Plug-In" tooltip="FFMpeg video and audio decoding plug-in" description="This package contains the FFMpeg plug-in, which is used for decoding video and audio files with OpenAL.')
  587. if PkgSkip("VORBIS") and PkgSkip("OPUS"):
  588. dist.write(' It is not required for loading .wav files, which Panda3D can read out of the box.">\n')
  589. elif PkgSkip("VORBIS"):
  590. dist.write(' It is not required for loading .wav or .opus files, which Panda3D can read out of the box.">\n')
  591. elif PkgSkip("OPUS"):
  592. dist.write(' It is not required for loading .wav or .ogg files, which Panda3D can read out of the box.">\n')
  593. else:
  594. dist.write(' It is not required for loading .wav, .ogg or .opus files, which Panda3D can read out of the box.">\n')
  595. dist.write(' <pkg-ref id="org.panda3d.panda3d.ffmpeg.pkg"/>\n')
  596. dist.write(' </choice>\n')
  597. #if not PkgSkip("OPENAL"):
  598. # dist.write(' <choice id="openal" title="OpenAL Audio Plug-In" tooltip="OpenAL audio output plug-in" description="This package contains the OpenAL audio plug-in, which is an open-source library for playing sounds.">\n')
  599. # dist.write(' <pkg-ref id="org.panda3d.panda3d.openal.pkg"/>\n')
  600. # dist.write(' </choice>\n')
  601. if not PkgSkip("FMODEX"):
  602. dist.write(' <choice id="fmodex" title="FMOD Ex Plug-In" tooltip="FMOD Ex audio output plug-in" description="This package contains the FMOD Ex audio plug-in, which is a commercial library for playing sounds. It is an optional component as Panda3D can use the open-source alternative OpenAL instead.">\n')
  603. dist.write(' <pkg-ref id="org.panda3d.panda3d.fmodex.pkg"/>\n')
  604. dist.write(' </choice>\n')
  605. if os.path.isdir("samples"):
  606. dist.write(' <choice id="samples" title="Sample Programs" tooltip="Python sample programs that use Panda3D" description="This package contains the Python sample programs that can help you with learning how to use Panda3D.&#10;&#10;Location: /Developer/Examples/Panda3D/">\n')
  607. dist.write(' <pkg-ref id="org.panda3d.panda3d.samples.pkg"/>\n')
  608. dist.write(' </choice>\n')
  609. dist.write(' <choice id="headers" title="C++ Header Files" tooltip="Header files for C++ development with Panda3D" description="This package contains the C++ header files that are needed in order to do C++ development with Panda3D. You don\'t need this if you want to develop in Python.&#10;&#10;Location: /Developer/Panda3D/include/" start_selected="false">\n')
  610. dist.write(' <pkg-ref id="org.panda3d.panda3d.headers.pkg"/>\n')
  611. dist.write(' </choice>\n')
  612. for pkg in pkgs:
  613. size = GetDirectorySize("dstroot/" + pkg) // 1024
  614. dist.write(' <pkg-ref id="org.panda3d.panda3d.%s.pkg" installKBytes="%d" version="1" auth="Root">file:./Contents/Packages/%s.pkg</pkg-ref>\n' % (pkg, size, pkg))
  615. dist.write('</installer-script>\n')
  616. dist.close()
  617. oscmd('hdiutil create Panda3D-rw.dmg -volname "Panda3D SDK %s" -srcfolder dstroot/Panda3D' % (version))
  618. oscmd('hdiutil convert Panda3D-rw.dmg -format UDBZ -o %s' % (dmg_name))
  619. oscmd('rm -f Panda3D-rw.dmg')
  620. def MakeInstallerFreeBSD(version, runtime=False, **kwargs):
  621. outputdir = GetOutputDir()
  622. oscmd("rm -rf targetroot +DESC pkg-plist +MANIFEST")
  623. oscmd("mkdir targetroot")
  624. # Invoke installpanda.py to install it into a temporary dir
  625. if runtime:
  626. InstallRuntime(destdir="targetroot", prefix="/usr/local", outputdir=outputdir)
  627. else:
  628. InstallPanda(destdir="targetroot", prefix="/usr/local", outputdir=outputdir)
  629. if not os.path.exists("/usr/sbin/pkg"):
  630. exit("Cannot create an installer without pkg")
  631. plist_txt = ''
  632. for root, dirs, files in os.walk("targetroot/usr/local/", True):
  633. for f in files:
  634. plist_txt += os.path.join(root, f)[21:] + "\n"
  635. if not runtime:
  636. plist_txt += "@postexec /sbin/ldconfig -m /usr/local/lib/panda3d\n"
  637. plist_txt += "@postunexec /sbin/ldconfig -R\n"
  638. for remdir in ("lib/panda3d", "share/panda3d", "include/panda3d"):
  639. for root, dirs, files in os.walk("targetroot/usr/local/" + remdir, False):
  640. for d in dirs:
  641. plist_txt += "@dir %s\n" % os.path.join(root, d)[21:]
  642. plist_txt += "@dir %s\n" % remdir
  643. oscmd("echo \"`pkg config abi | tr '[:upper:]' '[:lower:]' | cut -d: -f1,2`:*\" > " + outputdir + "/tmp/architecture.txt")
  644. pkg_arch = ReadFile(outputdir+"/tmp/architecture.txt").strip()
  645. dependencies = ''
  646. if not PkgSkip("PYTHON"):
  647. # If this version of Python was installed from a package or ports, let's mark it as dependency.
  648. oscmd("rm -f %s/tmp/python_dep" % outputdir)
  649. if "PYTHONVERSION" in SDK:
  650. pyver_nodot = SDK["PYTHONVERSION"][6:9:2]
  651. else:
  652. pyver_nodot = "%d%d" % (sys.version_info[:2])
  653. oscmd("pkg query \"\n\t%%n : {\n\t\torigin : %%o,\n\t\tversion : %%v\n\t},\n\" python%s > %s/tmp/python_dep" % (pyver_nodot, outputdir), True)
  654. if os.path.isfile(outputdir + "/tmp/python_dep"):
  655. python_pkg = ReadFile(outputdir + "/tmp/python_dep")
  656. if python_pkg:
  657. dependencies += python_pkg
  658. manifest_txt = INSTALLER_PKG_MANIFEST_FILE[1:].replace("NAME", 'panda3d' if not runtime else 'panda3d-runtime')
  659. manifest_txt = manifest_txt.replace("VERSION", version)
  660. manifest_txt = manifest_txt.replace("ARCH", pkg_arch)
  661. manifest_txt = manifest_txt.replace("ORIGIN", 'devel/panda3d' if not runtime else 'graphics/panda3d-runtime')
  662. manifest_txt = manifest_txt.replace("DEPENDS", dependencies)
  663. manifest_txt = manifest_txt.replace("INSTSIZE", str(GetDirectorySize("targetroot") // 1024 // 1024))
  664. WriteFile("pkg-plist", plist_txt)
  665. WriteFile("+DESC", INSTALLER_PKG_DESCR_FILE[1:] if not runtime else RUNTIME_INSTALLER_PKG_DESCR_FILE[1:])
  666. WriteFile("+MANIFEST", manifest_txt)
  667. oscmd("pkg create -p pkg-plist -r %s -m . -o . %s" % (os.path.abspath("targetroot"), "--verbose" if GetVerbose() else "--quiet"))
  668. def MakeInstallerAndroid(version, **kwargs):
  669. outputdir = GetOutputDir()
  670. oscmd("rm -rf apkroot")
  671. oscmd("mkdir apkroot")
  672. # Also remove the temporary apks.
  673. apk_unaligned = os.path.join(outputdir, "tmp", "panda3d-unaligned.apk")
  674. apk_unsigned = os.path.join(outputdir, "tmp", "panda3d-unsigned.apk")
  675. if os.path.exists(apk_unaligned):
  676. os.unlink(apk_unaligned)
  677. if os.path.exists(apk_unsigned):
  678. os.unlink(apk_unsigned)
  679. # Compile the Java classes into a Dalvik executable.
  680. dx_cmd = "dx --dex --output=apkroot/classes.dex "
  681. if GetOptimize() <= 2:
  682. dx_cmd += "--debug "
  683. if GetVerbose():
  684. dx_cmd += "--verbose "
  685. if "ANDROID_API" in SDK:
  686. dx_cmd += "--min-sdk-version=%d " % (SDK["ANDROID_API"])
  687. dx_cmd += os.path.join(outputdir, "classes")
  688. oscmd(dx_cmd)
  689. # Copy the libraries one by one. In case of library dependencies, strip
  690. # off any suffix (eg. libfile.so.1.0), as Android does not support them.
  691. source_dir = os.path.join(outputdir, "lib")
  692. target_dir = os.path.join("apkroot", "lib", SDK["ANDROID_ABI"])
  693. oscmd("mkdir -p %s" % (target_dir))
  694. # Determine the library directories we should look in.
  695. libpath = [source_dir]
  696. for dir in os.environ.get("LD_LIBRARY_PATH", "").split(':'):
  697. dir = os.path.expandvars(dir)
  698. dir = os.path.expanduser(dir)
  699. if os.path.isdir(dir):
  700. dir = os.path.realpath(dir)
  701. if not dir.startswith("/system") and not dir.startswith("/vendor"):
  702. libpath.append(dir)
  703. def copy_library(source, base):
  704. # Copy file to destination, stripping version suffix.
  705. target = os.path.join(target_dir, base)
  706. if not target.endswith('.so'):
  707. target = target.rpartition('.so.')[0] + '.so'
  708. if os.path.isfile(target):
  709. # Already processed.
  710. return
  711. oscmd("cp %s %s" % (source, target))
  712. # Walk through the library dependencies.
  713. oscmd("ldd %s | grep .so > %s/tmp/otool-libs.txt" % (target, outputdir), True)
  714. for line in open(outputdir + "/tmp/otool-libs.txt", "r"):
  715. line = line.strip()
  716. if not line:
  717. continue
  718. if '.so.' in line:
  719. dep = line.rpartition('.so.')[0] + '.so'
  720. oscmd("patchelf --replace-needed %s %s %s" % (line, dep, target), True)
  721. else:
  722. dep = line
  723. # Find it on the LD_LIBRARY_PATH.
  724. for dir in libpath:
  725. fulldep = os.path.join(dir, dep)
  726. if os.path.isfile(fulldep):
  727. copy_library(os.path.realpath(fulldep), dep)
  728. break
  729. # Now copy every lib in the lib dir, and its dependencies.
  730. for base in os.listdir(source_dir):
  731. if not base.startswith('lib'):
  732. continue
  733. if not base.endswith('.so') and '.so.' not in base:
  734. continue
  735. source = os.path.join(source_dir, base)
  736. if os.path.islink(source):
  737. continue
  738. copy_library(source, base)
  739. # Same for Python extension modules. However, Android is strict about
  740. # library naming, so we have a special naming scheme for these, in
  741. # conjunction with a custom import hook to find these modules.
  742. if not PkgSkip("PYTHON"):
  743. suffix = GetExtensionSuffix()
  744. source_dir = os.path.join(outputdir, "panda3d")
  745. for base in os.listdir(source_dir):
  746. if not base.endswith(suffix):
  747. continue
  748. modname = base[:-len(suffix)]
  749. if '.' not in modname:
  750. source = os.path.join(source_dir, base)
  751. copy_library(source, "libpy.panda3d.{}.so".format(modname))
  752. # Same for standard Python modules.
  753. import _ctypes
  754. source_dir = os.path.dirname(_ctypes.__file__)
  755. for base in os.listdir(source_dir):
  756. if not base.endswith('.so'):
  757. continue
  758. modname = base.partition('.')[0]
  759. source = os.path.join(source_dir, base)
  760. copy_library(source, "libpy.{}.so".format(modname))
  761. def copy_python_tree(source_root, target_root):
  762. for source_dir, dirs, files in os.walk(source_root):
  763. if 'site-packages' in dirs:
  764. dirs.remove('site-packages')
  765. if not any(base.endswith('.py') for base in files):
  766. continue
  767. target_dir = os.path.join(target_root, os.path.relpath(source_dir, source_root))
  768. target_dir = os.path.normpath(target_dir)
  769. os.makedirs(target_dir, 0o755)
  770. for base in files:
  771. if base.endswith('.py'):
  772. target = os.path.join(target_dir, base)
  773. shutil.copy(os.path.join(source_dir, base), target)
  774. # Copy the Python standard library to the .apk as well.
  775. from distutils.sysconfig import get_python_lib
  776. stdlib_source = get_python_lib(False, True)
  777. stdlib_target = os.path.join("apkroot", "lib", "python{0}.{1}".format(*sys.version_info))
  778. copy_python_tree(stdlib_source, stdlib_target)
  779. # But also copy over our custom site.py.
  780. shutil.copy("panda/src/android/site.py", os.path.join(stdlib_target, "site.py"))
  781. # And now make a site-packages directory containing our direct/panda3d/pandac modules.
  782. for tree in "panda3d", "direct", "pandac":
  783. copy_python_tree(os.path.join(outputdir, tree), os.path.join(stdlib_target, "site-packages", tree))
  784. # Copy the models and config files to the virtual assets filesystem.
  785. oscmd("mkdir apkroot/assets")
  786. oscmd("cp -R %s apkroot/assets/models" % (os.path.join(outputdir, "models")))
  787. oscmd("cp -R %s apkroot/assets/etc" % (os.path.join(outputdir, "etc")))
  788. # Make an empty res folder. It's needed for the apk to be installable, apparently.
  789. oscmd("mkdir apkroot/res")
  790. # Now package up the application
  791. oscmd("cp panda/src/android/pview_manifest.xml apkroot/AndroidManifest.xml")
  792. aapt_cmd = "aapt package"
  793. aapt_cmd += " -F %s" % (apk_unaligned)
  794. aapt_cmd += " -M apkroot/AndroidManifest.xml"
  795. aapt_cmd += " -A apkroot/assets -S apkroot/res"
  796. aapt_cmd += " -I $PREFIX/share/aapt/android.jar"
  797. oscmd(aapt_cmd)
  798. # And add all the libraries to it.
  799. oscmd("cd apkroot && aapt add ../%s classes.dex" % (apk_unaligned))
  800. for path, dirs, files in os.walk('apkroot/lib'):
  801. if files:
  802. rel = os.path.relpath(path, 'apkroot')
  803. oscmd("cd apkroot && aapt add ../%s %s/*" % (apk_unaligned, rel))
  804. # Now align the .apk, which is necessary for Android to load it.
  805. oscmd("zipalign -v -p 4 %s %s" % (apk_unaligned, apk_unsigned))
  806. # Finally, sign it using a debug key. This is generated if it doesn't exist.
  807. oscmd("apksigner debug.ks %s panda3d.apk" % (apk_unsigned))
  808. # Clean up.
  809. oscmd("rm -rf apkroot")
  810. os.unlink(apk_unaligned)
  811. os.unlink(apk_unsigned)
  812. def MakeInstaller(version, **kwargs):
  813. target = GetTarget()
  814. if target == 'windows':
  815. fn = "Panda3D-"
  816. dir = "Panda3D-" + version
  817. runtime = kwargs.get('runtime', False)
  818. if runtime:
  819. fn += "Runtime-"
  820. title = "Panda3D " + version
  821. else:
  822. title = "Panda3D SDK " + version
  823. fn += version
  824. python_versions = kwargs.get('python_versions', [])
  825. if not runtime and len(python_versions) == 1 and python_versions[0]["version"] != "2.7":
  826. fn += '-py' + python_versions[0]["version"]
  827. if GetOptimize() <= 2:
  828. fn += "-dbg"
  829. if GetTargetArch() == 'x64':
  830. fn += '-x64'
  831. dir += '-x64'
  832. MakeInstallerNSIS(version, fn + '.exe', title, 'C:\\' + dir, **kwargs)
  833. if not runtime:
  834. MakeDebugSymbolArchive(fn + '-pdb.zip', dir)
  835. elif target == 'linux':
  836. MakeInstallerLinux(version, **kwargs)
  837. elif target == 'darwin':
  838. MakeInstallerOSX(version, **kwargs)
  839. elif target == 'freebsd':
  840. MakeInstallerFreeBSD(version, **kwargs)
  841. elif target == 'android':
  842. MakeInstallerAndroid(version, **kwargs)
  843. else:
  844. exit("Do not know how to make an installer for this platform")
  845. if __name__ == "__main__":
  846. version = ParsePandaVersion("dtool/PandaVersion.pp")
  847. parser = OptionParser()
  848. parser.add_option('', '--version', dest='version', help='Panda3D version number (default: %s)' % (version), default=version)
  849. parser.add_option('', '--debversion', dest='debversion', help='Version number for .deb file', default=None)
  850. parser.add_option('', '--rpmrelease', dest='rpmrelease', help='Release number for .rpm file', default='1')
  851. parser.add_option('', '--outputdir', dest='outputdir', help='Makepanda\'s output directory (default: built)', default='built')
  852. parser.add_option('', '--verbose', dest='verbose', help='Enable verbose output', action='store_true', default=False)
  853. parser.add_option('', '--runtime', dest='runtime', help='Runtime instead of SDK', action='store_true', default=False)
  854. parser.add_option('', '--lzma', dest='compressor', help='Use LZMA compression', action='store_const', const='lzma', default='zlib')
  855. (options, args) = parser.parse_args()
  856. SetVerbose(options.verbose)
  857. SetOutputDir(options.outputdir)
  858. # Read out the optimize option.
  859. opt = ReadFile(os.path.join(options.outputdir, "tmp", "optimize.dat"))
  860. SetOptimize(int(opt.strip()))
  861. # Read out whether we should set PkgSkip("PYTHON") and some others.
  862. # Temporary hack; needs better solution.
  863. pkg_list = "PYTHON", "NVIDIACG", "FFMPEG", "OPENAL", "FMODEX", "PVIEW", "NVIDIACG", "VORBIS", "OPUS"
  864. PkgListSet(pkg_list)
  865. for pkg in pkg_list:
  866. dat_path = "dtool_have_%s.dat" % (pkg.lower())
  867. content = ReadFile(os.path.join(options.outputdir, "tmp", dat_path))
  868. if int(content.strip()):
  869. PkgEnable(pkg)
  870. else:
  871. PkgDisable(pkg)
  872. # Parse the version.
  873. match = re.match(r'^\d+\.\d+\.\d+', options.version)
  874. if not match:
  875. exit("version requires three digits")
  876. MakeInstaller(version=match.group(),
  877. outputdir=options.outputdir,
  878. optimize=GetOptimize(),
  879. compressor=options.compressor,
  880. debversion=options.debversion,
  881. rpmrelease=options.rpmrelease,
  882. runtime=options.runtime,
  883. python_versions=ReadPythonVersionInfoFile())