Add output directories for each configuration type as needed by MSVC.
[SquirrelJME.git] / utils-dev / fmv.sh
blob0a594304431abfacee6b5163c06453fd67c97b0e
1 #!/bin/sh
2 # ---------------------------------------------------------------------------
3 # Multi-Phasic Applications: SquirrelJME
4 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 # Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
6 # ---------------------------------------------------------------------------
7 # SquirrelJME is under the GNU General Public License v3, or later.
8 # For more information see license.txt.
9 # ---------------------------------------------------------------------------
10 # DESCRIPTION: Moves a file within the repository to another destination.
12 # Force C locale
13 export LC_ALL=C
15 # Directory of this script
16 __exedir="$(dirname -- "$0")"
18 # Prints usage
19 __help()
21 echo "Usage: $0 [-x] (from...) (to)" 1>&2
22 echo " If there are multiple source files, to must be a dir." 1>&2
23 echo " -x Do nothing, just print what would be done."
26 # Handle arguments
27 __noop="0"
28 while getopts "x" __arg
30 case $__arg in
32 __noop="1"
36 __help
37 exit 1
39 esac
40 done
42 # Down they go
43 shift $(($OPTIND - 1))
45 # Not enough arguments
46 if [ "$#" -lt "2" ]
47 then
48 __help
49 exit 1
52 # Destination file or directory
53 __dest="$("$__exedir/lastarg.sh" "$@")"
55 # The number of files to consider
56 __count="$(($# - 1))"
58 # Copy of multiple files, target cannot be a non-directory
59 #if [ "$__count" -gt 1 ] && [ ! -d "$__dest" ]
60 #then
61 # echo "Destination '$__dest' is not a directory!" 1>&2
62 # exit 1
63 #fi
65 # Copy each file
66 for __i in $(seq 1 $__count)
68 # Read source file
69 __src="$1"
70 shift
72 # Determine the target file name
73 if [ "$__count" -gt 1 ]
74 then
75 __target="$__dest/$(basename -- "$__src")"
76 else
77 if [ -d "$__dest" ]
78 then
79 __target="$__dest/$(basename -- "$__src")"
80 else
81 __target="$__dest"
85 # Make relative for simpler handling
86 __rsrc="$("$__exedir/relative.sh" "$__src")"
87 __rtrg="$("$__exedir/relative.sh" "$__target")"
89 # Mark how the file is moving
90 echo "$__rsrc" 1>&2
91 echo " -> $__rtrg" 1>&2
93 # If the source is a directory, use directory move script
94 if [ -d "$__src" ]
95 then
96 if [ "$__noop" != 0 ]
97 then
98 "$__exedir/dirmv.sh" "-x" "$__src" "$__target"
100 else
101 "$__exedir/dirmv.sh" "$__src" "$__target"
104 # Otherwise treat as normal file move/rename
105 else
106 __targetdir="$(dirname -- "$__target")"
107 __maketargetdir="0"
108 if [ ! -d "$__targetdir" ]
109 then
110 __maketargetdir="1"
111 __rtd="$("$__exedir/relative.sh" "$__targetdir")"
112 echo " md $__rtd" 1>&2
115 # Not actually going to move anything
116 if [ "$__noop" != 0 ]
117 then
118 continue
121 # Make target directory?
122 if [ "$__maketargetdir" != "0" ]
123 then
124 mkdir -p "$__targetdir"
127 # Move fossil file first
128 if fossil mv "$__src" "$__target" > /dev/null
129 then
130 if ! mv "$__src" "$__target" > /dev/null
131 then
132 echo " !! FAILED TO MOVE REGULAR FILE." 1>&2
134 else
135 echo " !! FAILED TO MOVE FOSSIL FILE." 1>&2
138 done
140 # Okay!
141 exit 0