1################################################################################
2#
3# nvidia-driver
4#
5################################################################################
6
7NVIDIA_DRIVER_VERSION = 390.151
8NVIDIA_DRIVER_SUFFIX = $(if $(BR2_x86_64),_64)
9NVIDIA_DRIVER_SITE = http://download.nvidia.com/XFree86/Linux-x86$(NVIDIA_DRIVER_SUFFIX)/$(NVIDIA_DRIVER_VERSION)
10NVIDIA_DRIVER_SOURCE = NVIDIA-Linux-x86$(NVIDIA_DRIVER_SUFFIX)-$(NVIDIA_DRIVER_VERSION)$(if $(BR2_x86_64),-no-compat32).run
11NVIDIA_DRIVER_LICENSE = NVIDIA Software License
12NVIDIA_DRIVER_LICENSE_FILES = LICENSE
13NVIDIA_DRIVER_REDISTRIBUTE = NO
14NVIDIA_DRIVER_INSTALL_STAGING = YES
15
16ifeq ($(BR2_PACKAGE_NVIDIA_DRIVER_XORG),y)
17
18# Since nvidia-driver are binary blobs, the below dependencies are not
19# strictly speaking build dependencies of nvidia-driver. However, they
20# are build dependencies of packages that depend on nvidia-driver, so
21# they should be built prior to those packages, and the only simple
22# way to do so is to make nvidia-driver depend on them.
23NVIDIA_DRIVER_DEPENDENCIES += mesa3d-headers xlib_libX11 xlib_libXext
24NVIDIA_DRIVER_PROVIDES += libgl libegl libgles
25
26# libGL.so.$(NVIDIA_DRIVER_VERSION) is the legacy libGL.so library; it
27# has been replaced with libGL.so.1.0.0. Installing both is technically
28# possible, but great care must be taken to ensure they do not conflict,
29# so that EGL still works. The legacy library exposes an NVidia-specific
30# API, so it should not be needed, except for legacy, binary-only
31# applications (in other words: we don't care).
32#
33# libGL.so.1.0.0 is the new vendor-neutral library, aimed at replacing
34# the old libGL.so.$(NVIDIA_DRIVER_VERSION) library. The latter contains
35# NVidia extensions (which is deemed bad now), while the former follows
36# the newly-introduced vendor-neutral "dispatching" API/ABI:
37#   https://github.com/aritger/linux-opengl-abi-proposal/blob/master/linux-opengl-abi-proposal.txt
38# However, this is not very useful to us, as we don't support multiple
39# GL providers at the same time on the system, which this proposal is
40# aimed at supporting.
41#
42# So we only install the legacy library for now.
43NVIDIA_DRIVER_LIBS_GL = \
44	libGLX.so.0 \
45	libGL.so.$(NVIDIA_DRIVER_VERSION) \
46	libGLX_nvidia.so.$(NVIDIA_DRIVER_VERSION)
47
48NVIDIA_DRIVER_LIBS_EGL = \
49	libEGL.so.1.1.0 \
50	libGLdispatch.so.0 \
51	libEGL_nvidia.so.$(NVIDIA_DRIVER_VERSION)
52
53NVIDIA_DRIVER_LIBS_GLES = \
54	libGLESv1_CM.so.1.2.0 \
55	libGLESv2.so.2.1.0 \
56	libGLESv1_CM_nvidia.so.$(NVIDIA_DRIVER_VERSION) \
57	libGLESv2_nvidia.so.$(NVIDIA_DRIVER_VERSION)
58
59NVIDIA_DRIVER_LIBS_MISC = \
60	libnvidia-eglcore.so.$(NVIDIA_DRIVER_VERSION) \
61	libnvidia-egl-wayland.so.1.0.2 \
62	libnvidia-glcore.so.$(NVIDIA_DRIVER_VERSION) \
63	libnvidia-glsi.so.$(NVIDIA_DRIVER_VERSION) \
64	tls/libnvidia-tls.so.$(NVIDIA_DRIVER_VERSION) \
65	libvdpau_nvidia.so.$(NVIDIA_DRIVER_VERSION):vdpau/ \
66	libnvidia-ml.so.$(NVIDIA_DRIVER_VERSION)
67
68NVIDIA_DRIVER_LIBS += \
69	$(NVIDIA_DRIVER_LIBS_GL) \
70	$(NVIDIA_DRIVER_LIBS_EGL) \
71	$(NVIDIA_DRIVER_LIBS_GLES) \
72	$(NVIDIA_DRIVER_LIBS_MISC)
73
74# Install the gl.pc file
75define NVIDIA_DRIVER_INSTALL_GL_DEV
76	$(INSTALL) -D -m 0644 $(@D)/libGL.la $(STAGING_DIR)/usr/lib/libGL.la
77	$(SED) 's:__GENERATED_BY__:Buildroot:' $(STAGING_DIR)/usr/lib/libGL.la
78	$(SED) 's:__LIBGL_PATH__:/usr/lib:' $(STAGING_DIR)/usr/lib/libGL.la
79	$(SED) 's:-L[^[:space:]]\+::' $(STAGING_DIR)/usr/lib/libGL.la
80	$(INSTALL) -D -m 0644 package/nvidia-driver/gl.pc $(STAGING_DIR)/usr/lib/pkgconfig/gl.pc
81	$(INSTALL) -D -m 0644 package/nvidia-driver/egl.pc $(STAGING_DIR)/usr/lib/pkgconfig/egl.pc
82endef
83
84# Those libraries are 'private' libraries requiring an agreement with
85# NVidia to develop code for those libs. There seems to be no restriction
86# on using those libraries (e.g. if the user has such an agreement, or
87# wants to run a third-party program developed under such an agreement).
88ifeq ($(BR2_PACKAGE_NVIDIA_DRIVER_PRIVATE_LIBS),y)
89NVIDIA_DRIVER_LIBS += \
90	libnvidia-ifr.so.$(NVIDIA_DRIVER_VERSION) \
91	libnvidia-fbc.so.$(NVIDIA_DRIVER_VERSION)
92endif
93
94# We refer to the destination path; the origin file has no directory component
95NVIDIA_DRIVER_LIBS += \
96	nvidia_drv.so:xorg/modules/drivers/ \
97	libglx.so.$(NVIDIA_DRIVER_VERSION):xorg/modules/extensions/
98
99# libglx needs a symlink according to the driver README. It has no SONAME
100define NVIDIA_DRIVER_SYMLINK_LIBGLX
101	ln -sf libglx.so.$(NVIDIA_DRIVER_VERSION) \
102		$(TARGET_DIR)/usr/lib/xorg/modules/extensions/libglx.so
103endef
104
105endif # X drivers
106
107ifeq ($(BR2_PACKAGE_NVIDIA_DRIVER_CUDA),y)
108NVIDIA_DRIVER_LIBS += \
109	libcuda.so.$(NVIDIA_DRIVER_VERSION) \
110	libnvidia-compiler.so.$(NVIDIA_DRIVER_VERSION) \
111	libnvcuvid.so.$(NVIDIA_DRIVER_VERSION) \
112	libnvidia-fatbinaryloader.so.$(NVIDIA_DRIVER_VERSION) \
113	libnvidia-ptxjitcompiler.so.$(NVIDIA_DRIVER_VERSION) \
114	libnvidia-encode.so.$(NVIDIA_DRIVER_VERSION)
115ifeq ($(BR2_PACKAGE_NVIDIA_DRIVER_CUDA_PROGS),y)
116NVIDIA_DRIVER_PROGS = nvidia-cuda-mps-control nvidia-cuda-mps-server
117endif
118endif
119
120ifeq ($(BR2_PACKAGE_NVIDIA_DRIVER_OPENCL),y)
121NVIDIA_DRIVER_LIBS += \
122	libOpenCL.so.1.0.0 \
123	libnvidia-opencl.so.$(NVIDIA_DRIVER_VERSION)
124NVIDIA_DRIVER_DEPENDENCIES += mesa3d-headers
125NVIDIA_DRIVER_PROVIDES += libopencl
126endif
127
128# Build and install the kernel modules if needed
129ifeq ($(BR2_PACKAGE_NVIDIA_DRIVER_MODULE),y)
130
131NVIDIA_DRIVER_MODULES = nvidia nvidia-modeset nvidia-drm
132ifeq ($(BR2_x86_64),y)
133NVIDIA_DRIVER_MODULES += nvidia-uvm
134endif
135
136# They can't do everything like everyone. They need those variables,
137# because they don't recognise the usual variables set by the kernel
138# build system. We also need to tell them what modules to build.
139NVIDIA_DRIVER_MODULE_MAKE_OPTS = \
140	IGNORE_CC_MISMATCH=1 \
141	NV_KERNEL_SOURCES="$(LINUX_DIR)" \
142	NV_KERNEL_OUTPUT="$(LINUX_DIR)" \
143	NV_KERNEL_MODULES="$(NVIDIA_DRIVER_MODULES)"
144
145NVIDIA_DRIVER_MODULE_SUBDIRS = kernel
146
147$(eval $(kernel-module))
148
149endif # BR2_PACKAGE_NVIDIA_DRIVER_MODULE == y
150
151# The downloaded archive is in fact an auto-extract script. So, it can run
152# virtually everywhere, and it is fine enough to provide useful options.
153# Except it can't extract into an existing (even empty) directory.
154define NVIDIA_DRIVER_EXTRACT_CMDS
155	$(SHELL) $(NVIDIA_DRIVER_DL_DIR)/$(NVIDIA_DRIVER_SOURCE) --extract-only --target \
156		$(@D)/tmp-extract
157	chmod u+w -R $(@D)
158	mv $(@D)/tmp-extract/* $(@D)/tmp-extract/.manifest $(@D)
159	rm -rf $(@D)/tmp-extract
160endef
161
162# Helper to install libraries
163# $1: library name
164# $2: target directory
165#
166# For all libraries, we install them and create a symlink using
167# their SONAME, so we can link to them at runtime; we also create
168# the no-version symlink, so we can link to them at build time.
169define NVIDIA_DRIVER_INSTALL_LIB
170	$(INSTALL) -D -m 0644 $(@D)/$(1) $(2)$(notdir $(1))
171	libsoname="$$( $(TARGET_READELF) -d "$(@D)/$(1)" \
172		|sed -r -e '/.*\(SONAME\).*\[(.*)\]$$/!d; s//\1/;' )"; \
173	if [ -n "$${libsoname}" -a "$${libsoname}" != "$(notdir $(1))" ]; then \
174		ln -sf $(notdir $(1)) $(2)$${libsoname}; \
175	fi
176	baseso=$(firstword $(subst .,$(space),$(notdir $(1)))).so; \
177	if [ -n "$${baseso}" -a "$${baseso}" != "$(notdir $(1))" ]; then \
178		ln -sf $(notdir $(1)) $(2)$${baseso}; \
179	fi
180endef
181
182# Helper to install libraries
183# $1: destination directory (target or staging)
184define NVIDIA_DRIVER_INSTALL_LIBS
185	$(foreach lib,$(NVIDIA_DRIVER_LIBS),
186		$(call NVIDIA_DRIVER_INSTALL_LIB,$(word 1,$(subst :, ,$(lib))), \
187			$(1)/usr/lib/$(word 2,$(subst :, ,$(lib))))
188	)
189endef
190
191# For staging, install libraries and development files
192define NVIDIA_DRIVER_INSTALL_STAGING_CMDS
193	$(call NVIDIA_DRIVER_INSTALL_LIBS,$(STAGING_DIR))
194	$(NVIDIA_DRIVER_INSTALL_GL_DEV)
195endef
196
197# For target, install libraries and X.org modules
198define NVIDIA_DRIVER_INSTALL_TARGET_CMDS
199	$(call NVIDIA_DRIVER_INSTALL_LIBS,$(TARGET_DIR))
200	$(foreach p,$(NVIDIA_DRIVER_PROGS), \
201		$(INSTALL) -D -m 0755 $(@D)/$(p) \
202			$(TARGET_DIR)/usr/bin/$(p)
203	)
204	$(NVIDIA_DRIVER_SYMLINK_LIBGLX)
205	$(NVIDIA_DRIVER_INSTALL_KERNEL_MODULE)
206endef
207
208# Due to a conflict with xserver_xorg-server, this needs to be performed when
209# finalizing the target filesystem to make sure this version is used.
210NVIDIA_DRIVER_TARGET_FINALIZE_HOOKS += NVIDIA_DRIVER_SYMLINK_LIBGLX
211
212$(eval $(generic-package))
213