Recent

Author Topic: Compile lazarus from beginning  (Read 3241 times)

hamacker

  • New Member
  • *
  • Posts: 18
Compile lazarus from beginning
« on: November 12, 2021, 09:10:53 pm »
Hi ALL, I try to compile lazarus from sources.
1. First I download FPC-3.2.2 and install into C:\FPC\3.2.2
2. Add C:\FPC\3.2.2\bin\i386-win32 to enviroment path
3. Run cmd.exe and ...
set path=C:\FPC\3.2.2\bin\i386-win32 // overwrite a Delphi path because 'make.exe' from delphi has priority
mkdir c:\lazarus2
cd c:\l
git clone https://gitlab.com/freepascal.org/lazarus/lazarus.git
cd C:\lazarus
make clean bigide
and after build all then
lazarus.exe
And IDE start and keep searching 'FPC Sources' and not found, and ask where is fpc sources, I try:
C:\lazarus\units\i386-win32\win32[\rtl]
C:\FPC\3.2.2\units\i386-win32[\rtl]
and anyone can pass.

What are missing?

wp

  • Hero Member
  • *****
  • Posts: 9571
Re: Compile lazarus from beginning
« Reply #1 on: November 12, 2021, 09:57:02 pm »
"FPC Source" is the folder within the FPC installation folder tree which contains the "rtl" and "packages" subfolders. In your case, this should be C:\FPC\3.2.2\source
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

hamacker

  • New Member
  • *
  • Posts: 18
Re: Compile lazarus from beginning
« Reply #2 on: November 12, 2021, 10:05:22 pm »

First, I try from git, but it´s fail then  I donwloaded zip/gz from
I found in: https://www.freepascal.org/down/source/sources.html
And extract to c:\fpc\...
and now everithing is OK.

Thanks a lot!


thierrybo

  • Full Member
  • ***
  • Posts: 132
Re: Compile lazarus from beginning
« Reply #3 on: November 12, 2021, 11:19:58 pm »
I also used to build fpc/lazarus from source with my own build script for years but I stopped as soon as I tried fpcupdeluxe! :)

nummer8

  • Jr. Member
  • **
  • Posts: 89
Re: Compile lazarus from beginning
« Reply #4 on: November 12, 2021, 11:45:22 pm »
Would you be willing to share that build script?

thierrybo

  • Full Member
  • ***
  • Posts: 132
Re: Compile lazarus from beginning
« Reply #5 on: November 13, 2021, 12:21:57 am »
It does not work anymore since the move to git (built using TortoisSVN command line tools) and I don't maintain it anymore.

also need binutils and a bootstrap fpc compiler

nummer8

  • Jr. Member
  • **
  • Posts: 89
Re: Compile lazarus from beginning
« Reply #6 on: November 13, 2021, 09:24:44 am »
Thank you for sharing!
It is clear that the script needs an update before it will work but it gives me some insight.

dbannon

  • Hero Member
  • *****
  • Posts: 2019
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Compile lazarus from beginning
« Reply #7 on: November 13, 2021, 12:00:42 pm »
nummer8, are you aware of https://wiki.freepascal.org/Installing_Lazarus_on_Windows ?

It has not been updated since Lazarus moved to git but apart from the downloading aspect, it should be pretty right.

https://gitlab.com/freepascal.org/lazarus/lazarus

Downloading the source ?  You can obviously use git but unless you want a constantly updated version, I would recommend downloading the zip file. It takes only a handful of seconds on my system and it requires no additional infrastructure.

As far as using a script goes, be careful, scripts need to have error and sanity checking, the old adage is never try to script something you cannot, first, do by hand.

Once you get on top of what you are doing, maybe you might consider updating that wiki page I pointed to at the top of this post ?  Really needs a Windows user, rev and I have hacked away at it but he is a Mac user and I, Linux !

 %)

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

wp

  • Hero Member
  • *****
  • Posts: 9571
Re: Compile lazarus from beginning
« Reply #8 on: November 13, 2021, 12:18:08 pm »
I read the wiki article from section "Building Lazarus" and it is correct.

As you already noted, the downloading part should be rewritten for git, all mentions of svn should be removed.

I also don't like section "Installing Lazarus on a portable USB device" to be at the top. This is really not what people expect when asking for how to install Lazarus. It should be moved towards the end of the article.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

nummer8

  • Jr. Member
  • **
  • Posts: 89
Re: Compile lazarus from beginning
« Reply #9 on: November 13, 2021, 08:13:19 pm »
Davo,

Thank You, I am aware of that article.
I am trying to get a grip on directory layout and config for FPC. There is a difference in directory lay-out for FPC between windows and *nix.
At this point I can't see clear how the install works on a file (directory) level. What is needed and in what directory is it. I have red the buildfaq.pdf and I am trying install and compile FPC (including crosscompile) with a few scripts as starting point.
Not just to run them but to extract the different commands from them and replay the complete compile steps.
You are right, a script is a bunch of commands that you should have tested individually!!

Getting the sourcecode from gitlab is  not the problem. Understanding which directory is needed for what is the problem for me.
If I understand what is put where and for what reason, then I can use it in any situation.

The install through scripts and by hand is the learning purpose.

Installing Lazarus from hand is the easy part. After setting the FPC in the right spot, download and compile of Lazarus is almost everytime without a problem.

 

wp

  • Hero Member
  • *****
  • Posts: 9571
Re: Compile lazarus from beginning
« Reply #10 on: November 13, 2021, 10:21:57 pm »
This is the basic batch file which I am running the create my FPC/main/fixes installations on Windows:
Code: [Select]
set FPC_DEST_DIR=c:\Lazarus\fpc-main
set BINUTILS_DIR=C:\Lazarus\fpc_bootstrap_compiler\3.2.2\i386-win32
set BOOTSTRAP_COMPILER=%BINUTILS_DIR%\ppc386.exe
set BIN_DIR=bin\i386-win32
set FPC_BIN_DIR=%FPC_DEST_DIR%\%BIN_DIR%
set OPTIONS="-dDEBUG -gl -gw2"     

::------------------------------------------------------------------------------
:: Prepare directories
::------------------------------------------------------------------------------
mkdir %FPC_DEST_DIR%
cd %FPC_DEST_DIR%

::------------------------------------------------------------------------------
:: Clone git repository
::------------------------------------------------------------------------------
:: Use this for first installation (don't remove the '.' from the end!)
git clone https://gitlab.com/freepascal.org/fpc/source .
:: Use this for updates
::git pull --rebase

::------------------------------------------------------------------------------
:: Set Path
::------------------------------------------------------------------------------
path %BINUTILS_DIR%;%PATH%

::------------------------------------------------------------------------------
:: Preparations
::------------------------------------------------------------------------------
mkdir %FPC_DEST_DIR%
cd %FPC_DEST_DIR%
md %FPC_BIN_DIR%
copy %BINUTILS_DIR%\*.* %FPC_BIN_DIR% > nul
del /q /s %FPC_DEST_DIR%\units > nul
rmdir /s /q %FPC_DEST_DIR%\units

::------------------------------------------------------------------------------
:: Build FPC
::------------------------------------------------------------------------------
make clean all install OPT=%OPTIONS% PREFIX=%FPC_DEST_DIR% FPC=%BOOTSTRAP_COMPILER%

::------------------------------------------------------------------------------
:: Make fpc.cfg
::------------------------------------------------------------------------------
cd %FPC_DEST_DIR%
fpcmkcfg -d basepath=%FPC_DEST_DIR% -o %FPC_BIN_DIR%\fpc.cfg

It is less flexible, but simpler than the script posted by thierrybo above. You have to make a few modifications to adjust it to your situations:
  • Adjust the variable FPC_DEST_DIR to the directory into which you want to install FPC
  • Adjust BINUTILS_DIR to the directory which contains fpc.exe and the other binary utilities of the the current FPC release version, v2.2.2 or v2.2.0. This means that in order to install FPC/main or FPC/fixes you must already have one of these releases on your disk because they are able to build the new FPC. (If you don't want to install a full FPC you can also download the binutils directory from somewhere - I don't know the exact location ATM).
  • There are two occurencies of "i386-win32" in the batch - this means that this batch will install the 32-bit version of FPC. For the 64-bit version you'll have to replace this by "x86_64-win64"
  • The OPTIONS in this particular file are for building the debug version of FPC. Change it accordingly if you need something else.
  • The git command is shown for cloning the initial version. The URL is given for FPC/main. Replace it accordingly if you want fixes. When you later want to update your installation, comment this line out and activate the "git pull" line. Or deactivate both git lines when you made modifications of RTL/FCL sources yourself and want to rebuild FPC without interference from git updates.
  • The section "Preparations" creates directories needed etc. it also deletes previously compiled units - I found this to be essential because without it the update sometimes does not work.
  • The "Build FPC" block contains the only command to compile FPC and everything related. The OPT parameter is taken from the OPTIONS variable above, PREFIX defines the location where FPC will be built as given by the FPC_DEST_DIR variable, and FPC defines the compiler used for building as set up by the BINUTILS_DIR variable.
  • Finally we need to write a valid fpc.cfg file which contains all these hard-coded paths. This is done by calling the fpcmkcfg utility.





Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

nummer8

  • Jr. Member
  • **
  • Posts: 89
Re: Compile lazarus from beginning
« Reply #11 on: November 13, 2021, 10:40:41 pm »
@wp
Thank you for this very instructive explination.
I will use it and experiment with the options.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9979
  • FPC developer.
Re: Compile lazarus from beginning
« Reply #12 on: November 13, 2021, 10:51:03 pm »
This is the basic batch file which I am running the create my FPC/main/fixes installations on Windows:


Here's mine (a .cmd)

Code: Text  [Select][+][-]
  1. @echo off
  2. rem A simple build script for Windows. 2018 version; switching between 32-bit and 64-bit
  3. rem nicer output due to stdout capturing.
  4.  
  5. rem uncomment OS, en select if CPU has avx 1 or 2. rem Both host and target.  
  6. rem I have ivy bridge, skylake and Ryzen machines, roughly avx1 vs avx2.
  7. rem so that's why I model it that way. For the few runs I still do on older machines, I manually change the script.
  8.  
  9. rem set OS=win64
  10. set OS=win32
  11. set AVX=1
  12.  
  13. rem CROSSOPTS64 is only added if 64-bit, to allow setting SIMD fpu option only for 64-bit.
  14.  
  15. if %AVX% equ 1 goto:ivy
  16. rem Ryzen 5 2600 or Skylake laptop
  17. set CPUOPTS=-O2  -Opcoreavx2 -Cpcoreavx2
  18. set CPUOPTS64=-Cfavx2
  19. set CORES=5
  20. goto donecpuopts
  21.  
  22. :ivy
  23. rem Ivy Bridge i7-3770
  24. set CPUOPTS=-O2  -Opcoreavx -Cpcoreavx
  25. set CPUOPTS64=-Cfavx
  26. set CORES=5
  27.  
  28. :donecpuopts
  29.  
  30. rem  ----   decode OS to cpu and compiler name.
  31.  
  32. set OS_TARGET=%OS%
  33. if "%OS%"=="win32" goto:win32
  34. if "%OS%"=="win64" goto:win64
  35. echo Unknown OS: %OS%
  36. exit /b
  37. :contosok
  38.  
  39. rem A bit of a mess. A mix of configurable settings and variables mostly dependent on detected variables.
  40.  
  41. set BASEDRV=c:
  42. set SRCDIR=%BASEDRV%\repo\fpcgit
  43. set PPCNAME=ppc%COMPSUFFIX%.exe
  44. rem set FPCSTART=c:\fpc\3.2.2\bin\i386-win32\ppc386.exe
  45.  set FPCSTART=c:\pp32rel\bin\i386-win32\ppc386.exe
  46.  
  47.  
  48. rem %SRCDIR%/utils/fpcm/  for cross? x32->x64 ?
  49.  
  50. set LOGDIR=%BASEDRV%\repo
  51. set INSTALLDIR=%BASEDRV%\pp%BITS%
  52. set DESTCOMPILER=%SRCDIR%/compiler/%PPCNAME%
  53. set CROSSOPTS=
  54.  
  55. rem small FPC script to replace unix "time"
  56. set DUMPTIME=c:\usr\dumptime.exe
  57.  
  58. if "%BITS%"=="64" set CROSSOPTS= OS_TARGET=win64 CPU_TARGET=x86_64
  59.  
  60. set OPTS=   -gw2 -godwarfsets -gl    
  61. set COMMONOPTS= COPYTREE=echo OPT="%OPTS% "  NOWPOCYCLE=1 OVERRIDEVERSIONCHECK=1
  62.  
  63. rem use only if starting compiler does not
  64. set NEWOPT= %CPUOPTS%
  65.  
  66. rem === invariant part ===
  67.  
  68. cd /d %SRCDIR%
  69.  
  70. for /f %%i in ('%FPCSTART% -iV') do set STARTINGVERSION=%%i
  71. for /f %%i in ('%FPCSTART% -iTO') do set STARTINGOS=%%i
  72. for /f %%i in ('%FPCSTART% -iTP') do set STARTINGARCH=%%i
  73.  
  74. echo Starting compiler %STARTINGVERSION% on %STARTINGARCH%-%STARTINGOS%
  75.  
  76. rem a small fpc program that dumps time, as substitute for *nix time
  77.  
  78. if exist %DUMPTIME% (
  79. %DUMPTIME% set %temp%\stdbuild%BITS%.txt
  80. )
  81.  
  82. echo Cleaning
  83. make -j %CORES% RELEASE=0 %CROSSOPTS% distclean FPMAKEOPT="-T %CORES%" %COMMONOPTS% FPC=%FPCSTART% NEWOPT="%NEWOPT%"  ALLOW_WARNINGS=1 1> %LOGDIR%\cleanlog%BITS%.txt 2>&1
  84.  
  85. echo building %CPU_TARGET%-%OS%  
  86. make -j %CORES% RELEASE=0 %CROSSOPTS% all FPMAKEOPT="-T %CORES%" %COMMONOPTS% FPC=%FPCSTART% NEWOPT="%NEWOPT%"  ALLOW_WARNINGS=1 1> %LOGDIR%\buildlog%BITS%.txt 2>&1
  87.  
  88. IF %ERRORLEVEL% EQU 0 GOTO:buildOK
  89. echo build failed, skipping installation
  90. exit /b
  91.  
  92. :buildOK
  93. for /f %%i in ('%DESTCOMPILER% -iV') do set DESTVERSION=%%i
  94. for /f %%i in ('%DESTCOMPILER% -iTO') do set DESTOS=%%i
  95. for /f %%i in ('%DESTCOMPILER% -iTP') do set DESTARCH=%%i
  96. echo Generated compiler %DESTVERSION% on %DESTARCH%-%DESTOS%
  97.  
  98. set FPCMAKENEW=%SRCDIR%/utils/fpcm/bin/%STARTINGARCH%-%STARTINGOS%
  99.  
  100. REM separate install step for crossversion purposes (and under Unix sudo) FPCMAKENEW required for crossbuilding.
  101.  
  102. echo installing
  103. make install %COMMONOPTS% %CROSSOPTS% INSTALL_PREFIX=%INSTALLDIR%  FPC=%DESTCOMPILER% FPCMAKENEW=%FPCMAKENEW%/fpcmake.exe 1> %LOGDIR%\installlog%BITS%.txt   2>&1
  104.  
  105. rem otherwise %%i is parsed when if block is parsed and misses content changes inbetween
  106. setlocal EnableDelayedExpansion
  107.  
  108. if exist %DUMPTIME% (
  109. for /f "delims=#" %%i in ('%DUMPTIME% get %temp%\stdbuild%BITS%.txt') do set THETIME=%%i
  110. echo Ok, building and installing took !THETIME!
  111. )
  112.  
  113. IF %ERRORLEVEL% EQU 0 GOTO:theend
  114.  
  115. echo install failed!
  116. exit /b
  117.  
  118. :win32
  119. set BITS=32
  120. set COMPSUFFIX=386
  121. set CPU_TARGET=i386
  122. goto:contosok
  123.  
  124. :win64
  125. set BITS=64
  126. set COMPSUFFIX=x64
  127. set CPU_TARGET=x86_64
  128. set CPUOPTS=%CPUOPTS% %CPUOPTS64%
  129. goto:contosok
  130.  
  131. :theend
  132.  
  133.  

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1963
  • Former Delphi 1-7, 10.2 user
Re: Compile lazarus from beginning
« Reply #13 on: November 14, 2021, 12:59:01 am »
I've updated the Windows article for git from GitLab (and svn from GitHub). While I only very rarely use Windows (no more than half a dozen times a year), I believe what I've written is accurate, but someone may like to run their eye over it.
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.3.1
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.3.1

 

TinyPortal © 2005-2018