File indexing completed on 2024-04-21 05:41:57

0001 #!/bin/sh
0002 # Modifies the Makefile in the current directory (and optionally its subdirs),
0003 # - to add debug info (-g3)
0004 # - optionally (default) remove optimizations (-O[1-9]?)
0005 # - optionally remove -DNDEBUG and -DNO_DEBUG
0006 
0007 # depth is 3 because flags.make is within CMakeFiles/foo.dir/
0008 keep=
0009 mxdp="-maxdepth 3"
0010 ndebug=
0011 for i in "$@"; do
0012   case $i in
0013     -k) keep=1;;
0014     -r) mxdp=;;
0015     -n) ndebug=1;;
0016     *) printf "Usage: adddebug [-k] [-r] [-n]\n  -k: keep optimizations (removed by default)\n  -r: recursive (process all subdirectories)\n  -n: compile without NDEBUG and NO_DEBUG being defined (makes kDebug calls work)\n"; exit 1;;
0017   esac
0018 done
0019 
0020 xpr='s/^((C|CXX|LD)_FLAGS[ \t]*=.*)$/\1 -g3/'
0021 if test -z $keep; then
0022   xpr="$xpr;"'s/[\t ]-O[1-9]?\b//g'
0023   xpr="$xpr;"'s/[\t ]-march=\S+\b//g'
0024 fi
0025 if test -z $ndebug; then
0026   xpr="$xpr;"'s/[\t ]-DNDEBUG\b//g'
0027   xpr="$xpr;"'s/[\t ]-DNO_DEBUG\b//g'
0028 fi
0029 find . $mxdp -name flags.make -print0 | xargs -0 perl -i "$xpr"