@@ -13,12 +13,31 @@ install_erlang() {
13
13
ensure_kerl_setup
14
14
local build_name
15
15
16
+ install_dependency_checks
17
+ ensure_kerl_config_opts
18
+ set_unixodbc_opt
19
+ set_ssl_opt
20
+ add_openjdk_to_path
21
+ ensure_ulimit
22
+
23
+ echo " [asdf-erlang] 📦 Building with $( env | grep KERL_CONFIGURE_OPTIONS) "
24
+
16
25
build_name=" asdf_$ASDF_INSTALL_VERSION "
17
26
18
27
export MAKEFLAGS=" -j$ASDF_CONCURRENCY "
19
28
20
- $( kerl_path) delete installation " $build_name " || true
21
- $( kerl_path) delete build " $build_name " || true
29
+ if $( kerl_path) list installations | grep -q " $build_name " ; then
30
+ echo " [asdf-erlang] 🧹 Cleanup kerl installation $build_name "
31
+ $( kerl_path) delete installation " $build_name " || true
32
+ else
33
+ echo " [asdf-erlang] ❄️ No kerl installation to cleanup for $build_name "
34
+ fi
35
+ if $( kerl_path) list builds | grep -q " $build_name " ; then
36
+ echo " [asdf-erlang] 🧹 Cleanup kerl build $build_name "
37
+ $( kerl_path) delete build " $build_name " || true
38
+ else
39
+ echo " [asdf-erlang] ❄️ No kerl build to cleanup for $build_name "
40
+ fi
22
41
23
42
if [ " $ASDF_INSTALL_TYPE " = " ref" ]; then
24
43
$( kerl_path) build git " ${OTP_GITHUB_URL:- https:// github.com/ erlang/ otp.git} " " $ASDF_INSTALL_VERSION " " $build_name "
@@ -29,10 +48,16 @@ install_erlang() {
29
48
# We hide all output from this command so the
30
49
# "You can activate this installation running the following command:"
31
50
# that doesn't apply is hidden
51
+ echo " 🧹 Cleanup kerl install $build_name $ASDF_INSTALL_PATH "
32
52
$( kerl_path) install " $build_name " " $ASDF_INSTALL_PATH " > /dev/null 2>&1
53
+
54
+ echo " 🧹 Cleanup kerl build $build_name "
33
55
$( kerl_path) cleanup " $build_name "
34
56
57
+ echo " 🔗 Linking app executables $ASDF_INSTALL_PATH "
35
58
link_app_executables " $ASDF_INSTALL_PATH "
59
+ cleanup_custom_env_vars
60
+ echo " 👍 Installed erlang ${ASDF_INSTALL_VERSION} "
36
61
}
37
62
38
63
link_app_executables () {
@@ -53,4 +78,140 @@ link_app_executables() {
53
78
done
54
79
}
55
80
81
+ install_dependency_checks () {
82
+ if [[ " $OSTYPE " == " darwin" * ]]; then
83
+ installed_packages=()
84
+ for package in fop openssl unixodbc openjdk wxmac; do
85
+ if brew list --versions " $package " > /dev/null 2>&1 ; then
86
+ installed_packages+=(" $package " )
87
+ else
88
+ if [ " $package " = " wxmac" ]; then
89
+ echo " [asdf-erlang] ⚠️ Warning: $package is optional and not installed. You can install it using 'brew install --build-from-source wxmac'."
90
+ echo " [asdf-erlang] ⚠️ Note: wxmac is required for building Erlang/OTP with a working :observer"
91
+ else
92
+ echo " [asdf-erlang] ⚠️ Warning: $package is optional and not installed. Please install it using 'brew install $package '."
93
+ fi
94
+ fi
95
+ done
96
+ fi
97
+ }
98
+
99
+ ensure_kerl_config_opts () {
100
+ if [[ -z " ${KERL_CONFIGURE_OPTIONS:- } " ]]; then
101
+ export KERL_CONFIGURE_OPTIONS=" "
102
+ fi
103
+ }
104
+
105
+ set_unixodbc_opt () {
106
+ if [[ " $OSTYPE " == " darwin" * ]]; then
107
+ # If no unixodbc is installed, then skip.
108
+ if ! brew --prefix unixodbc > /dev/null 2>&1 ; then
109
+ return
110
+ fi
111
+
112
+ if [[ ! " $KERL_CONFIGURE_OPTIONS " =~ unixodbc ]]; then
113
+ local kerl_unixodbc_opt
114
+ kerl_unixodbc_opt=" --with-odbc=$( brew --prefix unixodbc) "
115
+ export KERL_CONFIGURE_OPTIONS+=" $kerl_unixodbc_opt "
116
+ echo " [asdf-erlang] 🛟 Added unixodbc to KERL_CONFIGURE_OPTIONS: $kerl_unixodbc_opt "
117
+ fi
118
+
119
+ # If CC not set, then set CC.
120
+ # ELSE add the unixodbc include path to CC.
121
+ if [ -z " ${CC:- } " ]; then
122
+ CC=" /usr/bin/clang -I$( brew --prefix unixodbc) /include"
123
+ export CC
124
+ echo " [asdf-erlang] 🛟 No CC found. Setting CC to: $CC "
125
+ CC_SET_BY_ASDF_ERLANG=1 # so that we can clear it later.
126
+ elif [[ " $CC " != * unixodbc* ]]; then
127
+ CC+=" -I$( brew --prefix unixodbc) /include"
128
+ export CC
129
+ echo " [asdf-erlang] 🛟 Added unixodbc include path to CC: $CC "
130
+ fi
131
+
132
+ # If LDFLAGS not set, then set LDFLAGS.
133
+ # ELSE add the unixodbc library path to LDFLAGS.
134
+ if [ -z " ${LDFLAGS:- } " ]; then
135
+ LDFLAGS=" -L$( brew --prefix unixodbc) /lib"
136
+ export LDFLAGS
137
+ echo " [asdf-erlang] 🛟 No LDFLAGS found. Setting LDFLAGS to: $LDFLAGS "
138
+ LDFLAGS_SET_BY_ASDF_ERLANG=1 # so that we can clear it later.
139
+ elif [[ " $LDFLAGS " != * unixodbc* ]]; then
140
+ local unixodbc_lib_path
141
+ unixodbc_lib_path=" $( brew --prefix unixodbc) /lib"
142
+ export LDFLAGS+=" -L$unixodbc_lib_path "
143
+ echo " [asdf-erlang] 🛟 Added $unixodbc_lib_path to LDFLAGS env var"
144
+ fi
145
+ fi
146
+ }
147
+
148
+ add_openjdk_to_path () {
149
+ if [[ " $OSTYPE " == " darwin" * ]]; then
150
+ if ! brew --prefix openjdk > /dev/null 2>&1 ; then
151
+ return
152
+ fi
153
+
154
+ local openjdk_path
155
+ openjdk_path=" $( brew --prefix openjdk) "
156
+ if [[ " :$PATH :" != * " :$openjdk_path /bin:" * ]]; then
157
+ export PATH=" $openjdk_path /bin:$PATH "
158
+ echo " [asdf-erlang] 🛟 OpenJDK has been added to PATH for this terminal session: $openjdk_path /bin"
159
+ echo " [asdf-erlang] Please ensure this is included in your shell's dot files (.zshrc, .bashrc, etc.)"
160
+ fi
161
+ fi
162
+ }
163
+
164
+ ensure_ulimit () {
165
+ if [ " $( ulimit -n) " -lt 1000 ]; then
166
+ ulimit -n 65536
167
+ echo " [asdf-erlang] 🛟 ulimit was low. It has been set to 65536 for this terminal session"
168
+ fi
169
+ }
170
+
171
+ set_ssl_opt () {
172
+ if [[ " $OSTYPE " == " darwin" * ]]; then
173
+ # If this is a ref install, then we don't need to set the ssl option.
174
+ # Reason: Don't want to handle that for now.
175
+ if [[ " $ASDF_INSTALL_TYPE " == " ref" ]]; then
176
+ echo " [asdf-erlang] ⚠️ Skipping setting --with-ssl in KERL_CONFIGURE_OPTIONS for ref install"
177
+ return
178
+ fi
179
+
180
+ otp_major=$( echo " $ASDF_INSTALL_VERSION " | cut -d. -f1)
181
+ otp_minor=$( echo " $ASDF_INSTALL_VERSION " | cut -d. -f2)
182
+
183
+ # Copied IF condition check from the kerl binary to match their version check.
184
+ # We only have to fix/handle newer erlang+openssl versions because of kerl looking for [email protected] instead of openssl#3.
185
+ # The erlang version that use openssl 1.1 should be fine (or as is).
186
+ if [ " $otp_major " = ' git' ] || [ " $otp_major " -lt 25 ] || { [ " $otp_major " -eq 25 ] && [ " $otp_minor " -lt 1 ]; }; then
187
+ echo " [asdf-erlang] ⚠️ Skipping setting --with-ssl in KERL_CONFIGURE_OPTIONS. This erlang version uses openssl v1.x"
188
+ return
189
+ fi
190
+
191
+ # Only set the ssl option for newer erlang versions that use openssl@3.
192
+ if ! brew --prefix openssl@3 > /dev/null 2>&1 ; then
193
+ echo " [asdf-erlang] ⚠️ Skipping setting --with-ssl in KERL_CONFIGURE_OPTIONS. brew prefix path for openssl@3 not found."
194
+ return
195
+ fi
196
+
197
+ # If openssl is not already in KERL_CONFIGURE_OPTIONS, then add it.
198
+ if [[ ! " $KERL_CONFIGURE_OPTIONS " =~ openssl ]]; then
199
+ local kerl_ssl_opt
200
+ kerl_ssl_opt=" --with-ssl=$( brew --prefix openssl@3) "
201
+ export KERL_CONFIGURE_OPTIONS+=" $kerl_ssl_opt "
202
+ echo " [asdf-erlang] 🛟 Added openssl to KERL_CONFIGURE_OPTIONS: $kerl_ssl_opt "
203
+ fi
204
+ fi
205
+ }
206
+
207
+ cleanup_custom_env_vars () {
208
+ if [[ " ${LDFLAGS_SET_BY_ASDF_ERLANG:- } " == " 1" ]]; then
209
+ unset LDFLAGS
210
+ fi
211
+
212
+ if [[ " ${CC_SET_BY_ASDF_ERLANG:- } " == " 1" ]]; then
213
+ unset CC
214
+ fi
215
+ }
216
+
56
217
install_erlang
0 commit comments