makepackage.py 54 KB

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