Debian Codegraph @

init/Makefile

raw
1 .PHONY: dist-win install install-testconfig uninstall-testconfig uninstall \
2 clean
3
4 # use bash shell to correctly expand the $'' syntax used in translate-in-script
5 SHELL = /usr/bin/env bash
6
7 # commands to install files
8 INSTALL = install
9 INSTALL_DIR = $(INSTALL) -d -m 755
10 INSTALL_DATA = $(INSTALL) -m 644
11
12 SH_LIKE = sh ksh bash zsh profile.sh
13 CSH_LIKE = csh tcsh tcsh_completion profile.csh
14 OTHER = perl.pm python.py ruby.rb lisp tcl fish cmake r.R pwsh.ps1
15
16 # example modulefiles to install
17 EXAMPLE_MODFILES_SRCDIR := ../share/modulefiles
18 EXAMPLE_MODFILES = dot module-git module-info modules null use.own
19 EXAMPLE_WIN_MODFILES = module-git module-info null
20 EXAMPLE_TESTCONFIG_MODFILES = null
21
22 # source definitions shared across the Makefiles of this project
23 ifneq ($(wildcard ../Makefile.inc),../Makefile.inc)
24 $(error ../Makefile.inc is missing, please run '../configure')
25 endif
26 include ../Makefile.inc
27
28 # generate 'module use' commands to put in initrc from modulepath unless
29 # if the modulespath config file should be deployed
30 ifeq ($(setmodulespath),n)
31 # need to escape eventual space character in each modulepath/loadedmodule
32 # entry to correctly produce the module use/module load rules
33 space := $(subst ,, )
34 modulerc := \\\n\# enable default modulepaths
35 modulerc := $(modulerc)$(subst |,$(space),$(addprefix \\\nmodule use --append {,\
36 $(subst :,} ,$(subst $(space),|,$(modulepath)))}))
37 endif
38 # generate 'module load' commands to put in initrc from loadedmodules
39 ifneq ($(loadedmodules),)
40 modulerc := $(modulerc)$(subst |,$(space),$(addprefix \\\nmodule load {,\
41 $(subst :,} ,$(subst $(space),|,$(loadedmodules)))}))
42 endif
43 ifneq ($(modulerc),)
44 modulerc := $(modulerc)\\\n
45 endif
46
47 # setup summary echo rules unless silent mode set
48 ECHO_DIR_PREFIX = init/
49 ifneq ($(findstring s,$(MAKEFLAGS)),s)
50 ECHO_GEN = @echo ' ' GEN $(ECHO_DIR_PREFIX)$@;
51 endif
52
53 ALL_SHELLS = $(SH_LIKE) $(CSH_LIKE) $(OTHER)
54
55 all: $(ALL_SHELLS) initrc bash_completion zsh-functions/_module $(EXAMPLE_MODFILES_SRCDIR)/modules
56 ifeq ($(versioning),y)
57 all: $(EXAMPLE_MODFILES_SRCDIR)/version
58 endif
59 ifeq ($(setmodulespath),y)
60 # both configuration files will be installed and in this case default init
61 # scripts will use both files, modulespath evaluated prior initrc. In this
62 # case the modulespaths sets are only generated in modulespath config file.
63 all: modulespath
64 endif
65
66 # define init configs location
67 ifeq ($(initconfin),etcdir)
68 modulespath := $(etcdir)/modulespath
69 initrc := $(etcdir)/initrc
70 else
71 modulespath := $(initdir)/.modulespath
72 initrc := $(initdir)/modulerc
73 endif
74
75 # define shell completion location
76 ifeq ($(bashcompletiondir),)
77 bashcompletiondir := $(initdir)
78 makebashcompdir := n
79 else
80 makebashcompdir := y
81 endif
82 ifeq ($(fishcompletiondir),)
83 fishcompletiondir := $(initdir)
84 makefishcompdir := n
85 else
86 makefishcompdir := y
87 endif
88 ifeq ($(zshcompletiondir),)
89 zshcompletiondir := $(initdir)/zsh-functions
90 setzshfpathre := s|@setzshfpath@||g
91 else
92 setzshfpathre := /@setzshfpath@/d
93 endif
94
95 # comment entries if feature not enabled
96 ifeq ($(versioning),y)
97 versdir := $(baseprefix)/versions
98 setversioning :=
99 else
100 setversioning := \#
101 endif
102
103 # define translation rules for quarantine mechanism
104 ifeq ($(quarantinevars),)
105 setquarvarsre := /@setquarvars@/d
106 notsetquarvarsre := s|@notsetquarvars@||g
107 else
108 setquarvarsre := s|@setquarvars@||g
109 notsetquarvarsre := /@notsetquarvars@/d
110 define runenvvarre
111 $(if $(filter-out ${1},${2}),s|\(@\(.*\)RUNENV_VAR\(.*\)RUNENV_VAL\(.*\)@\)|\2MODULES_RUNENV_${1}\3${2}\4\n\1|g;)
112 endef
113 quarvarsre = -e 's|@RUN_QUARANTINE@|$(foreach vv,$(quarantinevars),$(firstword\
114 $(subst =, ,$(vv))))|g;
115 quarvarsre += $(foreach vv,$(quarantinevars),$(call runenvvarre,$(firstword\
116 $(subst =, ,$(vv))),$(subst $(firstword $(subst =, ,$(vv)))=,,$(vv))))
117 quarvarsre += s/@.*RUNENV_VAR.*@//;'
118 endif
119
120 # define variables for shell completion
121 comp_cmds := add add-any apropos aliases avail append-path cachebuild cacheclear clear config del describe disable display edit help initadd initclear initlist initprepend initrm is-loaded is-saved is-used is-avail info-loaded keyword lint list load load-any mod-to-sh path paths purge prepend-path refresh reload reset restore rm remove remove-path save savelist saveshow saverm search show sh-to-mod source spider stash stashclear stashlist stashpop stashrm stashshow state swap switch test try-add try-load unload unuse update use whatis
122 comp_long_opts := --debug --dumpname --help --silent --trace --verbose --version --paginate --no-pager --color --color= --width --width= --ignore-cache --ignore-user-rc
123 comp_opts := -D -h -s -T -v -V -w $(comp_long_opts)
124 comp_load_opts := --auto --no-auto --force -f --icase -i --tag --tag=
125 comp_unload_opts := --auto --no-auto --force -f --icase -i
126 comp_list_opts := -a -j -l -o -t --all --json --long --output --output= --terse
127 comp_stashlist_opts := -j -l -t --json --long --terse
128 comp_clear_opts := --force -f
129 comp_avail_opts := -a -C -d -i -j -L -l -o -S -t --all --contains --default --icase --json --latest --long --output --output= --starts-with --terse --indepth --no-indepth
130 comp_mfile_opts := -i --icase
131 comp_whatis_opts := -a -i -j --all --icase --json
132 comp_search_opts := -a -j --all --json
133 comp_aliases_opts := -a --all
134 comp_isavail_opts := -a -i --all --icase
135 comp_lint_opts := -a -i --all --icase
136 comp_modtosh_opts := --auto --no-auto --force -f --icase -i
137 comp_path_opts := -d --delim --duplicates
138 comp_rm_path_opts := -d --delim --index
139 comp_config_opts := --dump-state --reset abort_on_error advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output cache_buffer_bytes cache_expiry_secs collection_pin_version collection_pin_tag collection_target color colors conflict_unload contact editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_user_rc implicit_default implicit_requirement list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml nearly_forbidden_days pager protected_envvars quarantine_support rcfile redirect_output require_via reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277
140
141 define translate-in-script
142 $(ECHO_GEN)
143 sed -e 's|@prefix@|$(prefix)|g' \
144 -e 's|@baseprefix@|$(baseprefix)|g' \
145 -e 's|@libexecdir@|$(libexecdir)|g' \
146 -e 's|@initdir@|$(initdir)|g' \
147 -e 's|@etcdir@|$(etcdir)|g' \
148 -e 's|@modulefilesdir@|$(modulefilesdir)|g' \
149 -e 's|@bindir@|$(bindir)|g' \
150 -e 's|@mandir@|$(mandir)|g' \
151 -e 's|@comp_cmds@|$(comp_cmds)|g' \
152 -e 's|@comp_long_opts@|$(comp_long_opts)|g' \
153 -e 's|@comp_opts@|$(comp_opts)|g' \
154 -e 's|@comp_load_opts@|$(comp_load_opts)|g' \
155 -e 's|@comp_unload_opts@|$(comp_unload_opts)|g' \
156 -e 's|@comp_list_opts@|$(comp_list_opts)|g' \
157 -e 's|@comp_stashlist_opts@|$(comp_stashlist_opts)|g' \
158 -e 's|@comp_clear_opts@|$(comp_clear_opts)|g' \
159 -e 's|@comp_avail_opts@|$(comp_avail_opts)|g' \
160 -e 's|@comp_mfile_opts@|$(comp_mfile_opts)|g' \
161 -e 's|@comp_whatis_opts@|$(comp_whatis_opts)|g' \
162 -e 's|@comp_search_opts@|$(comp_search_opts)|g' \
163 -e 's|@comp_aliases_opts@|$(comp_aliases_opts)|g' \
164 -e 's|@comp_isavail_opts@|$(comp_isavail_opts)|g' \
165 -e 's|@comp_lint_opts@|$(comp_lint_opts)|g' \
166 -e 's|@comp_modtosh_opts@|$(comp_modtosh_opts)|g' \
167 -e 's|@comp_path_opts@|$(comp_path_opts)|g' \
168 -e 's|@comp_rm_path_opts@|$(comp_rm_path_opts)|g' \
169 -e 's|@comp_config_opts@|$(comp_config_opts)|g' \
170 -e '$(setzshfpathre)' \
171 -e $$'s|@modulerc@|$(modulerc)|g' \
172 -e 's|@modulepath@|$(modulepath)|g' \
173 -e '$(setquarvarsre)' $(quarvarsre) \
174 -e '$(notsetquarvarsre)' \
175 -e 's|@SHELLNAME@|$@|g' \
176 -e 's|@VERSIONING@|$(setversioning)|g' \
177 -e 's|@VERSION@|$(VERSION)|g' \
178 -e 's|@SED_ERE@|$(SED_ERE)|g' \
179 -e 's|@PS@|$(PS)|g' \
180 -e 's|@BASENAME@|$(BASENAME)|g' \
181 -e 's|@TCLSH@|$(TCLSH)|g' $< > $@
182 endef
183
184 # avoid shared definitions to be rebuilt by make
185 ../Makefile.inc: ;
186
187 %: %.in
188 $(translate-in-script)
189
190 # workaround '\\\n' issue on Linux with Make 3.81
191 initrc: initrc.in
192 $(translate-in-script)
193 mv $@ ${@}.tmp
194 sed -e 's|\\$$||' ${@}.tmp > $@
195 rm -f ${@}.tmp
196
197 # tcsh is derivated from csh init script
198 tcsh: csh.in
199 $(translate-in-script)
200
201 # this rule is needed for profile.sh to get matched
202 profile.sh: profile.sh.in
203 $(translate-in-script)
204
205 $(EXAMPLE_MODFILES_SRCDIR)/modules: $(EXAMPLE_MODFILES_SRCDIR)/modules.in
206 $(translate-in-script)
207
208 $(EXAMPLE_MODFILES_SRCDIR)/version: $(EXAMPLE_MODFILES_SRCDIR)/version.in
209 $(translate-in-script)
210
211 dist-win: pwsh.ps1
212 $(INSTALL_DIR) '$(DIST_WIN_PREFIX)/init'
213 $(INSTALL_DATA) cmd.cmd '$(DIST_WIN_PREFIX)/init/'
214 $(INSTALL_DATA) pwsh.ps1 '$(DIST_WIN_PREFIX)/init/'
215 $(INSTALL_DIR) '$(DIST_WIN_PREFIX)/modulefiles'
216 $(INSTALL_DATA) $(addprefix $(EXAMPLE_MODFILES_SRCDIR)/,$(EXAMPLE_WIN_MODFILES)) '$(DIST_WIN_PREFIX)/modulefiles/'
217
218 # example configs for test rules
219 install-testconfig:
220 $(INSTALL_DIR) '$(DESTDIR)$(initdir)'
221 $(INSTALL_DIR) '$(DESTDIR)$(etcdir)'
222 $(INSTALL_DIR) '$(DESTDIR)$(prefix)/etc'
223 $(INSTALL_DIR) '$(DESTDIR)$(modulefilesdir)'
224 $(INSTALL_DIR) '$(DESTDIR)$(prefix)/test/modulefiles' '$(DESTDIR)$(prefix)/test/etc'
225 $(INSTALL_DATA) $(addprefix $(EXAMPLE_MODFILES_SRCDIR)/,$(EXAMPLE_TESTCONFIG_MODFILES)) '$(DESTDIR)$(modulefilesdir)/'
226
227 uninstall-testconfig:
228 rmdir '$(DESTDIR)$(prefix)/test/modulefiles' '$(DESTDIR)$(prefix)/test/etc' '$(DESTDIR)$(prefix)/test'
229 rm -f $(foreach modfile,$(EXAMPLE_TESTCONFIG_MODFILES),'$(DESTDIR)$(modulefilesdir)/$(modfile)')
230 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(modulefilesdir)' || true
231 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(etcdir)' || true
232 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(initdir)' || true
233
234 install: all
235 $(INSTALL_DIR) '$(DESTDIR)$(initdir)'
236 $(INSTALL_DIR) '$(DESTDIR)$(initdir)/ksh-functions'
237 ifeq ($(initconfin),etcdir)
238 $(INSTALL_DIR) '$(DESTDIR)$(etcdir)'
239 endif
240 ifeq ($(makebashcompdir),y)
241 $(INSTALL_DIR) '$(DESTDIR)$(bashcompletiondir)'
242 endif
243 ifeq ($(makefishcompdir),y)
244 $(INSTALL_DIR) '$(DESTDIR)$(fishcompletiondir)'
245 endif
246 $(INSTALL_DIR) '$(DESTDIR)$(zshcompletiondir)'
247 $(INSTALL_DIR) '$(DESTDIR)$(modulefilesdir)'
248 $(INSTALL_DATA) $(ALL_SHELLS) '$(DESTDIR)$(initdir)/'
249 ifeq ($(windowssupport),y)
250 $(INSTALL_DATA) cmd.cmd '$(DESTDIR)$(initdir)/'
251 endif
252 ifeq ($(makefishcompdir),y)
253 $(INSTALL_DATA) fish_completion '$(DESTDIR)$(fishcompletiondir)/module.fish'
254 else
255 $(INSTALL_DATA) fish_completion '$(DESTDIR)$(fishcompletiondir)/'
256 endif
257 ifeq ($(makebashcompdir),y)
258 $(INSTALL_DATA) bash_completion '$(DESTDIR)$(bashcompletiondir)/module'
259 ln -s module '$(DESTDIR)$(bashcompletiondir)/ml'
260 else
261 $(INSTALL_DATA) bash_completion '$(DESTDIR)$(bashcompletiondir)/'
262 endif
263 $(INSTALL_DATA) zsh-functions/_module '$(DESTDIR)$(zshcompletiondir)/'
264 $(INSTALL_DATA) ksh '$(DESTDIR)$(initdir)/ksh-functions/module'
265 $(INSTALL_DATA) ksh '$(DESTDIR)$(initdir)/ksh-functions/ml'
266 $(INSTALL_DATA) initrc '$(DESTDIR)$(initrc)'
267 ifeq ($(setmodulespath),y)
268 $(INSTALL_DATA) modulespath $(DESTDIR)$(modulespath)
269 endif
270 ifeq ($(examplemodulefiles),y)
271 $(INSTALL_DATA) $(addprefix $(EXAMPLE_MODFILES_SRCDIR)/,$(EXAMPLE_MODFILES)) '$(DESTDIR)$(modulefilesdir)/'
272 endif
273 ifeq ($(versioning),y)
274 $(INSTALL_DIR) '$(DESTDIR)$(versdir)'
275 $(INSTALL_DATA) $(EXAMPLE_MODFILES_SRCDIR)/version '$(DESTDIR)$(versdir)/$(VERSION)'
276 endif
277
278 uninstall:
279 rm -f $(foreach initscript,$(ALL_SHELLS),'$(DESTDIR)$(initdir)/$(initscript)')
280 ifeq ($(windowssupport),y)
281 rm -f '$(DESTDIR)$(initdir)/cmd.cmd'
282 endif
283 rm -f '$(DESTDIR)$(initdir)/ksh-functions/module'
284 rm -f '$(DESTDIR)$(initdir)/ksh-functions/ml'
285 ifeq ($(makebashcompdir),y)
286 rm -f '$(DESTDIR)$(bashcompletiondir)/ml'
287 rm -f '$(DESTDIR)$(bashcompletiondir)/module'
288 else
289 rm -f '$(DESTDIR)$(bashcompletiondir)/bash_completion'
290 endif
291 ifeq ($(makefishcompdir),y)
292 rm -f '$(DESTDIR)$(fishcompletiondir)/module.fish'
293 else
294 rm -f '$(DESTDIR)$(fishcompletiondir)/fish_completion'
295 endif
296 rm -f '$(DESTDIR)$(zshcompletiondir)/_module'
297 rm -f '$(DESTDIR)$(modulespath)' '$(DESTDIR)$(initrc)'
298 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(modulefilesdir)' || true
299 @if [ -d '$(DESTDIR)$(modulefilesdir)' ]; then echo; echo "WARNING: '$(DESTDIR)$(modulefilesdir)' is not empty so skip removal" >&2; echo; fi
300 rmdir '$(DESTDIR)$(initdir)/ksh-functions'
301 ifeq ($(makebashcompdir),y)
302 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(bashcompletiondir)' || true
303 endif
304 ifeq ($(makefishcompdir),y)
305 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(fishcompletiondir)' || true
306 endif
307 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(zshcompletiondir)' || true
308 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(initdir)' || true
309 @if [ -d '$(DESTDIR)$(initdir)' ]; then echo; echo "WARNING: '$(DESTDIR)$(initdir)' is not empty so skip removal" >&2; echo; fi
310 ifeq ($(versioning),y)
311 rm -f '$(DESTDIR)$(versdir)/$(VERSION)'
312 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(versdir)' || true
313 @if [ -d '$(DESTDIR)$(versdir)' ]; then echo; echo "WARNING: '$(DESTDIR)$(versdir)' is not empty so skip removal" >&2; echo; fi
314 endif
315
316 clean:
317 rm -f $(ALL_SHELLS) initrc bash_completion zsh-functions/_module modulespath $(EXAMPLE_MODFILES_SRCDIR)/modules
318 ifeq ($(versioning),y)
319 rm -f $(EXAMPLE_MODFILES_SRCDIR)/version
320 endif
321
322 # quiet all commands unless verbose mode set
323 ifeq ($(VERBOSE),1)
324 V = 1
325 endif
326 # let verbose by default the install/clean/test and other specific non-build targets
327 $(V).SILENT: sh ksh bash zsh csh tcsh fish perl.pm python.py ruby.rb lisp tcl \
328 cmake r.R bash_completion tcsh_completion zsh-functions/_module profile.sh \
329 profile.csh modulespath initrc $(EXAMPLE_MODFILES_SRCDIR)/modules \
330 $(EXAMPLE_MODFILES_SRCDIR)/version pwsh.ps1