You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
224
226
225
227
clean:
226
228
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
227
229
\end{code}
228
230
229
-
And finally just:
231
+
In \verb|Makefile|, \verb|$(CURDIR)| can set to the absolute pathname of the current working directory(after all \verb|-C| options are processed, if any).
232
+
See more about \verb|CURDIR| in \href{https://www.gnu.org/software/make/manual/make.html}{GNU make manual}.
233
+
234
+
And finally, just run \verb|make| directly.
235
+
230
236
\begin{codebash}
231
237
make
232
238
\end{codebash}
233
239
240
+
If there is no \verb|PWD := $(CURDIR)| statement in Makefile, then it may not compile correctly with \verb|sudo make|.
241
+
Because some environment variables are specified by the security policy, they can't be inherited.
242
+
The default security policy is \verb|sudoers|.
243
+
In the \verb|sudoers| security policy, \verb|env_reset| is enabled by default, which restricts environment variables.
244
+
Specifically, path variables are not retained from the user environment, they are set to default values (For more information see: \href{https://www.sudo.ws/docs/man/sudoers.man/}{sudoers manual}).
245
+
You can see the environment variable settings by:
246
+
247
+
\begin{verbatim}
248
+
$ sudo -s
249
+
# sudo -V
250
+
\end{verbatim}
251
+
252
+
Here is a simple Makefile as an example to demonstrate the problem mentioned above.
253
+
254
+
\begin{code}
255
+
all:
256
+
echo $(PWD)
257
+
\end{code}
258
+
259
+
Then, we can use \verb|-p| flag to print out the environment variable values from the Makefile.
260
+
261
+
\begin{verbatim}
262
+
$ make -p | grep PWD
263
+
PWD = /home/ubuntu/temp
264
+
OLDPWD = /home/ubuntu
265
+
echo $(PWD)
266
+
\end{verbatim}
267
+
268
+
The \verb|PWD| variable won't be inherited with \verb|sudo|.
269
+
270
+
\begin{verbatim}
271
+
$ sudo make -p | grep PWD
272
+
echo $(PWD)
273
+
\end{verbatim}
274
+
275
+
However, there are three ways to solve this problem.
276
+
277
+
\begin{enumerate}
278
+
\item {
279
+
You can use the \verb|-E| flag to temporarily preserve them.
280
+
281
+
\begin{codebash}
282
+
$ sudo -E make -p | grep PWD
283
+
PWD = /home/ubuntu/temp
284
+
OLDPWD = /home/ubuntu
285
+
echo $(PWD)
286
+
\end{codebash}
287
+
}
288
+
289
+
\item {
290
+
You can set the \verb|env_reset| disabled by editing the \verb|/etc/sudoers| with root and \verb|visudo|.
291
+
292
+
\begin{code}
293
+
## sudoers file.
294
+
##
295
+
...
296
+
Defaults env_reset
297
+
## Change env_reset to !env_reset in previous line to keep all environment variables
298
+
\end{code}
299
+
300
+
Then execute \verb|env| and \verb|sudo env| individually.
0 commit comments