Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 1 | @echo off |
| 2 | goto :Run |
| 3 | |
| 4 | :Usage |
| 5 | echo. |
| 6 | echo Before running prepare_libffi.bat |
| 7 | echo LIBFFI_SOURCE environment variable must be set to the location of |
| 8 | echo of python-source-deps clone of libffi branch |
| 9 | echo VCVARSALL must be set to location of vcvarsall.bat |
| 10 | echo cygwin must be installed (see below) |
| 11 | echo SH environment variable must be set to the location of sh.exe |
| 12 | echo. |
| 13 | echo Tested with cygwin-x86 from https://www.cygwin.com/install.html |
| 14 | echo Select http://mirrors.kernel.org as the download site |
| 15 | echo Include the following cygwin packages in cygwin configuration: |
| 16 | echo make, autoconf, automake, libtool, dejagnu |
| 17 | echo. |
| 18 | echo NOTE: dejagnu is only required for running tests. |
| 19 | echo set LIBFFI_TEST=1 to run tests (optional) |
| 20 | echo. |
| 21 | echo Based on https://github.com/libffi/libffi/blob/master/.appveyor.yml |
| 22 | echo. |
| 23 | echo. |
| 24 | echo.Available flags: |
| 25 | echo. -x64 build for x64 |
| 26 | echo. -x86 build for x86 |
Paul Monson | 11efd79 | 2019-04-17 18:09:16 -0700 | [diff] [blame] | 27 | echo. -arm32 build for arm32 |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 28 | echo. -arm64 build for arm64 |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 29 | echo. -? this help |
| 30 | echo. --install-cygwin install cygwin to c:\cygwin |
| 31 | exit /b 127 |
| 32 | |
| 33 | :Run |
| 34 | |
| 35 | set BUILD_X64= |
| 36 | set BUILD_X86= |
Paul Monson | 11efd79 | 2019-04-17 18:09:16 -0700 | [diff] [blame] | 37 | set BUILD_ARM32= |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 38 | set BUILD_ARM64= |
| 39 | set BUILD_PDB= |
| 40 | set BUILD_NOOPT= |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 41 | set INSTALL_CYGWIN= |
| 42 | |
| 43 | :CheckOpts |
| 44 | if "%1"=="" goto :CheckOptsDone |
| 45 | if /I "%1"=="-x64" (set BUILD_X64=1) & shift & goto :CheckOpts |
| 46 | if /I "%1"=="-x86" (set BUILD_X86=1) & shift & goto :CheckOpts |
Paul Monson | 11efd79 | 2019-04-17 18:09:16 -0700 | [diff] [blame] | 47 | if /I "%1"=="-arm32" (set BUILD_ARM32=1) & shift & goto :CheckOpts |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 48 | if /I "%1"=="-arm64" (set BUILD_ARM64=1) & shift & goto :CheckOpts |
| 49 | if /I "%1"=="-pdb" (set BUILD_PDB=-g) & shift & goto :CheckOpts |
| 50 | if /I "%1"=="-noopt" (set BUILD_NOOPT=CFLAGS='-Od -warn all') & shift & goto :CheckOpts |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 51 | if /I "%1"=="-?" goto :Usage |
| 52 | if /I "%1"=="--install-cygwin" (set INSTALL_CYGWIN=1) & shift & goto :CheckOpts |
| 53 | goto :Usage |
| 54 | |
| 55 | :CheckOptsDone |
| 56 | |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 57 | if NOT DEFINED BUILD_X64 if NOT DEFINED BUILD_X86 if NOT DEFINED BUILD_ARM32 if NOT DEFINED BUILD_ARM64 ( |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 58 | set BUILD_X64=1 |
| 59 | set BUILD_X86=1 |
Paul Monson | 11efd79 | 2019-04-17 18:09:16 -0700 | [diff] [blame] | 60 | set BUILD_ARM32=1 |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 61 | set BUILD_ARM64=1 |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 62 | ) |
| 63 | |
| 64 | if "%INSTALL_CYGWIN%"=="1" call :InstallCygwin |
| 65 | |
| 66 | setlocal |
| 67 | if NOT DEFINED SH if exist c:\cygwin\bin\sh.exe set SH=c:\cygwin\bin\sh.exe |
| 68 | |
| 69 | if 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 | ) |
| 74 | if ^%VCVARSALL:~0,1% NEQ ^" SET VCVARSALL="%VCVARSALL%" |
| 75 | |
| 76 | if NOT DEFINED LIBFFI_SOURCE echo.&&echo ERROR LIBFFI_SOURCE environment variable not set && goto :Usage |
| 77 | if NOT DEFINED SH echo ERROR SH environment variable not set && goto :Usage |
| 78 | |
| 79 | if not exist %SH% echo ERROR %SH% does not exist && goto :Usage |
| 80 | if not exist %LIBFFI_SOURCE% echo ERROR %LIBFFI_SOURCE% does not exist && goto :Usage |
| 81 | |
| 82 | set OLDPWD=%LIBFFI_SOURCE% |
| 83 | pushd %LIBFFI_SOURCE% |
| 84 | |
| 85 | %SH% --login -lc "cygcheck -dc cygwin" |
| 86 | set GET_MSVCC=%SH% -lc "cd $OLDPWD; export MSVCC=`/usr/bin/find $PWD -name msvcc.sh`; echo ${MSVCC};" |
| 87 | FOR /F "usebackq delims==" %%i IN (`%GET_MSVCC%`) do @set MSVCC=%%i |
| 88 | |
| 89 | echo. |
| 90 | echo VCVARSALL : %VCVARSALL% |
| 91 | echo SH : %SH% |
| 92 | echo LIBFFI_SOURCE: %LIBFFI_SOURCE% |
| 93 | echo MSVCC : %MSVCC% |
| 94 | echo. |
| 95 | |
| 96 | if not exist Makefile.in (%SH% -lc "(cd $LIBFFI_SOURCE; ./autogen.sh;)") |
| 97 | |
Paul Monson | 11efd79 | 2019-04-17 18:09:16 -0700 | [diff] [blame] | 98 | if "%BUILD_X64%"=="1" call :BuildOne x64 x86_64-w64-cygwin x86_64-w64-cygwin |
| 99 | if "%BUILD_X86%"=="1" call :BuildOne x86 i686-pc-cygwin i686-pc-cygwin |
| 100 | if "%BUILD_ARM32%"=="1" call :BuildOne x86_arm i686-pc-cygwin arm-w32-cygwin |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 101 | if "%BUILD_ARM64%"=="1" call :BuildOne x86_arm64 i686-pc-cygwin aarch64-w64-cygwin |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 102 | |
| 103 | popd |
| 104 | endlocal |
| 105 | exit /b 0 |
| 106 | REM all done |
| 107 | |
| 108 | |
| 109 | REM this subroutine is called once for each architecture |
| 110 | :BuildOne |
| 111 | |
| 112 | setlocal |
| 113 | |
| 114 | REM Initialize variables |
| 115 | set VCVARS_PLATFORM=%1 |
| 116 | set BUILD=%2 |
| 117 | set HOST=%3 |
| 118 | set ASSEMBLER= |
| 119 | set SRC_ARCHITECTURE=x86 |
| 120 | |
| 121 | if NOT DEFINED VCVARS_PLATFORM echo ERROR bad VCVARS_PLATFORM&&exit /b 123 |
| 122 | |
| 123 | if /I "%VCVARS_PLATFORM%" EQU "x64" ( |
| 124 | set ARCH=amd64 |
| 125 | set ARTIFACTS=%LIBFFI_SOURCE%\x86_64-w64-cygwin |
| 126 | set ASSEMBLER=-m64 |
| 127 | set SRC_ARCHITECTURE=x86 |
| 128 | ) |
| 129 | if /I "%VCVARS_PLATFORM%" EQU "x86" ( |
| 130 | set ARCH=win32 |
| 131 | set ARTIFACTS=%LIBFFI_SOURCE%\i686-pc-cygwin |
| 132 | set ASSEMBLER= |
| 133 | set SRC_ARCHITECTURE=x86 |
| 134 | ) |
Paul Monson | 11efd79 | 2019-04-17 18:09:16 -0700 | [diff] [blame] | 135 | if /I "%VCVARS_PLATFORM%" EQU "x86_arm" ( |
| 136 | set ARCH=arm32 |
| 137 | set ARTIFACTS=%LIBFFI_SOURCE%\arm-w32-cygwin |
| 138 | set ASSEMBLER=-marm |
| 139 | set SRC_ARCHITECTURE=ARM |
| 140 | ) |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 141 | if /I "%VCVARS_PLATFORM%" EQU "x86_arm64" ( |
| 142 | set ARCH=arm64 |
| 143 | set ARTIFACTS=%LIBFFI_SOURCE%\aarch64-w64-cygwin |
| 144 | set ASSEMBLER=-marm64 |
| 145 | set SRC_ARCHITECTURE=aarch64 |
| 146 | ) |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 147 | |
| 148 | if NOT DEFINED LIBFFI_OUT set LIBFFI_OUT=%~dp0\..\externals\libffi |
| 149 | set _LIBFFI_OUT=%LIBFFI_OUT%\%ARCH% |
| 150 | |
| 151 | echo get VS build environment |
| 152 | call %VCVARSALL% %VCVARS_PLATFORM% |
| 153 | |
| 154 | echo clean %_LIBFFI_OUT% |
| 155 | if exist %_LIBFFI_OUT% (rd %_LIBFFI_OUT% /s/q) |
| 156 | |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 157 | echo ================================================================ |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 158 | echo Configure the build to generate fficonfig.h and ffi.h |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 159 | echo ================================================================ |
| 160 | %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;)" |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 161 | |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 162 | echo ================================================================ |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 163 | echo Building libffi |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 164 | echo ================================================================ |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 165 | %SH% -lc "(cd $OLDPWD; export PATH=/usr/bin:$PATH; cp src/%SRC_ARCHITECTURE%/ffitarget.h include; make; find .;)" |
| 166 | |
| 167 | REM Tests are not needed to produce artifacts |
| 168 | if "%LIBFFI_TEST%" EQU "1" ( |
| 169 | echo "Running tests..." |
| 170 | %SH% -lc "(cd $OLDPWD; export PATH=/usr/bin:$PATH; cp `find $PWD -name 'libffi-?.dll'` $HOST/testsuite/; make check; cat `find ./ -name libffi.log`)" |
| 171 | ) else ( |
| 172 | echo "Not running tests" |
| 173 | ) |
| 174 | |
| 175 | |
| 176 | echo copying files to %_LIBFFI_OUT% |
| 177 | if not exist %_LIBFFI_OUT%\include (md %_LIBFFI_OUT%\include) |
| 178 | copy %ARTIFACTS%\.libs\libffi-7.dll %_LIBFFI_OUT% |
| 179 | copy %ARTIFACTS%\.libs\libffi-7.lib %_LIBFFI_OUT% |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 180 | copy %ARTIFACTS%\.libs\libffi-7.pdb %_LIBFFI_OUT% |
Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 181 | copy %ARTIFACTS%\fficonfig.h %_LIBFFI_OUT%\include |
| 182 | copy %ARTIFACTS%\include\*.h %_LIBFFI_OUT%\include |
| 183 | |
| 184 | endlocal |
| 185 | exit /b |
| 186 | |
| 187 | :InstallCygwin |
| 188 | setlocal |
| 189 | |
| 190 | if NOT DEFINED CYG_ROOT (set CYG_ROOT=c:/cygwin) |
| 191 | if NOT DEFINED CYG_CACHE (set CYG_CACHE=C:/cygwin/var/cache/setup) |
| 192 | if NOT DEFINED CYG_MIRROR (set CYG_MIRROR=http://mirrors.kernel.org/sourceware/cygwin/) |
| 193 | |
| 194 | powershell -c "md $env:CYG_ROOT -ErrorAction SilentlyContinue" |
| 195 | powershell -c "$setup = $env:CYG_ROOT+'/setup.exe'; if (!(Test-Path $setup)){invoke-webrequest https://cygwin.com/setup-x86.exe -outfile $setup} |
| 196 | %CYG_ROOT%/setup.exe -qnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P make -P autoconf -P automake -P libtool -P dejagnu |
| 197 | |
| 198 | endlocal |
| 199 | exit /b |
| 200 | |