forked from unicorn-engine/unicorn
-
Notifications
You must be signed in to change notification settings - Fork 2
/
windows_export.bat
49 lines (42 loc) · 1.95 KB
/
windows_export.bat
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
@echo off
setlocal ENABLEDELAYEDEXPANSION
if not "%1"=="x86" if not "%1"=="x64" (
echo Usage: windows_export.bat (x86 ^| x64^)
exit /b 1
)
:: This script invokes the Visual Studio linker to construct a static library file that can be used outside of Mingw.
:: The unicorn.def file that it references below is produced by the Mingw compiler via a linker flag.
:: The arch (x86 or x64) we are working on should be passed via the first argument to this script.
:: Look up the Visual Studio install path via the registry
:: http://stackoverflow.com/questions/445167/how-can-i-get-the-value-of-a-registry-key-from-within-a-batch-script
:: There's no way to get the current installed VS version other than enumerating a version whitelist
:: If anyone ever tells you that Windows is a reasonable operating system, they are wrong
echo Searching for installed visual studio version...
for %%V in (
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\15.0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\12.0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\14.0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\15.0
) do (
echo ...trying registry key %%V
for /F "usebackq tokens=3*" %%A IN (`REG QUERY %%V /v InstallDir 2^>NUL`) DO (
set appdir=%%A %%B
)
if not "!appdir!"=="" goto :break
)
:break
if not "%CI%" == "" (
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %1
call lib /machine:%1 /def:unicorn.def
) else (
if "%appdir%"=="" (
cho Could not find an installed visual studio version. Abandoning windows static lib export operation.
) else (
:: Add the Visual Studio binaries to our path and run the linker
call "%appdir%..\..\VC\vcvarsall.bat" %1
call lib /machine:%1 /def:unicorn.def
)
)
exit /b 0