CalcProgrammer1

build-mesa-upstream-with-gallium-nine.py 4/27/2016

Apr 27th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.47 KB | None | 0 0
  1. #
  2. # Mesa Git Packaging Script for Debian Unstable
  3. #
  4. # This script will create Debian (unstable) packages for Mesa from upstream git sources.
  5. # It will skip building swx11 versions of the Mesa libraries as these are not used in systems with a GPU
  6. # By default this script expects the Debian version to use llvm (and libclang) 3.7 and will change it to use llvm 3.9
  7. # If Debian updates their copy to use a different llvm version, or if a new version of llvm is released, this script must be updated
  8. #
  9. # This script expects to be placed in /opt along with the other scripts and the Mesa git source to be present at /opt/mesa-git
  10. #
  11. # The building system must have build-essential and devscripts installed
  12. #
  13. # It is highly recommended to build using a dual chroot setup, one amd64 and one i386. Run this script from the amd64 chroot to build amd64 .deb packages
  14. # and then exit out, chroot into the i386 chroot, cd to /opt/mesa/mesa-<latest version>/ and run dpkg-buildpackage -us -B -j24 to build i386 .deb packages
  15. #
  16. # I use the following paths for my chroots:
  17. # /chroot/chroot-debian-unstable-amd64/
  18. # /chroot/chroot-debian-unstable-i386/
  19. #
  20. # Create the chroots using debootstrap:
  21. # debootstrap --arch amd64 unstable /chroot/chroot-debian-unstable-amd64 http://ftp.debian.org/debian/
  22. # debootstrap --arch i386 unstable /chroot/chroot-debian-unstable-i386 http://ftp.debian.org/debian/
  23. #
  24. # I have configured these in /etc/schroot/schroot.conf:
  25. #
  26. # [debian-unstable-i386]
  27. # description=Debian Unstable i386
  28. # directory=/chroot/chroot-debian-unstable-i386/
  29. # users=adam
  30. # root-groups=root
  31. # aliases=unstable-i386
  32. #
  33. # [debian-unstable-amd64]
  34. # description=Debian Unstable amd64
  35. # directory=/chroot/chroot-debian-unstable-amd64/
  36. # users=adam
  37. # root-groups=root
  38. # aliases=unstable-amd64
  39. #
  40. # Bind mount /opt into the chroots as I use /opt as my build directory
  41. # sudo mount -o bind /opt /chroot/chroot-debian-unstable-amd64/opt
  42. # sudo mount -o bind /opt /chroot/chroot-debian-unstable-i386/opt
  43. #
  44. # Enter the chroots using the following commands:
  45. # sudo schroot -c debian-unstable-amd64
  46. # sudo schroot -c debian-unstable-i386
  47. #
  48. # Install build-essential, devscripts, git in both chroots
  49. # sudo apt-get install build-essential devscripts git
  50. #
  51. # At the time of this writing (4/27/2016) it is recommended to install the LLVM development APT repository on your system (chroots included) to get the
  52. # most recent version of LLVM. LLVM contains much of the radeonsi driver functionality and improvements to LLVM will likely improve your performance.
  53. # You can install this repository by adding the following lines to your /etc/apt/sources.list (both your main install and both chroots):
  54. #
  55. # deb http://llvm.org/apt/unstable/ llvm-toolchain main
  56. # deb-src http://llvm.org/apt/unstable/ llvm-toolchain main
  57. #
  58. # Install llvm-3.9, libclang-3.9-dev
  59. # sudo apt-get install llvm-3.9 libclang-3.9-dev
  60. #
  61. # Copy this file to /opt/build-mesa-upstream-with-gallium-nine.py, since /opt is bind mounted it will show in both chroots
  62. # Copy patch.txt to /opt/patch.txt
  63. # Copy update-symbols.py to /opt/update-symbols.py
  64. #
  65. # Clone the Mesa source repository to /opt/mesa-git
  66. # cd /opt
  67. # git clone git://anongit.freedesktop.org/mesa/mesa mesa-git
  68. #
  69. # Or, if you want to try the Gallium Nine development tree:
  70. # cd /opt
  71. # git clone https://github.com/iXit/Mesa-3D
  72. #
  73. # To begin build, enter your amd64 chroot and:
  74. # cd /opt
  75. # python build-mesa-upstream-with-gallium-nine.py
  76. #
  77. # You may have to hit yes to some install prompts as the script will attempt to install build dependencies.
  78. # Then it will perform the build (dpkg-buildpackage -us -B -j24), which will likely fail the first time due to symbols mismatch with the Debian
  79. # version of the source as it is outdated.
  80. # This script will automatically attempt to resolve the symbols files (calling update-symbols.py) and then continue the build
  81. # where it left off (dpkg-buildpackage -us -B -j24 -nc)
  82. #
  83. # If successful, a series of .deb files will be located in /opt/mesa
  84. #
  85. # If these exist, you should now build i386 versions. Enter your i386 chroot and:
  86. # cd /opt/mesa/mesa-<development version number>/ (use tab complete, it is 11.3 as of now)
  87. # dpkg-buildpackage -us -B -j24
  88. #
  89. # If there are build dependencies to install, use
  90. # mk-build-deps --install debian/control
  91. # and then try the dpkg-buildpackage command again
  92. #
  93. # If successful, i386 .deb packages will be located along with the amd64 versions in /opt/mesa
  94. #
  95. # You may then install these on your main install with dpkg -i *.deb followed by apt-get -f install, or set up a local Debian repository
  96. # using reprepro and apache. I'm not going into detail on how to set the repository server up in this document. The packages are unsigned,
  97. # so installing them with apt-get will prompt you with a security warning. This is OK for personal use but I would recommend signing your
  98. # packages if you intend to host a public repository.
  99. #
  100. # Written by Adam Honse (calcprogrammer1) 4/27/2016
  101. #
  102.  
  103. import os
  104.  
  105. print "Create mesa working directory in /opt"
  106.  
  107. os.chdir("/opt")
  108. os.popen("rm -r mesa").read()
  109. os.mkdir("mesa")
  110. os.chdir("/opt/mesa")
  111.  
  112. print "Update apt sources"
  113. os.popen("apt-get update").read()
  114.  
  115. print "Download mesa official sources"
  116. os.popen("apt-get source mesa").read()
  117.  
  118. print "Save original folder name"
  119. for file in os.listdir("/opt/mesa"):
  120. if os.path.isdir(file):
  121. orig_name = file
  122.  
  123. orig_path = "/opt/mesa/" + orig_name + "/"
  124.  
  125. print "Print original name"
  126. print orig_name
  127.  
  128. print "Pull latest git changes"
  129. os.chdir("/opt/mesa-git")
  130. os.popen("git pull").read()
  131. #os.popen("git clone https://github.com/iXit/Mesa-3D mesa").read()
  132. #os.popen("git clone git://anongit.freedesktop.org/mesa/mesa mesa").read()
  133.  
  134. print "Copy upstream files from git source directory"
  135. os.popen("cp -r /opt/mesa-git /opt/mesa/mesa").read()
  136.  
  137. print "Get revision"
  138. os.chdir("/opt/mesa/mesa")
  139. git_version = os.popen("git rev-parse --short HEAD").read().rstrip()
  140. print git_version
  141.  
  142. print "Read Mesa version from upstream sources"
  143. upstream_version = os.popen("cat VERSION").read().rstrip()
  144. print upstream_version
  145.  
  146. print "Move git mesa directory"
  147. os.chdir("/opt/mesa")
  148. new_name = "mesa-" + upstream_version + "-" + git_version + "-galliumnine"
  149. new_path = "/opt/mesa/" + new_name + "/"
  150. print new_path
  151. os.rename("/opt/mesa/mesa", new_path)
  152.  
  153. print "Copy debian folder"
  154. os.chdir("/opt/mesa")
  155. os.popen("cp -rp " + orig_path + "debian" + " " + new_path + "debian").read()
  156.  
  157. print "Remove patches"
  158. os.chdir(new_path + "debian/patches")
  159. os.popen("rm *").read()
  160. os.popen("touch series")
  161.  
  162. print "Update debian/control file"
  163.  
  164. f1 = open(new_path + "debian/control", 'r')
  165. f2 = open(new_path + "debian/control.tmp", 'w')
  166.  
  167. swx11_block = 0
  168.  
  169. for line in f1:
  170.  
  171. if swx11_block == 0:
  172. #Look for Package and swx11 in the same line
  173. if "Package" in line and "swx11" in line:
  174. #If inside swx11 block, do not write to new file until we see Package again
  175. swx11_block = 1
  176.  
  177. else:
  178. #Look for llvm and libclang 3.7, replace with 3.8
  179. f2.write(line.replace('llvm-3.7-dev', 'llvm-3.9-dev').replace('libclang-3.7-dev', 'libclang-3.9-dev'))
  180.  
  181. elif swx11_block == 1:
  182. if "Package" in line and not "swx11" in line:
  183. swx11_block = 0
  184. f2.write(line)
  185.  
  186. f1.close()
  187. f2.close()
  188.  
  189. os.remove(new_path + "debian/control")
  190. os.rename(new_path + "debian/control.tmp", new_path + "debian/control")
  191.  
  192. print "Update debian/rules file"
  193.  
  194. os.popen("patch " + new_path + "debian/rules < /opt/patch.txt").read()
  195.  
  196. print "Add Gallium Nine include to mesa-common-dev"
  197. f1 = open(new_path + "debian/mesa-common-dev.install.in", 'a')
  198. f1.write("dri/usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig/d3d.pc usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig/")
  199. f1.write("dri/usr/include/GL/internal/mesa_glinterop.h /usr/include/GL/internal/")
  200.  
  201. print "Update changelog"
  202. os.chdir(new_path)
  203. os.popen("dch -d \"git commit " + git_version + "\"").read()
  204.  
  205. print "Install build dependencies"
  206. os.system("mk-build-deps --tool \"apt-get --no-install-recommends -y\" --install " + new_path + "debian/control")
  207.  
  208. print "Begin building"
  209. os.system("dpkg-buildpackage -us -B -j24")
  210.  
  211. print "It probably had an error due to missing symbols. Update the symbols files"
  212. os.system("python /opt/update-symbols.py")
  213.  
  214. print "Resume building"
  215. os.system("dpkg-buildpackage -us -B -j24 -nc")
Add Comment
Please, Sign In to add comment