1#!/bin/bash
2
3#Caveat emptor:
4#
5#-This script is based on the output generated by gcc when a specific
6# header is not found, should the format change at any time in the
7# future, this script is rendered useless
8#
9#-We assume no other includes are lacking than boost includes
10#
11#-We assume the boost includes are in the form of fully qualified
12# includes, and not relative includes
13#
14#-This script needs to be called multiple times untill no errors are found.
15
16#Notes:
17#
18#Before starting a series of these scripts, the following command may
19#be run in the internal coin boost directory to clean it out:
20#
21#  find -type f -not -path '*/.hg/*' -delete
22#
23#To clean up afterwards:
24#  hg st . | egrep '^!'  | cut -d\  -f2- | xargs hg remove
25#  hg st . | egrep '^\?'  | cut -d\  -f2- | xargs hg add
26#
27#To check that everything is in order, the following command should return empty:
28# hg st . | egrep -v '^A' | egrep -v '^D'
29#
30#Also always remember if you have eg. a system installation of boost,
31#you will want to make sure it is not picked up, when you are syncing
32#against another boost base.
33
34
35OS=$(uname)
36if [ "${OS}" = "SunOS" ]
37then
38  MKDIRHIER="/usr/X11/bin/mkdirhier"
39else
40  MKDIRHIER="mkdirhierWorkaround"
41fi
42
43#Since mkdirhier is not working with absolute paths on cygwin, lets do a workaround
44mkdirhierWorkaround() {
45    if [ -n $(echo -n $1 | cut -d/ -f1) ]
46    then
47      (cd / && mkdirhier $(echo -n $1 | cut -d/  -f2-))
48    else
49        mkdirhier $1
50    fi
51}
52
53error() {
54    echo $@ >/dev/stderr
55    exit -1
56}
57
58usage() {
59    echo -e "Usage is:\n\t $0 <BUILDDIR> <BOOSTDIR>";
60}
61
62#If the destination directory doesn't exist, we'll create it.
63reallyCopy() {
64    if ! cp $1 $2
65    then
66        ${MKDIRHIER} $(dirname $2)
67        cp $1 $2
68    fi
69}
70
71BASEDIR=$(pwd)
72cd $(dirname $0)/..
73COINDIR=$(pwd)
74cd ${BASEDIR}
75
76if [ -z "$1" ] || [ -z "$2" ]
77then
78    usage
79    exit -1
80fi
81
82cd $1 2>/dev/null || error "No such directory: $1"
83BUILDDIR=$(pwd)
84cd ${BASEDIR}
85cd $2 2>/dev/null || error "No such directory: $2"
86BOOSTDIR=$(pwd)
87cd ${BASEDIR}
88
89if [ -z "${BUILDDIR}" ]
90then
91    usage
92    exit 1
93fi
94
95if [ "${OS}" = "SunOS" ]
96then
97  DETECTCOMMAND="make 2>&1 | egrep ': Error: Could not open include file' | cut -d: -f3- | cut -d\< -f2- | cut -d\> -f1 | cut -d/ -f2- | sort | uniq"
98else
99  DETECTCOMMAND="make 2>&1 | egrep ': No such file or directory' | cut -d: -f5 | cut -d/ -f2- | cut -d\'  -f1 | sort | uniq"
100fi
101
102CONFIGDIRS="
103config
104"
105
106#We will always keep the platform configuration files.
107for cdir in ${CONFIGDIRS}
108do
109    oneup=$(dirname ${cdir})
110    #name=$(basename ${cdir})
111    ${MKDIERHIER} ${COINDIR}/include/boost/${oneup}
112    cp -r ${BOOSTDIR}/${cdir} ${COINDIR}/include/boost/${oneup} || error -e "No such file or directory: ${BOOSTDIR}/${cdir}.\nYou need to revise your special includes."
113done
114
115cd ${BUILDDIR}
116for file in $(eval ${DETECTCOMMAND})
117do
118    reallyCopy ${BOOSTDIR}/$file ${COINDIR}/include/boost/$file
119done
120REMAINING=$(eval ${DETECTCOMMAND})
121echo "${REMAINING}"
122if [ -n "${REMAINING}" ]
123then
124    exitStatus=$(echo "${REMAINING}" | wc -l)
125else
126    exitStatus=0
127fi
128echo ${exitStatus}
129exit ${exitStatus}
130