@@ -161,14 +161,13 @@ __caf_err_report() {
161161trap ' __caf_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
162162
163163# See if we are compiling or compiling and/or linking
164- __only_compiling () {
165- for arg in " ${@ } " ; do
166- if [[ " ${arg} " == " -c" ]]; then
167- return 0
168- fi
169- done
170- return 1
171- }
164+ with_link=" true"
165+ for arg in " ${@ } " ; do
166+ if [[ " ${arg} " == " -c" || " ${arg} " == " -cpp" ]]; then
167+ with_link=" false"
168+ break
169+ fi
170+ done
172171
173172# --------------------------------------------------------------------------
174173# End configured variables, now process them and build compile/link command
@@ -223,16 +222,14 @@ if [[ -n "${mpi_compile_flags[*]:-}" ]]; then
223222 caf_pre_flags+=(" ${compileflag} " )
224223 done
225224fi
226- if [[ -n " ${mpi_link_flags[*]:- } " ]]; then
227- if ! __only_compiling " ${@ } " ; then
228- for linkflag in " ${mpi_link_flags[@]:- } " ; do
229- caf_pre_flags+=(" ${linkflag} " )
230- done
231- fi
225+ if [[ -n " ${mpi_link_flags[*]:- } " && " ${with_link} " == " true" ]]; then
226+ for linkflag in " ${mpi_link_flags[@]:- } " ; do
227+ caf_pre_flags+=(" ${linkflag} " )
228+ done
232229fi
233230
234231# Now do libraries, IN CORRECT ORDER, to append to command
235- if [[ -n " ${caf_libs[*]:- } " ]]; then
232+ if [[ " ${with_link} " == " true " && -n " ${caf_libs[*]:- } " ]]; then
236233 for lib in " ${caf_libs[@]:- } " ; do
237234 caf_added_libs+=(" $( substitute_lib " ${prefix%/ } /${lib} " ) " )
238235 done
@@ -242,7 +239,7 @@ if [[ -n "${threads_lib}" ]]; then
242239 caf_added_libs+=(" ${threads_lib} " )
243240fi
244241
245- if [[ -n " ${mpi_libs[*]:- } " ]]; then
242+ if [[ " ${with_link} " == " true " && -n " ${mpi_libs[*]:- } " ]]; then
246243 for lib in " ${mpi_libs[@]:- } " ; do
247244 caf_added_libs+=(" $( substitute_lib " ${lib} " ) " )
248245 done
@@ -330,10 +327,8 @@ elif [[ ${1} == '-s' || ${1} == '--show' || ${1} == '-show' ]]; then
330327 if [[ " ${args} " ]]; then
331328 compiler_args+=(" ${args} " )
332329 fi
333- if [[ " ${caf_added_libs[*]:- } " ]]; then
334- if ! __only_compiling " ${@ } " ; then
335- compiler_args+=(" ${caf_added_libs[@]} " )
336- fi
330+ if [[ " ${caf_added_libs[*]:- } " && " ${with_link} " == " true" ]]; then
331+ compiler_args+=(" ${caf_added_libs[@]} " )
337332 fi
338333 echo " ${cafc} " " ${compiler_args[@]} "
339334 exit 0
365360if [[ " ${*:- } " ]]; then
366361 compiler_args+=(" ${@ } " )
367362fi
368- if [[ " ${caf_added_libs[*]:- } " ]]; then
369- if ! __only_compiling " ${@ } " ; then
370- compiler_args+=(" ${caf_added_libs[@]} " )
371- fi
363+ if [[ " ${caf_added_libs[*]:- } " && " ${with_link} " == " true" ]]; then
364+ compiler_args+=(" ${caf_added_libs[@]} " )
372365fi
373366# set -o xtrace # Show what we're doing
374367set +o errtrace
0 commit comments