1# 2# Copyright (C) 2008 NVIDIA Corporation 3# 4# Permission is hereby granted, free of charge, to any person obtaining a 5# copy of this software and associated documentation files (the "Software"), 6# to deal in the Software without restriction, including without limitation 7# the rights to use, copy, modify, merge, publish, distribute, sublicense, 8# and/or sell copies of the Software, and to permit persons to whom the 9# Software is furnished to do so, subject to the following conditions: 10# 11# The above copyright notice and this permission notice shall be included in 12# all copies or substantial portions of the Software. 13# 14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20# DEALINGS IN THE SOFTWARE. 21# 22# 23# utils.mk: common Makefile fragment used by nvidia-xconfig, 24# nvidia-installer, and nvidia-settings 25# 26 27 28 29############################################################################## 30# The calling Makefile (when building as part of the NVIDIA graphics 31# driver) may export any of the following variables; we assign default 32# values if they are not exported by the caller 33############################################################################## 34 35CC ?= gcc 36CXX ?= g++ 37LD ?= ld 38AR ?= ar 39# only set these warnings if CFLAGS is unset 40CFLAGS ?= -Wall 41# always set these -f CFLAGS 42CFLAGS += -fno-strict-aliasing -fno-omit-frame-pointer -Wformat=2 43CC_ONLY_CFLAGS ?= -Wstrict-prototypes -Wold-style-definition 44CXX_ONLY_CFLAGS ?= 45LDFLAGS ?= 46BIN_LDFLAGS ?= 47EXTRA_CFLAGS ?= 48 49STACK_USAGE_WARNING ?= 50CFLAGS += $(if $(STACK_USAGE_WARNING),-Wstack-usage=$(STACK_USAGE_WARNING)) 51 52HOST_CC ?= $(CC) 53HOST_LD ?= $(LD) 54HOST_CFLAGS ?= $(CFLAGS) 55HOST_CC_ONLY_CFLAGS ?= 56HOST_CXX_ONLY_CFLAGS ?= 57HOST_LDFLAGS ?= $(LDFLAGS) 58HOST_BIN_LDFLAGS ?= 59 60# always disable warnings that will break the build 61CC_ONLY_CFLAGS += -Wno-format-zero-length 62CFLAGS += -Wno-unused-parameter 63HOST_CC_ONLY_CFLAGS += -Wno-format-zero-length 64HOST_CFLAGS += -Wno-unused-parameter 65 66# Treat warnings as errors, if requested 67WARNINGS_AS_ERRORS ?= 68CFLAGS += $(if $(WARNINGS_AS_ERRORS),-Werror) 69 70DEBUG ?= 71DEVELOP ?= 72 73ifeq ($(DEBUG),1) 74 STRIP_CMD ?= true 75 DO_STRIP ?= 76 CFLAGS += -O0 -g 77 CFLAGS += -DDEBUG=1 78else 79 CFLAGS += -O2 80endif 81 82ifeq ($(DEVELOP),1) 83 STRIP_CMD ?= true 84 DO_STRIP ?= 85 CFLAGS += -DDEVELOP=1 86endif 87 88CFLAGS += $(EXTRA_CFLAGS) 89 90STRIP_CMD ?= strip 91DO_STRIP ?= 1 92 93INSTALL ?= install 94INSTALL_BIN_ARGS ?= -m 755 95INSTALL_LIB_ARGS ?= -m 644 96INSTALL_DOC_ARGS ?= -m 644 97 98M4 ?= m4 99SED ?= sed 100M4 ?= m4 101ECHO ?= echo 102PRINTF ?= printf 103MKDIR ?= mkdir -p 104RM ?= rm -f 105TOUCH ?= touch 106HARDLINK ?= ln -f 107DATE ?= date 108GZIP_CMD ?= gzip 109CHMOD ?= chmod 110OBJCOPY ?= objcopy 111XZ ?= xz 112WHOAMI ?= whoami 113PKG_CONFIG ?= pkg-config 114 115ifndef HOSTNAME 116 HOSTNAME = $(shell hostname) 117endif 118 119 120NV_AUTO_DEPEND ?= 1 121NV_VERBOSE ?= 0 122 123ifndef TARGET_OS 124 TARGET_OS := $(shell uname) 125endif 126 127ifeq ($(TARGET_OS),Linux) 128 CFLAGS += -DNV_LINUX 129endif 130 131ifeq ($(TARGET_OS),FreeBSD) 132 CFLAGS += -DNV_BSD 133endif 134 135ifeq ($(TARGET_OS),SunOS) 136 CFLAGS += -DNV_SUNOS 137endif 138 139ifndef TARGET_ARCH 140 ifneq ($(TARGET_OS),SunOS) 141 TARGET_ARCH := $(shell uname -m) 142 else 143 TARGET_ARCH := $(shell isainfo -n) 144 endif 145 TARGET_ARCH := $(subst i386,x86,$(TARGET_ARCH)) 146 TARGET_ARCH := $(subst i486,x86,$(TARGET_ARCH)) 147 TARGET_ARCH := $(subst i586,x86,$(TARGET_ARCH)) 148 TARGET_ARCH := $(subst i686,x86,$(TARGET_ARCH)) 149 TARGET_ARCH := $(subst amd64,x86_64,$(TARGET_ARCH)) 150endif 151 152ifeq ($(TARGET_ARCH),x86) 153 CFLAGS += -DNV_X86 -DNV_ARCH_BITS=32 154endif 155 156ifeq ($(TARGET_ARCH),x86_64) 157 CFLAGS += -DNV_X86_64 -DNV_ARCH_BITS=64 158endif 159 160ifeq ($(TARGET_ARCH),armv7l) 161 CFLAGS += -DNV_ARMV7 -DNV_ARCH_BITS=32 162endif 163 164ifeq ($(TARGET_ARCH),aarch64) 165 CFLAGS += -DNV_AARCH64 -DNV_ARCH_BITS=64 166endif 167 168ifeq ($(TARGET_ARCH),ppc64le) 169 CFLAGS += -DNV_PPC64LE -DNV_ARCH_BITS=64 170endif 171 172ifeq ($(TARGET_OS),Linux) 173 LIBDL_LIBS = -ldl 174else 175 LIBDL_LIBS = 176endif 177 178# This variable controls which floating-point ABI is targeted. For ARM, it 179# defaults to "gnueabi" for softfp. Another option is "gnueabihf" for 180# hard(fp). This is necessary to pick up the correct rtld_test binary. 181# All other architectures default to empty. 182ifeq ($(TARGET_ARCH),armv7l) 183 TARGET_ARCH_ABI ?= gnueabi 184endif 185TARGET_ARCH_ABI ?= 186 187ifeq ($(TARGET_ARCH_ABI),gnueabi) 188 CFLAGS += -DNV_GNUEABI 189endif 190 191ifeq ($(TARGET_ARCH_ABI),gnueabihf) 192 CFLAGS += -DNV_GNUEABIHF 193endif 194 195OUTPUTDIR ?= _out/$(TARGET_OS)_$(TARGET_ARCH) 196OUTPUTDIR_ABSOLUTE ?= $(CURDIR)/$(OUTPUTDIR) 197 198NV_SEPARATE_DEBUG_INFO ?= 199NV_KEEP_UNSTRIPPED_BINARIES ?= 200 201NV_QUIET_COMMAND_REMOVED_TARGET_PREFIX ?= 202 203NV_GENERATED_HEADERS ?= 204 205############################################################################## 206# This makefile uses the $(eval) builtin function, which was added in 207# GNU make 3.80. Check that the current make version recognizes it. 208# Idea suggested by "The GNU Make Book" by John Graham-Cumming. 209############################################################################## 210 211_eval_available := 212$(eval _eval_available := T) 213 214ifneq ($(_eval_available),T) 215 $(error This Makefile requires a GNU Make that supports 'eval'. Please upgrade to GNU make 3.80 or later) 216endif 217 218############################################################################## 219# Test passing $(1) to $(CC). If $(CC) succeeds, then echo $(1). 220# 221# Because this uses $(shell), it is best to use this to assign simply expanded 222# variables (e.g., ":="). 223# 224# Example usage: 225# CONDITIONAL_CFLAGS := $(call TEST_CC_ARG, -ffoo) 226############################################################################## 227 228TEST_CC_ARG = \ 229 $(shell $(CC) -c -x c /dev/null -Werror $(1) -o /dev/null > /dev/null 2>&1 && \ 230 $(ECHO) $(1)) 231 232 233############################################################################## 234# Test if instruction $(1) is understood by the assembler 235# Returns "1" if the instruction is understood, else returns empty string. 236# 237# Example usage: 238# ENDBR_SUPPORTED := $(call AS_HAS_INSTR, endbr64) 239############################################################################## 240 241AS_HAS_INSTR = \ 242 $(shell if ($(ECHO) "$(1)" | $(CC) -c -x assembler - -o /dev/null) >/dev/null 2>&1 ;\ 243 then $(ECHO) "1"; else $(ECHO) ""; fi) 244 245 246############################################################################## 247# define variables used when installing the open source utilities from 248# the source tarball 249############################################################################## 250 251PREFIX ?= /usr/local 252 253BINDIR = $(DESTDIR)$(PREFIX)/bin 254LIBDIR = $(DESTDIR)$(PREFIX)/lib 255MANDIR = $(DESTDIR)$(PREFIX)/share/man/man1 256 257 258############################################################################## 259# default build rule, so that nothing here in utils.mk accidentally 260# gets selected as the default rule 261############################################################################## 262 263default build: all 264.PHONY: default build 265 266############################################################################## 267# get the definition of NVIDIA_VERSION from version.mk 268# 269# version.mk may be in one of two places: either in $(OUTPUTDIR) when 270# building as part of the NVIDIA driver build, or directly in the 271# source directory when building from the source tarball 272# 273# Throw an error if one of these two places did not define NVIDIA_VERSION. 274############################################################################## 275 276VERSION_MK_DIR ?= . 277VERSION_MK := $(wildcard $(OUTPUTDIR)/version.mk $(VERSION_MK_DIR)/version.mk ) 278include $(VERSION_MK) 279 280ifndef NVIDIA_VERSION 281$(error NVIDIA_VERSION undefined) 282endif 283 284############################################################################## 285# NV_GET_SOURCE_TYPE: if the source file $(1) should be compiled as C, this 286# evalutes to "CC"; if the source file $(1) should be compiled as C++, this 287# evalutes to "CXX". 288############################################################################## 289 290NV_GET_SOURCE_TYPE = $(strip \ 291 $(if $(filter %.c, $(1)),CC, \ 292 $(if $(filter %.cpp, $(1)),CXX, \ 293 $(error Unrecognized source $(1))))) 294 295 296############################################################################## 297# Several of the functions below take an argument that indicates if 298# the expression is for the target platform (the system the built 299# program is going to run on) or the host platform (the system 300# performing the build). The argument is either "HOST" or "TARGET" 301# and needs to be converted: 302# 303# "HOST" -> "HOST_" 304# "TARGET" -> "" 305############################################################################## 306 307host_target = $(patsubst HOST,HOST_,$(patsubst TARGET,,$(1))) 308 309 310############################################################################## 311# To generate the dependency files: 312# 313# - Use the compiler's "-MMD" option to generate output of the form 314# "foo.o : foo.c foo.h bar.h". 315# 316# - Also, "-MMD" will cause the compiler to name the target as if it were in the 317# current directory ("foo.o: "); use -MT to rename the target in the output 318# directory ("_out/Linux_x86/foo.o: ") so that the target actually applies to 319# the object files produced in the build. 320# 321# - Use -MP to generate a phony target for each of those prerequisites (except 322# the source file being compiled). E.g., 323# "foo.o : foo.c foo.h bar.h 324# foo.h: 325# bar.h:" 326# so that the makefile can handle incremental builds after a prerequisite has 327# been deleted from source control. 328# 329# - Use sed to remove the source file from the list of prerequisties in the 330# above, so that the makefile can handle increment builds after the source has 331# moved from one directory to another. The DEFINE_OBJECT_RULE macro spells 332# out the obj: src dependency, so we don't require it here. 333############################################################################## 334 335ifeq ($(NV_AUTO_DEPEND),1) 336 AUTO_DEP_SUFFIX = -MMD -MF $$(@:.o=.d.to_be_processed) -MP -MT $$@ && \ 337 $$(SED) -e "1,3s| $$< | |" < $$(@:.o=.d.to_be_processed) > $$(@:.o=.d) 338else 339 AUTO_DEP_SUFFIX = 340endif 341 342 343############################################################################## 344# echo minimal compile information in the non-NV_VERBOSE case 345# 346# NV_MODULE_LOGGING_NAME can be set to prepend quiet build output with a 347# label of which build component is being built 348############################################################################## 349 350NV_MODULE_LOGGING_NAME ?= 351 352ifeq ($(NV_VERBOSE),0) 353 at_if_quiet := @ 354 quiet_cmd_no_at = $(PRINTF) \ 355 " $(if $(NV_MODULE_LOGGING_NAME),[ %-17.17s ],%s) $(quiet_$(1))\n" \ 356 "$(NV_MODULE_LOGGING_NAME)" && $($(1)) 357 quiet_cmd = @$(quiet_cmd_no_at) 358else 359 at_if_quiet := 360 quiet_cmd_no_at = $($(1)) 361 quiet_cmd = $($(1)) 362endif 363 364# define LINK and HOST_LINK to be the same as CC; this is so that, 365# even though we use CC to link programs, we can have a different 366# quiet rule that uses '$@' as it's arg, rather than '$<' 367LINK = $(CC) 368HOST_LINK = $(HOST_CC) 369 370# strip NV_QUIET_COMMAND_REMOVED_TARGET_PREFIX from the target string 371define_quiet_cmd = $(1) $(patsubst $(NV_QUIET_COMMAND_REMOVED_TARGET_PREFIX)/%,%,$(2)) 372 373# define the quiet commands: 374quiet_CC = $(call define_quiet_cmd,CC ,$<) 375quiet_CXX = $(call define_quiet_cmd,CXX ,$<) 376quiet_HOST_CC = $(call define_quiet_cmd,HOST_CC ,$<) 377quiet_HOST_CXX = $(call define_quiet_cmd,HOST_CXX ,$<) 378quiet_LINK = $(call define_quiet_cmd,LINK ,$@) 379quiet_HOST_LINK = $(call define_quiet_cmd,HOST_LINK ,$@) 380quiet_M4 = $(call define_quiet_cmd,M4 ,$<) 381quiet_STRIP_CMD = $(call define_quiet_cmd,STRIP ,$@) 382quiet_HARDLINK = $(call define_quiet_cmd,HARDLINK ,$@) 383quiet_LD = $(call define_quiet_cmd,LD ,$@) 384quiet_OBJCOPY = $(call define_quiet_cmd,OBJCOPY ,$@) 385quiet_AR = $(call define_quiet_cmd,AR ,$@) 386quiet_XZ = $(call define_quiet_cmd,XZ ,$@) 387 388############################################################################## 389# Tell gmake to delete the target of a rule if it has changed and its 390# commands exit with a nonzero exit status. 391############################################################################## 392.DELETE_ON_ERROR: 393 394 395############################################################################## 396# function to generate a list of object files from their corresponding 397# source files using the specified path. The _WITH_DIR variant takes an 398# output path as the second argument while the BUILD_OBJECT_LIST defaults 399# to using the value of OUTPUTDIR as the output path. example usage: 400# 401# OBJS = $(call BUILD_OBJECT_LIST_WITH_DIR,$(SRC),$(DIR)) 402############################################################################## 403 404BUILD_OBJECT_LIST_WITH_DIR = \ 405 $(addprefix $(2)/,$(notdir $(addsuffix .o,$(basename $(1))))) 406 407BUILD_OBJECT_LIST = \ 408 $(call BUILD_OBJECT_LIST_WITH_DIR,$(1),$(OUTPUTDIR)) 409 410############################################################################## 411# function to generate a list of dependency files from their 412# corresponding source files using the specified path. The _WITH_DIR 413# variant takes an output path as the second argument while the 414# BUILD_DEPENDENCY_LIST default to using the value of OUTPUTDIR as the 415# output path. example usage: 416# 417# DEPS = $(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(SRC),$(DIR)) 418############################################################################## 419 420BUILD_DEPENDENCY_LIST_WITH_DIR = \ 421 $(addprefix $(2)/,$(notdir $(addsuffix .d,$(basename $(1))))) 422 423BUILD_DEPENDENCY_LIST = \ 424 $(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(1),$(OUTPUTDIR)) 425 426 427############################################################################## 428# functions to define a rule to build an object file; the first 429# argument for all functions is whether the rule is for the target or 430# host platform ("HOST" or "TARGET"), the second argument for all 431# functions is the source file to compile. 432# 433# An order-only dependency is added on any generated header files listed in 434# $(NV_GENERATED_HEADERS), to ensure they're present before invoking the 435# compiler. For incremental builds where the object file already exists, a 436# real (not order-only) dependency will be created by automatic dependency 437# tracking if needed. 438# 439# The _WITH_OBJECT_NAME and _WITH_DIR function name suffixes describe 440# the third and possibly fourth arguments based on order. The 441# _WITH_OBJECT_NAME argument is the object filename to produce while 442# the _WITH_DIR argument is the destination path for the object file. 443# 444# Example usage: 445# 446# $(eval $(call DEFINE_OBJECT_RULE,TARGET,foo.c)) 447# 448# Note this also attempts to include the dependency file for this 449# source file. 450# 451# The DEFINE_OBJECT_RULE is functionally equivalent to 452# DEFINE_OBJECT_RULE_WITH_OBJECT_NAME, but infers the object file name 453# from the source file name (this is normally what you want). 454# 455# Arguments: 456# $(1) : HOST or TARGET 457# $(2) : source file 458# $(3) : object file 459# $(4) : directory 460############################################################################## 461 462define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR 463 $(3): NV_SOURCE_TYPE = $$(call NV_GET_SOURCE_TYPE,$(2)) 464 465 # obj: {HOST_,}CFLAGS += $$({HOST_,}{CC,CXX}_ONLY_CFLAGS) 466 $(3): $$(call host_target,$(1))CFLAGS += \ 467 $$($(call host_target,$(1))$$(NV_SOURCE_TYPE)_ONLY_CFLAGS) 468 469 $(3): $(2) | $$(NV_GENERATED_HEADERS) 470 @$(MKDIR) $(4) 471 $$(call quiet_cmd,$(call host_target,$(1))$$(NV_SOURCE_TYPE)) \ 472 $$($(call host_target,$(1))CFLAGS) -c $$< -o $$@ \ 473 $(AUTO_DEP_SUFFIX) 474 475 -include $$(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(3),$(4)) 476 477 # declare empty rule for generating dependency file; we generate the 478 # dependency files implicitly when compiling the source file (see 479 # AUTO_DEP_SUFFIX above), so we don't want gmake to spend time searching 480 # for an explicit rule to generate the dependency file 481 $$(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(3),$(4)): ; 482 483endef 484 485define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME 486 $$(eval $$(call DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR,$(1),$(2),\ 487 $(3),$(OUTPUTDIR))) 488endef 489 490define DEFINE_OBJECT_RULE_WITH_DIR 491 $$(eval $$(call DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR,$(1),$(2),\ 492 $$(call BUILD_OBJECT_LIST_WITH_DIR,$(2),$(3)),$(3))) 493endef 494 495define DEFINE_OBJECT_RULE 496 $$(eval $$(call DEFINE_OBJECT_RULE_WITH_DIR,$(1),$(2),$(OUTPUTDIR))) 497endef 498 499# This is a function that will generate rules to build 500# files with separate debug information, if so requested. 501# 502# It takes one parameter: (1) Name of unstripped binary 503# 504# When used, the target for linking should be named (1).unstripped 505# 506# If separate debug information is requested, it will 507# generate a rule to build one from the unstripped binary. 508# If requested, it will also retain the unstripped binary. 509define DEBUG_INFO_RULES 510 $(1): $(1).unstripped 511 ifneq ($(or $(DO_STRIP),$(NV_SEPARATE_DEBUG_INFO)),) 512 $$(call quiet_cmd,STRIP_CMD) -o $$@ $$< 513 else 514 $$(call quiet_cmd,HARDLINK) $$^ $$@ 515 endif 516 ifeq ($(NV_SEPARATE_DEBUG_INFO),1) 517 $(1).debug: $(1).unstripped 518 $$(call quiet_cmd,STRIP_CMD) --only-keep-debug -o $$@ $$< 519 $(1): $(1).debug 520 endif 521 ifneq ($(NV_KEEP_UNSTRIPPED_BINARIES),1) 522 .INTERMEDIATE: $(1).unstripped 523 endif 524endef 525 526############################################################################## 527# Define rule for generating a source file containing identification information 528# for the build. 529# 530# $(1) string name 531# $(2) module name 532# $(3) prerequisite object files 533############################################################################## 534 535NVIDSTRING = $(OUTPUTDIR)/g_nvid_string.c 536 537ifeq ($(DEBUG),1) 538 NVIDSTRING_BUILD_TYPE_STRING = Debug Build 539else 540 NVIDSTRING_BUILD_TYPE_STRING = Release Build 541endif 542 543define GENERATE_NVIDSTRING 544 # g_nvid_string.c depends on all objects except g_nvid_string.o, and version.mk 545 $(NVIDSTRING): $$(filter-out $$(call BUILD_OBJECT_LIST,$$(NVIDSTRING)), $(3)) $$(VERSION_MK) 546 $(at_if_quiet)$$(MKDIR) $$(dir $$@) 547 $(at_if_quiet)$$(ECHO) "const char $(1)[] = \"nvidia id: NVIDIA $$(strip $(2)) for $$(TARGET_ARCH) $$(NVIDIA_VERSION) $$(NVIDSTRING_BUILD_TYPE_STRING) (`$$(WHOAMI)`@$$(HOSTNAME)) `$$(DATE)`\";" > $$@ 548 $(at_if_quiet)$$(ECHO) "const char *const p$$(strip $(1)) = $(1) + 11;" >> $$@; 549endef 550 551 552############################################################################## 553# Define rules that can be used for embedding a file into an ELF object that 554# contains the raw contents of that file and symbols pointing to the embedded 555# data. 556# 557# Note that objcopy will name the symbols in the resulting object file based on 558# the filename specified in $(1). For example, 559# 560# $(eval $(call $(READ_ONLY_OBJECT_FROM_FILE_RULE),a/b/c)) 561# 562# will create an object named $(OUTPUTDIR)/c.o with the symbols _binary_c_start, 563# _binary_c_end, and _binary_c_size. 564# 565# Arguments: 566# $(1): Path to the file to convert 567############################################################################## 568 569LD_TARGET_EMULATION_FLAG = 570LD_TARGET_EMULATION_FLAG_Linux_x86 = elf_i386 571LD_TARGET_EMULATION_FLAG_Linux_x86_64 = elf_x86_64 572LD_TARGET_EMULATION_FLAG_Linux_aarch64 = aarch64elf 573LD_TARGET_EMULATION_FLAG_Linux_ppc64le = elf64lppc 574LD_TARGET_EMULATION_FLAG_SunOS_x86 = elf_i386_sol2 575LD_TARGET_EMULATION_FLAG_SunOS_x86_64 = elf_x86_64_sol2 576LD_TARGET_EMULATION_FLAG_FreeBSD_x86 = elf_i386_fbsd 577LD_TARGET_EMULATION_FLAG_FreeBSD_x86_64 = elf_x86_64_fbsd 578 579# Different linkers (GNU ld versus ld.lld versus ld.gold) expect different 580# target architecture values for '-m'. Empirically, only ld.lld appears to 581# actually need it, so only add the option when linking with ld.lld. Example 582# `ld.lld -v` output: "LLD 15.0.7 (compatible with GNU linkers)". 583LD_IS_LLD := $(if $(filter LLD,$(shell $(LD) -v)),1) 584 585ifdef LD_TARGET_EMULATION_FLAG_$(TARGET_OS)_$(TARGET_ARCH) 586 LD_TARGET_EMULATION_FLAG = $(if $(LD_IS_LLD), -m $(LD_TARGET_EMULATION_FLAG_$(TARGET_OS)_$(TARGET_ARCH))) 587endif 588 589define READ_ONLY_OBJECT_FROM_FILE_RULE 590 $$(OUTPUTDIR)/$$(notdir $(1)).o: $(1) 591 $(at_if_quiet)$$(MKDIR) $$(OUTPUTDIR) 592 $(at_if_quiet)cd $$(dir $(1)); \ 593 $$(call quiet_cmd_no_at,LD) -r -z noexecstack --format=binary \ 594 $$(LD_TARGET_EMULATION_FLAG) \ 595 $$(notdir $(1)) -o $$(OUTPUTDIR_ABSOLUTE)/$$(notdir $$@) 596 $$(call quiet_cmd,OBJCOPY) \ 597 --rename-section .data=.rodata,contents,alloc,load,data,readonly \ 598 $$@ 599endef 600 601define BINARY_DATA_HEADER_RULE 602 $$(OUTPUTDIR)/$(notdir $(1)).h: 603 $(at_if_quiet)$(MKDIR) $$(OUTPUTDIR) 604 $(at_if_quiet){ \ 605 $$(PRINTF) "extern const char _binary_$(subst -,_,$(subst .,_,$(notdir $(1))))_start[];\n"; \ 606 $$(PRINTF) "extern const char _binary_$(subst -,_,$(subst .,_,$(notdir $(1))))_end[];\n"; \ 607 } > $$@ 608endef 609