makepackage.py 51 KB

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