forked from gildor2/UEViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·189 lines (173 loc) · 5.5 KB
/
build.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# Parse command line parameters
while [ "$1" ]; do
case "$1" in
--debug)
# enable debug build
debug=1
shift
;;
--vc)
vc_ver=$2
shift 2
;;
--64)
# switch to 64 bit platform (Win64)
PLATFORM="vc-win64"
VC32TOOLS_OPTIONS="--64"
shift
;;
--file)
# compile a single file from VSCode, should replace slashes
single_file=${2//\\//}
shift 2
;;
*)
echo "Usage: build.sh [--debug] [--vc <version>] [--64] [--file <cpp file>]"
exit
;;
esac
done
#-------------------------------------------------------------
# Get revision number from Git
revision="(unversioned)" # this value will be used in a case of missing git
version_file="UmodelTool/Version.h"
if [ -d .git ]; then
git=`type -p git` # equals to `which git`
if [ -z "$git" ]; then
if [ "$OSTYPE" == "msys" ]; then
# assume Windows, find local git distribution
# progs="${PROGRAMFILES//\\//}" # get from environment with slash replacement
# progs="/${progs//:/}" # for msys: convert "C:/Program Files" to "/C/Program Files"
[ -d "$PROGRAMFILES/Git" ] && gitpath="$PROGRAMFILES/Git/bin"
[ -d "$PROGRAMW6432/Git" ] && gitpath="$PROGRAMW6432/Git/bin"
! [ "$gitpath" ] && [ -d "$PROGRAMFILES/SmartGitHg/git" ] && gitpath="$PROGRAMFILES/SmartGitHg/git/bin"
! [ "$gitpath" ] && [ -d "$LOCALAPPDATA/Atlassian/SourceTree/git_local" ] && gitpath="$LOCALAPPDATA/Atlassian/SourceTree/git_local/bin"
[ "$gitpath" ] && PATH="$PATH:$gitpath"
# find git
git=`type -p git`
fi
fi
[ "$git" ] && revision=`git rev-list --count HEAD`
fi
# update tool version
# read current revision
[ -f "$version_file" ] && [ "$revision" ] && read last_revision < $version_file
last_revision=${last_revision##* } # cut "#define ..."
# write back to a file if value differs or if file doesn't exist (only for UModel project, i.e. when $project is empty)
[ -z "$project" ] && [ "$last_revision" != "$revision" ] && echo "#define GIT_REVISION $revision" > $version_file
#-------------------------------------------------------------
[ "$PLATFORM" ] || PLATFORM="vc-win32"
# force PLATFORM=linux under Linux OS
[ "$OSTYPE" == "linux-gnu" ] || [ "$OSTYPE" == "linux" ] && PLATFORM="linux"
#[ "$PLATFORM" == "linux" ] && PLATFORM="linux64"
if [ "${PLATFORM:0:3}" == "vc-" ]; then
# Visual C++ compiler
# setup default compiler version
[ "$vc_ver" ] || vc_ver=latest
# Find Visual Studio
. vc32tools $VC32TOOLS_OPTIONS --version=$vc_ver --check
[ -z "$found_vc_year" ] && exit 1 # nothing found
# Adjust vc_ver to found one
vc_ver=$found_vc_year
# echo "Found: $found_vc_year $workpath [$vc_ver]"
GENMAKE_OPTIONS=VC_VER=$vc_ver # specify compiler for genmake script
fi
[ "$project" ] || project="UmodelTool/umodel" # setup default prohect name
[ "$root" ] || root="."
[ "$render" ] || render=1
# build shader includes before call to genmake
if [ $render -eq 1 ]; then
# 'cd' calls below won't work if we're not calling from the project's root
if [ "$root" != "." ]; then
echo "Bad 'root'"
exit 1
fi
# build shaders
#?? move to makefile
cd "Unreal/Shaders"
./make.pl
cd "../.."
fi
# prepare makefile parameters, store in obj directory
projectName=${project##*/}
makefile="$root/obj/$projectName-$PLATFORM"
if ! [ -d $root/obj ]; then
mkdir $root/obj
fi
if [ "$debug" ]; then
makefile="${makefile}-debug"
GENMAKE_OPTIONS+=" DEBUG=1"
fi
makefile="${makefile}.mak"
# update makefile when needed
# [ $makefile -ot $project ] &&
$root/Tools/genmake $project.project TARGET=$PLATFORM $GENMAKE_OPTIONS > $makefile
if [ "$single_file" ]; then
# Using perl with HEREDOC for parsing of makefile to find object file matching required target.
# Code layout: target=`perl << 'EOF'
# EOF
# `
# 1) using quoted 'EOF' to prevent variable expansion
# 2) passing parameters to a script using 'export <variable', return value - as output capture
# 3) putting perl command into `` (inverse quotes)
# 4) s/// command in perl code has extra quote for '$'
export makefile
export single_file
target=`perl <<'EOF'
open(FILE, $ENV{"makefile"}) or die;
$defines = ();
while ($line = <FILE>)
{
next if $line !~ /^\S+/; # we're interested only in lines starting without indent
next if $line =~ /^\#/; # no comments
$line =~ s/(\r|\n)//; # string end of line
# print($line."\n");
# parse assignment
($var, $val) = $line =~ /^(\w+)\s*\=\s*(.*)$/;
if (defined($var) && defined($val)) {
$defines{$var} = $val;
} else {
# parse target
($target, $cpp) = $line =~ /^(\S+)\s*\:\s*(\S+)(\s|$)/;
if (defined($target) && defined($cpp)) {
next if $cpp ne $ENV{"single_file"}; # match with single_file value
# print("$cpp -> $target\n");
for my $key (keys(%defines)) {
my $value = $defines{$key};
$target =~ s/\\$\($key\)/$value/g; # replace $(var) with value
}
# print("$cpp -> $target\n");
print("$target");
exit;
}
}
}
EOF
`
#echo "[$target]"
if [ -z "$target" ]; then echo "Error: failed to find build target for '$single_file'"; exit; fi
# end of parsing
fi
# build
# if $target is empty, whole project will be built, otherwise a single file
case "$PLATFORM" in
"vc-win32")
Make $makefile $target || exit 1
cp $root/libs/SDL2/x86/SDL2.dll .
;;
"vc-win64")
Make $makefile $target || exit 1
cp $root/libs/SDL2/x64/SDL2.dll .
;;
"mingw32"|"cygwin")
PATH=/bin:/usr/bin:$PATH # configure paths for Cygwin
gccfilt make -f $makefile $target || exit 1
;;
linux*)
make -j 4 -f $makefile $target || exit 1 # use 4 jobs for build
;;
*)
echo "Unknown PLATFORM=\"$PLATFORM\""
exit 1
esac