File: rules

package info (click to toggle)
nvidia-cuda-toolkit 12.4.1-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 18,505,836 kB
  • sloc: ansic: 203,477; cpp: 64,769; python: 34,699; javascript: 22,006; xml: 13,410; makefile: 3,085; sh: 2,343; perl: 352
file content (866 lines) | stat: -rwxr-xr-x 43,239 bytes parent folder | download | duplicates (2)
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
#!/usr/bin/make -f

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

# cuda-gdb/README mentions --enable-targets="x86_64-unknown-linux-gnu,arm-elf-linux-gnu,m68k-unknown-linux-gnu"
CUDA_GDB_FLAGS	 =
CUDA_GDB_FLAGS	+= --program-prefix=cuda-
CUDA_GDB_FLAGS	+= --with-gdb-datadir='$${prefix}/share/cuda-gdb'
CUDA_GDB_FLAGS	+= --with-jit-reader-dir='$${libdir}/cuda-gdb'
CUDA_GDB_FLAGS	+= --with-system-gdbinit='$${sysconfdir}/cuda-gdb/gdbinit'
CUDA_GDB_FLAGS	+= --with-system-gdbinit-dir='$${sysconfdir}/cuda-gdb/gdbinit.d'
CUDA_GDB_FLAGS	+= --enable-cuda
CUDA_GDB_FLAGS	+= --enable-targets="$(DEB_HOST_GNU_TYPE),m68k-unknown-linux-gnu"
CUDA_GDB_FLAGS	+= --disable-nls
CUDA_GDB_FLAGS	+= --disable-inprocess-agent
CUDA_GDB_FLAGS	+= --disable-rpath
CUDA_GDB_FLAGS	+= --disable-gprofng
# the following flags were taken from gdb 13.1 (bookworm)
CUDA_GDB_FLAGS	+= --disable-gdbtk
CUDA_GDB_FLAGS	+= --disable-shared
CUDA_GDB_FLAGS	+= --disable-readline
CUDA_GDB_FLAGS	+= --with-system-readline
CUDA_GDB_FLAGS	+= --with-expat
CUDA_GDB_FLAGS	+= --with-system-zlib
CUDA_GDB_FLAGS	+= --without-guile
CUDA_GDB_FLAGS	+= --with-debuginfod
CUDA_GDB_FLAGS	+= --with-babeltrace
ifneq (,$(filter $(DEB_HOST_ARCH),amd64))
CUDA_GDB_FLAGS	+= --with-intel-pt
endif
CUDA_GDB_FLAGS	+= --enable-tui
CUDA_GDB_FLAGS	+= --with-lzma
CUDA_GDB_FLAGS	+= --with-python=python3
CUDA_GDB_FLAGS	+= --with-xxhash
CUDA_GDB_FLAGS	+= --with-mpfr
CUDA_GDB_FLAGS	+= --enable-64-bit-bfd
CUDA_GDB_FLAGS	+= --disable-sim
CUDA_GDB_FLAGS	+= --enable-obsolete
CUDA_GDB_FLAGS	+= --with-python=no

DEB_BUILD_MAINT_OPTIONS		 = hardening=+all
DEB_CPPFLAGS_MAINT_APPEND	 = -I$(CURDIR)/nvidia-cuda-tree-$(DEB_HOST_ARCH)/cuda_cudart/include
DEB_LDFLAGS_MAINT_APPEND	 = -pthread

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk

VENDOR			?= $(call dpkg_late_eval,VENDOR,dpkg-vendor --derives-from Ubuntu && echo Ubuntu || echo Debian)


aval			 = $(or $($(strip $1).$(or $(strip $2),$(DEB_HOST_ARCH))),$($(strip $1).default),$(error Not defined: $(strip $1)($(or $(strip $2),$(DEB_HOST_ARCH)))))
-include debian/rules.version
include debian/rules.soversion
include debian/rules.version_prefix
include debian/rules.defs
CUDA_ARCH_LIST			?= amd64
CUDA_ARCH_LIST_NO_DRIVER	?=
CUDA_ARCH_LIST_NO_OPENJDK	?=
CUDA_VERSION_TOOLKIT	?= $(DEB_VERSION_UPSTREAM)
CUDA_VERSION_MAJOR	?= $(word 1,$(subst ., ,$(CUDA_VERSION_TOOLKIT)))
CUDA_VERSION_MINOR	?= $(word 2,$(subst ., ,$(CUDA_VERSION_TOOLKIT)))
CUDA_VERSION		?= $(CUDA_VERSION_MAJOR).$(CUDA_VERSION_MINOR)
version_driver		 = $(call aval,CUDA_VERSION_DRIVER_MINIMAL)
PACKAGE_LIST		:= $(shell dh_listpackages)
CUDA_GDB_VERSION	?= $(CUDA_VERSION_cuda_gdb)
DEFAULT_GCC_VERSION	?= $(error Undefined DEFAULT_GCC_VERSION)
CCCL_VERSION		?= $(or $(strip $(shell perl -ne 'if (/define\s+CCCL_VERSION\s+(\d*)/) { printf "%d.%d.%d\n", $$1 / 1000000, $$1 / 1000 % 1000, $$1 % 1000; }' nvidia-cuda/cuda_cccl/include/cuda/std/detail/libcxx/include/__cccl/version.h)),$(error empty CCCL_VERSION))
NVIDIA_FS_DKMS_VERSION	?= $(nvidia-fs-dkms.VERSION)
NVIDIA_FS_DKMS_SHORTVER	?= $(word 1,$(subst ., ,$(nvidia-fs-dkms.VERSION))).$(word 2,$(subst ., ,$(nvidia-fs-dkms.VERSION)))
CUDA_JAVA_HOME		?= /usr/lib/jvm/java-8-openjdk-$(DEB_HOST_ARCH)
libdir			 = usr/lib/$(DEB_HOST_MULTIARCH)
jre_pkg			?= $(filter nvidia-openjdk-8-jre,$(PACKAGE_LIST))
nvidia_profiler_pkg	?= $(filter nvidia-profiler,$(PACKAGE_LIST))
visual_profiler_pkg	?= $(filter nvidia-visual-profiler,$(PACKAGE_LIST))

UPSTREAM_HOST_ARCH	?= $(call aval,UPSTREAM_HOST_ARCH)
JAVA_HOST_ARCH		?= $(DEB_HOST_ARCH:ppc64el=ppc64le)

export NSIGHT_COMPUTE_DESKTOP_DIR	 = $(NSIGHT_COMPUTE_DESKTOP_DIR.$(DEB_HOST_ARCH))
export NSIGHT_SYSTEMS_HOST_DIR		 = $(NSIGHT_SYSTEMS_HOST_DIR.$(DEB_HOST_ARCH))
export NSIGHT_SYSTEMS_TARGET_DIR	 = $(NSIGHT_SYSTEMS_TARGET_DIR.$(DEB_HOST_ARCH))
export NVIDIA_FS_DKMS_VERSION

package_libcuda1	 = $(package_libcuda1.$(VENDOR))
package_libcuda1	+= libcuda.so.1 (>= $${nvidia:MinVersion}) |
package_libcuda1	+= libcuda-$(CUDA_VERSION_MAJOR).$(CUDA_VERSION_MINOR)-1 |
package_libcuda1	+= no-libcuda1 [$${cuda:arch:has-no-driver}] |

package_libnvidia-ml1	 = $(package_libnvidia-ml1.$(VENDOR))
package_libnvidia-ml1	+= libnvidia-ml.so.1 (>= $${nvidia:MinVersion}) |
package_libnvidia-ml1	+= no-libcuda1 [$${cuda:arch:has-no-driver}] |

package_driver		 = $(package_driver.$(VENDOR))

package_nvidia-kernel-dkms	 = $(package_nvidia-kernel-dkms.$(VENDOR))
package_nvidia-kernel-dkms	+= nvidia-kernel-dkms-any (>= $${nvidia:MinVersion}) |
package_nvidia-kernel-dkms	+= nvidia-open-kernel-dkms-any (>= $${nvidia:MinVersion}) |

# do not build nvidia-openjdk-8-jre on Ubuntu
ifneq (,$(jre_pkg))
ifeq ($(VENDOR),Ubuntu)
export DH_OPTIONS := $(DH_OPTIONS) -N$(jre_pkg)
jre_pkg			 =
endif
endif

OPENJDK_VERSION		 = $(call aval,OPENJDK_VERSION,$(DEB_HOST_ARCH))
make_component_version	?= $(subst -deb,-d,$(subst +,-,$(subst ~,-,$1)))
get_openjdk_component		?= openjdk-8-$1-$(call make_component_version,$(call aval,OPENJDK_VERSION,$2))
get_openjdk_source_component	?= $(call get_openjdk_component,source,$1)
get_openjdk_jre_component	?= $(call get_openjdk_component,jre-$1,$1)

jre_pkg_dep		?= $(if $(jre_pkg),$(jre_pkg) (>= 9.+8u252))
jre_depends.Debian	?= $(if $(jre_pkg),$(jre_pkg_dep) |) openjdk-8-jre
jre_depends.Ubuntu	?= openjdk-8-jre | $(jre_pkg_dep)

ifneq (,$(jre_pkg))
$(jre_pkg).VERSION	 = $(subst ~,~~,$(OPENJDK_VERSION))
endif

TEMPLATES	:= $(wildcard debian/*.in debian/patches/*.in)
SOVERTEMPLATES	:= $(wildcard debian/*SOVER*)
AUTOGEN		+= $(patsubst %.in,%,$(TEMPLATES))
AUTOGEN		+= $(foreach t,$(sort $(patsubst %.in,%,$(SOVERTEMPLATES))),$(subst SOVER,$(or $($(firstword $(subst SOVER, ,$(notdir $t))).SOVERSION),XXX),$t))
AUTOGEN		+= debian/g++
AUTOCLEAN	 = $(AUTOGEN)
AUTOCLEAN	+= debian/shlibs.local


.PHONY: autogen prepare
autogen: $(AUTOGEN)
prepare: autogen unpack-stamp compare-copyright-license
prepare: update-version-prefix


# deep copy, files will get irreversibly modified via hardlinks in the build target
define nvidia-cuda-unpack-repack
	dh_testdir
	$(RM) -r $@ $@.tmp
	cp -a $1 $@
endef

nvidia-cuda-tree-%:
	$(call nvidia-cuda-unpack-$(call aval,CUDA_TAR_TYPE,$*),$*)

unpack-stamp: $(filter debian/patches%,$(AUTOGEN))
unpack-stamp: nvidia-cuda-tree-$(DEB_HOST_ARCH)
	$(RM) nvidia-cuda
	! grep -l __Float32x4_t arm64/cuda_nvcc/bin/cudafe++
	ln -sf nvidia-cuda-tree-$(DEB_HOST_ARCH) nvidia-cuda
ifneq (amd64,$(DEB_HOST_ARCH))
	# sync timestamps from amd64 for reproducible arch:all builds on all architectures
	cd nvidia-cuda && find -type f -exec sh -c 'f="{}"; test ! -f ../amd64/"$$f" || touch -r ../amd64/"$$f" "$$f"' \;
	cd nvidia-cuda && find -type d -exec sh -c 'd="{}"; test ! -d ../amd64/"$$d" || touch -r ../amd64/"$$d" "$$d"' \;
endif
	$(RM) -r cuda-gdb-$(CUDA_GDB_VERSION) cuda-gdb
ifneq (arm64,$(DEB_HOST_ARCH))
	tar xf nvidia-cuda/cuda_gdb/extras/cuda-gdb-$(CUDA_GDB_VERSION).src.tar.gz
else
	tar xf amd64/cuda_gdb/extras/cuda-gdb-$(CUDA_GDB_VERSION).src.tar.gz
endif
	mv cuda-gdb-$(CUDA_GDB_VERSION) cuda-gdb
ifneq (ppc64el,$(DEB_HOST_ARCH))
	mv nvidia-cuda/nvidia_fs/usr/src/nvidia-fs-$(NVIDIA_FS_DKMS_SHORTVER) nvidia-cuda/nvidia_fs/usr/src/nvidia-fs
endif
ifneq (,$(jre_pkg))
	$(RM) -r openjdk-8-jre
	dpkg -x $(call get_openjdk_jre_component,$(DEB_HOST_ARCH))/openjdk-8-jre-headless_$(OPENJDK_VERSION)_$(DEB_HOST_ARCH).deb openjdk-8-jre
	dpkg -x $(call get_openjdk_jre_component,$(DEB_HOST_ARCH))/openjdk-8-jre_$(OPENJDK_VERSION)_$(DEB_HOST_ARCH).deb openjdk-8-jre
	$(RM) -v openjdk-8-jre/usr/lib/jvm/java-8-openjdk-*/docs
	cp openjdk-8-jre/usr/share/doc/openjdk-8-jre-headless/copyright debian/$(jre_pkg).copyright
endif
	QUILT_PATCHES=debian/patches QUILT_SERIES=series-postunpack quilt --quiltrc /dev/null push -a || test $$? = 2
	touch $@

# Reformat the EULA to the format needed for debian/copyright.
nvidia-cuda/EULA.txt: unpack-stamp
EULA.fmt: nvidia-cuda/EULA.txt
	cat $< \
		| fromdos | fromdos | expand \
		| iconv -f UTF-8 -t latin1//TRANSLIT \
		| fold -s -w 80 \
		| sed -e 's/ *$$//;s/^$$/./;s/^/ /;' \
		> $@

# Compare the license in debian/copyright with the EULA shipped in the archive.
compare-copyright-license: EULA.fmt
	sed -e '1,/^License: other-NVIDIA-CUDA-TOOLKIT/d; /^$$/,$$d; /^ .$$/d' debian/copyright > copyright.tmp
	sed -e '/^ .$$/d' EULA.fmt > EULA.tmp
	diff -w copyright.tmp EULA.tmp
	rm -f copyright.tmp EULA.tmp

dpkg-compare-versions = $(shell dpkg --compare-versions "$(1)" "$(2)" "$(3)" && echo "$(2)")

# $1 = key, $2 = value, $3 = append_to_file
define echokv
	echo '$(shell printf "%-39s" $(1)) = $(2)'	>> $(3)

endef

define update-version-prefix
	$(if $($(1).VERSION_PREFIX),$(if $(call dpkg-compare-versions,$($(1).VERSION_PREFIX),le,$(call get-upstream-version,$(1),1)),
		: DROP PREFIX $(1) $($(1).VERSION_PREFIX) $(call get-upstream-version,$(1),1)
		$(eval $(1).VERSION_PREFIX =)))
	$(if $(call dpkg-compare-versions,$($(1).PREV_VERSION),le,$(call get-current-version,$(1))),,
		$(if $(call get-upstream-version,$(1),),,$(error MISSING VERSION FOR $(1)))
		: ADD PREFIX $(1) $($(1).PREV_VERSION) $(call get-current-version,$(1))
		$(eval $(1).VERSION_PREFIX = $($(1).PREV_VERSION)+~))
	echo '' >> $(2)
	$(if $($(1).VERSION_PREFIX),$(call echokv,$(1).VERSION_PREFIX,$($(1).VERSION_PREFIX),$(2)))
	$(call echokv,$(1).PREV_VERSION,$(call get-current-version,$(1)),$(2))

endef

update-version-prefix: unpack-stamp
	echo "# This file is generated/updated by 'debian/rules update-version-prefix'." > debian/rules.version_prefix.new
	$(foreach pkg,$(OTHER_PACKAGES) $(LIB_PACKAGES),$(call update-version-prefix,$(pkg),debian/rules.version_prefix.new))
	echo >> debian/rules.version_prefix.new
	$(call echokv,CCCL.PREV_VERSION,$(CCCL_VERSION),debian/rules.version_prefix.new)
	mv debian/rules.version_prefix.new debian/rules.version_prefix


.PHONY: binary binary-arch binary-indep build build-arch build-indep clean install
binary binary-arch binary-indep build build-arch build-indep clean install:
	dh $@

build-stamp: unpack-stamp
	$(RM) -r build
	cp -al nvidia-cuda-tree-$(DEB_HOST_ARCH)/ build
ifneq (amd64,$(DEB_HOST_ARCH))
	# take missing examples from amd64
	test -d build/libcublas/src || cp -alv amd64/libcublas/src build/libcublas/
	test -d build/libcusparse/src || cp -alv amd64/libcusparse/src build/libcusparse/
	test -d build/cuda_cupti/extras/CUPTI/samples/profiling_injection || cp -alv amd64/cuda_cupti/extras/CUPTI/samples/profiling_injection build/cuda_cupti/extras/CUPTI/samples/
endif
	# fix permissions
ifneq (,$(visual_profiler_pkg))
	chmod -v -x build/cuda_nvvp/libnvvp/*.xpm
endif
	chmod -v -x build/cuda_cupti/extras/CUPTI/samples/pc_sampling_utility/pc_sampling_utility_helper.h
	# remove tracking scripts
	find build \( -name google-analytics-tracker.js -o -name google-analytics-write.js -o -name tynt.js \) -exec rm -v {} +
	# remove tracking images
	@set -e -x ; for dir in \
		build/cuda_sanitizer_api/compute-sanitizer/docs \
		build/cuda_nvvp/libnvvp \
	; do test ! -d $$dir || find $$dir \
	    -name '*.html' -exec sed -r -i \
		-e 's,(<script type="text/javascript" )src(="http://w.sharethis.com/button/buttons.js"[^>]*></script>),<!-- \1DISABLED\2 -->,' \
		-e 's,(<script (type="text/javascript" charset="utf-8" )?)src(="(https:)?//assets.adobedtm.com/5d4962a43b79/c1061d2c5e7b/launch-191c2462b890.min.js"[^>]*></script>),<!-- \1DISABLED\3 -->,' \
		{} + ; \
	done
	# replace embedded javascript libraries
	set -e ; for dir in \
		build/cuda_cupti/extras/CUPTI/doc/html \
		build/nsight_compute/docs \
		build/nsight_systems/documentation \
	; do test ! -d $$dir || while read file trg ; \
		do test ! -f $$dir/$$file || if [ "$$trg" ]]; then ln -sfv $$trg $$dir/$$file; else $(RM) -v $$dir/$$file ; fi ; \
		done < debian/sphinx-links ; \
	done
	find build -name html5shiv-printshiv.min.js -exec ln -sfv /usr/share/javascript/html5shiv/html5shiv-printshiv.min.js {} \;
	find build -name jquery.min.js -exec ln -sfv /usr/share/javascript/jquery/jquery.min.js {} \;
	# reduce 'dh_missing --list-missing' noise
	@set -e -x ; for dir in build/*/include build/*/lib64 ; do if [ -h "$$dir" ] ; then target=$$(readlink -f $$dir) ; $(RM) $$dir ; mv -v $$target $$dir ; fi ; done
	! cmp -s build/cuda_documentation/EULA.txt build/EULA.txt || $(RM) -v build/EULA.txt
	! cmp -s build/cuda_documentation/EULA.txt build/libnvjitlink/LICENSE || $(RM) -v build/libnvjitlink/LICENSE
	! cmp -s build/cuda_documentation/EULA.txt build/libnvfatbin/LICENSE || $(RM) -v build/libnvfatbin/LICENSE
	$(RM) -rv build/cuda_demo_suite
	# libcudacxx, cub and thrust are packaged separately
	$(RM) -r build/cuda_cccl/include/cuda
	$(RM) -r build/cuda_cccl/include/nv
	$(RM) -r build/cuda_cccl/include/cub
	$(RM) -r build/cuda_cccl/include/thrust
	$(RM) -r build/cuda_cccl/lib64/cmake
ifneq (,$(visual_profiler_pkg))
	# split arch and indep eclipse plugins
	mkdir build/cuda_nvvp/libnvvp/plugins-arch
	mv build/cuda_nvvp/libnvvp/plugins/org.eclipse.equinox.launcher.gtk.linux.* build/cuda_nvvp/libnvvp/plugins-arch/
endif
	# replace embedded shared libraries with system libraries
	find build -name libssh.so -exec sh -c 'l="{}"; ln -sfv /$(libdir)/libssh.so.4 "$$l.4"; ln -sfv libssh.so.4 "$$l"' \;
#
	# clean up nsight_compute
ifeq (arm64,$(DEB_HOST_ARCH))
	@set -e -x ; for lib in libQt6Positioning.so.6 libQt6QmlModels.so.6 libQt6Quick.so.6 libQt6WebChannel.so.6 libQt6WebEngineCore.so.6 ; do \
		test -f build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/$$lib || \
		cp -alv build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/$$lib build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/ ; \
	done
endif
ifeq (amd64,$(DEB_HOST_ARCH))
	$(RM) -rv build/nsight_compute/host/$(NSIGHT_SYSTEMS_TARGET_DIR)/
	$(RM) -rv build/nsight_compute/target/$(NSIGHT_COMPUTE_DESKTOP_DIR.i386)/
	$(RM) -rv build/nsight_compute/target/$(NSIGHT_COMPUTE_DESKTOP_DIR.ppc64el)/
	$(RM) -rv build/nsight_compute/target/$(NSIGHT_COMPUTE_DESKTOP_DIR.arm64)/
endif
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/Mesa/libGL.so*
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6Designer*.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6Help.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6Multimedia*.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6QuickParticles.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6QuickTest.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6Sensors.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6Sql.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6SvgWidgets.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6Test.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6WaylandCompositor.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQt6WaylandEglCompositorHwIntegration.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libboost_python*.so.1.*
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libcrypto.so*
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libfreetype.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libpfm.so.4
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libssl.so*
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libstdc++.so.6
	$(RM) -v build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libzstd.so.1
ifeq (amd64,$(DEB_HOST_ARCH))
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libpapi.so.5
endif
ifeq (arm64,$(DEB_HOST_ARCH))
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/CrashReporter
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/OpenGLVersionChecker
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/Plugins/CorePlugin/libCorePlugin.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/Plugins/RebelPlugin/libRebelPlugin.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/Plugins/SassDebuggerPlugin/libSassDebuggerPlugin.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/Plugins/libArmServerPlatformPlugin.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/Plugins/libExternalIntegrationPlugin.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/Plugins/libTPSConnectionPlugin.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/Plugins/libTPSSystemServerPlugin.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libAppLib.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libAppLibInterfaces.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libGenericHierarchy.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libNvQtGui.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libQtPropertyBrowser.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libTimelineAssert.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libTimelineCommon.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libTimelineUIUtils.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libTimelineWidget.so
	chrpath -d build/nsight_compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)/ncu-ui.bin
endif
ifneq (amd64,$(DEB_HOST_ARCH))
	chrpath -d build/nsight_compute/target/$(NSIGHT_COMPUTE_DESKTOP_DIR)/libTreeLauncherTargetInjection.so
endif
#
	# clean up nsight_systems
ifeq (amd64,$(DEB_HOST_ARCH))
	chmod -v +x build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/Scripts/VncContainer/Scripts/*.sh
	$(RM) -rv build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/Scripts/DependenciesInstaller
endif
	mkdir build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)-examples
	mv build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/Scripts build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)-examples
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/NVIDIA_SLA.pdf
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/Mesa/libGL.so*
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6Charts.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6Designer*.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6Help.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6Multimedia*.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6QuickParticles.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6QuickTest.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6Sensors.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6Sql.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6SvgWidgets.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6Test.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6WaylandCompositor.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQt6WaylandEglCompositorHwIntegration.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libboost_python*.so.1.*
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libcrypto.so*
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libfreetype.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libjpeg.so.8
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libpfm.so.4
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libsqlite3.so.0
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libssl.so*
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libstdc++.so.6
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libelf.so*
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libz.so*
ifeq (amd64,$(DEB_HOST_ARCH))
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libpapi.so.5
else
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/QdstrmImporter
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libAgentAPI.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libAnalysis.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libAnalysisContainersData.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libAnalysisData.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libAnalysisProto.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libAssert.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libCommonProtoServices.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libCommonProtoStreamSections.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libCore.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libCudaDrvApiWrapper.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libDeviceProperty.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libDevicePropertyProto.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libEventSource.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libGpuInfo.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libGpuTraits.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libHostCommon.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libInjectionCommunicator.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libInterfaceData.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libInterfaceSharedBase.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libInterfaceSharedLoggers.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libLinuxPerf.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libNvmlWrapper.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libNvtxExtData.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libProcessLauncher.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libProtobufComm.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libProtobufCommClient.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libProtobufCommProto.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQuiverContainers.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQuiverEvents.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libStreamSections.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libSymbolAnalyzerLight.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libTimelineAssert.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libTimelineCommon.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libparquet.so.500.0.0
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjection64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionMPICH64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionOpenMPI64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionOpenSHMEM64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionProxy64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionUCP64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/nsys
ifeq (arm64,$(DEB_HOST_ARCH))
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/CrashReporter
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/Plugins/CorePlugin/libCorePlugin.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/Plugins/QuadDPlugin/libQuadDPlugin.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/Plugins/TimelinePlugin/libTimelinePlugin.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libAppLib.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libAppLibInterfaces.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libEventsView.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libGenericHierarchy.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libInterfaceShared.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libInterfaceSharedCore.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libNvQtGui.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libQtPropertyBrowser.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libSshClient.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libTelemetryQuadDClient.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libTimelineUIUtils.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libTimelineWidget.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/libexporter.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/nsys-ui.bin
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libLinuxKeyboardInterceptorProxy.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionCuBLAS64_10.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionCuBLAS64_11.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionCuDNN64_7.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionCuDNN64_8.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionNvMedia64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionNvMediaLegacy64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionPythonBacktrace64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionPythonGilTracing64.so
	chrpath -d build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/libToolsInjectionPythonNvtxAnnotations64.so
endif
endif
ifneq (ppc64el,$(DEB_HOST_ARCH))
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/python/bin/python
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/python/lib/gpustats.py
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/python/lib/nsysstats.py
	sed -i '1s%/usr/bin/env python$$%/usr/bin/python3%' build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/reports/*.py
	sed -i '1s%/usr/bin/env python$$%/usr/bin/python3%' build/nsight_systems/$(NSIGHT_SYSTEMS_HOST_DIR)/rules/*.py
endif
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/python/bin/python
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/python/packages/nsys_recipe/third_party/_sqlite3.cpython-*.so
	$(RM) -v build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/python/packages/nsys_recipe/third_party/sqlite3/*.py
	sed -i '1s%/usr/bin/env python$$%/usr/bin/python3%' build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/reports/*.py
	sed -i '1s%/usr/bin/env python$$%/usr/bin/python3%' build/nsight_systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/rules/*.py
#
	# clean up compute-sanitizer
ifneq (amd64,$(DEB_HOST_ARCH))
	chrpath -d build/cuda_sanitizer_api/compute-sanitizer/libTreeLauncherTargetInjection.so
endif
ifeq (amd64,$(DEB_HOST_ARCH))
	# i386 binaries
	$(RM) -rv build/cuda_sanitizer_api/compute-sanitizer/x86
endif
#
ifneq (ppc64el,$(DEB_HOST_ARCH))
	# clean up gds
	maxver=$$(grep -h '^ ' debian/libcufile*.symbols* | awk '{print $$2}' | sort -Vu | tail -n 1) && echo $$maxver && \
	       dpkg --compare-versions $$maxver le $(call get-custom-version,libcufile)~$(DEB_VERSION)
	chmod -v -x build/libcufile/gds/tools/run_gdsio.cfg
	! cmp -s build/libcufile/gds/doc/copyright build/libcufile/gds-$(CUDA_VERSION)/copyright || $(RM) -v build/libcufile/gds-$(CUDA_VERSION)/copyright
	! diff -q -w build/libcufile/gds/doc/copyright build/libcufile/gds/EULA.txt || $(RM) -v build/libcufile/gds/EULA.txt
	$(RM) -v build/libcufile/lib64/lib64
	$(RM) -v build/libcufile/include/include
endif
#
	# remove empty directories
	find build -depth -type d -exec sh -c 'd="{}"; rmdir --ignore-fail-on-non-empty "$$d" ; test -d "$$d" || echo "removed $$d"' \;
	touch $@

execute_before_dh_update_autotools_config: $(AUTOGEN) unpack-stamp

override_dh_auto_configure-arch:
	dh_auto_configure --sourcedirectory=cuda-gdb -- $(CUDA_GDB_FLAGS)

execute_before_dh_auto_build: build-stamp

override_dh_auto_build-arch:
	dh_auto_build --sourcedirectory=cuda-gdb -- V=1

ifneq (,$(jre_pkg))
execute_before_dh_auto_test-arch:
	openjdk-8-jre/$(CUDA_JAVA_HOME)/bin/java -version
endif

execute_before_dh_auto_install:
	rm -rf debian/tmp
	cp -al build/ debian/tmp

override_dh_auto_install-arch:
	dh_auto_install --sourcedirectory=cuda-gdb/gdb
	dh_auto_install --sourcedirectory=cuda-gdb/gdbserver

ifeq (amd64,$(DEB_HOST_ARCH))
override_dh_installchangelogs:
	dh_installchangelogs -plibcufile-dev build/libcufile/gds/doc/changelog
	dh_installchangelogs -pgds-tools build/libcufile/gds-$(CUDA_VERSION)/changelog
	dh_installchangelogs --remaining-packages
endif

override_dh_installman:
	dh_installman --language=C

override_dh_dkms:
	dh_dkms -V'$(NVIDIA_FS_DKMS_VERSION)'

override_dh_python3:
	dh_python3 --skip-private --no-ext-rename

override_dh_makeshlibs:
	dh_makeshlibs -X/stubs/ -VNone

override_dh_shlibdeps:
	$(RM) -r libcuda
	mkdir libcuda
	ln -s ../nvidia-cuda/cuda_cudart/lib64/stubs/libcuda.so libcuda/libcuda.so.1
	echo 'libcuda 1 XXXlibcuda1XXX' > debian/shlibs.local
	echo 'libucm 0 libucx0' >> debian/shlibs.local
	echo 'libucp 0 libucx0' >> debian/shlibs.local
	echo 'libucs 0 libucx0' >> debian/shlibs.local
	echo 'libuct 0 libucx0' >> debian/shlibs.local
	dh_shlibdeps -pnvidia-cuda-toolkit -- \
		-l/usr/lib/nvidia-cuda-toolkit/compute-sanitizer
	dh_shlibdeps -pnvidia-cuda-dev -X/stubs/
	dh_shlibdeps -pnsight-compute \
		-- \
		-l/usr/lib/nsight-compute/host/$(NSIGHT_COMPUTE_DESKTOP_DIR)
	dh_shlibdeps -pnsight-compute-target -- \
		-l/$(libdir)/nsight-compute/target/$(NSIGHT_COMPUTE_DESKTOP_DIR)
	dh_shlibdeps -pnsight-systems \
		-- \
		-l/usr/lib/nsight-systems/$(NSIGHT_SYSTEMS_HOST_DIR)
	dh_shlibdeps -pnsight-systems-target -- \
		-l/$(libdir)/nsight-systems/$(NSIGHT_SYSTEMS_TARGET_DIR) \
		-l/$(libdir)/nsight-systems/$(NSIGHT_SYSTEMS_TARGET_DIR)/CollectX \
		-llibcuda
ifneq (,$(jre_pkg))
	dh_shlibdeps -p$(jre_pkg) -- -l$(CUDA_JAVA_HOME)/jre/lib/$(JAVA_HOST_ARCH)/server
endif
	dh_shlibdeps --remaining-packages -- -llibcuda
	$(RM) -r libcuda debian/shlibs.local
	sed -r -i -e 's/XXXlibcuda1XXX/$${package:libcuda1}/g' \
		$(foreach lib,$(LIB_BASENAMES),-e 's/$(lib)$($(lib).SOVERSION)(,|$$)/$${$(lib):eq:Version}\1/g') \
		debian/*.substvars

# running dh_strip is not permitted by the NVIDIA license
override_dh_dwz:
	dh_dwz -pnvidia-cuda-gdb
override_dh_strip:
	dh_strip -pnvidia-cuda-gdb
override_dh_strip_nondeterminism-indep:
override_dh_strip_nondeterminism-arch:
	dh_strip_nondeterminism -pnvidia-cuda-gdb

execute_before_dh_installdeb-indep:
	hardlink -v -t debian/nvidia-cuda-toolkit-doc/usr/share/doc/nvidia-cuda-toolkit

# $1 = <lib_basename or pkgname>
get-custom-version	 = $(or $($(1).DEB_VERSION),$($(1).VERSION_PREFIX)$($(1).VERSION))
get-upstream-version	 = $(or $($(1).DEB_VERSION),$($(1).VERSION),$(if $(2),$(DEB_VERSION_UPSTREAM)))
get-previous-version	 = $($(1).PREV_VERSION)
get-current-version	 = $(or $(call get-custom-version,$(1)),$(DEB_VERSION_UPSTREAM))

substvars	+= -V'cuda:Version:Major=$(CUDA_VERSION_MAJOR)'
substvars	+= $(foreach pkg,$(filter-out $(PACKAGE_LIST),$(OTHER_PACKAGES)),-V'$(pkg):Version=0.not-built' -V'$(pkg):eq:Version=$(pkg) (= $${$(pkg):Version})')
substvars	+= $(foreach pkg,$(filter-out $(LIB_PACKAGES),$(PACKAGE_LIST)),$(if $(call get-custom-version,$(pkg)),-V'$(pkg):Version=$(call get-custom-version,$(pkg))~$(DEB_VERSION)' -V'$(pkg):eq:Version=$(pkg) (= $${$(pkg):Version})'))
substvars	+= $(foreach lib,$(LIB_BASENAMES),$(if $(call get-custom-version,$(lib)),-V'$(lib):Version=$(call get-custom-version,$(lib))~$(DEB_VERSION)'))
substvars	+= $(foreach lib,$(LIB_BASENAMES),-V'$(lib):eq:Version=$(lib)$($(lib).SOVERSION) (= $${$(if $(call get-custom-version,$(lib)),$(lib),binary):Version})')
substvars	+= -V'package:libcuda1=$(package_libcuda1)'
substvars	+= -V'package:libnvidia-ml1=$(package_libnvidia-ml1)'
substvars	+= -V'package:driver=$(package_driver)'
substvars	+= -V'package:nvidia-kernel-dkms=$(package_nvidia-kernel-dkms)'
substvars	+= -V'nvidia:MinVersion=$(version_driver)'
substvars	+= -V'cuda:gcc:DefaultVersion=$(DEFAULT_GCC_VERSION)'
substvars	+= -V'cccl:Version=$(CCCL_VERSION)'
substvars	+= -V'cuda:arch:has-no-driver=$(if $(filter $(DEB_HOST_ARCH),$(CUDA_ARCH_LIST_NO_DRIVER)),,!)$(DEB_HOST_ARCH)'
substvars	+= -V'cuda:arch:has-nvidia-profiler=$(if $(nvidia_profiler_pkg),,!)$(DEB_HOST_ARCH)'
substvars	+= -V'cuda:arch:has-nvidia-visual-profiler=$(if $(visual_profiler_pkg),,!)$(DEB_HOST_ARCH)'
substvars	+= -V'jre:Depends=$(jre_depends.$(VENDOR))'

define check-monotonic-version
	: $(shell printf "%-29s" "$(1)") ; dpkg --compare-versions "$(call get-previous-version,$(1))" le "$(call get-current-version,$(1))"

endef

define gencontrol-template
	dh_gencontrol $(1) -- $(2) \
		$(substvars)

endef

override_dh_gencontrol:
	$(foreach p,$(PACKAGE_LIST),$(call check-monotonic-version,$(p)))
	$(foreach p,$(PACKAGE_LIST),$(if $(call get-custom-version,$(p)),$(call gencontrol-template,-p$(p),-v$(call get-custom-version,$(p))~$(DEB_VERSION))))
	$(call gencontrol-template,--remaining-packages,)

execute_after_dh_autoreconf_clean:
	$(RM) -r .pc
	$(RM) -r nvidia-cuda-tree-amd64*
	$(RM) -r nvidia-cuda-tree-ppc64el*
	$(RM) -r nvidia-cuda-tree-arm64*
	$(RM) nvidia-cuda*
	$(RM) -r build
	$(RM) -r libcuda
	$(RM) EULA.fmt EULA.tmp copyright.tmp
	$(RM) -r openjdk-8-jre
	$(RM) debian/$(jre_pkg).copyright

execute_after_dh_clean:
	$(RM) -r get-orig-source
	$(RM) -r cuda-gdb-$(CUDA_GDB_VERSION) cuda-gdb
	$(RM) $(AUTOCLEAN)
	$(RM) debian/rules.version debian/rules.soversion


debian/rules.version: amd64/version.json
	sed -r -n '/: \{/{s/.*"(.*)".*/\1/;h};/"version" :/{s/.*: "(.*)".*/\1/;H;x;s/^/CUDA_VERSION_/;s/\n/ = /;p}' $< > $@

debian/rules.soversion: debian/control
	sed -rn 's/Package: (lib.*[^0-9.]+)([0-9.]+)$$/LIB_PACKAGES += \1\2\nLIB_BASENAMES += \1\n\1.SOVERSION = \2/p; s/Package: (.*)/OTHER_PACKAGES += \1/p' $< > $@

# Generating control files
%:: %.in debian/rules debian/rules.defs
	perl -p \
	-e 's{#VERSION_TOOLKIT#}{$(CUDA_VERSION_TOOLKIT)}g;' \
	-e 's{#DEFAULT_GCC_VERSION#}{$(DEFAULT_GCC_VERSION)}g;' \
	-e 's{#DEB_HOST_MULTIARCH#}{$(DEB_HOST_MULTIARCH)}g;' \
	-e 's{#LIBDIR#}{$(libdir)}g;' \
	-e 's{#!ppc64el#}{$(if $(filter ppc64el,$(DEB_HOST_ARCH)),#)}g;' \
	-e 's{#arm64#}{$(if $(filter arm64,$(DEB_HOST_ARCH)),,#)}g;' \
	-e 's{#!arm64#}{$(if $(filter arm64,$(DEB_HOST_ARCH)),#)}g;' \
	-e 's{#CUDA_JAVA_HOME#}{$(CUDA_JAVA_HOME)}g;' \
	-e 's{#NSIGHT_COMPUTE_DESKTOP_DIR#}{$(NSIGHT_COMPUTE_DESKTOP_DIR)}g;' \
	-e 's{#NSIGHT_SYSTEMS_HOST_DIR#}{$(NSIGHT_SYSTEMS_HOST_DIR)}g;' \
	-e 's{#NSIGHT_SYSTEMS_TARGET_DIR#}{$(NSIGHT_SYSTEMS_TARGET_DIR)}g;' \
	-e 's{#UPSTREAM_HOST_ARCH#}{$(UPSTREAM_HOST_ARCH)}g;' \
	< $< > $@

# $1 = <lib_basename>, $2 = <soversion>
define sover-template
$(1).VERSION_PREFIX	?= $$($(1)$(2).VERSION_PREFIX)
$(1)$(2).VERSION	?= $$($(1).VERSION)
$(1)$(2).%:: $(1)SOVER.%
	perl -p \
	-e 's{#SOVERSION#}{$(2)}g;' \
	-e 's{#VERSION#}{$$(or $$($(1).LIBVERSION),$$($(1).VERSION),$$(error $(1).VERSION))}g;' \
	< $$< > $$@
endef
$(foreach lib,$(LIB_BASENAMES),$(eval $(call sover-template,$(lib),$($(lib).SOVERSION))))

debian/g++: debian/gcc
	sed '/prog=/s/gcc-/g++-/g' < $< > $@
	chmod 0755 $< $@

# only invoked manually
check-whitespace:
	grep -r --exclude-dir=.svn --exclude-dir=.git --exclude '*.patch*' -E '\s$$' debian || true

############################################################################

# $1 = <arch>
get_origdir		 = $(or $(ORIGDIR.$(strip $1)),$(ORIGDIR_BASE)-$(strip $1))
get_tarball		 = $(or $(TARBALL.$(strip $1)),$(TARBALL_BASE)-$(strip $1))$(TARBALL_SUFFIX)

# these must be defined in rules.defs
get_dl_url		?= $(error Undefined: get_dl_url)
get_dl_filename		?= $(error Undefined: get_dl_filename)
get_dl_type		?= $(error Undefined: get_dl_type)

UPSTREAM_NAME		 = nvidia-cuda-toolkit
UPSTREAM_VERSION	 = $(CUDA_VERSION_TOOLKIT)
CUDA_TARBALL_LIST	 = $(foreach a,$(CUDA_ARCH_LIST),$(call get_tarball,$a))
OPENJDK_ARCH_LIST	 = $(filter-out $(CUDA_ARCH_LIST_NO_OPENJDK),$(CUDA_ARCH_LIST))
OPENJDK_TARBALL_LIST	 = $(sort $(foreach a,$(OPENJDK_ARCH_LIST),$(foreach j,source jre,$(call get_tarball,$(call get_openjdk_$(j)_component,$a)))))
TARBALL_LIST		 = $(call get_tarball,empty)
TARBALL_LIST		+= $(CUDA_TARBALL_LIST)
TARBALL_LIST		+= $(OPENJDK_TARBALL_LIST)

CACHE			?= ../.cache
COMPRESS_EXT		?= gz
COMPRESS.gz		?= gzip -n9
COMPRESS.xz		?= xz -T+1 -9
ORIGDIR_BASE		?= $(UPSTREAM_NAME)-$(UPSTREAM_VERSION).orig
TARBALL_BASE		?= $(UPSTREAM_NAME)_$(UPSTREAM_VERSION).orig
TARBALL_SUFFIX		?= .tar.$(COMPRESS_EXT)
ORIGDIR.empty		?= $(ORIGDIR_BASE)
TARBALL.empty		?= $(TARBALL_BASE)

# per-target variables
origdir			 = $(error Undefined: origdir)
tarball			 = $(error Undefined: tarball)
openjdk_arch		 = $(error Undefined: openjdk_arch)
openjdk_version		 = $(error Undefined: openjdk_version)

get-orig-source-prepare:
	$(RM) -r get-orig-source
	mkdir get-orig-source

get-orig-source-prepare/%: get-orig-source-prepare
	$(RM) $(tarball)
	mkdir get-orig-source/$(origdir)

get-orig-source-download/%: dl_filename = $(call get_dl_filename,$*)
get-orig-source-download/%: get-orig-source-prepare
	ln -v $(CACHE)/$(dl_filename) get-orig-source/ 2>/dev/null || \
		wget $(call get_dl_url,$*) -O get-orig-source/$(dl_filename)
	if [ -d $(CACHE) ] && [ ! -f $(CACHE)/$(dl_filename) ]; then \
		ln -v get-orig-source/$(dl_filename) $(CACHE) ; fi

get-orig-source-download-openjdk-8-source/%: get-orig-source-prepare/%
	cd get-orig-source/$(origdir) && (apt-get source -d openjdk-8=$(openjdk_version) || debsnap -v -f -d . openjdk-8 $(openjdk_version))

get-orig-source-download-openjdk-8-jre/%: get-orig-source-prepare/%
	cd get-orig-source/$(origdir) && (apt-get download openjdk-8-jre:$(openjdk_arch)=$(openjdk_version) || debsnap -v -f -a $(openjdk_arch) -d . openjdk-8-jre $(openjdk_version))
	cd get-orig-source/$(origdir) && (apt-get download openjdk-8-jre-headless:$(openjdk_arch)=$(openjdk_version) || debsnap -v -f -a $(openjdk_arch) -d . openjdk-8-jre-headless $(openjdk_version))

# unpack the all-in-one .run cuda installer containing toolkit, driver and samples
get-orig-source-run-unpack/%: get-orig-source-prepare/% get-orig-source-download/%
	@set -e -x ; \
	    cd get-orig-source ; \
	    sh $(call get_dl_filename,$*) --nox11 --noexec --keep --target tmp.$* ; \
	    find tmp.$* -ls ; \
	    if [ -d tmp.$*/builds/cuda-toolkit ]; then \
		mv tmp.$*/builds/cuda-toolkit/* $(origdir)/ ; \
	    elif [ -d tmp.$*/builds/cuda_cudart ]; then \
		$(RM) -v tmp.$*/builds/NVIDIA-Linux*.run ; \
		mv tmp.$*/builds/* $(origdir)/ ; \
	    else \
	        false ; \
	    fi ; \
	    $(RM) -r tmp.$*

get-orig-source-files/%: get-orig-source-unpack/%
	@set -e -x ; \
	    cd get-orig-source ; \
	    touch $(origdir).stamp -r $$(find $(origdir) -type f | xargs -r ls -tr | tail -n 1)

get-orig-source-files/empty: origdir = $(call get_origdir,empty)
get-orig-source-files/empty: get-orig-source-prepare/empty $(CUDA_TARBALL_LIST)
	touch get-orig-source/$(origdir).stamp -r $$(ls -tr $(CUDA_TARBALL_LIST) | tail -n 1)

get-orig-source-pack/%: origdir = $(call get_origdir,$*)
get-orig-source-pack/%: tarball = $(call get_tarball,$*)
get-orig-source-pack/%: get-orig-source-files/%
	@set -e -x ; \
	    cd get-orig-source ; \
	    tar cfv - \
	        --clamp-mtime --mtime="./$(origdir).stamp" \
		--sort=name \
		--owner=root --group=src \
		$(origdir) \
		| $(COMPRESS.$(COMPRESS_EXT)) > $(tarball); \
	    touch $(tarball) -r $(origdir).stamp
	mv get-orig-source/$(tarball) .

$(call get_tarball,empty): get-orig-source-pack/empty

# $1 = <arch>
define get-orig-source-template
get-orig-source-unpack/$1: get-orig-source-$$(call get_dl_type,$1)-unpack/$1
$$(call get_tarball,$1): get-orig-source-pack/$1
endef

# $1 = <arch>, $2 = <component>, $3 = source|jre
define get-orig-source-openjdk-8-template
ORIGDIR.$2	?= $$(UPSTREAM_NAME).orig-$2
$$(call get_tarball,$2): openjdk_arch=$1
$$(call get_tarball,$2): openjdk_version=$$(call aval,OPENJDK_VERSION,$1)
get-orig-source-unpack/$2: get-orig-source-download-openjdk-8-$3/$2
$$(call get_tarball,$2): get-orig-source-pack/$2
endef

# $1 = <arch>
define get-orig-source-openjdk-8-source-template
$(call get-orig-source-openjdk-8-template,$1,$$(call get_openjdk_source_component,$1),source)
endef

# $1 = <arch>
define get-orig-source-openjdk-8-jre-template
$(call get-orig-source-openjdk-8-template,$1,$$(call get_openjdk_jre_component,$1),jre)
endef

$(foreach a,$(CUDA_ARCH_LIST),\
	$(eval $(call get-orig-source-template,$a))\
	$(eval $(call get-orig-source-openjdk-8-source-template,$a))\
	$(eval $(call get-orig-source-openjdk-8-jre-template,$a)))

get-orig-source-openjdk-8: $(OPENJDK_TARBALL_LIST)

.PHONY: get-orig-source
get-orig-source: $(TARBALL_LIST)
	$(RM) -r get-orig-source

list-tarballs:
	@for t in $(TARBALL_LIST) ; do echo "$$t" ; done

############################################################################

# The tarballs are kept in a separate git repository and use the git-lfs
# storage backend. To keep the local disk usage low, this repository is
# checked out sparsely, only tarballs for versions that have been built
# locally will be available locally.

GIT			?= git
TARBALL_REPOSITORY	 = https://salsa.debian.org/nvidia-team/tarballs-$(UPSTREAM_NAME).git
TARBALL_TREE		 = ../tarballs-$(UPSTREAM_NAME)

define sparse-checkout-current
	grep '^$(UPSTREAM_VERSION)/' $(TARBALL_TREE)/.git/info/sparse-checkout || \
		echo '$(UPSTREAM_VERSION)/*' >> $(TARBALL_TREE)/.git/info/sparse-checkout

endef

define test-file-exists
	test -f $1

endef

$(TARBALL_TREE):
	$(RM) -r $@.tmp
	$(GIT) clone --no-checkout $(TARBALL_REPOSITORY) $@.tmp
	cd $@.tmp && $(GIT) lfs install --local
	cd $@.tmp && $(GIT) config --local core.sparsecheckout true
	echo .gitattributes >> $@.tmp/.git/info/sparse-checkout
	cd $@.tmp && $(GIT) checkout
	mv $@.tmp $@

$(TARBALL_TREE)/$(UPSTREAM_VERSION): | $(TARBALL_TREE)
	$(sparse-checkout-current)
	cd $(TARBALL_TREE) && $(GIT) pull --ff-only && $(GIT) checkout

tarball-tree: $(TARBALL_TREE)

# only invoked manually
writable-tarball-tree: tarball-tree
	cd $(TARBALL_TREE) && $(GIT) remote set-url origin $(patsubst https://salsa.debian.org/%,git@salsa.debian.org:%,$(TARBALL_REPOSITORY))

# invoked from gbp buildpackage preexport hook
check-current-tarballs: $(TARBALL_TREE)/$(UPSTREAM_VERSION)
	$(foreach t,$(TARBALL_LIST),$(call test-file-exists,$(TARBALL_TREE)/$(UPSTREAM_VERSION)/$t))

# only invoked manually
commit-current-tarballs: get-orig-source
	$(sparse-checkout-current)
	mkdir -p $(TARBALL_TREE)/$(UPSTREAM_VERSION)
	mv $(TARBALL_LIST) $(TARBALL_TREE)/$(UPSTREAM_VERSION)/
	cd $(TARBALL_TREE) && $(GIT) add $(UPSTREAM_VERSION) && if $(GIT) status -s $(UPSTREAM_VERSION) | grep ^A ; then $(GIT) commit -m "add $(UPSTREAM_VERSION) tarballs" $(UPSTREAM_VERSION) ; fi