blob: 307739d874a2130bc6dd98509ab3c2cc21647463 [file] [log] [blame]
Paul Monson32119e12019-03-29 16:30:10 -07001@echo off
2goto :Run
3
4:Usage
5echo.
6echo Before running prepare_libffi.bat
7echo LIBFFI_SOURCE environment variable must be set to the location of
8echo of python-source-deps clone of libffi branch
9echo VCVARSALL must be set to location of vcvarsall.bat
10echo cygwin must be installed (see below)
11echo SH environment variable must be set to the location of sh.exe
12echo.
13echo Tested with cygwin-x86 from https://www.cygwin.com/install.html
14echo Select http://mirrors.kernel.org as the download site
15echo Include the following cygwin packages in cygwin configuration:
16echo make, autoconf, automake, libtool, dejagnu
17echo.
18echo NOTE: dejagnu is only required for running tests.
19echo set LIBFFI_TEST=1 to run tests (optional)
20echo.
21echo Based on https://github.com/libffi/libffi/blob/master/.appveyor.yml
22echo.
23echo.
24echo.Available flags:
25echo. -x64 build for x64
26echo. -x86 build for x86
Paul Monson11efd792019-04-17 18:09:16 -070027echo. -arm32 build for arm32
Paul Monson32119e12019-03-29 16:30:10 -070028echo. -? this help
29echo. --install-cygwin install cygwin to c:\cygwin
30exit /b 127
31
32:Run
33
34set BUILD_X64=
35set BUILD_X86=
Paul Monson11efd792019-04-17 18:09:16 -070036set BUILD_ARM32=
Paul Monson32119e12019-03-29 16:30:10 -070037set INSTALL_CYGWIN=
38
39:CheckOpts
40if "%1"=="" goto :CheckOptsDone
41if /I "%1"=="-x64" (set BUILD_X64=1) & shift & goto :CheckOpts
42if /I "%1"=="-x86" (set BUILD_X86=1) & shift & goto :CheckOpts
Paul Monson11efd792019-04-17 18:09:16 -070043if /I "%1"=="-arm32" (set BUILD_ARM32=1) & shift & goto :CheckOpts
Paul Monson32119e12019-03-29 16:30:10 -070044if /I "%1"=="-?" goto :Usage
45if /I "%1"=="--install-cygwin" (set INSTALL_CYGWIN=1) & shift & goto :CheckOpts
46goto :Usage
47
48:CheckOptsDone
49
50if NOT DEFINED BUILD_X64 if NOT DEFINED BUILD_X86 if NOT DEFINED BUILD_ARM32 (
51 set BUILD_X64=1
52 set BUILD_X86=1
Paul Monson11efd792019-04-17 18:09:16 -070053 set BUILD_ARM32=1
Paul Monson32119e12019-03-29 16:30:10 -070054)
55
56if "%INSTALL_CYGWIN%"=="1" call :InstallCygwin
57
58setlocal
59if NOT DEFINED SH if exist c:\cygwin\bin\sh.exe set SH=c:\cygwin\bin\sh.exe
60
61if NOT DEFINED VCVARSALL (
62 if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" (
63 set VCVARSALL="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"
64 )
65)
66if ^%VCVARSALL:~0,1% NEQ ^" SET VCVARSALL="%VCVARSALL%"
67
68if NOT DEFINED LIBFFI_SOURCE echo.&&echo ERROR LIBFFI_SOURCE environment variable not set && goto :Usage
69if NOT DEFINED SH echo ERROR SH environment variable not set && goto :Usage
70
71if not exist %SH% echo ERROR %SH% does not exist && goto :Usage
72if not exist %LIBFFI_SOURCE% echo ERROR %LIBFFI_SOURCE% does not exist && goto :Usage
73
74set OLDPWD=%LIBFFI_SOURCE%
75pushd %LIBFFI_SOURCE%
76
77%SH% --login -lc "cygcheck -dc cygwin"
78set GET_MSVCC=%SH% -lc "cd $OLDPWD; export MSVCC=`/usr/bin/find $PWD -name msvcc.sh`; echo ${MSVCC};"
79FOR /F "usebackq delims==" %%i IN (`%GET_MSVCC%`) do @set MSVCC=%%i
80
81echo.
82echo VCVARSALL : %VCVARSALL%
83echo SH : %SH%
84echo LIBFFI_SOURCE: %LIBFFI_SOURCE%
85echo MSVCC : %MSVCC%
86echo.
87
88if not exist Makefile.in (%SH% -lc "(cd $LIBFFI_SOURCE; ./autogen.sh;)")
89
Paul Monson11efd792019-04-17 18:09:16 -070090if "%BUILD_X64%"=="1" call :BuildOne x64 x86_64-w64-cygwin x86_64-w64-cygwin
91if "%BUILD_X86%"=="1" call :BuildOne x86 i686-pc-cygwin i686-pc-cygwin
92if "%BUILD_ARM32%"=="1" call :BuildOne x86_arm i686-pc-cygwin arm-w32-cygwin
Paul Monson32119e12019-03-29 16:30:10 -070093
94popd
95endlocal
96exit /b 0
97REM all done
98
99
100REM this subroutine is called once for each architecture
101:BuildOne
102
103setlocal
104
105REM Initialize variables
106set VCVARS_PLATFORM=%1
107set BUILD=%2
108set HOST=%3
109set ASSEMBLER=
110set SRC_ARCHITECTURE=x86
111
112if NOT DEFINED VCVARS_PLATFORM echo ERROR bad VCVARS_PLATFORM&&exit /b 123
113
114if /I "%VCVARS_PLATFORM%" EQU "x64" (
115 set ARCH=amd64
116 set ARTIFACTS=%LIBFFI_SOURCE%\x86_64-w64-cygwin
117 set ASSEMBLER=-m64
118 set SRC_ARCHITECTURE=x86
119)
120if /I "%VCVARS_PLATFORM%" EQU "x86" (
121 set ARCH=win32
122 set ARTIFACTS=%LIBFFI_SOURCE%\i686-pc-cygwin
123 set ASSEMBLER=
124 set SRC_ARCHITECTURE=x86
125)
Paul Monson11efd792019-04-17 18:09:16 -0700126if /I "%VCVARS_PLATFORM%" EQU "x86_arm" (
127 set ARCH=arm32
128 set ARTIFACTS=%LIBFFI_SOURCE%\arm-w32-cygwin
129 set ASSEMBLER=-marm
130 set SRC_ARCHITECTURE=ARM
131)
Paul Monson32119e12019-03-29 16:30:10 -0700132
133if NOT DEFINED LIBFFI_OUT set LIBFFI_OUT=%~dp0\..\externals\libffi
134set _LIBFFI_OUT=%LIBFFI_OUT%\%ARCH%
135
136echo get VS build environment
137call %VCVARSALL% %VCVARS_PLATFORM%
138
139echo clean %_LIBFFI_OUT%
140if exist %_LIBFFI_OUT% (rd %_LIBFFI_OUT% /s/q)
141
142echo Configure the build to generate fficonfig.h and ffi.h
143%SH% -lc "(cd $OLDPWD; ./configure CC='%MSVCC% %ASSEMBLER%' CXX='%MSVCC% %ASSEMBLER%' LD='link' CPP='cl -nologo -EP' CXXCPP='cl -nologo -EP' CPPFLAGS='-DFFI_BUILDING_DLL' NM='dumpbin -symbols' STRIP=':' --build=$BUILD --host=$HOST;)"
144
145echo Building libffi
146%SH% -lc "(cd $OLDPWD; export PATH=/usr/bin:$PATH; cp src/%SRC_ARCHITECTURE%/ffitarget.h include; make; find .;)"
147
148REM Tests are not needed to produce artifacts
149if "%LIBFFI_TEST%" EQU "1" (
150 echo "Running tests..."
151 %SH% -lc "(cd $OLDPWD; export PATH=/usr/bin:$PATH; cp `find $PWD -name 'libffi-?.dll'` $HOST/testsuite/; make check; cat `find ./ -name libffi.log`)"
152) else (
153 echo "Not running tests"
154)
155
156
157echo copying files to %_LIBFFI_OUT%
158if not exist %_LIBFFI_OUT%\include (md %_LIBFFI_OUT%\include)
159copy %ARTIFACTS%\.libs\libffi-7.dll %_LIBFFI_OUT%
160copy %ARTIFACTS%\.libs\libffi-7.lib %_LIBFFI_OUT%
161copy %ARTIFACTS%\fficonfig.h %_LIBFFI_OUT%\include
162copy %ARTIFACTS%\include\*.h %_LIBFFI_OUT%\include
163
164endlocal
165exit /b
166
167:InstallCygwin
168setlocal
169
170if NOT DEFINED CYG_ROOT (set CYG_ROOT=c:/cygwin)
171if NOT DEFINED CYG_CACHE (set CYG_CACHE=C:/cygwin/var/cache/setup)
172if NOT DEFINED CYG_MIRROR (set CYG_MIRROR=http://mirrors.kernel.org/sourceware/cygwin/)
173
174powershell -c "md $env:CYG_ROOT -ErrorAction SilentlyContinue"
175powershell -c "$setup = $env:CYG_ROOT+'/setup.exe'; if (!(Test-Path $setup)){invoke-webrequest https://cygwin.com/setup-x86.exe -outfile $setup}
176%CYG_ROOT%/setup.exe -qnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P make -P autoconf -P automake -P libtool -P dejagnu
177
178endlocal
179exit /b
180