b3a3dd1c61c75730e418e8bd35a5dd9dfded591f
[feisty_meow.git] / scripts / generator / wrapdoze.sh
1 #!/bin/bash
2
3 source $FEISTY_MEOW_SCRIPTS/core/functions.sh
4
5 #hmmm: make this support multiple vars as parameters.
6 # replaces a specific environment variable with a dos approved equivalent.
7 function dossify_environment_variable()
8 {
9   local var="$1"; shift
10
11   old_value="${!var}"
12   if [[ ! "$old_value" =~ \/cygdrive\/ ]]; then
13 #echo didnt have a cygdrive in it: $old_value
14     return 0
15 #hmmm: want this to continue in multi parm version.
16   fi
17
18   # replace single back-slashes with double ones.
19   local new_value="$(unix_to_dos_path "${old_value}")"
20
21   # remove any quote characters in the value.
22   new_value="${new_value//\"/}"
23
24 #  echo "new value: $var  =  $new_value"
25   eval "export $var=\"$new_value\""
26 }
27
28 # for a windows build, this will replace any forward slashes
29 # and other cygwin notation with the appropriate dos style paths.
30 function dossify_and_run_commands()
31 {
32   if [ "$OS" != "Windows_NT" ]; then
33     # for non windows, just run the commands straight up.
34     eval "${@}"
35     return $?
36   fi
37
38   # force all slashes to be dossy.
39 #  export SERIOUS_SLASH_TREATMENT=true
40
41   dossify_environment_variable INCLUDE
42
43   declare -a darc_commands=()
44
45   for i in "$@"; do
46     if [[ "$i" =~ ^-[a-zA-z][/\"].* ]]; then
47       flag="${i:0:2}"
48       filename="$(unix_to_dos_path ${i:2})"
49 #echo "first two chars are $flag"
50 #echo "last after that are $filename"
51       recombined="$flag$filename"
52 #echo combined flag and file is $recombined
53       darc_commands+=("$recombined")
54     elif [[ "$i" =~ ^-libpath:.* ]]; then
55       flag="-libpath:"
56       filename="$(unix_to_dos_path ${i:9})"
57 #echo "libflag flag is $flag"
58 #echo "name after that is $filename"
59       recombined="$flag$filename"
60 #echo combined flag and file is $recombined
61       darc_commands+=("$recombined")
62     else 
63       darc_commands+=($(unix_to_dos_path $i))
64     fi
65   done
66
67   declare -a real_commands=()
68   for i in "${darc_commands[@]}"; do
69     real_commands+=($(echo $i | sed -e 's/\//\\/g'))
70   done
71
72   if [ ! -z "$SHELL_DEBUG" ]; then
73     echo commands are now:
74     for i in "${real_commands[@]}"; do
75       echo -n "$i "
76     done
77     echo
78   fi
79
80 # this nonsense is only necessary because cygwin is screwing up our carefully constructed
81 # command line.  it can't seem to leave the dos style paths alone in some cases, and insists
82 # on changing their form to use forward slashes, which breaks the windows compiler.
83 # this is NOT what cygwin is supposed to be doing, according to their documentation that
84 # claims all styles of paths are supported.  and of course this worked fine in msys.
85
86   # now actually run the chewed command.
87
88 # old approach, not working since cygwin is hosing us on some paths.
89 #cmd /c "${real_commands[@]}"
90
91 #new approach that creates a cmd file.
92   cmdfile="$(mktemp $CLAM_TMP/build_cmds.XXXXXX)"
93   echo "${real_commands[@]}" >"$cmdfile"
94 #echo "**** cmd file is $cmdfile"
95   cmd /c $(cat "$cmdfile")
96   retval=$?
97   rm "$cmdfile"
98
99   return $retval
100 }
101
102 dossify_and_run_commands "$@"
103