diff --git a/flang/tools/f18/flang b/flang/tools/f18/flang --- a/flang/tools/f18/flang +++ b/flang/tools/f18/flang @@ -123,14 +123,15 @@ # $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##*.} @@ -144,7 +145,7 @@ 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 @@ -330,6 +331,7 @@ exit 0 fi + # Source, object and library files provided by the user local fortran_source_files=() local other_source_files=() local object_files=() @@ -388,6 +390,8 @@ # 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 `. This # is because we are using the unparsed rather than the original source file @@ -402,7 +406,7 @@ 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 @@ -425,7 +429,7 @@ 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 @@ -433,7 +437,7 @@ 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" @@ -442,7 +446,7 @@ 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 @@ -453,7 +457,7 @@ # Delete intermediate object files for idx in "${!fortran_source_files[@]}"; do - rm "${object_files[$idx]}" + rm "${temp_object_files[$idx]}" done }