Skip to content

Commit

Permalink
fix and simplify
Browse files Browse the repository at this point in the history
- avoid adding "include Makefile_taf.dep" multiple times at bottom of Makefile
  by doing this as part of "make depend"
- simplify `f90mkdepend_taf` (remove "-clean" option) and pass name of output file
  as first argument.
- add 1 line to "Clean" target to remove "include Makefile_taf.dep" from bottom
  of Makefile and, if sucessful, remove file "Makefile_taf.dep".
  • Loading branch information
jm-c committed Jan 31, 2025
1 parent fd445fe commit ee3ac9c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 47 deletions.
53 changes: 10 additions & 43 deletions tools/f90mkdepend_taf
Original file line number Diff line number Diff line change
@@ -1,59 +1,27 @@
#!/bin/bash
#
# Generate make file dependency entries for TAF generated AD files
# passed as arguments
#

# process option arguments
CLEAN=
adfiles=
key_prev=
for key in "$@"; do
if [[ -n "$key_prev" ]]; then
eval "$key_prev=\$key"
key_prev=
continue
fi
# passed as arguments after output dependency file

case $key in
-clean | --clean)
CLEAN=true
;;
-taf | --taf)
key_prev="adfiles"
;;
-*)
echo "f90mkdepend_taf wrong key: $key"
exit 1
;;
*)
# Append non-option arguments to adfiles
adfiles="${adfiles:+$adfiles }$key"
;;
esac
done
if [ $# -eq 0 ]; then
echo "Usage: `basename $0` output_file list_of_TAF_generated_files"
exit 1
else
dep_file=$1 ; shift
fi

# don't complain if *.F90 doesn't match any files
shopt -s nullglob

# init files
#log_file="`basename $0`.log"
log_file="f90mkdepend_taf.log"
dep_file="Makefile_taf.dep"

cat /dev/null > $log_file
cat /dev/null > $dep_file

# OPTION to clean Makefile of $dep_file
MAKEFILE=Makefile
if test -n "$CLEAN"; then
if [[ $(tail -n 1 $MAKEFILE) == "include $dep_file" ]]; then
head -n -1 $MAKEFILE > tmp && mv tmp $MAKEFILE
fi
rm -rf $dep_file $log_file
exit 0
fi

# append module dependencies to Makefile
adfiles=$*
for filename in ${adfiles}; do
# quick check for "use" to speed up processing
if grep -iq '^ *use ' $filename; then
Expand All @@ -79,5 +47,4 @@ for filename in ${adfiles}; do
echo $depline >> $dep_file
fi
done

echo "include $dep_file"
exit 0
21 changes: 17 additions & 4 deletions tools/genmake2
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ TAPENADECMD=tapenade
OPENAD=
AD_OPTFILE=
CAT_SRC_FOR_TAF=1
DEP_TAF_FILE='Makefile_taf.dep'
TAF=
AD_TAF_FLAGS=
FTL_TAF_FLAGS=
Expand Down Expand Up @@ -3361,6 +3362,12 @@ depend:
\$(MAKEDEPEND) -f \$(MAKEFILE) -a -o .$FS90 \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F90_SRC_FILES)
\$(TOOLSDIR)/f90mkdepend -fs $FS -fs90 $FS90 >> \$(MAKEFILE)
-rm -f makedepend.out
EOF
if test $CAT_SRC_FOR_TAF = 0 ; then
echo " -touch $DEP_TAF_FILE" >> $MAKEFILE
echo " -echo 'include $DEP_TAF_FILE' >> \$(MAKEFILE)" >> $MAKEFILE
fi
cat >>$MAKEFILE <<EOF
lib: libmitgcmuv.a
Expand All @@ -3387,9 +3394,15 @@ Clean:
@\$(MAKE) -f \$(MAKEFILE) cleanlinks
-rm -rf *.flowdir
-rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
-rm -f taf_ad.f90
-rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
-\$(TOOLSDIR)/f90mkdepend_taf -clean
EOF
if test $CAT_SRC_FOR_TAF = 0 ; then
cat >>$MAKEFILE <<EOF
-sed "/^include $DEP_TAF_FILE/d" \$(MAKEFILE) > tmp_Mkfile && mv -f tmp_Mkfile \$(MAKEFILE) && rm -f $DEP_TAF_FILE
-rm -f taf_ad.f90 taf_tl.f90 f90mkdepend_taf.log
EOF
fi
cat >>$MAKEFILE <<EOF
# remove also the executable, files that "genmake2" generates (except Makefile)
# and output from a run (plus log files from testreport)
Expand Down Expand Up @@ -3631,7 +3644,7 @@ else
cat >>$MAKEFILE <<EOF
# ... send multiple files to TAF ...
adj_depend:
\$(TOOLSDIR)/f90mkdepend_taf -taf \$(AD_F90FILES:.$FS90=_ad.$FS90) \$(AD_FILES:.$FS=_ad.$FS) >> \$(MAKEFILE)
\$(TOOLSDIR)/f90mkdepend_taf $DEP_TAF_FILE \$(AD_F90FILES:.$FS90=_ad.$FS90) \$(AD_FILES:.$FS=_ad.$FS)
ad_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_F90FILES) \$(AD_FILES)
@$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
Expand Down Expand Up @@ -3739,7 +3752,7 @@ else
cat >>$MAKEFILE <<EOF
# ... send multiple files to TAF ...
ftl_depend:
\$(TOOLSDIR)/f90mkdepend_taf -taf \$(AD_F90FILES:.$FS90=_tl.$FS90) \$(AD_FILES:.$FS=_tl.$FS) >> \$(MAKEFILE)
\$(TOOLSDIR)/f90mkdepend_taf $DEP_TAF_FILE \$(AD_F90FILES:.$FS90=_tl.$FS90) \$(AD_FILES:.$FS=_tl.$FS)
ftl_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_F90FILES) \$(AD_FILES)
@$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
Expand Down

0 comments on commit ee3ac9c

Please sign in to comment.