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