aboutsummaryrefslogtreecommitdiff
path: root/client/cpp/dotd.sh
blob: 989d928c95280b8227d21df893a56b63ccac6993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
#
# dotd.sh
#
# Generate .d Makefile fragments, so we can use #include statements in source
# for dependency info.  Adapted from the GNU make manual:
#
# http://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html
#
# We are putting this in shell, so we just have 'sed in bash'.  Not an unholy
# mix of 'sed in bash in Make'.

set -o nounset
set -o pipefail
set -o errexit

# Munge gcc -MM output into .d files.
main() {
  if [ ! -d _tmp ]; then mkdir _tmp; fi
  local basename=$1
  local dotd=$2  # .d output name
  shift 2  # rest of args are gcc invocation

  rm --verbose -f $dotd  # in case of failure?

  # Execute the gcc -MM invocation.
  #
  # Change
  #   rappor_sim.o: rappor.sim.cc
  # to
  #   _tmp/rappor_sim.o _tmp/rappor_sim.d : rappor.sim.cc
  "$@" | sed "s|\($basename\).o|_tmp/\1.o _tmp/\1.d |" > $dotd
}

main "$@"