Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlfaultinjection / repo / third_party / nlbuild-autotools / repo / make / host / tools / tools.mak
1 #
2 #    Copyright (c) 2019 Google LLC. All Rights Reserved.
3 #    Copyright (c) 2018 Nest Labs Inc. All Rights Reserved.
4 #
5 #    Licensed under the Apache License, Version 2.0 (the "License");
6 #    you may not use this file except in compliance with the License.
7 #    You may obtain a copy of the License at
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #    Unless required by applicable law or agreed to in writing, software
12 #    distributed under the License is distributed on an "AS IS" BASIS,
13 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #    See the License for the specific language governing permissions and
15 #    limitations under the License.
16 #
17
18 #
19 #    Description:
20 #      This file is the generic "header" or pre make header for all
21 #      common host-specific (i.e., non-target and -toolchain-specific)
22 #      tools included in any makefile used in the build tree.
23 #
24
25 CAT                              ?= cat
26 CHMOD                            ?= chmod
27 CMP                              ?= cmp
28 CUT                              ?= cut
29 DIFF                             ?= diff
30 FIND                             ?= find
31 GIT                              ?= git
32 GREP                             ?= grep
33 GZIP                             ?= gzip
34 MKDIR                            ?= mkdir
35 MKDIR_P                          ?= $(MKDIR) -p                  
36 MV                               ?= mv
37
38 RMFLAGS                           = -f
39 ifeq ($(V),1)
40 RMFLAGS                          += -v
41 endif
42 RM                               ?= rm $(RMFLAGS)
43
44 RMDIR                            ?= rmdir
45 SED                              ?= sed
46 SORT                             ?= sort
47 TAR                              ?= tar
48 UNIQ                             ?= uniq
49 XZ                               ?= xz
50
51 #
52 # nl-create-dir <directory>
53 #
54 # Create the specified directory, including any parent directories
55 # that may not exist.
56 #
57 define nl-create-dir
58 $(NL_V_PROGRESS_MKDIR)
59 $(NL_V_AT)$(MKDIR_P) "$(1)"
60 endef # nl-create-dir
61
62 #
63 # nl-remove-dir <directory>
64 #
65 # If the specified directory exists, then ensure all of the
66 # directories are writable by the current user, and then forcibly
67 # remove the directory and all of its contents, sleeping for five (5)
68 # seconds and failure before trying the removal again.
69 #
70 define nl-remove-dir
71 $(NL_V_PROGRESS_RMDIR)
72 $(NL_V_AT)if [ -d "$(1)" ]; then \
73     $(FIND) "$(1)" -type d ! -perm -200 -exec $(CHMOD) u+w {} ';' \
74     && $(RM) -rf "$(1)" \
75     || { sleep 5 && $(RM) -rf "$(1)"; }; \
76 fi
77 endef # nl-remove-dir
78
79 #
80 # nl-check-file-with-subroutine <subroutine prefix> <macro suffix>
81 #
82 # Check whether a file, referenced by the $(@) variable, should be
83 # updated / regenerated based on its dependencies, referenced by the
84 # $(<) variable by running the make macro check-file-<macro suffix>.
85 #
86 # The $(<) is passed as the first argument if the macro wants to process
87 # it and the prospective new output file, which the macro MUST
88 # generate, as the second.
89 #
90 # This macro will ensure that any required parent directories are created
91 # prior to invoking the subroutine <subroutine prefix>-<macro suffix>.
92 #
93 # This macro is similar to and inspired by that from Linux Kbuild and
94 # elsewhere.
95 #
96 #   <subroutine prefix> - The subroutine name, prefixed to "-<macro suffix>",
97 #                         which, together with <macro suffix>, indicates the
98 #                         make macro to invoke to actually check the file.
99 #
100 #   <macro suffix>      - The name, suffixed to "<subroutine prefix>-", which
101 #                         together with <subroutine prefix>, indicates the
102 #                         make macro to invoke to actually check the file.
103 #
104 #
105 nl-check-file-N:=$(shell echo N$$$$)
106 define nl-check-file-with-subroutine
107 $(NL_V_AT)$(_NL_PROGRESS) "CHECK" "$(@)";              \
108 $(MKDIR_P) $(dir $(@));                                \
109 $(call $(1)-$(2),$(<),$(@).$(nl-check-file-N));        \
110 if [ -r "$(@)" ] &&                                    \
111     $(CMP) -s "$(@)" "$(@).$(nl-check-file-N)"; then   \
112     rm -f "$(@).$(nl-check-file-N)";                   \
113 else                                                   \
114     $(_NL_PROGRESS) "GEN" "$(@)";                      \
115     mv -f "$(@).$(nl-check-file-N)" "$(@)";            \
116 fi
117 endef # nl-check-file
118
119 #
120 # nl-check-file <macro suffix>
121 #
122 # Check whether a file, referenced by the $(@) variable, should be
123 # updated / regenerated based on its dependencies, referenced by the
124 # $(<) variable by running the make macro check-file-<macro suffix>.
125 #
126 # The $(<) is passed as the first argument if the macro wants to process
127 # it and the prospective new output file, which the macro MUST
128 # generate, as the second.
129 #
130 # This macro will ensure that any required parent directories are created
131 # prior to invoking check-file-<macro suffix>.
132 #
133 # This macro is similar to and inspired by that from Linux Kbuild and
134 # elsewhere.
135 #
136 #   <macro suffix> - The name, suffixed to "check-file-", which indicates
137 #                    the make macro to invoke.
138 #
139 #
140 define nl-check-file
141 $(call nl-check-file-with-subroutine,nl-check-file,$(1))
142 endef # nl-check-file
143
144 #
145 # nl-create-link
146 #
147 # Create the symbolic link with the source of the $(<) variable and
148 # the destination of the $(@) variable, using the LN_S macro.
149 #
150 define nl-create-link
151 $(NL_V_PROGRESS_LN_S)
152 $(NL_V_AT)$(LN_S) $(<) $(@)
153 endef # nl-create-link