1#!/bin/sh
2
3if [ $# != 1 ]; then
4  echo "Bad number of arguments";
5  exit 2
6fi
7
8exch_file=$1
9
10cp $exch_file $exch_file.saved
11
12# Save stdin and use exchange file as input.
13exec >&3
14exec < $exch_file
15
16# Save and set IFS to new line.
17OLD_IFS=$IFS
18IFS="
19"
20
21# Parse exchange file.
22section='Unknown'
23dep_files=""
24bindsec='Unknown'
25nm="nm-not-defined"
26cc="cc-not-defined"
27verbose=""
28
29while read line; do
30   case $line in
31      "[MAIN BASE NAME]")  section="base name" ;;
32      "[COMPILER PATH]") section="discard" ;;
33      "[COMPILER OPTIONS]") section="discard" ;;
34      "[DEPENDENCY FILES]") section="dependency" ;;
35      "[BINDING OPTIONS]") section="options" ;;
36      "[VERBOSE]") verbose=y; section="Unknown" ;;
37      \[*)  echo "Unknown section ($line)"; exit 1 ;;
38      *) case $section in
39        "discard") ;;
40        "Unknown") echo "Malformed exchange file"; exit 1 ;;
41        "base name") basename=$line ;;
42        "dependency") dep_files="$dep_files $line" ;;
43        "options")
44           case $line in
45              --nm=*) nm=`echo $line | sed -e "s/^--nm=//"` ;;
46              --cc=*) cc=`echo $line | sed -e "s/^--cc=//"` ;;
47              *) echo "Unknown binder option ($line)" ;;
48           esac ;;
49        *) echo "Internal error (section $section) unhandled"; exit 1 ;;
50        esac
51   esac
52done
53
54# Restore IFS and stdin.
55IFS=$OLD_IFS
56exec 3>&1
57exec 3>&-
58
59# Convert dependancy files to object files.
60object_files=`echo $dep_files | sed -e 's/\\.d\$/.o/'`
61
62# Do the real work.
63$nm $object_files | munch > cpp__$basename.c
64$cc -c cpp__$basename.c
65
66# Generate the exchange file.
67cat > $1 <<EOF
68[GENERATED SOURCE FILES]
69cpp__$basename.c
70[GENERATED OBJECT FILE]
71cpp__$basename.o
72EOF
73