Skip to content

Commit 283e24f

Browse files
committed
[ATfL] A script which generates modulefiles directory tree that could be pointed at with MODULEPATH
This is a proof of concept script which generates a directory tree with modulefiles. It may be used later when the RPM and DEB post-install shell scripts are being implemented. Currently it can be used as such: In the ATfL tarball (as created by build.sh) a new directory called 'arm' is being created containing the mkmodulesdir.sh script. This script is being amended by build.sh in order to adjust the ATfL version info. After unpacking the tarball, an user can execute this script, it will create three directories in the current directory: moduledeps modulefiles moduleglobals These contain all the files needed to load ATfL as a module. Assuming this script has been executed in the atfl/arm directory in the user's $HOME, ATfL can be loaded as such: $ MODULEPATH=$HOME/atfl/arm/modulefiles module load atfl/0.0
1 parent f750796 commit 283e24f

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

arm-software/linux/build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fi
1111

1212
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1313
README_MD_PATH=${README_MD_PATH:-"${BASE_DIR}/README.md"}
14+
MKMODULEDIRS_PATH=${MKMODULEDIRS_PATH:-"${BASE_DIR}/mkmoduledirs.sh.var"}
1415
SOURCES_DIR=${SOURCES_DIR:-"${BASE_DIR}/src"}
1516
LIBRARIES_DIR=${LIBRARIES_DIR:-"${BASE_DIR}/lib"}
1617
PATCHES_DIR=${PATCHES_DIR:-"${BASE_DIR}/patches"}
@@ -166,6 +167,8 @@ Environment Variables:
166167
167168
README_MD_PATH Specifies the location of the README.md file to bundle
168169
(default: ${README_MD_PATH})
170+
MKMODULEDIRS_PATH Specifies the location of mkmoduledirs.sh.var to tweak
171+
(default: ${MKMODULEDIRS_PATH})
169172
SOURCES_DIR The directory where all source code will be stored
170173
(default: $SOURCES_DIR)
171174
LIBRARIES_DIR The directory where the ArmPL veclibs will be stored
@@ -354,6 +357,12 @@ shared_lib_build() {
354357

355358
package() {
356359
cp "${README_MD_PATH}" "${ATFL_DIR}/README.md"
360+
mkdir -p "${ATFL_DIR}/arm"
361+
cp "${MKMODULEDIRS_PATH}" "${ATFL_DIR}/arm/mkmoduledirs.sh"
362+
sed -i "s/%ATFL_VERSION%/${ATFL_VERSION}/g" "${ATFL_DIR}/arm/mkmoduledirs.sh"
363+
sed -i "s/%ATFL_BUILD%/unknown/g" "${ATFL_DIR}/arm/mkmoduledirs.sh"
364+
sed -i "s/%ATFL_INSTALL_PREFIX%/\$\(dirname \$\(dirname \`realpath \$BASH_SOURCE\`\)\)/g" "${ATFL_DIR}/arm/mkmoduledirs.sh"
365+
chmod 0755 ${ATFL_DIR}/arm/mkmoduledirs.sh
357366
cp "${LIBRARIES_DIR}/libamath.a" \
358367
"${ATFL_DIR}/lib/aarch64-unknown-linux-gnu"
359368
cp "${LIBRARIES_DIR}/libamath.so" \
@@ -425,6 +434,12 @@ then
425434
exit 1
426435
fi
427436

437+
if ! [[ -f "${MKMODULEDIRS_PATH}" ]]
438+
then
439+
echo "The path to mkmoduledirs.sh.var file is configured incorrectly or does not exist."
440+
exit 1
441+
fi
442+
428443
if ! [[ -e "${SOURCES_DIR}" ]]
429444
then
430445
echo "The sources directory is configured incorrectly or does not exist."
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/usr/bin/env bash
2+
3+
ATFL_VERSION="%ATFL_VERSION%"
4+
ATFL_BUILD="%ATFL_BUILD%"
5+
ATFL_INSTALL_PREFIX="%ATFL_INSTALL_PREFIX%"
6+
7+
mkdir -p "moduledeps/atfl/${ATFL_VERSION}/clang-autocomplete"
8+
(
9+
cat <<EOT
10+
----------------------------------------------------------------
11+
--
12+
-- clang-autocomplete
13+
--
14+
--
15+
-- Copyright 2015-2025 Arm Limited. All rights reserved.
16+
--
17+
18+
---------------------------------------------------------------------------
19+
-- Variable definitions --
20+
---------------------------------------------------------------------------
21+
22+
-- Base install directory of ATfL
23+
local install_prefix = "${ATFL_INSTALL_PREFIX}"
24+
25+
---------------------------------------------------------------------------
26+
-- Main section --
27+
---------------------------------------------------------------------------
28+
29+
-- Install directory of this package
30+
local package_prefix = pathJoin(install_prefix, "")
31+
32+
local autocomplete_file = pathJoin(package_prefix, "/share/clang/bash-autocomplete.sh")
33+
34+
execute{cmd="source " .. autocomplete_file, modeA={"load"}}
35+
36+
-- Lmod can't figure out how to unsource files without help, so we undo it here
37+
execute{cmd="complete -r armclang armflang armclang++", modeA={"unload"}}
38+
execute{cmd="unset -f _clang", modeA={"unload"}}
39+
EOT
40+
) > "moduledeps/atfl/${ATFL_VERSION}/clang-autocomplete/${ATFL_VERSION}.lua"
41+
42+
mkdir -p "modulefiles/atfl"
43+
(
44+
cat <<EOT
45+
#%Module1.0################################################################
46+
##
47+
## ATfL
48+
##
49+
##
50+
## Copyright 2015-2025 Arm Limited. All rights reserved.
51+
##
52+
53+
###########################################################################
54+
# Module description #
55+
###########################################################################
56+
57+
proc ModulesHelp { } {
58+
puts stderr " "
59+
puts stderr "This module loads the ATfL toolchain."
60+
puts stderr "\nVersion ${ATFL_VERSION}\n"
61+
}
62+
63+
module-whatis "Name: ATfL"
64+
module-whatis "Version: ${ATFL_VERSION}"
65+
module-whatis "Category: compiler, runtime support"
66+
module-whatis "Description: This module loads the ATfL toolchain, providing armclang, armclang++, and armflang."
67+
68+
###########################################################################
69+
# Variable definitions #
70+
###########################################################################
71+
72+
# Base install directory of ATfL
73+
set install_prefix ${ATFL_INSTALL_PREFIX}
74+
75+
# Base module directory of ATfL
76+
# This is worked out dynamically so that the modulefiles can be moved
77+
# from the install directory
78+
set module_prefix [file dirname \$ModulesCurrentModulefile]/../..
79+
80+
# Base directory of all dependant modules
81+
set moduledeps \$module_prefix/moduledeps
82+
83+
###########################################################################
84+
# Main section #
85+
###########################################################################
86+
# Pull in some utility functions
87+
source \$module_prefix/moduleglobals/compiler_functions/${ATFL_VERSION}
88+
89+
# Install directory of this package
90+
set package_prefix \$install_prefix
91+
92+
# Arm-specific environment variables
93+
setenv ARM_LINUX_COMPILER_DIR \$package_prefix
94+
setenv ARM_LINUX_COMPILER_BUILD ${ATFL_BUILD}
95+
96+
# Standard environment variables
97+
prepend-path PATH \$package_prefix/bin
98+
prepend-path CPATH \$package_prefix/include
99+
prepend-path LIBRARY_PATH \$package_prefix/lib
100+
append-path LIBRARY_PATH \$package_prefix/lib/aarch64-unknown-linux-gnu
101+
prepend-path MANPATH \$package_prefix/share/man
102+
103+
# Make dependant modules available
104+
prepend-path MODULEPATH \$moduledeps/atfl/${ATFL_VERSION}
105+
106+
if { [is-lmod] } {
107+
# Lmod family
108+
# When this modulefile is used with lmod, This ensures only one compiler is loaded at once
109+
family "compiler"
110+
}
111+
112+
# Source the bash-autocomplete.sh
113+
set SHELL [module-info shell]
114+
switch -- \$SHELL {
115+
{sh} - {bash} {
116+
if { [is-lmod] } {
117+
module load clang-autocomplete/${ATFL_VERSION}
118+
} else {
119+
set autocomplete_file \$package_prefix/share/clang/bash-autocomplete.sh
120+
if { [file exists \$autocomplete_file] } {
121+
puts "source \$autocomplete_file"
122+
}
123+
}
124+
}
125+
}
126+
EOT
127+
) > "modulefiles/atfl/${ATFL_VERSION}"
128+
129+
mkdir -p "moduleglobals/compiler_functions"
130+
(
131+
cat <<EOT
132+
#%Module1.0################################################################
133+
##
134+
## Utility functions for Arm modulefiles
135+
##
136+
##
137+
## Copyright 2015-2025 Arm Limited. All rights reserved.
138+
##
139+
140+
# Helper function, to load/unload a set of prerequisite modules
141+
proc depends-on {dependencies} {
142+
foreach dep \$dependencies {
143+
if { [module-info mode load] } {
144+
# This will load the module if it has not already been loaded
145+
# is-loaded only triggers on a mode load, so it would not allow an auto-unload
146+
if { ! [is-loaded \$dep] } {
147+
module load \$dep
148+
}
149+
}
150+
}
151+
}
152+
153+
proc is-lmod {} {
154+
global env
155+
if { [info exists env(LMOD_VERSION_MAJOR)] } {
156+
return true
157+
}
158+
return false
159+
}
160+
EOT
161+
) > "moduleglobals/compiler_functions/${ATFL_VERSION}"

0 commit comments

Comments
 (0)