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 env_modules.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 # define python module location
96 ifeq ($(pythondir),)
97 pythondir := $(initdir)
98 makepythondir := n
99 else
100 makepythondir := y
101 endif
102
103 # comment entries if feature not enabled
104 ifeq ($(versioning),y)
105 versdir := $(baseprefix)/versions
106 setversioning :=
107 else
108 setversioning := \#
109 endif
110
111 # define translation rules for quarantine mechanism
112 ifeq ($(quarantinevars),)
113 setquarvarsre := /@setquarvars@/d
114 notsetquarvarsre := s|@notsetquarvars@||g
115 else
116 setquarvarsre := s|@setquarvars@||g
117 notsetquarvarsre := /@notsetquarvars@/d
118 define runenvvarre
119 $(if $(filter-out ${1},${2}),s|\(@\(.*\)RUNENV_VAR\(.*\)RUNENV_VAL\(.*\)@\)|\2MODULES_RUNENV_${1}\3${2}\4\n\1|g;)
120 endef
121 quarvarsre = -e 's|@RUN_QUARANTINE@|$(foreach vv,$(quarantinevars),$(firstword\
122 $(subst =, ,$(vv))))|g;
123 quarvarsre += $(foreach vv,$(quarantinevars),$(call runenvvarre,$(firstword\
124 $(subst =, ,$(vv))),$(subst $(firstword $(subst =, ,$(vv)))=,,$(vv))))
125 quarvarsre += s/@.*RUNENV_VAR.*@//;'
126 endif
127
128 # define variables for shell completion
129 comp_cmds := add add-any apropos aliases avail append-path cachebuild cacheclear clear config delete describe disable display edit help 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
130 comp_long_opts := --debug --dumpname --help --silent --trace --verbose --version --paginate --no-pager --color --color= --width --width= --ignore-cache --ignore-user-rc --no-modulepath-ignore --timer --redirect --no-redirect
131 comp_opts := -D -h -s -T -v -V -p -P -w $(comp_long_opts)
132 comp_load_opts := --auto --no-auto --force -f --icase -i --tag --tag=
133 comp_unload_opts := --auto --no-auto --force -f --icase -i
134 comp_list_opts := -a -C -j -l -o -S -t --all --contains --json --long --output --output= --starts-with --terse
135 comp_savelist_opts := -a -C -j -l -S -t --all --contains --json --long --starts-with --terse
136 comp_stashlist_opts := -j -l -t --json --long --terse
137 comp_clear_opts := --force -f
138 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
139 comp_mfile_opts := -i --icase
140 comp_whatis_opts := -a -i -j --all --icase --json
141 comp_search_opts := -a -j --all --json
142 comp_aliases_opts := -a --all
143 comp_use_opts := -a --append -p --prepend
144 comp_isavail_opts := -i --icase
145 comp_lint_opts := -a -i --all --icase
146 comp_modtosh_opts := --auto --no-auto --force -f --icase -i
147 comp_purge_opts := --force -f
148 comp_reload_opts := --force -f
149 comp_reset_opts := --force -f
150 comp_restore_opts := --force -f
151 comp_stash_opts := --force -f
152 comp_stashpop_opts := --force -f
153 comp_source_opts := --auto --no-auto --force -f
154 comp_path_opts := -d --delim --duplicates
155 comp_rm_path_opts := -d --delim --index
156 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 csh_limit domainname editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_cache_subcmds ignore_user_rc ignored_dirs implicit_default implicit_requirement init_envvars info_extension linked_envvars list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml modulepath_ignore nearly_forbidden_days non_exportable_tags pager paginate path_entry_reorder 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 siteconfig source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_ext_lib tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277
157
158 define translate-in-script
159 $(ECHO_GEN)
160 sed -e 's|@prefix@|$(prefix)|g' \
161 -e 's|@baseprefix@|$(baseprefix)|g' \
162 -e 's|@libexecdir@|$(libexecdir)|g' \
163 -e 's|@initdir@|$(initdir)|g' \
164 -e 's|@etcdir@|$(etcdir)|g' \
165 -e 's|@modulefilesdir@|$(modulefilesdir)|g' \
166 -e 's|@bindir@|$(bindir)|g' \
167 -e 's|@mandir@|$(mandir)|g' \
168 -e 's|@comp_cmds@|$(comp_cmds)|g' \
169 -e 's|@comp_long_opts@|$(comp_long_opts)|g' \
170 -e 's|@comp_opts@|$(comp_opts)|g' \
171 -e 's|@comp_load_opts@|$(comp_load_opts)|g' \
172 -e 's|@comp_unload_opts@|$(comp_unload_opts)|g' \
173 -e 's|@comp_list_opts@|$(comp_list_opts)|g' \
174 -e 's|@comp_savelist_opts@|$(comp_savelist_opts)|g' \
175 -e 's|@comp_stashlist_opts@|$(comp_stashlist_opts)|g' \
176 -e 's|@comp_clear_opts@|$(comp_clear_opts)|g' \
177 -e 's|@comp_avail_opts@|$(comp_avail_opts)|g' \
178 -e 's|@comp_mfile_opts@|$(comp_mfile_opts)|g' \
179 -e 's|@comp_whatis_opts@|$(comp_whatis_opts)|g' \
180 -e 's|@comp_search_opts@|$(comp_search_opts)|g' \
181 -e 's|@comp_aliases_opts@|$(comp_aliases_opts)|g' \
182 -e 's|@comp_use_opts@|$(comp_use_opts)|g' \
183 -e 's|@comp_isavail_opts@|$(comp_isavail_opts)|g' \
184 -e 's|@comp_lint_opts@|$(comp_lint_opts)|g' \
185 -e 's|@comp_modtosh_opts@|$(comp_modtosh_opts)|g' \
186 -e 's|@comp_purge_opts@|$(comp_purge_opts)|g' \
187 -e 's|@comp_reload_opts@|$(comp_reload_opts)|g' \
188 -e 's|@comp_reset_opts@|$(comp_reset_opts)|g' \
189 -e 's|@comp_restore_opts@|$(comp_restore_opts)|g' \
190 -e 's|@comp_stash_opts@|$(comp_stash_opts)|g' \
191 -e 's|@comp_stashpop_opts@|$(comp_stashpop_opts)|g' \
192 -e 's|@comp_source_opts@|$(comp_source_opts)|g' \
193 -e 's|@comp_path_opts@|$(comp_path_opts)|g' \
194 -e 's|@comp_rm_path_opts@|$(comp_rm_path_opts)|g' \
195 -e 's|@comp_config_opts@|$(comp_config_opts)|g' \
196 -e 's|@comp_path_entry_reorder@|$(comp_path_entry_reorder)|g' \
197 -e '$(setzshfpathre)' \
198 -e $$'s|@modulerc@|$(modulerc)|g' \
199 -e 's|@modulepath@|$(modulepath)|g' \
200 -e '$(setquarvarsre)' $(quarvarsre) \
201 -e '$(notsetquarvarsre)' \
202 -e 's|@SHELLNAME@|$@|g' \
203 -e 's|@VERSIONING@|$(setversioning)|g' \
204 -e 's|@VERSION@|$(VERSION)|g' \
205 -e 's|@SED_ERE@|$(SED_ERE)|g' \
206 -e 's|@PS@|$(PS)|g' \
207 -e 's|@BASENAME@|$(BASENAME)|g' \
208 -e 's|@TCLSH@|$(TCLSH)|g' $< > $@
209 endef
210
211 # avoid shared definitions to be rebuilt by make
212 ../Makefile.inc: ;
213
214 # refresh files embedding shared definitions when ../configure updates them
215 initrc tcsh profile.sh $(EXAMPLE_MODFILES_SRCDIR)/modules \
216 $(EXAMPLE_MODFILES_SRCDIR)/version: ../Makefile.inc
217
218 %: %.in ../Makefile.inc
219 $(translate-in-script)
220
221 # workaround '\\\n' issue on Linux with Make 3.81
222 initrc: initrc.in
223 $(translate-in-script)
224 mv $@ ${@}.tmp
225 sed -e 's|\\$$||' ${@}.tmp > $@
226 rm -f ${@}.tmp
227
228 # tcsh is derivated from csh init script
229 tcsh: csh.in
230 $(translate-in-script)
231
232 # this rule is needed for profile.sh to get matched
233 profile.sh: profile.sh.in
234 $(translate-in-script)
235
236 $(EXAMPLE_MODFILES_SRCDIR)/modules: $(EXAMPLE_MODFILES_SRCDIR)/modules.in
237 $(translate-in-script)
238
239 $(EXAMPLE_MODFILES_SRCDIR)/version: $(EXAMPLE_MODFILES_SRCDIR)/version.in
240 $(translate-in-script)
241
242 dist-win: pwsh.ps1
243 $(INSTALL_DIR) '$(DIST_WIN_PREFIX)/init'
244 $(INSTALL_DATA) cmd.cmd '$(DIST_WIN_PREFIX)/init/'
245 $(INSTALL_DATA) pwsh.ps1 '$(DIST_WIN_PREFIX)/init/'
246 $(INSTALL_DIR) '$(DIST_WIN_PREFIX)/modulefiles'
247 $(INSTALL_DATA) $(addprefix $(EXAMPLE_MODFILES_SRCDIR)/,$(EXAMPLE_WIN_MODFILES)) '$(DIST_WIN_PREFIX)/modulefiles/'
248
249 # example configs for test rules
250 install-testconfig:
251 $(INSTALL_DIR) '$(DESTDIR)$(initdir)'
252 $(INSTALL_DIR) '$(DESTDIR)$(etcdir)'
253 $(INSTALL_DIR) '$(DESTDIR)$(prefix)/etc'
254 $(INSTALL_DIR) '$(DESTDIR)$(modulefilesdir)'
255 $(INSTALL_DIR) '$(DESTDIR)$(prefix)/test/modulefiles' '$(DESTDIR)$(prefix)/test/etc'
256 $(INSTALL_DATA) $(addprefix $(EXAMPLE_MODFILES_SRCDIR)/,$(EXAMPLE_TESTCONFIG_MODFILES)) '$(DESTDIR)$(modulefilesdir)/'
257
258 uninstall-testconfig:
259 rmdir '$(DESTDIR)$(prefix)/test/modulefiles' '$(DESTDIR)$(prefix)/test/etc' '$(DESTDIR)$(prefix)/test'
260 rm -f $(foreach modfile,$(EXAMPLE_TESTCONFIG_MODFILES),'$(DESTDIR)$(modulefilesdir)/$(modfile)')
261 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(modulefilesdir)' || true
262 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(etcdir)' || true
263 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(initdir)' || true
264
265 install: all
266 $(INSTALL_DIR) '$(DESTDIR)$(initdir)'
267 $(INSTALL_DIR) '$(DESTDIR)$(initdir)/ksh-functions'
268 ifeq ($(initconfin),etcdir)
269 $(INSTALL_DIR) '$(DESTDIR)$(etcdir)'
270 endif
271 ifeq ($(makebashcompdir),y)
272 $(INSTALL_DIR) '$(DESTDIR)$(bashcompletiondir)'
273 endif
274 ifeq ($(makefishcompdir),y)
275 $(INSTALL_DIR) '$(DESTDIR)$(fishcompletiondir)'
276 endif
277 ifeq ($(makepythondir),y)
278 $(INSTALL_DIR) '$(DESTDIR)$(pythondir)'
279 endif
280 $(INSTALL_DIR) '$(DESTDIR)$(zshcompletiondir)'
281 $(INSTALL_DIR) '$(DESTDIR)$(modulefilesdir)'
282 $(INSTALL_DATA) $(filter-out env_modules.py,$(ALL_SHELLS)) '$(DESTDIR)$(initdir)/'
283 $(INSTALL_DATA) env_modules.py '$(DESTDIR)$(pythondir)/'
284 ifeq ($(makepythondir),y)
285 ln -f -s '$(pythondir)/env_modules.py' '$(DESTDIR)$(initdir)/python.py'
286 else
287 ln -f -s env_modules.py '$(DESTDIR)$(initdir)/python.py'
288 endif
289 ifeq ($(windowssupport),y)
290 $(INSTALL_DATA) cmd.cmd '$(DESTDIR)$(initdir)/'
291 endif
292 ifeq ($(makefishcompdir),y)
293 $(INSTALL_DATA) fish_completion '$(DESTDIR)$(fishcompletiondir)/module.fish'
294 else
295 $(INSTALL_DATA) fish_completion '$(DESTDIR)$(fishcompletiondir)/'
296 endif
297 ifeq ($(makebashcompdir),y)
298 $(INSTALL_DATA) bash_completion '$(DESTDIR)$(bashcompletiondir)/module'
299 ln -s module '$(DESTDIR)$(bashcompletiondir)/ml'
300 else
301 $(INSTALL_DATA) bash_completion '$(DESTDIR)$(bashcompletiondir)/'
302 endif
303 $(INSTALL_DATA) zsh-functions/_module '$(DESTDIR)$(zshcompletiondir)/'
304 $(INSTALL_DATA) ksh '$(DESTDIR)$(initdir)/ksh-functions/module'
305 $(INSTALL_DATA) ksh '$(DESTDIR)$(initdir)/ksh-functions/ml'
306 $(INSTALL_DATA) initrc '$(DESTDIR)$(initrc)'
307 ifeq ($(setmodulespath),y)
308 $(INSTALL_DATA) modulespath $(DESTDIR)$(modulespath)
309 endif
310 ifeq ($(examplemodulefiles),y)
311 $(INSTALL_DATA) $(addprefix $(EXAMPLE_MODFILES_SRCDIR)/,$(EXAMPLE_MODFILES)) '$(DESTDIR)$(modulefilesdir)/'
312 endif
313 ifeq ($(versioning),y)
314 $(INSTALL_DIR) '$(DESTDIR)$(versdir)'
315 $(INSTALL_DATA) $(EXAMPLE_MODFILES_SRCDIR)/version '$(DESTDIR)$(versdir)/$(VERSION)'
316 endif
317
318 uninstall:
319 rm -f $(foreach initscript,$(filter-out env_modules.py,$(ALL_SHELLS)) python.py,'$(DESTDIR)$(initdir)/$(initscript)')
320 rm -f '$(DESTDIR)$(pythondir)/env_modules.py'
321 ifeq ($(windowssupport),y)
322 rm -f '$(DESTDIR)$(initdir)/cmd.cmd'
323 endif
324 rm -f '$(DESTDIR)$(initdir)/ksh-functions/module'
325 rm -f '$(DESTDIR)$(initdir)/ksh-functions/ml'
326 ifeq ($(makebashcompdir),y)
327 rm -f '$(DESTDIR)$(bashcompletiondir)/ml'
328 rm -f '$(DESTDIR)$(bashcompletiondir)/module'
329 else
330 rm -f '$(DESTDIR)$(bashcompletiondir)/bash_completion'
331 endif
332 ifeq ($(makefishcompdir),y)
333 rm -f '$(DESTDIR)$(fishcompletiondir)/module.fish'
334 else
335 rm -f '$(DESTDIR)$(fishcompletiondir)/fish_completion'
336 endif
337 rm -f '$(DESTDIR)$(zshcompletiondir)/_module'
338 rm -f '$(DESTDIR)$(modulespath)' '$(DESTDIR)$(initrc)'
339 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(modulefilesdir)' || true
340 @if [ -d '$(DESTDIR)$(modulefilesdir)' ]; then echo; echo "WARNING: '$(DESTDIR)$(modulefilesdir)' is not empty so skip removal" >&2; echo; fi
341 rmdir '$(DESTDIR)$(initdir)/ksh-functions'
342 ifeq ($(makebashcompdir),y)
343 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(bashcompletiondir)' || true
344 endif
345 ifeq ($(makefishcompdir),y)
346 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(fishcompletiondir)' || true
347 endif
348 ifeq ($(makepythondir),y)
349 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(pythondir)' || true
350 endif
351 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(zshcompletiondir)' || true
352 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(initdir)' || true
353 @if [ -d '$(DESTDIR)$(initdir)' ]; then echo; echo "WARNING: '$(DESTDIR)$(initdir)' is not empty so skip removal" >&2; echo; fi
354 ifeq ($(versioning),y)
355 rm -f '$(DESTDIR)$(versdir)/$(VERSION)'
356 $(RMDIR_IGN_NON_EMPTY) '$(DESTDIR)$(versdir)' || true
357 @if [ -d '$(DESTDIR)$(versdir)' ]; then echo; echo "WARNING: '$(DESTDIR)$(versdir)' is not empty so skip removal" >&2; echo; fi
358 endif
359
360 clean:
361 rm -f $(ALL_SHELLS) initrc bash_completion zsh-functions/_module modulespath $(EXAMPLE_MODFILES_SRCDIR)/modules
362 ifeq ($(versioning),y)
363 rm -f $(EXAMPLE_MODFILES_SRCDIR)/version
364 endif
365
366 # quiet all commands unless verbose mode set
367 ifeq ($(VERBOSE),1)
368 V = 1
369 endif
370 # let verbose by default the install/clean/test and other specific non-build targets
371 $(V).SILENT: sh ksh bash zsh csh tcsh fish perl.pm env_modules.py ruby.rb lisp tcl \
372 cmake r.R bash_completion tcsh_completion zsh-functions/_module profile.sh \
373 profile.csh modulespath initrc $(EXAMPLE_MODFILES_SRCDIR)/modules \
374 $(EXAMPLE_MODFILES_SRCDIR)/version pwsh.ps1