xref: /open-nvidia-gpu/utils.mk (revision b5bf85a8)
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
113
114ifndef HOSTNAME
115  HOSTNAME             = $(shell hostname)
116endif
117
118
119NV_AUTO_DEPEND        ?= 1
120NV_VERBOSE            ?= 0
121
122ifndef TARGET_OS
123  TARGET_OS           := $(shell uname)
124endif
125
126ifeq ($(TARGET_OS),Linux)
127  CFLAGS += -DNV_LINUX
128endif
129
130ifeq ($(TARGET_OS),FreeBSD)
131  CFLAGS += -DNV_BSD
132endif
133
134ifeq ($(TARGET_OS),SunOS)
135  CFLAGS += -DNV_SUNOS
136endif
137
138ifndef TARGET_ARCH
139  TARGET_ARCH         := $(shell uname -m)
140  TARGET_ARCH         := $(subst i386,x86,$(TARGET_ARCH))
141  TARGET_ARCH         := $(subst i486,x86,$(TARGET_ARCH))
142  TARGET_ARCH         := $(subst i586,x86,$(TARGET_ARCH))
143  TARGET_ARCH         := $(subst i686,x86,$(TARGET_ARCH))
144endif
145
146ifeq ($(TARGET_ARCH),x86)
147  CFLAGS += -DNV_X86 -DNV_ARCH_BITS=32
148endif
149
150ifeq ($(TARGET_ARCH),x86_64)
151  CFLAGS += -DNV_X86_64 -DNV_ARCH_BITS=64
152endif
153
154ifeq ($(TARGET_ARCH),armv7l)
155  CFLAGS += -DNV_ARMV7 -DNV_ARCH_BITS=32
156endif
157
158ifeq ($(TARGET_ARCH),aarch64)
159  CFLAGS += -DNV_AARCH64 -DNV_ARCH_BITS=64
160endif
161
162ifeq ($(TARGET_ARCH),ppc64le)
163  CFLAGS += -DNV_PPC64LE -DNV_ARCH_BITS=64
164endif
165
166ifeq ($(TARGET_OS),Linux)
167  LIBDL_LIBS = -ldl
168else
169  LIBDL_LIBS =
170endif
171
172# This variable controls which floating-point ABI is targeted.  For ARM, it
173# defaults to "gnueabi" for softfp.  Another option is "gnueabihf" for
174# hard(fp).  This is necessary to pick up the correct rtld_test binary.
175# All other architectures default to empty.
176ifeq ($(TARGET_ARCH),armv7l)
177  TARGET_ARCH_ABI     ?= gnueabi
178endif
179TARGET_ARCH_ABI       ?=
180
181ifeq ($(TARGET_ARCH_ABI),gnueabi)
182  CFLAGS += -DNV_GNUEABI
183endif
184
185ifeq ($(TARGET_ARCH_ABI),gnueabihf)
186  CFLAGS += -DNV_GNUEABIHF
187endif
188
189OUTPUTDIR             ?= _out/$(TARGET_OS)_$(TARGET_ARCH)
190OUTPUTDIR_ABSOLUTE    ?= $(CURDIR)/$(OUTPUTDIR)
191
192NV_SEPARATE_DEBUG_INFO ?=
193NV_KEEP_UNSTRIPPED_BINARIES ?=
194
195NV_QUIET_COMMAND_REMOVED_TARGET_PREFIX ?=
196
197NV_GENERATED_HEADERS ?=
198
199PCIACCESS_CFLAGS      ?=
200PCIACCESS_LDFLAGS     ?=
201
202##############################################################################
203# This makefile uses the $(eval) builtin function, which was added in
204# GNU make 3.80.  Check that the current make version recognizes it.
205# Idea suggested by "The GNU Make Book" by John Graham-Cumming.
206##############################################################################
207
208_eval_available :=
209$(eval _eval_available := T)
210
211ifneq ($(_eval_available),T)
212  $(error This Makefile requires a GNU Make that supports 'eval'.  Please upgrade to GNU make 3.80 or later)
213endif
214
215##############################################################################
216# Test passing $(1) to $(CC).  If $(CC) succeeds, then echo $(1).
217#
218# Because this uses $(shell), it is best to use this to assign simply expanded
219# variables (e.g., ":=").
220#
221# Example usage:
222#  CONDITIONAL_CFLAGS := $(call TEST_CC_ARG, -ffoo)
223##############################################################################
224
225TEST_CC_ARG = \
226 $(shell $(CC) -c -x c /dev/null -Werror $(1) -o /dev/null > /dev/null 2>&1 && \
227   $(ECHO) $(1))
228
229
230##############################################################################
231# Test if instruction $(1) is understood by the assembler
232# Returns "1" if the instruction is understood, else returns empty string.
233#
234# Example usage:
235# ENDBR_SUPPORTED := $(call AS_HAS_INSTR, endbr64)
236##############################################################################
237
238AS_HAS_INSTR = \
239 $(shell if ($(ECHO) "$(1)" | $(CC) -c -x assembler - -o /dev/null) >/dev/null 2>&1 ;\
240   then $(ECHO) "1"; else $(ECHO) ""; fi)
241
242
243##############################################################################
244# define variables used when installing the open source utilities from
245# the source tarball
246##############################################################################
247
248PREFIX ?= /usr/local
249
250BINDIR = $(DESTDIR)$(PREFIX)/bin
251LIBDIR = $(DESTDIR)$(PREFIX)/lib
252MANDIR = $(DESTDIR)$(PREFIX)/share/man/man1
253
254
255##############################################################################
256# default build rule, so that nothing here in utils.mk accidentally
257# gets selected as the default rule
258##############################################################################
259
260default build: all
261.PHONY: default build
262
263##############################################################################
264# get the definition of NVIDIA_VERSION from version.mk
265#
266# version.mk may be in one of two places: either in $(OUTPUTDIR) when
267# building as part of the NVIDIA driver build, or directly in the
268# source directory when building from the source tarball
269#
270# Throw an error if one of these two places did not define NVIDIA_VERSION.
271##############################################################################
272
273VERSION_MK_DIR ?= .
274VERSION_MK := $(wildcard $(OUTPUTDIR)/version.mk $(VERSION_MK_DIR)/version.mk )
275include $(VERSION_MK)
276
277ifndef NVIDIA_VERSION
278$(error NVIDIA_VERSION undefined)
279endif
280
281##############################################################################
282# NV_GET_SOURCE_TYPE: if the source file $(1) should be compiled as C, this
283# evalutes to "CC"; if the source file $(1) should be compiled as C++, this
284# evalutes to "CXX".
285##############################################################################
286
287NV_GET_SOURCE_TYPE = $(strip \
288                     $(if $(filter %.c, $(1)),CC, \
289                     $(if $(filter %.cpp, $(1)),CXX, \
290                     $(error Unrecognized source $(1)))))
291
292
293##############################################################################
294# Several of the functions below take an argument that indicates if
295# the expression is for the target platform (the system the built
296# program is going to run on) or the host platform (the system
297# performing the build).  The argument is either "HOST" or "TARGET"
298# and needs to be converted:
299#
300# "HOST" -> "HOST_"
301# "TARGET" -> ""
302##############################################################################
303
304host_target = $(patsubst HOST,HOST_,$(patsubst TARGET,,$(1)))
305
306
307##############################################################################
308# To generate the dependency files:
309#
310# - Use the compiler's "-MMD" option to generate output of the form
311#     "foo.o : foo.c foo.h bar.h".
312#
313# - Also, "-MMD" will cause the compiler to name the target as if it were in the
314#   current directory ("foo.o: "); use -MT to rename the target in the output
315#   directory ("_out/Linux_x86/foo.o: ") so that the target actually applies to
316#   the object files produced in the build.
317#
318# - Use -MP to generate a phony target for each of those prerequisites (except
319#   the source file being compiled).  E.g.,
320#     "foo.o : foo.c foo.h bar.h
321#      foo.h:
322#      bar.h:"
323#   so that the makefile can handle incremental builds after a prerequisite has
324#   been deleted from source control.
325#
326# - Use sed to remove the source file from the list of prerequisties in the
327#   above, so that the makefile can handle increment builds after the source has
328#   moved from one directory to another.  The DEFINE_OBJECT_RULE macro spells
329#   out the obj: src dependency, so we don't require it here.
330##############################################################################
331
332ifeq ($(NV_AUTO_DEPEND),1)
333  AUTO_DEP_SUFFIX = -MMD -MF $$(@:.o=.d.to_be_processed) -MP -MT $$@ && \
334    $$(SED) -e "1,3s| $$< | |" < $$(@:.o=.d.to_be_processed) > $$(@:.o=.d)
335else
336  AUTO_DEP_SUFFIX =
337endif
338
339
340##############################################################################
341# echo minimal compile information in the non-NV_VERBOSE case
342#
343# NV_MODULE_LOGGING_NAME can be set to prepend quiet build output with a
344# label of which build component is being built
345##############################################################################
346
347NV_MODULE_LOGGING_NAME ?=
348
349ifeq ($(NV_VERBOSE),0)
350  at_if_quiet := @
351  quiet_cmd_no_at = $(PRINTF) \
352    " $(if $(NV_MODULE_LOGGING_NAME),[ %-17.17s ],%s)  $(quiet_$(1))\n" \
353    "$(NV_MODULE_LOGGING_NAME)" && $($(1))
354  quiet_cmd = @$(quiet_cmd_no_at)
355else
356  at_if_quiet :=
357  quiet_cmd_no_at = $($(1))
358  quiet_cmd = $($(1))
359endif
360
361# define LINK and HOST_LINK to be the same as CC; this is so that,
362# even though we use CC to link programs, we can have a different
363# quiet rule that uses '$@' as it's arg, rather than '$<'
364LINK = $(CC)
365HOST_LINK = $(HOST_CC)
366
367# strip NV_QUIET_COMMAND_REMOVED_TARGET_PREFIX from the target string
368define_quiet_cmd = $(1) $(patsubst $(NV_QUIET_COMMAND_REMOVED_TARGET_PREFIX)/%,%,$(2))
369
370# define the quiet commands:
371quiet_CC           = $(call define_quiet_cmd,CC          ,$<)
372quiet_CXX          = $(call define_quiet_cmd,CXX         ,$<)
373quiet_HOST_CC      = $(call define_quiet_cmd,HOST_CC     ,$<)
374quiet_HOST_CXX     = $(call define_quiet_cmd,HOST_CXX    ,$<)
375quiet_LINK         = $(call define_quiet_cmd,LINK        ,$@)
376quiet_HOST_LINK    = $(call define_quiet_cmd,HOST_LINK   ,$@)
377quiet_M4           = $(call define_quiet_cmd,M4          ,$<)
378quiet_STRIP_CMD    = $(call define_quiet_cmd,STRIP       ,$@)
379quiet_HARDLINK     = $(call define_quiet_cmd,HARDLINK    ,$@)
380quiet_LD           = $(call define_quiet_cmd,LD          ,$@)
381quiet_OBJCOPY      = $(call define_quiet_cmd,OBJCOPY     ,$@)
382quiet_AR           = $(call define_quiet_cmd,AR          ,$@)
383quiet_XZ           = $(call define_quiet_cmd,XZ          ,$@)
384
385##############################################################################
386# Tell gmake to delete the target of a rule if it has changed and its
387# commands exit with a nonzero exit status.
388##############################################################################
389.DELETE_ON_ERROR:
390
391
392##############################################################################
393# function to generate a list of object files from their corresponding
394# source files using the specified path. The _WITH_DIR variant takes an
395# output path as the second argument while the BUILD_OBJECT_LIST defaults
396# to using the value of OUTPUTDIR as the output path. example usage:
397#
398# OBJS = $(call BUILD_OBJECT_LIST_WITH_DIR,$(SRC),$(DIR))
399##############################################################################
400
401BUILD_OBJECT_LIST_WITH_DIR = \
402  $(addprefix $(2)/,$(notdir $(addsuffix .o,$(basename $(1)))))
403
404BUILD_OBJECT_LIST = \
405  $(call BUILD_OBJECT_LIST_WITH_DIR,$(1),$(OUTPUTDIR))
406
407$(call BUILD_OBJECT_LIST,nvpci-utils.c): CFLAGS += $(PCIACCESS_CFLAGS)
408
409##############################################################################
410# function to generate a list of dependency files from their
411# corresponding source files using the specified path. The _WITH_DIR
412# variant takes an output path as the second argument while the
413# BUILD_DEPENDENCY_LIST default to using the value of OUTPUTDIR as the
414# output path. example usage:
415#
416# DEPS = $(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(SRC),$(DIR))
417##############################################################################
418
419BUILD_DEPENDENCY_LIST_WITH_DIR = \
420  $(addprefix $(2)/,$(notdir $(addsuffix .d,$(basename $(1)))))
421
422BUILD_DEPENDENCY_LIST = \
423  $(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(1),$(OUTPUTDIR))
424
425
426##############################################################################
427# functions to define a rule to build an object file; the first
428# argument for all functions is whether the rule is for the target or
429# host platform ("HOST" or "TARGET"), the second argument for all
430# functions is the source file to compile.
431#
432# An order-only dependency is added on any generated header files listed in
433# $(NV_GENERATED_HEADERS), to ensure they're present before invoking the
434# compiler.  For incremental builds where the object file already exists, a
435# real (not order-only) dependency will be created by automatic dependency
436# tracking if needed.
437#
438# The _WITH_OBJECT_NAME and _WITH_DIR function name suffixes describe
439# the third and possibly fourth arguments based on order. The
440# _WITH_OBJECT_NAME argument is the object filename to produce while
441# the _WITH_DIR argument is the destination path for the object file.
442#
443# Example usage:
444#
445#  $(eval $(call DEFINE_OBJECT_RULE,TARGET,foo.c))
446#
447# Note this also attempts to include the dependency file for this
448# source file.
449#
450# The DEFINE_OBJECT_RULE is functionally equivalent to
451# DEFINE_OBJECT_RULE_WITH_OBJECT_NAME, but infers the object file name
452# from the source file name (this is normally what you want).
453#
454# Arguments:
455# $(1) : HOST or TARGET
456# $(2) : source file
457# $(3) : object file
458# $(4) : directory
459##############################################################################
460
461define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR
462  $(3): NV_SOURCE_TYPE = $$(call NV_GET_SOURCE_TYPE,$(2))
463
464  # obj: {HOST_,}CFLAGS += $$({HOST_,}{CC,CXX}_ONLY_CFLAGS)
465  $(3): $$(call host_target,$(1))CFLAGS += \
466    $$($(call host_target,$(1))$$(NV_SOURCE_TYPE)_ONLY_CFLAGS)
467
468  $(3): $(2) | $$(NV_GENERATED_HEADERS)
469	@$(MKDIR) $(4)
470	$$(call quiet_cmd,$(call host_target,$(1))$$(NV_SOURCE_TYPE)) \
471	  $$($(call host_target,$(1))CFLAGS) -c $$< -o $$@ \
472	  $(AUTO_DEP_SUFFIX)
473
474  -include $$(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(3),$(4))
475
476  # declare empty rule for generating dependency file; we generate the
477  # dependency files implicitly when compiling the source file (see
478  # AUTO_DEP_SUFFIX above), so we don't want gmake to spend time searching
479  # for an explicit rule to generate the dependency file
480  $$(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(3),$(4)): ;
481
482endef
483
484define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME
485  $$(eval $$(call DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR,$(1),$(2),\
486    $(3),$(OUTPUTDIR)))
487endef
488
489define DEFINE_OBJECT_RULE_WITH_DIR
490  $$(eval $$(call DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR,$(1),$(2),\
491    $$(call BUILD_OBJECT_LIST_WITH_DIR,$(2),$(3)),$(3)))
492endef
493
494define DEFINE_OBJECT_RULE
495  $$(eval $$(call DEFINE_OBJECT_RULE_WITH_DIR,$(1),$(2),$(OUTPUTDIR)))
496endef
497
498# This is a function that will generate rules to build
499# files with separate debug information, if so requested.
500#
501# It takes one parameter: (1) Name of unstripped binary
502#
503# When used, the target for linking should be named (1).unstripped
504#
505# If separate debug information is requested, it will
506# generate a rule to build one from the unstripped binary.
507# If requested, it will also retain the unstripped binary.
508define DEBUG_INFO_RULES
509  $(1): $(1).unstripped
510  ifneq ($(or $(DO_STRIP),$(NV_SEPARATE_DEBUG_INFO)),)
511	$$(call quiet_cmd,STRIP_CMD) -o $$@ $$<
512  else
513	$$(call quiet_cmd,HARDLINK) $$^ $$@
514  endif
515  ifeq ($(NV_SEPARATE_DEBUG_INFO),1)
516    $(1).debug: $(1).unstripped
517	$$(call quiet_cmd,STRIP_CMD) --only-keep-debug -o $$@ $$<
518    $(1): $(1).debug
519  endif
520  ifneq ($(NV_KEEP_UNSTRIPPED_BINARIES),1)
521    .INTERMEDIATE: $(1).unstripped
522  endif
523endef
524
525##############################################################################
526# Define rule for generating a source file containing identification information
527# for the build.
528#
529# $(1) string name
530# $(2) module name
531# $(3) prerequisite object files
532##############################################################################
533
534NVIDSTRING = $(OUTPUTDIR)/g_nvid_string.c
535
536ifeq ($(DEBUG),1)
537  NVIDSTRING_BUILD_TYPE_STRING = Debug Build
538else
539  NVIDSTRING_BUILD_TYPE_STRING = Release Build
540endif
541
542define GENERATE_NVIDSTRING
543  # g_nvid_string.c depends on all objects except g_nvid_string.o, and version.mk
544  $(NVIDSTRING): $$(filter-out $$(call BUILD_OBJECT_LIST,$$(NVIDSTRING)), $(3)) $$(VERSION_MK)
545	$(at_if_quiet)$$(MKDIR) $$(dir $$@)
546	$(at_if_quiet)$$(ECHO) "const char $(1)[] = \"nvidia id: NVIDIA $$(strip $(2)) for $$(TARGET_ARCH)  $$(NVIDIA_VERSION)  $$(NVIDSTRING_BUILD_TYPE_STRING)  (`$$(WHOAMI)`@$$(HOSTNAME))  `$$(DATE)`\";" > $$@
547	$(at_if_quiet)$$(ECHO) "const char *const p$$(strip $(1)) = $(1) + 11;" >> $$@;
548endef
549
550
551##############################################################################
552# Define rules that can be used for embedding a file into an ELF object that
553# contains the raw contents of that file and symbols pointing to the embedded
554# data.
555#
556# Note that objcopy will name the symbols in the resulting object file based on
557# the filename specified in $(1).  For example,
558#
559#   $(eval $(call $(READ_ONLY_OBJECT_FROM_FILE_RULE),a/b/c))
560#
561# will create an object named $(OUTPUTDIR)/c.o with the symbols _binary_c_start,
562# _binary_c_end, and _binary_c_size.
563#
564# Arguments:
565#  $(1): Path to the file to convert
566##############################################################################
567
568LD_TARGET_EMULATION_FLAG =
569LD_TARGET_EMULATION_FLAG_Linux_x86      = elf_i386
570LD_TARGET_EMULATION_FLAG_Linux_x86_64   = elf_x86_64
571LD_TARGET_EMULATION_FLAG_Linux_aarch64  = aarch64elf
572LD_TARGET_EMULATION_FLAG_Linux_ppc64le  = elf64lppc
573LD_TARGET_EMULATION_FLAG_SunOS_x86      = elf_i386_sol2
574LD_TARGET_EMULATION_FLAG_SunOS_x86_64   = elf_x86_64_sol2
575LD_TARGET_EMULATION_FLAG_FreeBSD_x86    = elf_i386_fbsd
576LD_TARGET_EMULATION_FLAG_FreeBSD_x86_64 = elf_x86_64_fbsd
577
578ifdef LD_TARGET_EMULATION_FLAG_$(TARGET_OS)_$(TARGET_ARCH)
579  LD_TARGET_EMULATION_FLAG = -m $(LD_TARGET_EMULATION_FLAG_$(TARGET_OS)_$(TARGET_ARCH))
580endif
581
582define READ_ONLY_OBJECT_FROM_FILE_RULE
583  $$(OUTPUTDIR)/$$(notdir $(1)).o: $(1)
584	$(at_if_quiet)$$(MKDIR) $$(OUTPUTDIR)
585	$(at_if_quiet)cd $$(dir $(1)); \
586	$$(call quiet_cmd_no_at,LD) -r -z noexecstack --format=binary \
587	    $$(LD_TARGET_EMULATION_FLAG) \
588	    $$(notdir $(1)) -o $$(OUTPUTDIR_ABSOLUTE)/$$(notdir $$@)
589	$$(call quiet_cmd,OBJCOPY) \
590	    --rename-section .data=.rodata,contents,alloc,load,data,readonly \
591	    $$@
592endef
593