-
Notifications
You must be signed in to change notification settings - Fork 4
/
Make.sh
executable file
·139 lines (120 loc) · 4.35 KB
/
Make.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
if [ -t 1 ]; then
ANSI_RESET="$(tput sgr0)"
ANSI_UNDERLINE="$(tput smul)"
ANSI_RED="`[ $(tput colors) -ge 16 ] && tput setaf 9 || tput setaf 1 bold`"
ANSI_YELLOW="`[ $(tput colors) -ge 16 ] && tput setaf 11 || tput setaf 3 bold`"
ANSI_CYAN="`[ $(tput colors) -ge 16 ] && tput setaf 14 || tput setaf 6 bold`"
fi
while getopts ":h" OPT; do
case $OPT in
h)
echo
echo " SYNOPSIS"
echo -e " $(basename "$0") [${ANSI_UNDERLINE}operation${ANSI_RESET}]"
echo
echo -e " ${ANSI_UNDERLINE}operation${ANSI_RESET}"
echo " Operation to perform (all, clean, debug, release, test)."
echo
echo " DESCRIPTION"
echo " Make script compatible with both Windows and Linux."
echo
echo " SAMPLES"
echo " $(basename "$0")"
echo " $(basename "$0") all"
echo
exit 0
;;
\?) echo "${ANSI_RED}Invalid option: -$OPTARG!${ANSI_RESET}" >&2 ; exit 1 ;;
:) echo "${ANSI_RED}Option -$OPTARG requires an argument!${ANSI_RESET}" >&2 ; exit 1 ;;
esac
done
if ! command -v dotnet >/dev/null; then
echo "${ANSI_RED}No dotnet found!${ANSI_RESET}" >&2
exit 1
fi
trap "exit 255" SIGHUP SIGINT SIGQUIT SIGPIPE SIGTERM
trap "echo -n \"$ANSI_RESET\"" EXIT
BASE_DIRECTORY="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
SOLUTION_FILES="Medo.sln"
OUTPUT_FILES="Medo.dll Medo.pdb"
if [[ `uname -o` == "Msys" ]]; then # assume Windows
SOLUTION_FILES="Medo.Windows.sln"
OUTPUT_FILES="$OUTPUT_FILES Medo.Windows.Forms.dll Medo.Windows.Forms.pdb"
fi
function clean() {
if [[ "$BASE_DIRECTORY" == "~" ]] || [[ "$BASE_DIRECTORY" == "/" ]]; then return 1; fi
rm -r "$BASE_DIRECTORY/bin/" 2>/dev/null
rm -r "$BASE_DIRECTORY/build/" 2>/dev/null
rm -r "$BASE_DIRECTORY/src/**/bin/" 2>/dev/null
rm -r "$BASE_DIRECTORY/src/**/obj/" 2>/dev/null
return 0
}
function debug() {
echo ".NET `dotnet --version`"
mkdir -p "$BASE_DIRECTORY/bin/"
mkdir -p "$BASE_DIRECTORY/build/debug/"
for SOLUTION_FILE in $SOLUTION_FILES; do
dotnet build "$BASE_DIRECTORY/src/$SOLUTION_FILE" \
--configuration "Debug" \
--output "$BASE_DIRECTORY/build/debug/" \
--verbosity "minimal" \
|| return 1
echo
done
for FILE in $OUTPUT_FILES; do
cp "$BASE_DIRECTORY/build/debug/$FILE" "$BASE_DIRECTORY/bin/$FILE" || return 1
done
echo "${ANSI_CYAN}Output in 'bin/'${ANSI_RESET}"
}
function release() {
if [[ `shell git status -s 2>/dev/null | wc -l` -gt 0 ]]; then
echo "${ANSI_YELLOW}Uncommited changes present.${ANSI_RESET}" >&2
fi
echo ".NET `dotnet --version`"
mkdir -p "$BASE_DIRECTORY/bin/"
mkdir -p "$BASE_DIRECTORY/build/release/"
for SOLUTION_FILE in $SOLUTION_FILES; do
dotnet build "$BASE_DIRECTORY/src/$SOLUTION_FILE" \
--configuration "Release" \
--output "$BASE_DIRECTORY/build/release/" \
--verbosity "minimal" \
|| return 1
echo
done
for FILE in $OUTPUT_FILES; do
cp "$BASE_DIRECTORY/build/release/$FILE" "$BASE_DIRECTORY/bin/$FILE" || return 1
done
echo "${ANSI_CYAN}Output in 'bin/'${ANSI_RESET}"
}
function test() {
echo ".NET `dotnet --version`"
mkdir -p "$BASE_DIRECTORY/build/tests/"
for SOLUTION_FILE in $SOLUTION_FILES; do
dotnet test "$BASE_DIRECTORY/src/$SOLUTION_FILE" \
--configuration "Debug" \
--output "$BASE_DIRECTORY/build/tests/" \
--verbosity "minimal" \
|| return 1
echo
done
}
if [ $# -gt 1 ]; then
echo "${ANSI_RED}Too many arguments!${ANSI_RESET}" >&2
exit 1
fi
OK=0
OPERATION="$1"
if [[ "$OPERATION" == "" ]]; then OPERATION="all"; fi
case "$OPERATION" in
all) clean && OK=1 ; release && OK=1 ;;
clean) clean && OK=1 ;;
debug) debug && OK=1 ;;
release) release && OK=1 ;;
test) test && OK=1 ;;
*) echo "${ANSI_RED}Unknown operation '$OPERATION'!${ANSI_RESET}" >&2 ; exit 1 ;;
esac
if ! [[ $OK ]]; then
echo "${ANSI_RED}Error performing '$OPERATION' operation!${ANSI_RESET}" >&2
exit 1
fi