Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Fr0sT-Brutal authored and Fr0sT-Brutal committed Mar 22, 2017
0 parents commit 88ce75b
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Building FreePascal and Lazarus from sources on Windows
=======================================================

This repo contains two scripts for Windows to grab FPC and Lazarus sources and build them including cross-build.

Prerequisites
-------------

1. `git` binary in `PATH`.

Source retrieval uses git repositories so git must be accessible. Exporting from SVN is not supported.

2. Minimal FPC distribution

Get it from [here](https://www.getlazarus.org/setup/minimal).

3. Linux binaries and libs

For cross-compiling to Linux, binaries and libs are needed. You can get them from Releases section of this repo or by installing [full setup](https://www.getlazarus.org/setup).


Steps
-----

1. Create a directory where FPC and Lazarus will be

2. Place `update.bat`, `build.bat`, `buildall.bat` to that folder

3. Download minimal FPC, unpack it to that folder and rename to `fpc-min`

4. **For Linux cross-compiling:** download [full setup](https://www.getlazarus.org/setup) and install it to temporary folder. Copy `i386-linux-*.exe` and `x86_64-linux-*.exe` from `{TmpFullInstall}\fpc\bin\i386-win32` to `{FPCFromSources}\fpc-min\bin\i386-win32`. Alternatively, you can get these binaries from Releases section of this repo.

4. Run `update.bat`. It will create necessary folders and pull current master branches from FPC and Lazarus repositories

5. Run `buildall.bat`. It will build FPC for Win/32, Win/64, Lin/32 and Lin/64 and Lazarus for Win/32. If you don't need any of these, comment out corresponding lines in `buildall.bat`.

6. **For Linux cross-compiling:** copy `{TmpFullInstall}\fpc\lib` folder to `{FPCFromSources}\FPC`. Alternatively, you can get these binaries from Releases section of this repo.

7. Now you can remove `fpc-min` folder and uninstall temporary full install

8. Run `startlazarus.exe` and set paths.
104 changes: 104 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
:: Batch file to build FPC & Lazarus from sources.
:: %1 - (opt) FPC|Laz
:: %1 - (opt) CPU target
:: %2 - (opt) OS target

@ECHO OFF

SETLOCAL

SET Base=%~dp0%
SET FPC_Opt=FPCOPT=""
SET Laz_Opt=FPCOPT="-O2 -g- -Xs"
SET Make_Opt=--quiet
SET FPCMin=%Base%\fpc-min\bin\i386-win32
SET FPCPath=%Base%\FPC
SET LazPath=%Base%\Lazarus

:: Use binaries from this path only
:: ! FPC makefile uses heuristic to determine OS so it needs ; in PATH for Windows
SET Path=%FPCMin%;blah

:: check for binary
CALL fpc.exe -iV 1>NUL 2>&1 || (ECHO No compiler fpc.exe found && GOTO :BuildErr)

:: Check parameters
IF NOT .%1.==.. (
IF .%1.==.FPC. SET DoFPC=1
IF .%1.==.Laz. SET DoLaz=1
) ELSE (
SET DoFPC=1
SET DoLaz=1
)

IF NOT .%2.==.. (
IF .%3.==.. (ECHO Must be defined both CPU and OS targets! && GOTO :BuildErr)
SET Cross=1
SET TargCPU=%2
SET TargOS=%3
) ELSE (
SET TargCPU=i386
SET TargOS=win32
)

:: Action
IF DEFINED DoFPC CALL :BuildFPC || GOTO :Err
IF DEFINED DoLaz CALL :BuildLaz || GOTO :Err
GOTO :EOF

:: ~~~ Build FPC ~~~
:: Uses externals: FPCMin, Make_Opt, FPCPath, TargCPU, TargOS, FPCOpt, Cross
:BuildFPC
ECHO Making FPC for %TargCPU% %TargOS%

PUSHD "%FPCPath%"
SETLOCAL

CALL make %Make_Opt% clean distclean || (ECHO Command "make clean" failed... && GOTO :BuildFPCErr)
IF NOT DEFINED Cross (
CALL make %Make_Opt% all %FPC_Opt% && make %Make_Opt% install INSTALL_PREFIX="%FPCPath%" || (ECHO Command "make all" for FPC failed... && GOTO :BuildFPCErr)
) ELSE (
rem Linux cross-compilation requires additional bin tools
SET Path=%Path%;%Base%\fpc-min\bin\%TargCPU%-%TargOS%
CALL make %Make_Opt% crossinstall %FPC_Opt% CPU_TARGET=%TargCPU% OS_TARGET=%TargOS% INSTALL_PREFIX="%FPCPath%" || (ECHO Command "make crossinstall" failed... && GOTO :BuildFPCErr)
)

SET NewFPC=%FPCPath%\bin\i386-win32
:: Generate config (for base compiler only)
IF NOT DEFINED Cross (
CALL "%NewFPC%\fpcmkcfg.exe" -d basepath="%FPCPath%" -o "%NewFPC%\fpc.cfg" || (ECHO Generating config failed... && GOTO :BuildFPCErr)
)

:: Copy missing files to base dir of new FPC
CALL "%SystemRoot%\System32\xcopy.exe" /D "%Base%\fpc-min\bin\*.*" "%NewFPC%\" 2>NUL 1>&2

POPD
:: xcopy might be setting error code to non-0, ignore
EXIT /B 0

:BuildFPCErr
POPD
EXIT /B 1

:: ~~~ Build Lazarus ~~~
:: Uses externals: Make_Opt, FPCPath, LazPath, TargCPU, TargOS, LazOpt
:BuildLaz
ECHO Making Lazarus for %TargCPU% %TargOS%

SETLOCAL
SET Path=%FPCPath%;%FPCPath%\bin\i386-win32;blah

PUSHD "%LazPath%"
CALL make %Make_Opt% clean || (ECHO Command "make clean" failed... && GOTO :BuildLazErr)
CALL make %Make_Opt% all %Laz_Opt% || (ECHO Command "make all" for Lazarus failed... && GOTO :BuildLazErr)
POPD

GOTO :EOF

:BuildLazErr
POPD
EXIT /B 1

:Err
POPD
%ComSpec% /C EXIT 1
17 changes: 17 additions & 0 deletions buildall.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@ECHO OFF

SETLOCAL

call build.bat FPC || GOTO :Err
call build.bat FPC x86_64 win64 || GOTO :Err
call build.bat FPC i386 linux || GOTO :Err
call build.bat FPC x86_64 linux || GOTO :Err

call build.bat Laz || GOTO :Err

timeout /t 5
GOTO :EOF

:Err
PAUSE
"%ComSpec%" /C EXIT 1
46 changes: 46 additions & 0 deletions update.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
:: Batch file to create and update FPC & Lazarus repositories.

@ECHO OFF

SETLOCAL

SET Base=%~dp0%
SET FPGit=http://github.com/graemeg/freepascal.git
SET LazGit=http://github.com/graemeg/lazarus.git
SET FPCPath=%Base%\FPC
SET LazPath=%Base%\Lazarus

:: ~~~ Create or update repos ~~~

:: check for git binary
CALL git.exe --version 1>nul 2>&1 || (ECHO Git binary not found && GOTO :Err)

:: FPC

IF NOT EXIST "%FPCPath%\.git" (
ECHO FreePascal repo not found - will create and update it
CALL git.exe clone %FPGit% "%FPCPath%" || (ECHO Creation of Git repo failed... && rd /Q/S "%FPCPath%\.git" && GOTO :Err)
) ELSE (
ECHO Updating FPC
PUSHD "%FPCPath%"
CALL git.exe pull || (POPD && ECHO Error updating FPC repo && GOTO :Err)
POPD
)

:: Lazarus

IF NOT EXIST "%LazPath%\.git" (
ECHO Lazarus repo not found - will create and update it
CALL git.exe clone %LazGit% "%LazPath%" || (ECHO Creation of Git repo failed... & rd /Q/S "%LazPath%\.git" & GOTO :Err)
) ELSE (
ECHO Updating Lazarus
PUSHD "%LazPath%"
CALL git.exe pull || (POPD && ECHO Error updating Lazarus repo && GOTO :Err)
POPD
)

timeout /t 5
GOTO :EOF

:Err
"%ComSpec%" /C EXIT 1

0 comments on commit 88ce75b

Please sign in to comment.