xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame^] | 1 | # 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). |
| 24 | subdirs := $(filter-out nptl_db,$(subdirs)) |
| 25 | sorted-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. |
| 30 | naclsrc = $(sysheaders)/native_client/src |
| 31 | |
| 32 | # How to find the directory containing this Makefile. |
| 33 | nacl = $(..)sysdeps/nacl |
| 34 | |
| 35 | # Generate our bits/errno.h with the numbers from NaCl's sys/errno.h file. |
| 36 | nacl-errno = $(naclsrc)/trusted/service_runtime/include/sys/errno.h |
| 37 | |
| 38 | bits-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 $@ |
| 48 | common-generated += stamp-errnos bits/errno.h |
| 49 | before-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. |
| 53 | nacl-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 $@ |
| 59 | common-generated += nacl-irt.h |
| 60 | before-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 |
| 65 | common-generated += nacl-interfaces.v |
| 66 | before-compile += $(common-objpfx)nacl-interfaces.v |
| 67 | |
| 68 | nacl-all-interfaces = $(nacl-mandatory-interfaces) $(nacl-optional-interfaces) |
| 69 | nacl-interface-routines = $(nacl-all-interfaces:%=nacl-interface-%) |
| 70 | |
| 71 | define 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 |
| 78 | mv -f $@T $@ |
| 79 | endef |
| 80 | |
| 81 | nacl-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 | |
| 92 | nacl-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. |
| 99 | define after-link |
| 100 | mv -f $1 $1.prevalidation |
| 101 | $(nacl)/nacl-after-link.sh '${READELF}' $1.prevalidation |
| 102 | mv -f $1.prevalidation $1 |
| 103 | endef |
| 104 | |
| 105 | # The test wrapper script takes care of running things under NaCl's sel_ldr. |
| 106 | test-wrapper-env-only = $(nacl)/nacl-test-wrapper.sh --arch=$(nacl-sdk-arch) |
| 107 | test-wrapper-env = $(test-wrapper-env-only) |
| 108 | test-wrapper = $(test-wrapper-env) -- |
| 109 | |
| 110 | ifeq ($(subdir),csu) |
| 111 | sysdep_routines += nacl_interface_query nacl_interface_ext_supply \ |
| 112 | nacl-interfaces $(call nacl-routines-of,libc) |
| 113 | endif |
| 114 | |
| 115 | ifeq ($(subdir),elf) |
| 116 | sysdep-dl-routines += $(call nacl-routines-of,rtld) |
| 117 | sysdep-rtld-routines += nacl-interfaces $(call nacl-routines-of,rtld) |
| 118 | endif |
| 119 | |
| 120 | ifeq ($(subdir),io) |
| 121 | sysdep_routines += xstatconv |
| 122 | endif |
| 123 | |
| 124 | ifeq ($(subdir),nptl) |
| 125 | # We do not need any wrappers in libpthread. |
| 126 | libpthread-routines := $(filter-out ptw-%,$(libpthread-routines)) |
| 127 | endif |
| 128 | |
| 129 | ifeq ($(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. |
| 134 | sysdep_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. |
| 143 | override sysdep_headers := $(sysdep_headers) |
| 144 | endif |