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