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