blob: 71a4f8fa4b0d804710e17894abcd4b808177b581 [file] [log] [blame]
xf.libdd93d52023-05-12 07:10:14 -07001# Makefile fragment for NaCl configurations.
2
3# Copyright (C) 2015-2016 Free Software Foundation, Inc.
4# This file is part of the GNU C Library.
5
6# The GNU C Library is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
10
11# The GNU C Library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15
16# You should have received a copy of the GNU Lesser General Public
17# License along with the GNU C Library; if not, see
18# <http://www.gnu.org/licenses/>.
19
20# The libthread_db code does not compile for NaCl because there is no
21# sys/procfs.h supplying the register layout types. But since libthread_db
22# will probably never be useful for NaCl, just elide the directory rather
23# than implementing stuff to make it compile (and never get used).
24subdirs := $(filter-out nptl_db,$(subdirs))
25sorted-subdirs := $(filter-out nptl_db,$(sorted-subdirs))
26
27# The (required) --with-headers option to configure sets sysheaders to the
28# location of the native_client/.. source directory. We'll get necessary
29# headers directly from there.
30naclsrc = $(sysheaders)/native_client/src
31
32# How to find the directory containing this Makefile.
33nacl = $(..)sysdeps/nacl
34
35# Generate our bits/errno.h with the numbers from NaCl's sys/errno.h file.
36nacl-errno = $(naclsrc)/trusted/service_runtime/include/sys/errno.h
37
38bits-errno = $(common-objpfx)bits/errno.h
39$(bits-errno): $(common-objpfx)stamp-errnos ;
40$(common-objpfx)stamp-errnos: $(nacl)/errnos.awk $(..)manual/errno.texi \
41 $(nacl-errno)
42 $(make-target-directory)
43 $(AWK) -f $^ > $(bits-errno)-tmp
44# Make it unwritable so noone will edit it by mistake.
45 -chmod a-w $(bits-errno)-tmp
46 $(move-if-change) $(bits-errno)-tmp $(bits-errno)
47 touch $@
48common-generated += stamp-errnos bits/errno.h
49before-compile += $(bits-errno)
50
51# Massage NaCl's irt.h (and irt_dev.h) into something we can use.
52# See irt.sed for details.
53nacl-irt.h = $(common-objpfx)nacl-irt.h
54$(nacl-irt.h): $(nacl)/irt.sed \
55 $(naclsrc)/untrusted/irt/irt.h \
56 $(naclsrc)/untrusted/irt/irt_dev.h
57 sed -f $^ > $@.new
58 mv -f $@.new $@
59common-generated += nacl-irt.h
60before-compile += $(nacl-irt.h)
61
62$(common-objpfx)nacl-interfaces.v.i: $(nacl)/nacl-interfaces.mk.in \
63 $(nacl)/nacl-interface-list.h
64-include $(common-objpfx)nacl-interfaces.v
65common-generated += nacl-interfaces.v
66before-compile += $(common-objpfx)nacl-interfaces.v
67
68nacl-all-interfaces = $(nacl-mandatory-interfaces) $(nacl-optional-interfaces)
69nacl-interface-routines = $(nacl-all-interfaces:%=nacl-interface-%)
70
71define nacl-interface-table-command
72(echo '#define INTERFACE_CATEGORY $1'; \
73 echo '#define INTERFACE_MODULE $(firstword $(subst -, ,$*))'; \
74 echo '#define INTERFACE_TYPE $(word 2,$(subst -, ,$*))'; \
75 echo '#define INTERFACE_STRING $(nacl-$*-string)'; \
76 echo '#include "nacl-interface-table.c"' \
77) > $@T
78mv -f $@T $@
79endef
80
81nacl-interface-pattern = $(objpfx)nacl-interface-%.c
82
83$(nacl-mandatory-interfaces:%=$(nacl-interface-pattern)): \
84 $(nacl-interface-pattern): $(nacl)/Makefile $(common-objpfx)nacl-interfaces.v
85 $(make-target-directory)
86 $(call nacl-interface-table-command,mandatory)
87$(nacl-optional-interfaces:%=$(nacl-interface-pattern)): \
88 $(nacl-interface-pattern): $(nacl)/Makefile $(common-objpfx)nacl-interfaces.v
89 $(make-target-directory)
90 $(call nacl-interface-table-command,optional)
91
92nacl-routines-of = $(filter nacl-interface-$1-%,$(nacl-interface-routines))
93
94
95# Run the NaCl code validator on binaries after we link them, so the
96# build does not succeed with any binary that won't pass validation.
97# Moving the file around makes sure that we don't leave a target
98# appearing complete after it fails validation.
99define after-link
100mv -f $1 $1.prevalidation
101$(nacl)/nacl-after-link.sh '${READELF}' $1.prevalidation
102mv -f $1.prevalidation $1
103endef
104
105# The test wrapper script takes care of running things under NaCl's sel_ldr.
106test-wrapper-env-only = $(nacl)/nacl-test-wrapper.sh --arch=$(nacl-sdk-arch)
107test-wrapper-env = $(test-wrapper-env-only)
108test-wrapper = $(test-wrapper-env) --
109
110ifeq ($(subdir),csu)
111sysdep_routines += nacl_interface_query nacl_interface_ext_supply \
112 nacl-interfaces $(call nacl-routines-of,libc)
113endif
114
115ifeq ($(subdir),elf)
116sysdep-dl-routines += $(call nacl-routines-of,rtld)
117sysdep-rtld-routines += nacl-interfaces $(call nacl-routines-of,rtld)
118endif
119
120ifeq ($(subdir),io)
121sysdep_routines += xstatconv
122endif
123
124ifeq ($(subdir),nptl)
125# We do not need any wrappers in libpthread.
126libpthread-routines := $(filter-out ptw-%,$(libpthread-routines))
127endif
128
129ifeq ($(subdir),misc)
130# We reuse the Linux file since the bits match. The file lives in the
131# top-level source tree so we can use it without reference to any
132# sysdeps/.../linux/ directories, but it's still a sysdeps decision to
133# install it.
134sysdep_headers += bits/mman-linux.h
135
136# This defeats sysdeps/gnu/Makefile's addition of sys/mtio.h, which
137# we do not want. This is a total kludge, but it seems no worse for
138# now than making the sysdeps/gnu/Makefile code conditional on a
139# variable we set here. If some sysdeps/.../Makefile that is later
140# in the list than sysdeps/gnu needed to add to sysdep_headers, this
141# would break it. But sysdeps/gnu is close to last in the list and
142# this coming up seems unlikely.
143override sysdep_headers := $(sysdep_headers)
144endif