This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
makefile.shade
264 lines (220 loc) · 13.6 KB
/
makefile.shade
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
var PRODUCT_VERSION = '1.10.0'
var AUTHORS='Microsoft Open Technologies, Inc.'
use-standard-lifecycle
k-standard-goals
var Configuration2 = '${E("Configuration")}'
var ROOT = '${Directory.GetCurrentDirectory()}'
var BUILD_DIR2 = '${Path.Combine(ROOT, "artifacts", "build")}'
var PROGRAM_FILES_X86 = '${Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)}'
var MSBUILD = '${Path.Combine(PROGRAM_FILES_X86, "MSBuild", "14.0", "Bin", "MSBuild.exe")}'
var CLANG = '${SearchForClang()}'
var FULL_VERSION = '${PRODUCT_VERSION + "-" + E("DOTNET_BUILD_VERSION")}'
#repo-initialize target='initialize'
git gitCommand="submodule update --init"
#native-compile
#build-compile target='compile'
#build-windows .ensure-msbuild target='build-compile' if='CanBuildForWindows'
@{
Exec(MSBUILD, Path.Combine(ROOT, "src\\libuv\\libuv.vcxproj") + " /p:Platform=Win32 /p:Configuration=" + Configuration2);
Exec(MSBUILD, Path.Combine(ROOT, "src\\libuv\\libuv.vcxproj") + " /p:Platform=x64 /p:Configuration=" + Configuration2);
Exec(MSBUILD, Path.Combine(ROOT, "src\\libuv\\libuv.vcxproj") + " /p:Platform=ARM /p:Configuration=" + Configuration2);
}
#copy-symbols target='build-compile' if='CanBuildForWindows'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\Win32", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "symbols\\Win32", Configuration2)}' include='*.pdb' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\x64", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "symbols\\x64", Configuration2)}' include='*.pdb' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\ARM", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "symbols\\ARM", Configuration2)}' include='*.pdb' overwrite='${true}'
#ensure-msbuild
@{
if (!File.Exists(MSBUILD))
{
Log.Warn("msbuild version 14 not found. Please ensure you have the VS 2015 C++ SDK installed.");
Environment.Exit(1);
}
}
#nuget-pack target='package' if='CanBuildForWindows'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\Win32", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win\\contents\\runtimes\\win-x86\\native")}' include='*.dll' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\x64", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win\\contents\\runtimes\\win-x64\\native")}' include='*.dll' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src\\libuv\\bin\\ARM", Configuration2)}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win\\contents\\runtimes\\win-arm\\native")}' include='*.dll' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win\\contents")}' include='*' exclude='*.nuspec' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-win")}' include='Microsoft.AspNetCore.Internal.libuv-Windows.nuspec' overwrite='${true}'
nuget-pack packageVersion='${FULL_VERSION}' outputDir='${BUILD_DIR2}' extra='-NoPackageAnalysis' nugetPath='.build/nuget.exe' nuspecFile='${Path.Combine(BUILD_DIR2, "package-src-win\\Microsoft.AspNetCore.Internal.libuv-Windows.nuspec")}'
#build-darwin .ensure-clang target='build-compile' if='CanBuildForDarwin'
@{
var libuvRoot = Path.Combine(ROOT, "submodules/libuv");
var sourceFiles = GetCommonSourceFiles(libuvRoot);
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/darwin.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/darwin-proctitle.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/kqueue.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/fsevents.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/pthread-barrier.c"));
var outputDir = Path.Combine(ROOT, "src/libuv/bin/darwin");
var outputPath = Path.Combine(outputDir, "libuv.dylib");
Directory.CreateDirectory(outputDir);
var sources = string.Join(" ", sourceFiles);
Exec(CLANG,
string.Format("{0} -lm -pthread -fPIC -shared -o {1} -I{2}/include -I{2}/src -Wall -Wextra -Wno-unused-parameter -g --std=gnu89 -pedantic -D_DARWIN_USE_64_BIT_INODE=1 -D_DARWIN_UNLIMITED_SELECT=1 -D_BUILDING_UV_SHARED=1 -arch i386 -arch x86_64",
sources, outputPath, libuvRoot));
}
#nuget-pack target='package' if='CanBuildForDarwin'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/darwin")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin/runtimes/osx/native")}' include='*.dylib' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin")}' include='*' overwrite='${true}'
nuget-pack packageVersion='${FULL_VERSION}' outputDir='${BUILD_DIR2}' extra='-NoPackageAnalysis -Properties TargetOS=Darwin' nugetPath='.build/nuget.exe' nuspecFile='${Path.Combine(BUILD_DIR2, "package-src-darwin/libuv.nuspec")}'
#build-linux .ensure-clang target='build-compile' if='CanBuildForLinux'
@{
var libuvRoot = Path.Combine(ROOT, "submodules/libuv");
var sourceFiles = GetCommonSourceFiles(libuvRoot);
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/linux-core.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/linux-inotify.c"));
sourceFiles.Add(Path.Combine(libuvRoot, "src/unix/linux-syscalls.c"));
var sources = string.Join(" ", sourceFiles);
var outputDir = Path.Combine(ROOT, "src/libuv/bin/linux");
var outputPath = Path.Combine(outputDir, "libuv.so");
Directory.CreateDirectory(outputDir);
var armOutputDir = Path.Combine(ROOT, "src/libuv/bin/linux-arm");
var armOutputPath = Path.Combine(armOutputDir, "libuv.so");
Directory.CreateDirectory(armOutputDir);
var arm64OutputDir = Path.Combine(ROOT, "src/libuv/bin/linux-arm64");
var arm64OutputPath = Path.Combine(arm64OutputDir, "libuv.so");
Directory.CreateDirectory(arm64OutputDir);
var armelOutputDir = Path.Combine(ROOT, "src/libuv/bin/linux-armel");
var armelOutputPath = Path.Combine(armelOutputDir, "libuv.so");
Directory.CreateDirectory(armelOutputDir);
var flags = string.Format("-lm -pthread -ldl -lrt -fPIC -shared -I{0}/include -I{0}/src -Wall -Wextra -Wno-unused-parameter -Wstrict-aliasing -g --std=gnu89 -pedantic -D_GNU_SOURCE -D_BUILDING_UV_SHARED=1", libuvRoot);
Exec(CLANG,
string.Format("{0} -o {1} {2}", sources, outputPath, flags));
// The "arm" target should align with what CoreFX is doing, see
// https://github.com/dotnet/corefx/blob/master/cross/arm/toolchain.cmake#L9
Exec(CLANG,
string.Format("{0} -target armv7-linux-gnueabihf -mfpu=vfpv3 -B/usr/arm-linux-gnueabihf/bin/ -B/usr/arm-linux-gnueabihf/lib/ -isystem /usr/arm-linux-gnueabihf/include -o {1} {2}", sources, armOutputPath, flags));
// The "arm64" target should align with what CoreFX is doing, see
// https://github.com/dotnet/corefx/blob/master/cross/arm64/toolchain.cmake
Exec(CLANG,
string.Format("{0} -target aarch64-linux-gnu -B/usr/aarch64-linux-gnu/bin/ -B/usr/aarch64-linux-gnu/lib/ -isystem /usr/aarch64-linux-gnu/include -o {1} {2}", sources, arm64OutputPath, flags));
// The "armel" target should align with what CoreFX is doing, see
// https://github.com/dotnet/corefx/blob/master/cross/armel/toolchain.cmake#L9
Exec(CLANG,
string.Format("{0} -target armv7-linux-gnueabi -mfpu=vfpv3 -mfloat-abi=softfp -B/usr/arm-linux-gnueabi/bin/ -B/usr/arm-linux-gnueabi/lib/ -isystem /usr/arm-linux-gnueabi/include -o {1} {2}", sources, armelOutputPath, flags));
}
#nuget-pack target='package' if='CanBuildForDarwin'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/darwin")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin/contents/runtimes/osx/native")}' include='*.dylib' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin/contents")}' include='*' exclude='*.nuspec' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-darwin")}' include='Microsoft.AspNetCore.Internal.libuv-Darwin.nuspec' overwrite='${true}'
nuget-pack packageVersion='${FULL_VERSION}' outputDir='${BUILD_DIR2}' extra='-NoPackageAnalysis' nugetPath='.build/nuget.exe' nuspecFile='${Path.Combine(BUILD_DIR2, "package-src-darwin/Microsoft.AspNetCore.Internal.libuv-Darwin.nuspec")}'
#nuget-pack target='package' if='CanBuildForLinux'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/linux-arm")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents/runtimes/linux-arm/native")}' include='*.so' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/linux-arm64")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents/runtimes/linux-arm64/native")}' include='*.so' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/linux-armel")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents/runtimes/linux-armel/native")}' include='*.so' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "src/libuv/bin/linux")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents/runtimes/linux-x64/native")}' include='*.so' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux/contents")}' include='*' exclude='*.nuspec' overwrite='${true}'
copy sourceDir='${Path.Combine(ROOT, "build")}' outputDir='${Path.Combine(BUILD_DIR2, "package-src-linux")}' include='Microsoft.AspNetCore.Internal.libuv-Linux.nuspec' overwrite='${true}'
nuget-pack packageVersion='${FULL_VERSION}' outputDir='${BUILD_DIR2}' extra='-NoPackageAnalysis' nugetPath='.build/nuget.exe' nuspecFile='${Path.Combine(BUILD_DIR2, "package-src-linux/Microsoft.AspNetCore.Internal.libuv-Linux.nuspec")}'
#ensure-clang
@{
if (CLANG == null || !File.Exists(CLANG))
{
Log.Warn("clang not found. Please ensure you have clang on the path or set CXX to a path to clang.");
Environment.Exit(1);
}
}
functions @{
bool CanBuildForWindows
{
get
{
var p = (int)Environment.OSVersion.Platform;
return (p != 4) && (p != 6) && (p != 128);
}
}
bool CanBuildForDarwin
{
get
{
return string.Equals(Uname(), "Darwin");
}
}
bool CanBuildForLinux
{
get
{
return string.Equals(Uname(), "Linux");
}
}
public string SearchForClang()
{
var CXX = Environment.GetEnvironmentVariable("CXX");
if (!string.IsNullOrEmpty(CXX))
{
return CXX;
}
foreach(var dir in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator))
{
if (File.Exists(Path.Combine(dir, "clang")))
{
return Path.Combine(dir, "clang");
}
else if (File.Exists(Path.Combine(dir, "clang-3.5")))
{
return Path.Combine(dir, "clang-3.5");
}
}
return null;
}
public string Uname()
{
try
{
string uname;
ExecuteAndRedirectOutput("uname", "", out uname);
return string.IsNullOrEmpty(uname) ? null : uname.Trim();
}
catch
{
return null;
}
}
int ExecuteAndRedirectOutput(string command, string argument, out string content)
{
var procStartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = argument,
WorkingDirectory = Directory.GetCurrentDirectory(),
UseShellExecute = false
};
procStartInfo.RedirectStandardOutput = true;
var process = Process.Start(procStartInfo);
content = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return process.ExitCode;
}
public List<string> GetCommonSourceFiles(string libuvRoot)
{
return new List<string>
{
Path.Combine(libuvRoot, "src/fs-poll.c"),
Path.Combine(libuvRoot, "src/inet.c"),
Path.Combine(libuvRoot, "src/threadpool.c"),
Path.Combine(libuvRoot, "src/uv-common.c"),
Path.Combine(libuvRoot, "src/version.c"),
Path.Combine(libuvRoot, "src/unix/async.c"),
Path.Combine(libuvRoot, "src/unix/core.c"),
Path.Combine(libuvRoot, "src/unix/dl.c"),
Path.Combine(libuvRoot, "src/unix/fs.c"),
Path.Combine(libuvRoot, "src/unix/getaddrinfo.c"),
Path.Combine(libuvRoot, "src/unix/getnameinfo.c"),
Path.Combine(libuvRoot, "src/unix/loop.c"),
Path.Combine(libuvRoot, "src/unix/loop-watcher.c"),
Path.Combine(libuvRoot, "src/unix/pipe.c"),
Path.Combine(libuvRoot, "src/unix/poll.c"),
Path.Combine(libuvRoot, "src/unix/process.c"),
Path.Combine(libuvRoot, "src/unix/signal.c"),
Path.Combine(libuvRoot, "src/unix/stream.c"),
Path.Combine(libuvRoot, "src/unix/tcp.c"),
Path.Combine(libuvRoot, "src/unix/thread.c"),
Path.Combine(libuvRoot, "src/unix/timer.c"),
Path.Combine(libuvRoot, "src/unix/tty.c"),
Path.Combine(libuvRoot, "src/unix/udp.c"),
Path.Combine(libuvRoot, "src/unix/proctitle.c"),
};
}
}