| @@ -1,218 +1,218 @@ | | | @@ -1,218 +1,218 @@ |
1 | # $NetBSD: build.mk,v 1.33 2020/04/25 21:36:17 rillig Exp $ | | 1 | # $NetBSD: build.mk,v 1.34 2020/06/12 17:33:23 rillig Exp $ |
2 | # | | 2 | # |
3 | # This file defines what happens in the build phase, excluding the | | 3 | # This file defines what happens in the build phase, excluding the |
4 | # self-test, which is defined in test.mk. | | 4 | # self-test, which is defined in test.mk. |
5 | # | | 5 | # |
6 | # Public targets for developers: | | 6 | # Public targets for developers: |
7 | # | | 7 | # |
8 | # build-env: | | 8 | # build-env: |
9 | # Runs an interactive shell (BUILD_ENV_SHELL) in the environment | | 9 | # Runs an interactive shell (BUILD_ENV_SHELL) in the environment |
10 | # that is used for building the package. | | 10 | # that is used for building the package. |
11 | # | | 11 | # |
12 | # Package-settable variables: | | 12 | # Package-settable variables: |
13 | # | | 13 | # |
14 | # BUILD_MAKE_FLAGS is the list of arguments that is passed to the make | | 14 | # BUILD_MAKE_FLAGS is the list of arguments that is passed to the make |
15 | # process, in addition to the usual MAKE_FLAGS. | | 15 | # process, in addition to the usual MAKE_FLAGS. |
16 | # | | 16 | # |
17 | # BUILD_TARGET is the target from ${MAKE_FILE} that should be invoked | | 17 | # BUILD_TARGET is the target from ${MAKE_FILE} that should be invoked |
18 | # to build the sources. | | 18 | # to build the sources. |
19 | # | | 19 | # |
20 | # MAKE_JOBS_SAFE | | 20 | # MAKE_JOBS_SAFE |
21 | # Whether the package supports parallel builds. If set to yes, | | 21 | # Whether the package supports parallel builds. If set to yes, |
22 | # at most MAKE_JOBS jobs are carried out in parallel. The default | | 22 | # at most MAKE_JOBS jobs are carried out in parallel. The default |
23 | # value is "yes", and packages that don't support it must | | 23 | # value is "yes", and packages that don't support it must |
24 | # explicitly set it to "no". | | 24 | # explicitly set it to "no". |
25 | # | | 25 | # |
26 | # Keywords: parallel | | 26 | # Keywords: parallel |
27 | # | | 27 | # |
28 | # Variables defined in this file: | | 28 | # Variables defined in this file: |
29 | # | | 29 | # |
30 | # BUILD_MAKE_CMD | | 30 | # BUILD_MAKE_CMD |
31 | # This command sets the proper environment for the build phase | | 31 | # This command sets the proper environment for the build phase |
32 | # and runs make(1) on it. It takes a list of make targets and | | 32 | # and runs make(1) on it. It takes a list of make targets and |
33 | # flags as argument. | | 33 | # flags as argument. |
34 | # | | 34 | # |
35 | # See also: | | 35 | # See also: |
36 | # mk/build/test.mk | | 36 | # mk/build/test.mk |
37 | # | | 37 | # |
38 | # Keywords: build make | | 38 | # Keywords: build make |
39 | | | 39 | |
40 | _VARGROUPS+= build | | 40 | _VARGROUPS+= build |
41 | _DEF_VARS.build= _MAKE_JOBS_N | | 41 | _DEF_VARS.build= _MAKE_JOBS_N |
42 | _USER_VARS.build= MAKE_JOBS BUILD_ENV_SHELL | | 42 | _USER_VARS.build= MAKE_JOBS BUILD_ENV_SHELL |
43 | _PKG_VARS.build= MAKE_ENV MAKE_FLAGS BUILD_MAKE_FLAGS BUILD_TARGET MAKE_JOBS_SAFE | | 43 | _PKG_VARS.build= MAKE_ENV MAKE_FLAGS BUILD_MAKE_FLAGS BUILD_TARGET MAKE_JOBS_SAFE |
44 | _SYS_VARS.build= BUILD_MAKE_CMD | | 44 | _SYS_VARS.build= BUILD_MAKE_CMD |
45 | _SORTED_VARS.build= *_ENV | | 45 | _SORTED_VARS.build= *_ENV |
46 | _LISTED_VARS.build= *_FLAGS *_CMD | | 46 | _LISTED_VARS.build= *_FLAGS *_CMD |
47 | | | 47 | |
48 | BUILD_MAKE_FLAGS?= # none | | 48 | BUILD_MAKE_FLAGS?= # none |
49 | BUILD_TARGET?= all | | 49 | BUILD_TARGET?= all |
50 | | | 50 | |
51 | BUILD_MAKE_CMD= \ | | 51 | BUILD_MAKE_CMD= \ |
52 | ${PKGSRC_SETENV} ${MAKE_ENV} \ | | 52 | ${PKGSRC_SETENV} ${MAKE_ENV} \ |
53 | ${MAKE_PROGRAM} ${_MAKE_JOBS} \ | | 53 | ${MAKE_PROGRAM} ${_MAKE_JOBS} \ |
54 | ${MAKE_FLAGS} ${BUILD_MAKE_FLAGS} \ | | 54 | ${MAKE_FLAGS} ${BUILD_MAKE_FLAGS} \ |
55 | -f ${MAKE_FILE} | | 55 | -f ${MAKE_FILE} |
56 | | | 56 | |
57 | .if defined(MAKE_JOBS_SAFE) && !empty(MAKE_JOBS_SAFE:M[nN][oO]) | | 57 | .if defined(MAKE_JOBS_SAFE) && !empty(MAKE_JOBS_SAFE:M[nN][oO]) |
58 | _MAKE_JOBS= # nothing | | 58 | _MAKE_JOBS= # nothing |
59 | _MAKE_JOBS_N= 1 | | 59 | _MAKE_JOBS_N= 1 |
60 | .elif defined(MAKE_JOBS.${PKGPATH}) | | 60 | .elif defined(MAKE_JOBS.${PKGPATH}) |
61 | _MAKE_JOBS= -j${MAKE_JOBS.${PKGPATH}} | | 61 | _MAKE_JOBS= -j${MAKE_JOBS.${PKGPATH}} |
62 | _MAKE_JOBS_N= ${MAKE_JOBS.${PKGPATH}} | | 62 | _MAKE_JOBS_N= ${MAKE_JOBS.${PKGPATH}} |
63 | .elif defined(MAKE_JOBS) | | 63 | .elif defined(MAKE_JOBS) |
64 | _MAKE_JOBS= -j${MAKE_JOBS} | | 64 | _MAKE_JOBS= -j${MAKE_JOBS} |
65 | _MAKE_JOBS_N= ${MAKE_JOBS} | | 65 | _MAKE_JOBS_N= ${MAKE_JOBS} |
66 | .else | | 66 | .else |
67 | _MAKE_JOBS_N= 1 | | 67 | _MAKE_JOBS_N= 1 |
68 | .endif | | 68 | .endif |
69 | | | 69 | |
70 | ###################################################################### | | 70 | ###################################################################### |
71 | ### build (PUBLIC) | | 71 | ### build (PUBLIC) |
72 | ###################################################################### | | 72 | ###################################################################### |
73 | ### build is a public target to build the sources from the package. | | 73 | ### build is a public target to build the sources from the package. |
74 | ### | | 74 | ### |
75 | _BUILD_TARGETS+= check-vulnerable | | 75 | _BUILD_TARGETS+= check-vulnerable |
76 | _BUILD_TARGETS+= configure | | 76 | _BUILD_TARGETS+= configure |
77 | _BUILD_TARGETS+= acquire-build-lock | | 77 | _BUILD_TARGETS+= acquire-build-lock |
78 | _BUILD_TARGETS+= ${_COOKIE.build} | | 78 | _BUILD_TARGETS+= ${_COOKIE.build} |
79 | _BUILD_TARGETS+= release-build-lock | | 79 | _BUILD_TARGETS+= release-build-lock |
80 | .if ${_USE_NEW_PKGINSTALL:Uno} == "no" | | 80 | .if ${_USE_NEW_PKGINSTALL:Uno} == "no" |
81 | _BUILD_TARGETS+= pkginstall | | 81 | _BUILD_TARGETS+= pkginstall |
82 | .endif | | 82 | .endif |
83 | | | 83 | |
84 | .PHONY: build | | 84 | .PHONY: build |
85 | .if !target(build) | | 85 | .if !target(build) |
86 | . if exists(${_COOKIE.build}) && !${_CLEANING} | | 86 | . if exists(${_COOKIE.build}) && !${_CLEANING} |
87 | build: | | 87 | build: |
88 | @${DO_NADA} | | 88 | @${DO_NADA} |
89 | . elif defined(_PKGSRC_BARRIER) | | 89 | . elif defined(_PKGSRC_BARRIER) |
90 | build: ${_BUILD_TARGETS} | | 90 | build: ${_BUILD_TARGETS} |
91 | . else | | 91 | . else |
92 | build: barrier | | 92 | build: barrier |
93 | . endif | | 93 | . endif |
94 | .endif | | 94 | .endif |
95 | | | 95 | |
96 | .PHONY: acquire-build-lock release-build-lock | | 96 | .PHONY: acquire-build-lock release-build-lock |
97 | acquire-build-lock: acquire-lock | | 97 | acquire-build-lock: acquire-lock |
98 | release-build-lock: release-lock | | 98 | release-build-lock: release-lock |
99 | | | 99 | |
100 | .if exists(${_COOKIE.build}) && !${_CLEANING} | | 100 | .if exists(${_COOKIE.build}) && !${_CLEANING} |
101 | ${_COOKIE.build}: | | 101 | ${_COOKIE.build}: |
102 | @${DO_NADA} | | 102 | @${DO_NADA} |
103 | .else | | 103 | .else |
104 | ${_COOKIE.build}: real-build | | 104 | ${_COOKIE.build}: real-build |
105 | .endif | | 105 | .endif |
106 | | | 106 | |
107 | ###################################################################### | | 107 | ###################################################################### |
108 | ### rebuild (PUBLIC) | | 108 | ### rebuild (PUBLIC) |
109 | ###################################################################### | | 109 | ###################################################################### |
110 | ### rebuild is a special target to re-run the build target. | | 110 | ### rebuild is a special target to re-run the build target. |
111 | ### | | 111 | ### |
112 | | | 112 | |
113 | .PHONY: rebuild | | 113 | .PHONY: rebuild |
114 | rebuild: build-clean | | 114 | rebuild: build-clean |
115 | ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} build | | 115 | ${RUN} ${RECURSIVE_MAKE} ${MAKEFLAGS} build |
116 | | | 116 | |
117 | ###################################################################### | | 117 | ###################################################################### |
118 | ### build-clean (PRIVATE) | | 118 | ### build-clean (PRIVATE) |
119 | ###################################################################### | | 119 | ###################################################################### |
120 | ### build-clean removes the state files for the "build" and | | 120 | ### build-clean removes the state files for the "build" and |
121 | ### later phases so that the "build" target may be re-invoked. | | 121 | ### later phases so that the "build" target may be re-invoked. |
122 | ### | | 122 | ### |
123 | .PHONY: build-clean | | 123 | .PHONY: build-clean |
124 | build-clean: install-clean _package-clean | | 124 | build-clean: install-clean _package-clean |
125 | ${RUN} ${RM} -f ${_COOKIE.build} | | 125 | ${RUN} ${RM} -f ${_COOKIE.build} |
126 | | | 126 | |
127 | ###################################################################### | | 127 | ###################################################################### |
128 | ### real-build (PRIVATE) | | 128 | ### real-build (PRIVATE) |
129 | ###################################################################### | | 129 | ###################################################################### |
130 | ### real-build is a helper target onto which one can hook all of the | | 130 | ### real-build is a helper target onto which one can hook all of the |
131 | ### targets that do the actual building of the sources. | | 131 | ### targets that do the actual building of the sources. |
132 | ### | | 132 | ### |
133 | _REAL_BUILD_TARGETS+= build-check-interactive | | 133 | _REAL_BUILD_TARGETS+= build-check-interactive |
134 | _REAL_BUILD_TARGETS+= build-message | | 134 | _REAL_BUILD_TARGETS+= build-message |
135 | _REAL_BUILD_TARGETS+= build-vars | | 135 | _REAL_BUILD_TARGETS+= build-vars |
136 | _REAL_BUILD_TARGETS+= pre-build-checks-hook | | 136 | _REAL_BUILD_TARGETS+= pre-build-checks-hook |
137 | _REAL_BUILD_TARGETS+= pre-build | | 137 | _REAL_BUILD_TARGETS+= pre-build |
138 | _REAL_BUILD_TARGETS+= do-build | | 138 | _REAL_BUILD_TARGETS+= do-build |
139 | _REAL_BUILD_TARGETS+= post-build | | 139 | _REAL_BUILD_TARGETS+= post-build |
140 | _REAL_BUILD_TARGETS+= build-cookie | | 140 | _REAL_BUILD_TARGETS+= build-cookie |
141 | _REAL_BUILD_TARGETS+= error-check | | 141 | _REAL_BUILD_TARGETS+= error-check |
142 | | | 142 | |
143 | .PHONY: real-build | | 143 | .PHONY: real-build |
144 | real-build: ${_REAL_BUILD_TARGETS} | | 144 | real-build: ${_REAL_BUILD_TARGETS} |
145 | | | 145 | |
146 | .PHONY: build-message | | 146 | .PHONY: build-message |
147 | build-message: | | 147 | build-message: |
148 | @${PHASE_MSG} "Building for ${PKGNAME}" | | 148 | @${PHASE_MSG} "Building for ${PKGNAME}" |
149 | | | 149 | |
150 | ###################################################################### | | 150 | ###################################################################### |
151 | ### build-check-interactive (PRIVATE) | | 151 | ### build-check-interactive (PRIVATE) |
152 | ###################################################################### | | 152 | ###################################################################### |
153 | ### build-check-interactive checks whether we must do an interactive | | 153 | ### build-check-interactive checks whether we must do an interactive |
154 | ### build or not. | | 154 | ### build or not. |
155 | ### | | 155 | ### |
156 | build-check-interactive: | | 156 | build-check-interactive: |
157 | .if !empty(INTERACTIVE_STAGE:Mbuild) && defined(BATCH) | | 157 | .if !empty(INTERACTIVE_STAGE:Mbuild) && defined(BATCH) |
158 | @${ERROR_MSG} "The build stage of this package requires user interaction" | | 158 | @${ERROR_MSG} "The build stage of this package requires user interaction" |
159 | @${ERROR_MSG} "Please build manually with:" | | 159 | @${ERROR_MSG} "Please build manually with:" |
160 | @${ERROR_MSG} " \"cd ${.CURDIR} && ${MAKE} build\"" | | 160 | @${ERROR_MSG} " \"cd ${.CURDIR} && ${MAKE} build\"" |
161 | ${RUN} ${FALSE} | | 161 | ${RUN} ${FALSE} |
162 | .else | | 162 | .else |
163 | @${DO_NADA} | | 163 | @${DO_NADA} |
164 | .endif | | 164 | .endif |
165 | | | 165 | |
166 | ###################################################################### | | 166 | ###################################################################### |
167 | ### pre-build, do-build, post-build (PUBLIC, override) | | 167 | ### pre-build, do-build, post-build (PUBLIC, override) |
168 | ###################################################################### | | 168 | ###################################################################### |
169 | ### {pre,do,post}-build are the heart of the package-customizable | | 169 | ### {pre,do,post}-build are the heart of the package-customizable |
170 | ### build targets, and may be overridden within a package Makefile. | | 170 | ### build targets, and may be overridden within a package Makefile. |
171 | ### | | 171 | ### |
172 | .PHONY: pre-build do-build post-build | | 172 | .PHONY: pre-build do-build post-build |
173 | | | 173 | |
174 | .if !target(do-build) | | 174 | .if !target(do-build) |
175 | do-build: | | 175 | do-build: |
176 | . for _dir_ in ${BUILD_DIRS} | | 176 | . for _dir_ in ${BUILD_DIRS} |
177 | ${RUN}${_ULIMIT_CMD} \ | | 177 | ${RUN}${_ULIMIT_CMD} \ |
178 | cd ${WRKSRC} && cd ${_dir_} && \ | | 178 | cd ${WRKSRC} && cd ${_dir_} && \ |
179 | ${BUILD_MAKE_CMD} ${BUILD_TARGET} | | 179 | ${BUILD_MAKE_CMD} ${BUILD_TARGET} |
180 | . endfor | | 180 | . endfor |
181 | .endif | | 181 | .endif |
182 | | | 182 | |
183 | .if !target(pre-build) | | 183 | .if !target(pre-build) |
184 | pre-build: | | 184 | pre-build: |
185 | @${DO_NADA} | | 185 | @${DO_NADA} |
186 | .endif | | 186 | .endif |
187 | | | 187 | |
188 | .if !target(post-build) | | 188 | .if !target(post-build) |
189 | post-build: | | 189 | post-build: |
190 | @${DO_NADA} | | 190 | @${DO_NADA} |
191 | .endif | | 191 | .endif |
192 | | | 192 | |
193 | # build-env: | | 193 | # build-env: |
194 | # Starts an interactive shell in WRKSRC. | | 194 | # Starts an interactive shell in WRKSRC. |
195 | # | | 195 | # |
196 | # This is only used during development and testing of a package | | 196 | # This is only used during development and testing of a package |
197 | # to work in the environment (MAKE_ENV) that is used by default | | 197 | # to work in the environment (MAKE_ENV) that is used by default |
198 | # for building the packages. | | 198 | # for building the packages. |
199 | # | | 199 | # |
200 | # User-settable variables: | | 200 | # User-settable variables: |
201 | # | | 201 | # |
202 | # BUILD_ENV_SHELL | | 202 | # BUILD_ENV_SHELL |
203 | # The shell to start. | | 203 | # The shell to start. |
204 | # | | 204 | # |
205 | # Default: ${SHELL}, fallback ${SH} | | 205 | # Default: ${SH}, to realistically match the build environment. |
206 | # | | 206 | # |
207 | # Keywords: debug build | | 207 | # Keywords: debug build |
208 | | | 208 | |
209 | BUILD_ENV_SHELL?= ${SHELL:U${SH}} | | 209 | BUILD_ENV_SHELL?= ${SH} |
210 | build-env: .PHONY ${_PKGSRC_BARRIER:Ubarrier:D_build-env} | | 210 | build-env: .PHONY ${_PKGSRC_BARRIER:Ubarrier:D_build-env} |
211 | _build-env: .PHONY configure | | 211 | _build-env: .PHONY configure |
212 | @${STEP_MSG} "Entering the build environment for ${PKGNAME}" | | 212 | @${STEP_MSG} "Entering the build environment for ${PKGNAME}" |
213 | .if ${BUILD_DIRS:[#]} > 1 || ${BUILD_DIRS} != ${WRKSRC} | | 213 | .if ${BUILD_DIRS:[#]} > 1 || ${BUILD_DIRS} != ${WRKSRC} |
214 | @${ECHO_MSG} "The BUILD_DIRS are:" \ | | 214 | @${ECHO_MSG} "The BUILD_DIRS are:" \ |
215 | ${BUILD_DIRS:S,^${WRKSRC}$,.,:S,^${WRKSRC}/,,:Q} | | 215 | ${BUILD_DIRS:S,^${WRKSRC}$,.,:S,^${WRKSRC}/,,:Q} |
216 | .endif | | 216 | .endif |
217 | ${RUN}${_ULIMIT_CMD} \ | | 217 | ${RUN}${_ULIMIT_CMD} \ |
218 | cd ${WRKSRC} && ${PKGSRC_SETENV} ${MAKE_ENV} ${BUILD_ENV_SHELL} | | 218 | cd ${WRKSRC} && ${PKGSRC_SETENV} ${MAKE_ENV} ${BUILD_ENV_SHELL} |