1 # $Id: sys.clean-env.mk,v 1.21 2016/02/18 21:16:40 sjg Exp $
3 # @(#) Copyright (c) 2009, Simon J. Gerraty
5 # This file is provided in the hope that it will
6 # be of use. There is absolutely NO WARRANTY.
7 # Permission to copy, redistribute or otherwise
8 # use this file is hereby granted provided that
9 # the above copyright notice and this notice are
12 # Please send copies of changes and bug-fixes to:
16 # This makefile would normally be included by sys.env.mk
18 # The variables used by this makefile include:
20 # MAKE_ENV_SAVE_VAR_LIST
21 # The actuall list of variables from the environment that will be
23 # MAKE_ENV_SAVE_PREFIX_LIST
24 # A list of prefixes to match against the environment - the results
25 # are added to MAKE_ENV_SAVE_VAR_LIST after being filtered by...
26 # MAKE_ENV_SAVE_EXCLUDE_LIST
27 # A list of words or patterns which is turned into a list of :N
30 .if
${.MAKE.LEVEL
} == 0 && ${MAKE_VERSION} >= 20100606
31 # We save any env var that starts with the words in MAKE_ENV_SAVE_PREFIX_LIST.
32 # This gets expanded to an egrep expression like '^(A|B|C...)'
33 # and added to MAKE_ENV_SAVE_VAR_LIST below.
34 # If any of these end up being too greedy, MAKE_ENV_SAVE_EXCLUDE_LIST
35 # can be used to filter.
36 MAKE_ENV_SAVE_PREFIX_LIST
+= \
54 # This could be a list of vars or patterns to explicitly exclude.
55 MAKE_ENV_SAVE_EXCLUDE_LIST ?
= _
57 # This is the actual list that we will save
58 # HOME is probably something worth clobbering eg.
60 MAKE_ENV_SAVE_VAR_LIST
+= \
69 ${_env_vars
:${MAKE_ENV_SAVE_EXCLUDE_LIST
:${M_ListToSkip}}}
71 _env_vars
!= env | egrep
'^(${MAKE_ENV_SAVE_PREFIX_LIST:ts|})' | sed
's,=.*,,'; echo
74 .for v in
${MAKE_ENV_SAVE_VAR_LIST
:O
:u
}
82 # Now, clobber the environment
85 # This is a list of vars that we handle specially below
86 _tricky_env_vars
= MAKEOBJDIR OBJTOP
87 # Export our selection - sans tricky ones
88 .
export ${_export_list
:${_tricky_env_vars
:${M_ListToSkip}}}
90 # This next bit may need tweaking
91 # if you don't happen to like the way I set it.
92 .if defined
(MAKEOBJDIR
)
93 # We are going to set this to the equivalent of the shell's
94 # MAKEOBJDIR='${.CURDIR:S,${SRCTOP},${OBJTOP},}'
95 _srctop
:= ${SRCTOP
:U
${SB_SRC
:U
${SB}/src
}}
96 _objroot
:= ${OBJROOT
:U
${SB_OBJROOT
:U
${SB}/${SB_OBJPREFIX}}}
97 .if
${MAKE_VERSION} < 20160218
98 _objtop
:= ${OBJTOP
:U
${_objroot}${MACHINE}}
99 # Take care of ${MACHINE}
100 .if
${MACHINE} == "host" ||
${OBJTOP} == ${HOST_OBJTOP
:Uno
}
101 OBJTOP
= ${_objtop
:S
,${HOST_TARGET}$,\
${MACHINE},}
103 OBJTOP
= ${_objtop
:S
,${MACHINE}$,\
${MACHINE},}
106 MAKEOBJDIR
= $${.CURDIR
:S
,${_srctop},$${OBJTOP},}
107 #.info ${MAKE_SAVE_ENV_VARS _srctop _objroot _objtop OBJTOP MAKEOBJDIR:L:@v@${.newline}$v=${$v}@}
109 # Export these as-is, and do not track...
110 # otherwise the environment will be ruined when we evaluate them below.
111 .export-env
${_tricky_env_vars}
113 # Now evaluate for ourselves
114 .for v in
${_tricky_env_vars}
118 # we cannot use the '$$' trick, anymore
119 # but we can export a literal (unexpanded) value
121 OBJROOT
:= ${_objroot}
122 OBJTOP
= ${OBJROOT}${MACHINE}
123 MAKEOBJDIR
= ${.CURDIR
:S
,${SRCTOP},${OBJTOP},}
124 .export-literal SRCTOP OBJROOT
${_tricky_env_vars}
126 #.info ${_tricky_env_vars:@v@${.newline}$v=${$v}@}
128 # @env | egrep 'OBJ|SRC'