# $2 - Fortran source files extracted from $1 (array, name reference)
# $3 - other source files extracted from $1 (array, name reference)
# $4 - object files extracted from $1 (array, name reference)
-# $4 - lib files extracted from $1 (array, name reference)
+# $5 - lib files extracted from $1 (array, name reference)
# =============================================================================
categorise_files()
{
local -n -r all_files=$1
local -n fortran_sources=$2
local -n other_sources=$3
- local -n libs=$4
+ local -n objects=$4
+ local -n libs=$5
for current_file in "${all_files[@]}"; do
file_ext=${current_file##*.}
elif [[ $file_ext == "a" ]] || [[ $file_ext == "so" ]]; then
libs+=($current_file)
elif [[ $file_ext == "o" ]]; then
- object_files+=($current_file)
+ objects+=($current_file)
else
other_sources+=($current_file)
fi
exit 0
fi
+ # Source, object and library files provided by the user
local fortran_source_files=()
local other_source_files=()
local object_files=()
# STEP 2: Compile Fortran Source Files
readonly ext_fc="${F18_FC:-gfortran}"
+ # Temporary object files generated by this script. To be deleted at the end.
+ local temp_object_files=()
for idx in "${!fortran_source_files[@]}"; do
# We always have to specify the output name with `-o <out_obj_file>`. This
# is because we are using the unparsed rather than the original source file
echo flang: in "$PWD", "$ext_fc" failed with exit status "$ret_status": "$ext_fc" "${ext_fc_options[@]}" "$@" >&2
exit "$ret_status"
fi
- object_files+=(${out_obj_file})
+ temp_object_files+=(${out_obj_file})
done
# Delete the unparsed files
echo flang: in "$PWD", "$ext_fc" failed with exit status "$ret_status": "$ext_fc" "${ext_fc_options[@]}" "$@" >&2
exit "$ret_status"
fi
- object_files+=(${out_obj_file})
+ temp_object_files+=(${out_obj_file})
done
# STEP 4: Link
exit 0;
fi
- if [[ ${#object_files[@]} -ge 1 ]]; then
+ if [[ ${#temp_object_files[@]} -ge 1 ]] || [[ ${#object_files[@]} -ge 1 ]] ; then
# If $OUTPUT_FILE was specified, use it for the output name.
if [[ ! -z ${OUTPUT_FILE:+x} ]]; then
output_definition="-o $OUTPUT_FILE"
fi
set +e
- $ext_fc "${ext_fc_options[@]}" "${object_files[@]}" "${lib_files[@]}" ${output_definition:+$output_definition}
+ $ext_fc "${ext_fc_options[@]}" "${object_files[@]}" "${temp_object_files[@]}" "${lib_files[@]}" ${output_definition:+$output_definition}
ret_status=$?
set -e
if [[ $ret_status != 0 ]]; then
# Delete intermediate object files
for idx in "${!fortran_source_files[@]}"; do
- rm "${object_files[$idx]}"
+ rm "${temp_object_files[$idx]}"
done
}