blob: f41ba83379af961e51467355867cf752ea979e24 [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 Monsonf96e7fd2019-05-17 10:07:24 -070028echo. -arm64 build for arm64
Paul Monson32119e12019-03-29 16:30:10 -070029echo. -? this help
30echo. --install-cygwin install cygwin to c:\cygwin
31exit /b 127
32
33:Run
34
35set BUILD_X64=
36set BUILD_X86=
Paul Monson11efd792019-04-17 18:09:16 -070037set BUILD_ARM32=
Paul Monsonf96e7fd2019-05-17 10:07:24 -070038set BUILD_ARM64=
39set BUILD_PDB=
40set BUILD_NOOPT=
Paul Monson32119e12019-03-29 16:30:10 -070041set INSTALL_CYGWIN=
42
43:CheckOpts
44if "%1"=="" goto :CheckOptsDone
45if /I "%1"=="-x64" (set BUILD_X64=1) & shift & goto :CheckOpts
46if /I "%1"=="-x86" (set BUILD_X86=1) & shift & goto :CheckOpts
Paul Monson11efd792019-04-17 18:09:16 -070047if /I "%1"=="-arm32" (set BUILD_ARM32=1) & shift & goto :CheckOpts
Paul Monsonf96e7fd2019-05-17 10:07:24 -070048if /I "%1"=="-arm64" (set BUILD_ARM64=1) & shift & goto :CheckOpts
49if /I "%1"=="-pdb" (set BUILD_PDB=-g) & shift & goto :CheckOpts
50if /I "%1"=="-noopt" (set BUILD_NOOPT=CFLAGS='-Od -warn all') & shift & goto :CheckOpts
Paul Monson32119e12019-03-29 16:30:10 -070051if /I "%1"=="-?" goto :Usage
52if /I "%1"=="--install-cygwin" (set INSTALL_CYGWIN=1) & shift & goto :CheckOpts
53goto :Usage
54
55:CheckOptsDone
56
Paul Monsonf96e7fd2019-05-17 10:07:24 -070057if NOT DEFINED BUILD_X64 if NOT DEFINED BUILD_X86 if NOT DEFINED BUILD_ARM32 if NOT DEFINED BUILD_ARM64 (
Paul Monson32119e12019-03-29 16:30:10 -070058 set BUILD_X64=1
59 set BUILD_X86=1
Paul Monson11efd792019-04-17 18:09:16 -070060 set BUILD_ARM32=1
Paul Monsonf96e7fd2019-05-17 10:07:24 -070061 set BUILD_ARM64=1
Paul Monson32119e12019-03-29 16:30:10 -070062)
63
64if "%INSTALL_CYGWIN%"=="1" call :InstallCygwin
65
66setlocal
67if NOT DEFINED SH if exist c:\cygwin\bin\sh.exe set SH=c:\cygwin\bin\sh.exe
68
69if NOT DEFINED VCVARSALL (
70 if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" (
71 set VCVARSALL="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"
72 )
73)
74if ^%VCVARSALL:~0,1% NEQ ^" SET VCVARSALL="%VCVARSALL%"
75
76if NOT DEFINED LIBFFI_SOURCE echo.&&echo ERROR LIBFFI_SOURCE environment variable not set && goto :Usage
77if NOT DEFINED SH echo ERROR SH environment variable not set && goto :Usage
78
79if not exist %SH% echo ERROR %SH% does not exist && goto :Usage
80if not exist %LIBFFI_SOURCE% echo ERROR %LIBFFI_SOURCE% does not exist && goto :Usage
81
82set OLDPWD=%LIBFFI_SOURCE%
83pushd %LIBFFI_SOURCE%
84
85%SH% --login -lc "cygcheck -dc cygwin"
86set GET_MSVCC=%SH% -lc "cd $OLDPWD; export MSVCC=`/usr/bin/find $PWD -name msvcc.sh`; echo ${MSVCC};"
87FOR /F "usebackq delims==" %%i IN (`%GET_MSVCC%`) do @set MSVCC=%%i
88
89echo.
90echo VCVARSALL : %VCVARSALL%
91echo SH : %SH%
92echo LIBFFI_SOURCE: %LIBFFI_SOURCE%
93echo MSVCC : %MSVCC%
94echo.
95
Steve Dowerde148f22019-11-20 09:30:47 -080096if not exist Makefile.in (
97 %SH% -lc "(cd $LIBFFI_SOURCE; ./autogen.sh;)"
98 if errorlevel 1 exit /B 1
99)
Paul Monson32119e12019-03-29 16:30:10 -0700100
Paul Monson11efd792019-04-17 18:09:16 -0700101if "%BUILD_X64%"=="1" call :BuildOne x64 x86_64-w64-cygwin x86_64-w64-cygwin
102if "%BUILD_X86%"=="1" call :BuildOne x86 i686-pc-cygwin i686-pc-cygwin
103if "%BUILD_ARM32%"=="1" call :BuildOne x86_arm i686-pc-cygwin arm-w32-cygwin
Paul Monsonf96e7fd2019-05-17 10:07:24 -0700104if "%BUILD_ARM64%"=="1" call :BuildOne x86_arm64 i686-pc-cygwin aarch64-w64-cygwin
Paul Monson32119e12019-03-29 16:30:10 -0700105
106popd
107endlocal
108exit /b 0
109REM all done
110
111
112REM this subroutine is called once for each architecture
113:BuildOne
114
115setlocal
116
117REM Initialize variables
118set VCVARS_PLATFORM=%1
119set BUILD=%2
120set HOST=%3
121set ASSEMBLER=
122set SRC_ARCHITECTURE=x86
123
124if NOT DEFINED VCVARS_PLATFORM echo ERROR bad VCVARS_PLATFORM&&exit /b 123
125
126if /I "%VCVARS_PLATFORM%" EQU "x64" (
127 set ARCH=amd64
128 set ARTIFACTS=%LIBFFI_SOURCE%\x86_64-w64-cygwin
129 set ASSEMBLER=-m64
130 set SRC_ARCHITECTURE=x86
131)
132if /I "%VCVARS_PLATFORM%" EQU "x86" (
133 set ARCH=win32
134 set ARTIFACTS=%LIBFFI_SOURCE%\i686-pc-cygwin
135 set ASSEMBLER=
136 set SRC_ARCHITECTURE=x86
137)
Paul Monson11efd792019-04-17 18:09:16 -0700138if /I "%VCVARS_PLATFORM%" EQU "x86_arm" (
139 set ARCH=arm32
140 set ARTIFACTS=%LIBFFI_SOURCE%\arm-w32-cygwin
141 set ASSEMBLER=-marm
142 set SRC_ARCHITECTURE=ARM
143)
Paul Monsonf96e7fd2019-05-17 10:07:24 -0700144if /I "%VCVARS_PLATFORM%" EQU "x86_arm64" (
145 set ARCH=arm64
146 set ARTIFACTS=%LIBFFI_SOURCE%\aarch64-w64-cygwin
147 set ASSEMBLER=-marm64
148 set SRC_ARCHITECTURE=aarch64
149)
Paul Monson32119e12019-03-29 16:30:10 -0700150
151if NOT DEFINED LIBFFI_OUT set LIBFFI_OUT=%~dp0\..\externals\libffi
152set _LIBFFI_OUT=%LIBFFI_OUT%\%ARCH%
153
154echo get VS build environment
155call %VCVARSALL% %VCVARS_PLATFORM%
156
157echo clean %_LIBFFI_OUT%
158if exist %_LIBFFI_OUT% (rd %_LIBFFI_OUT% /s/q)
159
Paul Monsonf96e7fd2019-05-17 10:07:24 -0700160echo ================================================================
Paul Monson32119e12019-03-29 16:30:10 -0700161echo Configure the build to generate fficonfig.h and ffi.h
Paul Monsonf96e7fd2019-05-17 10:07:24 -0700162echo ================================================================
163%SH% -lc "(cd $OLDPWD; ./configure CC='%MSVCC% %ASSEMBLER% %BUILD_PDB%' CXX='%MSVCC% %ASSEMBLER% %BUILD_PDB%' LD='link' CPP='cl -nologo -EP' CXXCPP='cl -nologo -EP' CPPFLAGS='-DFFI_BUILDING_DLL' %BUILD_NOOPT% NM='dumpbin -symbols' STRIP=':' --build=$BUILD --host=$HOST;)"
Steve Dowerde148f22019-11-20 09:30:47 -0800164if errorlevel 1 exit /B %ERRORLEVEL%
Paul Monson32119e12019-03-29 16:30:10 -0700165
Paul Monsonf96e7fd2019-05-17 10:07:24 -0700166echo ================================================================
Paul Monson32119e12019-03-29 16:30:10 -0700167echo Building libffi
Paul Monsonf96e7fd2019-05-17 10:07:24 -0700168echo ================================================================
Paul Monson32119e12019-03-29 16:30:10 -0700169%SH% -lc "(cd $OLDPWD; export PATH=/usr/bin:$PATH; cp src/%SRC_ARCHITECTURE%/ffitarget.h include; make; find .;)"
Steve Dowerde148f22019-11-20 09:30:47 -0800170if errorlevel 1 exit /B %ERRORLEVEL%
Paul Monson32119e12019-03-29 16:30:10 -0700171
172REM Tests are not needed to produce artifacts
173if "%LIBFFI_TEST%" EQU "1" (
174 echo "Running tests..."
175 %SH% -lc "(cd $OLDPWD; export PATH=/usr/bin:$PATH; cp `find $PWD -name 'libffi-?.dll'` $HOST/testsuite/; make check; cat `find ./ -name libffi.log`)"
176) else (
177 echo "Not running tests"
178)
179
180
181echo copying files to %_LIBFFI_OUT%
182if not exist %_LIBFFI_OUT%\include (md %_LIBFFI_OUT%\include)
183copy %ARTIFACTS%\.libs\libffi-7.dll %_LIBFFI_OUT%
184copy %ARTIFACTS%\.libs\libffi-7.lib %_LIBFFI_OUT%
Paul Monsonf96e7fd2019-05-17 10:07:24 -0700185copy %ARTIFACTS%\.libs\libffi-7.pdb %_LIBFFI_OUT%
Paul Monson32119e12019-03-29 16:30:10 -0700186copy %ARTIFACTS%\fficonfig.h %_LIBFFI_OUT%\include
187copy %ARTIFACTS%\include\*.h %_LIBFFI_OUT%\include
188
189endlocal
190exit /b
191
192:InstallCygwin
193setlocal
194
195if NOT DEFINED CYG_ROOT (set CYG_ROOT=c:/cygwin)
196if NOT DEFINED CYG_CACHE (set CYG_CACHE=C:/cygwin/var/cache/setup)
197if NOT DEFINED CYG_MIRROR (set CYG_MIRROR=http://mirrors.kernel.org/sourceware/cygwin/)
198
199powershell -c "md $env:CYG_ROOT -ErrorAction SilentlyContinue"
200powershell -c "$setup = $env:CYG_ROOT+'/setup.exe'; if (!(Test-Path $setup)){invoke-webrequest https://cygwin.com/setup-x86.exe -outfile $setup}
201%CYG_ROOT%/setup.exe -qnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P make -P autoconf -P automake -P libtool -P dejagnu
202
203endlocal
204exit /b
205