~ubuntu-branches/ubuntu/utopic/nvidia-graphics-drivers-331-updates/utopic-updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#!/usr/bin/make -f
#
# Copyright (C) 2009 Canonical Ltd
# Authors: Alberto Milone
#
# This file on the Mandriva nvidia packages, on Ubuntu's previous
# nvidia packaging scripts and on Ubuntu's fglrx scripts.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
# If the host is i386 set OTHER_ARCH to x86_64 and vice versa
OTHER_ARCH := $(shell (echo "$(DEB_HOST_MULTIARCH)" | grep i386 >/dev/null) && \
		echo "$(DEB_HOST_MULTIARCH)" | sed s/i386/x86_64/ || \
		echo "$(DEB_HOST_MULTIARCH)" | sed s/x86_64/i386/)

# Hack for pbuild
PATH := $(PATH):/usr/sbin

# Package names
PKG_flavour          := $(shell dpkg-parsechangelog | sed -n 's/^Source: //p' | sed 's/nvidia\-graphics\-drivers\-//g')
PKG_driver           := nvidia-$(PKG_flavour)
PKG_driver_dev       := $(PKG_driver)-dev
PKG_driver_uvm       := $(PKG_driver)-uvm
PKG_version          := $(shell dpkg-parsechangelog | awk -F' ' '/^Version:/ {print $$2}' | awk -F- '{print $$1}')
PKG_version          := $(shell echo $(PKG_version) | sed s/.*\.really\.//g)
PKG_source           := $(shell dpkg-parsechangelog | sed -n 's/^Source: //p')
PKG_module           := $(shell echo "$(PKG_driver)" | sed s/\-/_/g)
PKG_libcuda1         := libcuda1-$(PKG_flavour)
PKG_libopencl1       := nvidia-libopencl1-$(PKG_flavour)
PKG_opencl_icd       := nvidia-opencl-icd-$(PKG_flavour)


# Priority of the alternative
alt_priority         := 8604
pm_alt_priority      := 8603

# Installer details
dirname_x86          ?= NVIDIA-Linux-x86-$(PKG_version)
dirname_x86_64       ?= NVIDIA-Linux-x86_64-$(PKG_version)-no-compat32
dirname_armhf        ?= NVIDIA-Linux-armv7l-gnueabihf-$(PKG_version)
filename_x86         := $(dirname_x86).run
filename_x86_64      := $(dirname_x86_64).run
filename_armhf       := $(dirname_armhf).run
url_x86              := http://us.download.nvidia.com/XFree86/Linux-x86/$(PKG_version)/$(filename_x86)
url_x86_64           := http://us.download.nvidia.com/XFree86/Linux-x86_64/$(PKG_version)/$(filename_x86_64)
url_armhf            := http://us.download.nvidia.com/XFree86/Linux-x86-ARM/$(PKG_version)/$(filename_armhf)

ifeq ($(DEB_BUILD_ARCH),amd64)
filename             := $(filename_x86_64)
dirname              := $(dirname_x86_64)
url                  := $(url_x86_64)
web_arch             := amd64
else
ifeq ($(DEB_BUILD_ARCH),armhf)
filename             := $(filename_armhf)
dirname              := $(dirname_armhf)
url                  := $(url_armhf)
web_arch             := 32bit-arm
arm_excluded         := \#
else
filename             := $(filename_x86)
dirname              := $(dirname_x86)
url                  := $(url_x86)
web_arch             := ia32
endif
endif

release_notes        := http://www.nvidia.com/object/linux-display-$(web_arch)-$(PKG_version)-driver.html

bindir               := /usr/bin
datadir              := /usr/share
nvidia_share         := /usr/share/nvidia
PKG_datadir          := $(datadir)/$(PKG_driver)
libdir               := /usr/lib
libdir32             := /usr/lib32
libdir_multiarch     := $(libdir)/$(DEB_HOST_MULTIARCH)
libdir_multiarch_other := $(libdir)/$(OTHER_ARCH)
includedir           := /usr/include
sysconfdir           := /etc
PKG_libdir           := $(libdir)/$(PKG_driver)
PKG_libdir32         := $(libdir32)/$(PKG_driver)
mesa_libdir          := $(libdir)/$(DEB_HOST_MULTIARCH)/mesa
mesa_libdir_other    := $(libdir)/$(OTHER_ARCH)/mesa
xorg_libdir          := $(libdir)/xorg
xorg_extra_path      := $(libdir)/$(DEB_HOST_MULTIARCH)/xorg
xorg_extra_modules   := $(xorg_extra_path)/extra-modules
xorg_extensionsdir   := $(xorg_libdir)/modules/extensions
PKG_driversdir       := $(libdir)/$(PKG_driver)/xorg
PKG_extensionsdir    := $(PKG_driversdir)
PKG_bindir           := $(PKG_libdir)/bin
PKG_configdir        := $(PKG_libdir)
ld_so_conf_dir       := $(PKG_configdir)
ld_so_conf_file      := ld.so.conf
alt_ld_so_conf_file  := alt_ld.so.conf
ld_so_conf_path      := $(ld_so_conf_dir)/$(ld_so_conf_file)
alt_ld_so_conf_path  := $(ld_so_conf_dir)/$(alt_ld_so_conf_file)

#Prime
PKG_prime            := $(PKG_driver)-prime
PKG_prime_libdir     := $(libdir)/$(PKG_prime)
pm_ld_so_conf_path      := $(PKG_prime_libdir)/$(ld_so_conf_file)
pm_alt_ld_so_conf_path  := $(PKG_prime_libdir)/$(alt_ld_so_conf_file)

mandir               := /usr/share/man/man1
PKG_bugdir           := /usr/share/bug/$(PKG_driver)
PKG_vdpaudir         := $(PKG_libdir)/vdpau
PKG_tlsdir           := $(PKG_libdir)/tls
PKG_vdpaudir32       := $(PKG_libdir32)/vdpau
PKG_tlsdir32         := $(PKG_libdir32)/tls
vdpaudir             := $(libdir)/vdpau
tlsdir               := $(libdir)/tls
vdpaudir32           := $(libdir32)/vdpau
tlsdir32             := $(libdir32)/tls
grub_blacklistdir    := /usr/share/grub-gfxpayload-lists/blacklist

# This is a hack to make sure that
# the blacklist file is available
# early in the boot process when
# /usr is on a separate partition.
# See LP: #538071.
PKG_libconfdir := /lib/$(PKG_driver)

# blacklist either the -updates or the non updates flavour
opposite_flavour := $(shell (echo "$(PKG_driver)" | grep updates >/dev/null) && \
        echo "$(PKG_driver)" | sed s/-updates// || \
        echo "$(PKG_driver)-updates")

#These "define" bits are needed for the blacklist file
define newline


endef

define blacklist_file
# This file was installed by $(PKG_driver)
# Do not edit this file manually

blacklist nouveau
blacklist lbm-nouveau
blacklist nvidia-current
blacklist nvidia-173
blacklist nvidia-96
blacklist nvidia-current-updates
blacklist nvidia-173-updates
blacklist nvidia-96-updates
blacklist $(opposite_flavour)
alias nvidia $(PKG_module)
alias nvidia-uvm $(PKG_module)-uvm
alias nouveau off
alias lbm-nouveau off
endef

define blacklist_hybrid
# This file was installed by $(PKG_driver)
# Do not edit this file manually

blacklist nouveau
blacklist lbm-nouveau
alias nouveau off
alias lbm-nouveau off
endef

%:
	dh $@

override_dh_shlibdeps:
	dh_shlibdeps -Xtls -Xconf -X$(PKG_libdir32) -X$(libdir_multiarch_other) \
	-l$(CURDIR)/debian/$(PKG_driver)$(PKG_libdir)/:$(CURDIR)/debian/$(PKG_driver_dev)$(PKG_libdir)/:$(libdir)/

.PHONY: get-orig-source
get-orig-source:
	# Remove any previous installers
	rm -f NVIDIA-Linux-*.run
	# Downloads the installers from NVIDIA's website
	wget $(url_x86) $(url_x86_64) $(url_armhf)

.PHONY: gen-abi-substvars
gen-abi-substvars:
	# Generate the xserver ABI dependencies
	cat debian/substvars >> debian/$(PKG_driver).substvars

.PHONY: regen-from-templates
regen-from-templates:
	# Get rid of files belonging to different flavours
	for i in debian/templates/*.in; do \
		old=`echo $$i | sed -e "s|templates\/||g" | \
				sed -e "s|\.in\$$||g" | \
				sed -e "s|nvidia-graphics-drivers|nvidia-*|g" | \
				sed -e "s|flavour|*|g"`; \
		rm -f $$old; done
	# Create important strings
	for i in debian/templates/*.in; do \
		dest=`echo $$i | sed -e "s|templates\/||g" | \
				 sed -e "s|\.in\$$||g" | \
				 sed -e "s|nvidia-graphics-drivers|$(PKG_driver)|g" | \
				 sed -e "s|flavour|$(PKG_flavour)|g"`; \
		sed -e "s|#LIBDIR#|$(libdir)|g"         \
			-e "s|#LIBDIR32#|$(libdir32)|g"     \
			-e "s|#LIBDIRMULTIARCH#|$(libdir_multiarch)|g" \
			-e "s|#LIBDIRMULTIARCHOTHER#|$(libdir_multiarch_other)|g" \
			-e "s|#BINDIR#|$(bindir)|g"         \
			-e "s|#VERSION#|$(PKG_version)|g"   \
			-e "s|#SYSCONFDIR#|$(sysconfdir)|g" \
			-e "s|#MANDIR#|$(mandir)|g" \
			-e "s|#LDSOCONF#|$(ld_so_conf_path)|g" \
			-e "s|#ALTLDSOCONF#|$(alt_ld_so_conf_path)|g" \
			-e "s|#PMLDSOCONF#|$(pm_ld_so_conf_path)|g" \
			-e "s|#PMALTLDSOCONF#|$(pm_alt_ld_so_conf_path)|g" \
			-e "s|#ALTPRIORITY#|$(alt_priority)|g" \
			-e "s|#PMALTPRIORITY#|$(pm_alt_priority)|g" \
			-e "s|#DATADIR#|$(datadir)|g" \
			-e "s|#PKGDATADIR#|$(PKG_datadir)|g" \
			-e "s|#PKGCONFIGDIR#|$(PKG_configdir)|g" \
			-e "s|#PKGBINDIR#|$(PKG_bindir)|g" \
			-e "s|#PKGLIBDIR#|$(PKG_libdir)|g" \
			-e "s|#PKGLIBDIR32#|$(PKG_libdir32)|g" \
			-e "s|#PKGPRIMELIBDIR#|$(PKG_prime_libdir)|g" \
			-e "s|#MESALIBDIR#|$(mesa_libdir)|g" \
			-e "s|#MESALIBDIROTHER#|$(mesa_libdir_other)|g" \
			-e "s|#PKGDRIVERSDIR#|$(PKG_driversdir)|g" \
			-e "s|#XORGEXTRA#|$(xorg_extra_modules)|g" \
			-e "s|#XORGEXTRAPATH#|$(xorg_extra_path)|g" \
			-e "s|#NVIDIAEXTENSION#|$(PKG_extensionsdir)|g" \
			-e "s|#XORGEXTENSIONSDIR#|$(xorg_extensionsdir)|g" \
			-e "s|#FLAVOUR#|$(PKG_flavour)|g" \
			-e "s|#DRIVERNAME#|$(PKG_driver)|g" \
			-e "s|#DRIVERDEVNAME#|$(PKG_driver_dev)|g" \
			-e "s|#DRIVERUVMNAME#|$(PKG_driver_uvm)|g" \
			-e "s|#DRIVERSRCNAME#|$(PKG_source)|g" \
			-e "s|#MODULENAME#|$(PKG_module)|g" \
			-e "s|#LIBCUDA1#|$(PKG_libcuda1)|g" \
			-e "s|#LIBOPENCL1#|$(PKG_libopencl1)|g" \
			-e "s|#OPENCLICD#|$(PKG_opencl_icd)|g" \
			-e "s|#DIRNAME#|$(dirname)|g" \
			-e "s|#INCLUDEDIR#|$(includedir)|g" \
			-e "s|#URL#|$(url)|g" \
			-e "s|#VDPAUDIR#|$(vdpaudir)|g" \
			-e "s|#VDPAUDIR32#|$(vdpaudir32)|g" \
			-e "s|#TLSDIR#|$(tlsdir)|g" \
			-e "s|#PKGVDPAUDIR#|$(PKG_vdpaudir)|g" \
			-e "s|#PKGVDPAUDIR32#|$(PKG_vdpaudir32)|g" \
			-e "s|#PKGTLSDIR#|$(PKG_tlsdir)|g" \
			-e "s|#PKGTLSDIR32#|$(PKG_tlsdir32)|g" \
			-e "s|#PKGLIBCONFDIR#|$(PKG_libconfdir)|g" \
			-e "s|#GRUBBLKLISTDIR#|$(grub_blacklistdir)|g" \
			-e "s|#DEB_HOST_MULTIARCH#|$(DEB_HOST_MULTIARCH)|g" \
			-e "s|#OTHER_ARCH#|$(OTHER_ARCH)|g" \
			-e "s|#RELEASENOTES#|$(release_notes)|g" \
			-e "s|#NVIDIASHARE#|$(nvidia_share)|g" \
			-e "s|#ARM_EXCLUDED#|$(arm_excluded)|g" \
			$$i > $$dest;      \
	done
ifeq ($(DEB_BUILD_ARCH),amd64)
	# Deal with the links for 32 bit libraries

	# $(PKG_driver)
	cat $(CURDIR)/debian/$(PKG_driver).links $(CURDIR)/debian/$(PKG_driver).links32 > \
	$(CURDIR)/debian/$(PKG_driver).links_new
	mv -f $(CURDIR)/debian/$(PKG_driver).links_new $(CURDIR)/debian/$(PKG_driver).links

	# $(PKG_libcuda1)
	cat $(CURDIR)/debian/$(PKG_libcuda1).links $(CURDIR)/debian/$(PKG_libcuda1).links32 > \
	$(CURDIR)/debian/$(PKG_libcuda1).links_new
	mv -f $(CURDIR)/debian/$(PKG_libcuda1).links_new $(CURDIR)/debian/$(PKG_libcuda1).links

	# $(PKG_libopencl1)
	cat $(CURDIR)/debian/$(PKG_libopencl1).links $(CURDIR)/debian/$(PKG_libopencl1).links32 > \
	$(CURDIR)/debian/$(PKG_libopencl1).links_new
	mv -f $(CURDIR)/debian/$(PKG_libopencl1).links_new $(CURDIR)/debian/$(PKG_libopencl1).links

	# $(PKG_opencl_icd)
	cat $(CURDIR)/debian/$(PKG_opencl_icd).links $(CURDIR)/debian/$(PKG_opencl_icd).links32 > \
	$(CURDIR)/debian/$(PKG_opencl_icd).links_new
	mv -f $(CURDIR)/debian/$(PKG_opencl_icd).links_new $(CURDIR)/debian/$(PKG_opencl_icd).links

	cat $(CURDIR)/debian/$(PKG_driver).dirs $(CURDIR)/debian/$(PKG_driver).dirs32 > \
	$(CURDIR)/debian/$(PKG_driver).dirs_new
	mv -f $(CURDIR)/debian/$(PKG_driver).dirs_new $(CURDIR)/debian/$(PKG_driver).dirs
endif

override_dh_auto_configure:
	rm -rf $(dirname_x86) $(dirname_x86_64) $(dirname_armhf)

	# Extract the installers
	sh $(filename) --extract-only

ifeq ($(DEB_BUILD_ARCH),amd64)
	sh $(filename_x86) --extract-only
endif

ifneq ($(DEB_BUILD_ARCH),armhf)
	# Temporarily rename libnvidia-opencl so that the .install file does
	# not catch it, as $(PKG_libcuda1) will instead
	mv $(CURDIR)/$(dirname)/libnvidia-opencl.so.$(PKG_version) \
	   $(CURDIR)/$(dirname)/_libnvidia-opencl.so.$(PKG_version)
endif

	# Get around Xen checks
	mv $(dirname)/kernel/nv.c $(dirname)/kernel/nv1.c
	mv $(dirname)/kernel/nv-linux.h $(dirname)/kernel/nv-linux1.h
	sed 's/CONFIG_XEN/CONFIG_ALB/g'  $(dirname)/kernel/nv1.c > $(dirname)/kernel/nv.c
	sed 's/CONFIG_XEN/CONFIG_ALB/g'  $(dirname)/kernel/nv-linux1.h > $(dirname)/kernel/nv-linux.h
	rm -f $(dirname)/kernel/nv1.c
	rm -f $(dirname)/kernel/nv-linux1.h

	# kernel module source
	mkdir -p $(CURDIR)/debian/temp/modules/nvidia-kernel
	cp -Rf $(CURDIR)/$(dirname)/kernel $(CURDIR)/debian/temp/modules/nvidia-kernel/
	rm -rf $(CURDIR)/debian/temp/modules/nvidia-kernel/kernel/uvm
	if [ -e "$(CURDIR)/debian/temp/modules/nvidia-kernel/kernel/Makefile.kbuild" ] ; \
	then \
		cp -f $(CURDIR)/debian/temp/modules/nvidia-kernel/kernel/Makefile.kbuild \
		$(CURDIR)/debian/temp/modules/nvidia-kernel/kernel/Makefile ; \
	fi;

	mkdir -p $(CURDIR)/debian/dkms_nvidia
	cp -f $(CURDIR)/debian/dkms_nvidia.conf $(CURDIR)/debian/dkms_nvidia/dkms.conf

	# Disable the stack markings of binaries for security reasons.
	# See (LP: #409456)
	find $(CURDIR)/$(dirname) -name *.so* | xargs -n1 execstack -c

ifeq ($(DEB_BUILD_ARCH),amd64)
	# Disable the stack markings of 32bit binaries on amd64
	# See (LP: #409456)
	find $(CURDIR)/$(dirname_x86) -name *.so* | xargs -n1 execstack -c

	# Remove libGLES* for since it's 32 bit only
	find $(CURDIR)/$(dirname_x86) -name 'libGLES*.so*' | xargs /bin/rm -f
	find $(CURDIR)/$(dirname_x86) -name 'libnvidia-eglcore*.so*' | xargs /bin/rm -f

	# Temporarily rename libnvidia-opencl
	mv $(CURDIR)/$(dirname_x86)/libnvidia-opencl.so.$(PKG_version) \
	   $(CURDIR)/$(dirname_x86)/_libnvidia-opencl.so.$(PKG_version)
endif
	# Disable the stack markings of other binaries (only for the current arch)
	#   Note: don't use for loops or pass more than 1 argument to execstack
	#         or it will fail.
	execstack -c $(CURDIR)/$(dirname)/nvidia-xconfig || true
	execstack -c $(CURDIR)/$(dirname)/nvidia-smi || true
	execstack -c $(CURDIR)/$(dirname)/nvidia-persistenced || true

	# Part about $(PKG_driver_uvm)
	# Kernel module files
	mkdir -p $(CURDIR)/debian/temp/modules/nvidia-uvm-kernel
	cp -Rf $(CURDIR)/$(dirname)/kernel/uvm $(CURDIR)/debian/temp/modules/nvidia-uvm-kernel/

	mkdir -p $(CURDIR)/debian/dkms_nvidia_uvm
	cp -f $(CURDIR)/debian/dkms_nvidia_uvm.conf $(CURDIR)/debian/dkms_nvidia_uvm/dkms.conf

override_dh_install: gen-abi-substvars
	dh_install -p$(PKG_driver)
	dh_install -p$(PKG_driver_dev)
ifeq ($(DEB_BUILD_ARCH),amd64)
	#32 bit libraries on 64 bit
	dh_installdirs -p$(PKG_driver) "$(PKG_libdir32)"
	dh_installdirs -p$(PKG_driver) "$(PKG_tlsdir32)"

	dh_install -p$(PKG_driver) "$(dirname_x86)/libGL*.so*"  "$(PKG_libdir32)"
	dh_install -p$(PKG_driver) "$(dirname_x86)/libGL.la"  "$(PKG_libdir32)"
	dh_install -p$(PKG_driver) "$(dirname_x86)/libnvidia*.so*"  "$(PKG_libdir32)"

	dh_install -p$(PKG_driver)  "$(dirname_x86)/libvdpau*"  "$(PKG_vdpaudir32)"
	dh_install -p$(PKG_driver)  "$(dirname_x86)/tls/lib*"  "$(PKG_tlsdir32)"

	dh_install -p$(PKG_driver) "$(dirname_x86)/libnvidia-compiler*.so*"  "$(PKG_libdir32)"
	dh_install -p$(PKG_driver) "$(dirname_x86)/libnvcuvid*.so*"  "$(PKG_libdir32)"
	dh_install -p$(PKG_driver) "$(dirname_x86)/libnvidia-ml*.so*"  "$(PKG_libdir32)"

	# Move 32bit libnvidia-opencl back
	mv $(CURDIR)/$(dirname_x86)/_libnvidia-opencl.so.$(PKG_version) \
	   $(CURDIR)/$(dirname_x86)/libnvidia-opencl.so.$(PKG_version)
endif

ifneq ($(DEB_BUILD_ARCH),armhf)
	# Move libnvidia-opencl back
	mv $(CURDIR)/$(dirname)/_libnvidia-opencl.so.$(PKG_version) \
	   $(CURDIR)/$(dirname)/libnvidia-opencl.so.$(PKG_version)
endif

	# Generate modaliases for Jockey and nvidia-common
	mkdir -p $(CURDIR)/debian/$(PKG_driver)-modaliases/usr/share/jockey/modaliases/
	sh -e $(CURDIR)/debian/nvidia_supported \
		$(PKG_module) $(PKG_driver) \
		$(dirname)/README.txt \
		$(dirname)/kernel/nv-kernel.o \
		> $(CURDIR)/debian/$(PKG_driver).modaliases
	# Take additional card ids from a text file
	while read id sid; do \
		if [ -z $$sid ]; then \
			printf 'alias pci:v%08Xd%08Xsv*sd*bc03sc*i* %s %s\n' \
			0x10de "0x$$id" "$(PKG_module)" "$(PKG_driver)" \
		;else \
			printf 'alias pci:v%08Xd%08Xsv*sd%08Xbc03sc*i* %s %s\n' \
			0x10de "0x$$id" "0x$$sid" "$(PKG_module)" "$(PKG_driver)" \
		;fi \
	done <$(CURDIR)/debian/additional_card_ids >>$(CURDIR)/debian/$(PKG_driver).modaliases
	dh_modaliases
	rm -f $(CURDIR)/debian/$(PKG_driver).modaliases

	# Configuration stuff

	# ld.so.conf
	dh_installdirs -p$(PKG_driver) "$(ld_so_conf_dir)"
	echo "$(PKG_libdir)" >	"$(CURDIR)/debian/$(PKG_driver)$(ld_so_conf_path)"
	echo "$(mesa_libdir)" >	"$(CURDIR)/debian/$(PKG_driver)$(pm_ld_so_conf_path)"
ifeq ($(DEB_BUILD_ARCH),amd64)
	echo "$(PKG_libdir32)" >>	"$(CURDIR)/debian/$(PKG_driver)$(ld_so_conf_path)"
	echo "$(mesa_libdir_other)" >>	"$(CURDIR)/debian/$(PKG_driver)$(pm_ld_so_conf_path)"
endif
	# empty ld.so.conf for the fake multi-arch alternative
	$(shell touch "$(CURDIR)/debian/$(PKG_driver)$(alt_ld_so_conf_path)")
	$(shell touch "$(CURDIR)/debian/$(PKG_driver)$(pm_alt_ld_so_conf_path)")

	# Blacklist any other driver that udev may want to load instead of $(PKG_module)
	# and create an alias for the module so that it can be used as nvidia
	printf '$(subst $(newline),\n,${blacklist_file})' > $(CURDIR)/debian/$(PKG_driver)$(PKG_libconfdir)/modprobe.conf

	# Permanently blacklist nouveau so that hybrid graphics can work without having to rebuild
	# the initramfs when nvidia is installed but disabled
	printf '$(subst $(newline),\n,${blacklist_hybrid})' > \
               $(CURDIR)/debian/$(PKG_driver)$(sysconfdir)/modprobe.d/$(PKG_driver)_hybrid.conf

	dh_install -p$(PKG_driver) $(dirname)/nvidia-xconfig.1.gz "$(mandir)";
	dh_install -p$(PKG_driver) $(dirname)/nvidia-smi.1.gz "$(mandir)";
	dh_install -p$(PKG_driver) $(dirname)/nvidia-cuda-mps-control.1.gz "$(mandir)";
	dh_install -p$(PKG_driver) $(dirname)/nvidia-persistenced.1.gz "$(mandir)";

	# Rename the man pages in order to use alternatives
	for file in $(CURDIR)/debian/$(PKG_driver)$(mandir)/*.gz; do \
		mv $$file $(CURDIR)/debian/$(PKG_driver)$(mandir)/`basename $$file | sed 's/nvidia/alt-$(PKG_driver)/'`; \
	done

	rm -rf debian/temp/modules/nvidia-kernel

	# Remove libnvidia-opencl
	find $(CURDIR)/debian/$(PKG_driver) -name 'libnvidia-opencl*.so*' | xargs /bin/rm -f

	# Part about $(PKG_driver_uvm):
	dh_install -p$(PKG_driver_uvm)
	rm -rf debian/temp/modules/nvidia-uvm-kernel

	# Part about $(PKG_libcuda1):
	dh_install -p$(PKG_libcuda1)
ifeq ($(DEB_BUILD_ARCH),amd64)
	dh_installdirs -p$(PKG_libcuda1) "$(libdir_multiarch_other)"
	dh_install -p$(PKG_libcuda1) "$(dirname_x86)/libcuda*.so*"  "$(libdir_multiarch_other)"
endif

	# Part about $(PKG_libopencl1)
	dh_install -p$(PKG_libopencl1)
ifeq ($(DEB_BUILD_ARCH),amd64)
	dh_installdirs -p$(PKG_libopencl1) "$(libdir_multiarch_other)"
	dh_install -p$(PKG_libopencl1) "$(dirname_x86)/libOpenCL*.so*"  "$(libdir_multiarch_other)"
endif

	# Part about $(PKG_opencl_icd)
	dh_install -p$(PKG_opencl_icd)
ifeq ($(DEB_BUILD_ARCH),amd64)
	dh_installdirs -p$(PKG_opencl_icd) "$(libdir_multiarch_other)"
	dh_install -p$(PKG_opencl_icd) "$(dirname_x86)/libnvidia-opencl.so*"  "$(libdir_multiarch_other)"
endif

override_dh_strip:

override_dh_clean: regen-from-templates
	dh_clean
#clean: regen-from-templates
#	for file in $(CURDIR)/debian/*.in \
#	; do \
#		if [ `basename $$file` != "control.in" ]; then \
#			rm -f $(CURDIR)/debian/`basename $$file | sed 's/\.in\$$//'`; \
#		fi \
#	done
	rm -fr $(CURDIR)/$(dirname_x86) $(CURDIR)/$(dirname_x86_64) $(CURDIR)/$(dirname_armhf)
	rm -fr debian/temp
	rm -f debian/$(PKG_driver).substvars