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
|
#
# nvidia-installer: A tool for installing NVIDIA software packages on
# Unix and Linux systems.
#
# Copyright (C) 2008 NVIDIA Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses>.
#
#
# Makefile
#
##############################################################################
# include common variables and functions
##############################################################################
include utils.mk
##############################################################################
# The calling Makefile may export any of the following variables; we
# assign default values if they are not exported by the caller
##############################################################################
NCURSES_CFLAGS ?=
NCURSES_LDFLAGS ?=
PCIACCESS_CFLAGS ?=
PCIACCESS_LDFLAGS ?=
##############################################################################
# assign variables
##############################################################################
NVIDIA_INSTALLER = $(OUTPUTDIR)/nvidia-installer
MKPRECOMPILED = $(OUTPUTDIR)/mkprecompiled
MAKESELF_HELP_SCRIPT = $(OUTPUTDIR)/makeself-help-script
MAKESELF_HELP_SCRIPT_SH = $(OUTPUTDIR)/makeself-help-script.sh
NVIDIA_INSTALLER_PROGRAM_NAME = "nvidia-installer"
NVIDIA_INSTALLER_VERSION := $(NVIDIA_VERSION)
# We only need to run the TLS test on Linux-x86 and Linux-x86_64
ifeq ($(findstring Linux-x86,$(TARGET_OS)-$(TARGET_ARCH)),)
NEED_TLS_TEST =
else
NEED_TLS_TEST = 1
endif
NCURSES_UI_C = ncurses-ui.c
NCURSES_UI_SO = $(OUTPUTDIR)/nvidia-installer-ncurses-ui.so
NCURSES_UI_SO_C = $(OUTPUTDIR)/g_$(notdir $(NCURSES_UI_SO:.so=.c))
ifneq ($(NEED_TLS_TEST),)
TLS_TEST_C = $(OUTPUTDIR)/g_tls_test.c
TLS_TEST_DSO_C = $(OUTPUTDIR)/g_tls_test_dso.c
TLS_TEST = tls_test_$(TARGET_OS)-$(TARGET_ARCH)
TLS_TEST_DSO_SO = tls_test_dso_$(TARGET_OS)-$(TARGET_ARCH).so
TLS_TEST_32_C = $(OUTPUTDIR)/g_tls_test_32.c
TLS_TEST_DSO_32_C = $(OUTPUTDIR)/g_tls_test_dso_32.c
TLS_TEST_32 = tls_test_$(TARGET_OS)-x86
TLS_TEST_DSO_SO_32 = tls_test_dso_$(TARGET_OS)-x86.so
else
TLS_TEST_C =
TLS_TEST_DSO_C =
TLS_TEST =
TLS_TEST_DSO_SO =
TLS_TEST_32_C =
TLS_TEST_DSO_32_C =
TLS_TEST_32 =
TLS_TEST_DSO_SO_32 =
endif
RTLD_TEST_C = $(OUTPUTDIR)/g_rtld_test.c
RTLD_TEST = rtld_test_$(TARGET_OS)-$(TARGET_ARCH)$(if $(TARGET_ARCH_ABI),-$(TARGET_ARCH_ABI))
RTLD_TEST_32_C = $(OUTPUTDIR)/g_rtld_test_32.c
RTLD_TEST_32 = rtld_test_$(TARGET_OS)-x86
GEN_UI_ARRAY = $(OUTPUTDIR)/gen-ui-array
CONFIG_H = $(OUTPUTDIR)/config.h
MANPAGE = $(OUTPUTDIR)/nvidia-installer.1.gz
GEN_MANPAGE_OPTS = $(OUTPUTDIR_ABSOLUTE)/gen-manpage-opts
OPTIONS_1_INC = $(OUTPUTDIR)/options.1.inc
# Setup some architecture specific build options
ifeq ($(TARGET_OS)-$(TARGET_ARCH), Linux-x86_64)
TLS_MODEL = initial-exec
PIC = -fPIC
# Only Linux-x86_64 needs the tls_test_32 files
COMPAT_32_SRC = $(TLS_TEST_32_C) $(TLS_TEST_DSO_32_C) \
$(RTLD_TEST_32_C)
else
# So far all other platforms use local-exec
TLS_MODEL = local-exec
PIC =
# Non-Linux-x86_64 platforms do not include the tls_test_32 files
COMPAT_32_SRC =
endif
##############################################################################
# The common-utils directory may be in one of two places: either
# elsewhere in the driver source tree when building nvidia-installer
# as part of the NVIDIA driver build (in which case, COMMON_UTILS_DIR
# should be defined by the calling makefile), or directly in the
# source directory when building from the nvidia-installer source
# tarball (in which case, the below conditional assignments should be
# used)
##############################################################################
COMMON_UTILS_DIR ?= common-utils
# include the list of source files; defines SRC
include dist-files.mk
include $(COMMON_UTILS_DIR)/src.mk
SRC += $(addprefix $(COMMON_UTILS_DIR)/,$(COMMON_UTILS_SRC))
INSTALLER_SRC = $(SRC) $(NCURSES_UI_SO_C) $(TLS_TEST_C) $(TLS_TEST_DSO_C) \
$(RTLD_TEST_C) $(COMPAT_32_SRC) $(STAMP_C)
INSTALLER_OBJS = $(call BUILD_OBJECT_LIST,$(INSTALLER_SRC))
common_cflags = -I.
common_cflags += -imacros $(CONFIG_H)
common_cflags += -I $(OUTPUTDIR)
common_cflags += -I $(COMMON_UTILS_DIR)
common_cflags += $(if $(NEED_TLS_TEST),-DNV_TLS_TEST)
CFLAGS += $(common_cflags)
HOST_CFLAGS += $(common_cflags)
LDFLAGS += -L.
LIBS += -ldl
MKPRECOMPILED_SRC = crc.c mkprecompiled.c $(COMMON_UTILS_DIR)/common-utils.c \
precompiled.c $(COMMON_UTILS_DIR)/nvgetopt.c
MKPRECOMPILED_OBJS = $(call BUILD_OBJECT_LIST,$(MKPRECOMPILED_SRC))
MAKESELF_HELP_SCRIPT_SRC = makeself-help-script.c
MAKESELF_HELP_SCRIPT_SRC += $(COMMON_UTILS_DIR)/common-utils.c
MAKESELF_HELP_SCRIPT_SRC += $(COMMON_UTILS_DIR)/nvgetopt.c
MAKESELF_HELP_SCRIPT_SRC += $(COMMON_UTILS_DIR)/msg.c
BUILD_MAKESELF_OBJECT_LIST = \
$(patsubst %.o,%.makeself.o,$(call BUILD_OBJECT_LIST,$(1)))
MAKESELF_HELP_SCRIPT_OBJS = \
$(call BUILD_MAKESELF_OBJECT_LIST,$(MAKESELF_HELP_SCRIPT_SRC))
ALL_SRC = $(sort $(INSTALLER_SRC) $(NCURSES_UI_C) $(MKPRECOMPILED_SRC))
# define a quiet rule for GEN-UI-ARRAY
quiet_GEN_UI_ARRAY = GEN-UI-ARRAY $@
##############################################################################
# build rules
##############################################################################
.PNONY: all install NVIDIA_INSTALLER_install MKPRECOMPILED_install \
MANPAGE_install MAKESELF_HELP_SCRIPT_install clean clobber
all: $(NVIDIA_INSTALLER) $(MKPRECOMPILED) $(MAKESELF_HELP_SCRIPT) \
$(MAKESELF_HELP_SCRIPT_SH) $(MANPAGE)
install: NVIDIA_INSTALLER_install MKPRECOMPILED_install MANPAGE_install \
MAKESELF_HELP_SCRIPT_install
NVIDIA_INSTALLER_install: $(NVIDIA_INSTALLER)
$(MKDIR) $(BINDIR)
$(INSTALL) $(INSTALL_BIN_ARGS) $< $(BINDIR)/$(notdir $<)
MKPRECOMPILED_install: $(MKPRECOMPILED)
$(MKDIR) $(BINDIR)
$(INSTALL) $(INSTALL_BIN_ARGS) $< $(BINDIR)/$(notdir $<)
MAKESELF_HELP_SCRIPT_install: $(MAKESELF_HELP_SCRIPT)
$(MKDIR) $(BINDIR)
$(INSTALL) $(INSTALL_BIN_ARGS) $< $(BINDIR)/$(notdir $<)
MANPAGE_install: $(MANPAGE)
$(MKDIR) $(MANDIR)
$(INSTALL) $(INSTALL_DOC_ARGS) $< $(MANDIR)/$(notdir $<)
$(MKPRECOMPILED): $(MKPRECOMPILED_OBJS)
$(call quiet_cmd,LINK) $(CFLAGS) $(LDFLAGS) $(BIN_LDFLAGS) \
$(MKPRECOMPILED_OBJS) -o $@ $(LIBS)
$(call quiet_cmd,STRIP_CMD) $@
$(MAKESELF_HELP_SCRIPT): $(MAKESELF_HELP_SCRIPT_OBJS)
$(call quiet_cmd,HOST_LINK) $(HOST_CFLAGS) $(HOST_LDFLAGS) \
$(HOST_BIN_LDFLAGS) $(MAKESELF_HELP_SCRIPT_OBJS) -o $@
$(NVIDIA_INSTALLER): $(INSTALLER_OBJS)
$(call quiet_cmd,LINK) $(CFLAGS) $(LDFLAGS) $(PCIACCESS_LDFLAGS) \
$(BIN_LDFLAGS) $(INSTALLER_OBJS) -o $@ \
$(LIBS) -Bstatic -lpciaccess -Bdynamic
$(call quiet_cmd,STRIP_CMD) $@
$(GEN_UI_ARRAY): gen-ui-array.c $(CONFIG_H)
$(call quiet_cmd,HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) \
$(HOST_BIN_LDFLAGS) $< -o $@
$(NCURSES_UI_SO): $(call BUILD_OBJECT_LIST,ncurses-ui.c)
$(call quiet_cmd,LINK) -shared $(NCURSES_LDFLAGS) \
$(CFLAGS) $(LDFLAGS) $(BIN_LDFLAGS) $< -o $@ -lncurses $(LIBS)
$(NCURSES_UI_SO_C): $(GEN_UI_ARRAY) $(NCURSES_UI_SO)
$(call quiet_cmd,GEN_UI_ARRAY) $(NCURSES_UI_SO) ncurses_ui_array > $@
ifneq ($(NEED_TLS_TEST),)
$(TLS_TEST_C): $(GEN_UI_ARRAY) $(TLS_TEST)
$(call quiet_cmd,GEN_UI_ARRAY) $(TLS_TEST) tls_test_array > $@
$(TLS_TEST_DSO_C): $(GEN_UI_ARRAY) $(TLS_TEST_DSO_SO)
$(call quiet_cmd,GEN_UI_ARRAY) \
$(TLS_TEST_DSO_SO) tls_test_dso_array > $@
$(TLS_TEST_32_C): $(GEN_UI_ARRAY) $(TLS_TEST_32)
$(call quiet_cmd,GEN_UI_ARRAY) $(TLS_TEST_32) tls_test_array_32 > $@
$(TLS_TEST_DSO_32_C): $(GEN_UI_ARRAY) $(TLS_TEST_DSO_SO_32)
$(call quiet_cmd,GEN_UI_ARRAY) \
$(TLS_TEST_DSO_SO_32) tls_test_dso_array_32 > $@
endif
$(RTLD_TEST_C): $(GEN_UI_ARRAY) $(RTLD_TEST)
$(call quiet_cmd,GEN_UI_ARRAY) $(RTLD_TEST) rtld_test_array > $@
$(RTLD_TEST_32_C): $(GEN_UI_ARRAY) $(RTLD_TEST_32)
$(call quiet_cmd,GEN_UI_ARRAY) $(RTLD_TEST_32) rtld_test_array_32 > $@
# misc.c includes pciaccess.h
$(call BUILD_OBJECT_LIST,misc.c): CFLAGS += $(PCIACCESS_CFLAGS)
# ncurses-ui.c includes ncurses.h
$(call BUILD_OBJECT_LIST,ncurses-ui.c): CFLAGS += $(NCURSES_CFLAGS) -fPIC
# define the rule to build each object file
$(foreach src,$(ALL_SRC),$(eval $(call DEFINE_OBJECT_RULE,TARGET,$(src))))
# define a rule to build each makeself-help-script object file
$(foreach src,$(MAKESELF_HELP_SCRIPT_SRC),\
$(eval $(call DEFINE_OBJECT_RULE_WITH_OBJECT_NAME,HOST,$(src),\
$(call BUILD_MAKESELF_OBJECT_LIST,$(src)))))
# define the rule to generate $(STAMP_C)
$(eval $(call DEFINE_STAMP_C_RULE, $(INSTALLER_OBJS),$(NVIDIA_INSTALLER_PROGRAM_NAME)))
$(CONFIG_H): $(VERSION_MK)
@ $(RM) -f $@
@ $(MKDIR) $(OUTPUTDIR)
@ $(ECHO) "#define INSTALLER_OS \"$(TARGET_OS)\"" >> $@
@ $(ECHO) "#define INSTALLER_ARCH \"$(TARGET_ARCH)\"" >> $@
@ $(ECHO) -n "#define NVIDIA_INSTALLER_VERSION " >> $@
@ $(ECHO) "\"$(NVIDIA_INSTALLER_VERSION)\"" >> $@
@ $(ECHO) -n "#define PROGRAM_NAME " >> $@
@ $(ECHO) "\"$(NVIDIA_INSTALLER_PROGRAM_NAME)\"" >> $@
$(call BUILD_OBJECT_LIST,$(ALL_SRC)): $(CONFIG_H)
$(call BUILD_MAKESELF_OBJECT_LIST,$(MAKESELF_HELP_SCRIPT_SRC)): $(CONFIG_H)
clean clobber:
rm -rf $(OUTPUTDIR)
##############################################################################
# rule to rebuild tls_test and tls_test_dso; a precompiled tls_test
# and tls_test_dso is distributed with nvidia_installer because they
# require a recent toolchain to build.
##############################################################################
rebuild_tls_test: tls_test.c
gcc -Wall -O2 -fomit-frame-pointer -o $(TLS_TEST) -ldl $<
strip $(TLS_TEST)
rebuild_tls_test_dso: tls_test_dso.c
gcc -Wall -O2 $(PIC) -fomit-frame-pointer -c $< \
-ftls-model=$(TLS_MODEL)
gcc -o $(TLS_TEST_DSO_SO) -shared tls_test_dso.o
strip $(TLS_TEST_DSO_SO)
# dummy rule to override implicit rule that builds tls_test from
# tls_test.c
tls_test: tls_test.c
touch $@
# rule to rebuild rtld_test; a precompiled rtld_test is distributed with
# nvidia-installer to simplify x86-64 builds.
rebuild_rtld_test: rtld_test.c $(CONFIG_H)
$(call quiet_cmd,LINK) $(CFLAGS) $(LDFLAGS) $(BIN_LDFLAGS) -o $(RTLD_TEST) -lGL $<
$(call quiet_cmd,STRIP_CMD) $(RTLD_TEST)
# dummy rule to override implicit rule that builds dls_test from
# rtld_test.c
rtld_test: rtld_test.c
touch $@
##############################################################################
# rule to build MAKESELF_HELP_SCRIPT_SH; this shell script is packaged
# with the driver so that the script can be run on any platform when
# the driver is later repackaged
##############################################################################
$(MAKESELF_HELP_SCRIPT_SH): $(MAKESELF_HELP_SCRIPT)
@ $(ECHO) "#!/bin/sh" > $@
@ $(ECHO) "while [ \"\$$1\" ]; do" >> $@
@ $(ECHO) " case \$$1 in" >> $@
@ $(ECHO) " \"--advanced-options-args-only\")" >> $@
@ $(ECHO) " cat <<- \"ADVANCED_OPTIONS_ARGS_ONLY\"" >> $@
$(MAKESELF_HELP_SCRIPT) --advanced-options-args-only >> $@
@ $(ECHO) "ADVANCED_OPTIONS_ARGS_ONLY" >> $@
@ $(ECHO) " ;;" >> $@
@ $(ECHO) " \"--help-args-only\")" >> $@
@ $(ECHO) " cat <<- \"HELP_ARGS_ONLY\"" >> $@
$(MAKESELF_HELP_SCRIPT) --help-args-only >> $@
@ $(ECHO) "HELP_ARGS_ONLY" >> $@
@ $(ECHO) " ;;" >> $@
@ $(ECHO) " *)" >> $@
@ $(ECHO) " echo \"unrecognized option '$$1'"\" >> $@
@ $(ECHO) " break" >> $@
@ $(ECHO) " ;;" >> $@
@ $(ECHO) " esac" >> $@
@ $(ECHO) " shift" >> $@
@ $(ECHO) "done" >> $@
$(CHMOD) u+x $@
##############################################################################
# Documentation
##############################################################################
AUTO_TEXT = ".\\\" WARNING: THIS FILE IS AUTO-GENERATED! Edit $< instead."
doc: $(MANPAGE)
GEN_MANPAGE_OPTS_SRC = gen-manpage-opts.c
GEN_MANPAGE_OPTS_SRC += $(COMMON_UTILS_DIR)/gen-manpage-opts-helper.c
GEN_MANPAGE_OPTS_OBJS = $(call BUILD_OBJECT_LIST,$(GEN_MANPAGE_OPTS_SRC))
$(foreach src, $(GEN_MANPAGE_OPTS_SRC), \
$(eval $(call DEFINE_OBJECT_RULE,HOST,$(src))))
$(GEN_MANPAGE_OPTS_OBJS): $(CONFIG_H)
$(GEN_MANPAGE_OPTS): $(GEN_MANPAGE_OPTS_OBJS)
$(call quiet_cmd,HOST_LINK) \
$(HOST_CFLAGS) $(HOST_LDFLAGS) $(HOST_BIN_LDFLAGS) $^ -o $@
$(OPTIONS_1_INC): $(GEN_MANPAGE_OPTS)
@$< > $@
$(MANPAGE): nvidia-installer.1.m4 $(OPTIONS_1_INC) $(VERSION_MK)
$(call quiet_cmd,M4) \
-D__HEADER__=$(AUTO_TEXT) \
-D__VERSION__=$(NVIDIA_INSTALLER_VERSION) \
-D__DATE__="`$(DATE) +%F`" \
-D__INSTALLER_OS__="$(TARGET_OS)" \
-D__INSTALLER_ARCH__="$(TARGET_ARCH)" \
-D__DRIVER_VERSION__="$(NVIDIA_VERSION)" \
-D__OUTPUTDIR__=$(OUTPUTDIR) \
-I $(OUTPUTDIR) \
$< | $(GZIP_CMD) -9f > $@
|