~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/codetools/definetemplates.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
{ $Define VerboseDefineCache}
48
48
{ $Define VerboseFPCSrcScan}
49
49
{ $Define ShowTriedFiles}
 
50
{ $Define ShowTriedUnits}
50
51
 
51
52
interface
52
53
 
53
54
uses
54
 
  Classes, SysUtils, CodeToolsStrConsts, ExprEval, DirectoryCacher,
55
 
  BasicCodeTools, Laz_XMLCfg, AVL_Tree, CodeToolsStructs,
56
 
  Process, KeywordFuncLists, FileProcs;
 
55
  Classes, SysUtils, LazUTF8, CodeToolsStrConsts, ExprEval, DirectoryCacher,
 
56
  BasicCodeTools, Laz2_XMLCfg, lazutf8classes, AVL_Tree, CodeToolsStructs,
 
57
  Process, KeywordFuncLists, LinkScanner, FileProcs;
57
58
 
58
59
const
59
60
  ExternalMacroStart = ExprEval.ExternalMacroStart;
120
121
  FPCProcessorNames: array[1..6] of shortstring =(
121
122
      'i386', 'powerpc', 'm68k', 'x86_64', 'sparc', 'arm'
122
123
    );
123
 
  FPCSyntaxModes: array[1..5] of shortstring = (
124
 
    'FPC', 'ObjFPC', 'Delphi', 'TP', 'MacPas'
 
124
  FPCSyntaxModes: array[1..6] of shortstring = (
 
125
    'FPC', 'ObjFPC', 'Delphi', 'TP', 'MacPas', 'ISO'
125
126
    );
126
127
 
127
 
  Lazarus_CPU_OS_Widget_Combinations: array[1..62] of shortstring = (
 
128
  Lazarus_CPU_OS_Widget_Combinations: array[1..65] of shortstring = (
128
129
    'i386-linux-gtk',
129
130
    'i386-linux-gtk2',
130
131
    'i386-linux-qt',
173
174
    'arm-linux-gtk',
174
175
    'arm-linux-gtk2',
175
176
    'arm-linux-qt',
 
177
    'arm-linux-android',
176
178
    'arm-linux-nogui',
 
179
    'arm-darwin-carbon',
 
180
    'arm-darwin-nogui',
177
181
    'x86_64-freebsd-gtk',
178
182
    'x86_64-freebsd-gtk2',
179
183
    'x86_64-freebsd-qt',
506
510
    function CreateFPCSrcTemplate(const FPCSrcDir, UnitSearchPath, PPUExt,
507
511
                          DefaultTargetOS, DefaultProcessorName: string;
508
512
                          UnitLinkListValid: boolean; var UnitLinkList: string;
509
 
                          Owner: TObject): TDefineTemplate;
 
513
                          Owner: TObject): TDefineTemplate; deprecated;
510
514
    function CreateFPCCommandLineDefines(const Name, CmdLine: string;
511
515
                                         RecursiveDefines: boolean;
512
516
                                         Owner: TObject;
674
678
    RealTargetOS: string;
675
679
    RealTargetCPU: string;
676
680
    RealCompilerInPath: string; // the ppc<target> in PATH
 
681
    FullVersion: string;
677
682
    ConfigFiles: TFPCConfigFileStateList;
678
683
    UnitPaths: TStrings;
679
684
    Defines: TStringToStringTree; // macro to value
694
699
    procedure LoadFromFile(Filename: string);
695
700
    procedure SaveToFile(Filename: string);
696
701
    function NeedsUpdate: boolean;
 
702
    function GetFPCInfoCmdLineOptions(ExtraOptions: string): string;
697
703
    function Update(TestFilename: string; ExtraOptions: string = '';
698
704
                    const OnProgress: TDefinePoolProgress = nil): boolean;
699
705
    function FindRealCompilerInPath(aTargetCPU: string; ResolveLinks: boolean): string;
700
 
    function GetFPCVer(out FPCVersion, FPCRelease, FPCPatch: integer): boolean;
 
706
    function GetUnitPaths: string;
 
707
    function GetFPCVerNumbers(out FPCVersion, FPCRelease, FPCPatch: integer): boolean;
 
708
    function GetFPCVer: string; // e.g. 2.7.1
 
709
    function IndexOfUsedCfgFile: integer;
701
710
    procedure IncreaseChangeStamp;
702
711
    property ChangeStamp: integer read FChangeStamp;
703
712
  end;
723
732
    property ChangeStamp: integer read FChangeStamp;
724
733
    function Find(CompilerFilename, CompilerOptions, TargetOS, TargetCPU: string;
725
734
                  CreateIfNotExists: boolean): TFPCTargetConfigCache;
 
735
    function GetListing: string;
726
736
  end;
727
737
 
728
738
  TFPCSourceCaches = class;
832
842
    function GetSourceRules(AutoUpdate: boolean): TFPCSourceRules;
833
843
    function GetUnitToSourceTree(AutoUpdate: boolean): TStringToStringTree; // unit name to file name (maybe relative)
834
844
    function GetSourceDuplicates(AutoUpdate: boolean): TStringToStringTree; // unit to semicolon separated list of files
835
 
    function GetUnitSrcFile(const AUnitName: string;
 
845
    function GetUnitSrcFile(const AnUnitName: string;
836
846
                            MustHavePPU: boolean = true;
837
 
                            SkipPPUCheckIfNoneExists: boolean = true): string;
 
847
                            SkipPPUCheckIfTargetIsSourceOnly: boolean = true): string;
 
848
    function GetCompiledUnitFile(const AUnitName: string): string;
838
849
    property ChangeStamp: integer read FChangeStamp;
839
850
    class function GetInvalidChangeStamp: integer;
840
851
    procedure IncreaseChangeStamp;
841
852
    function GetUnitSetID: string;
 
853
    function GetFirstFPCCfg: string;
842
854
  end;
843
855
 
844
856
  { TFPCDefinesCache }
889
901
  var CPU, OS, WidgetSet: string);
890
902
function GetCompiledTargetOS: string;
891
903
function GetCompiledTargetCPU: string;
892
 
function GetDefaultCompilerFilename(const TargetCPU: string = ''): string;
 
904
function GetDefaultCompilerFilename(const TargetCPU: string = ''; Cross: boolean = false): string;
893
905
function GetFPCTargetOS(TargetOS: string): string;
894
906
function GetFPCTargetCPU(TargetCPU: string): string;
895
907
 
914
926
                        out FPCVersion, FPCRelease, FPCPatch: integer): boolean;
915
927
function ParseFPCVerbose(List: TStrings; // fpc -va output
916
928
                         out ConfigFiles: TStrings; // prefix '-' for file not found, '+' for found and read
917
 
                         out CompilerFilename: string; // what compiler is used by fpc
 
929
                         out RealCompilerFilename: string; // what compiler is used by fpc
918
930
                         out UnitPaths: TStrings; // unit search paths
919
931
                         out Defines, Undefines: TStringToStringTree): boolean;
920
932
function RunFPCVerbose(const CompilerFilename, TestFilename: string;
921
933
                       out ConfigFiles: TStrings;
922
 
                       out TargetCompilerFilename: string;
 
934
                       out RealCompilerFilename: string;
923
935
                       out UnitPaths: TStrings;
924
936
                       out Defines, Undefines: TStringToStringTree;
925
937
                       const Options: string = ''): boolean;
936
948
                           Owner: TObject): TDefineTemplate; overload;
937
949
function CreateFPCTemplate(Config: TFPCUnitSetCache;
938
950
                           Owner: TObject): TDefineTemplate; overload;
939
 
function CreateFPCSrcTemplate(Config: TFPCUnitSetCache;
940
 
                              Owner: TObject): TDefineTemplate; overload;
 
951
function CreateFPCSourceTemplate(Config: TFPCUnitSetCache;
 
952
                                 Owner: TObject): TDefineTemplate; overload;
 
953
function CreateFPCSourceTemplate(FPCSrcDir: string;
 
954
                                 Owner: TObject): TDefineTemplate; overload;
941
955
procedure CheckPPUSources(PPUFiles,  // unitname to filename
942
956
                          UnitToSource, // unitname to file name
943
957
                          UnitToDuplicates: TStringToStringTree; // unitname to semicolon separated list of files
951
965
procedure ParseMakefileFPC(const Filename, SrcOS: string;
952
966
                           var Dirs, SubDirs: string);
953
967
 
954
 
function CompareFPCSourceRulesViaFilenameStart(Rule1, Rule2: Pointer): integer;
 
968
function CompareFPCSourceRulesViaFilename(Rule1, Rule2: Pointer): integer;
955
969
function CompareFPCTargetConfigCacheItems(CacheItem1, CacheItem2: Pointer): integer;
956
970
function CompareFPCSourceCacheItems(CacheItem1, CacheItem2: Pointer): integer;
957
971
function CompareDirectoryWithFPCSourceCacheItem(AString, CacheItem: Pointer): integer;
1068
1082
  Abort:=false;
1069
1083
  try
1070
1084
    FileCount:=0;
1071
 
    Directory:=CleanAndExpandDirectory(Directory);
 
1085
    Directory:=TrimAndExpandDirectory(Directory);
 
1086
    if Directory='' then exit;
1072
1087
    Search('',0);
1073
1088
  finally
1074
1089
    if not Abort then
1214
1229
          OutLen:=TheProcess.Output.Read(Buf[1],length(Buf));
1215
1230
        end else
1216
1231
          OutLen:=0;
 
1232
        //debugln(['RunTool OutLen=',OutLen,' Buf="',copy(Buf,1,OutLen),'"']);
1217
1233
        LineStart:=1;
1218
1234
        i:=1;
1219
1235
        while i<=OutLen do begin
1228
1244
          end;
1229
1245
          inc(i);
1230
1246
        end;
1231
 
        OutputLine:=copy(Buf,LineStart,OutLen-LineStart+1);
 
1247
        OutputLine:=OutputLine+copy(Buf,LineStart,OutLen-LineStart+1);
1232
1248
      until OutLen=0;
 
1249
      //debugln(['RunTool Last=',OutputLine]);
 
1250
      if OutputLine<>'' then
 
1251
        Result.Add(OutputLine);
1233
1252
      TheProcess.WaitOnExit;
1234
1253
    finally
1235
1254
      TheProcess.Free;
1333
1352
end;
1334
1353
 
1335
1354
function ParseFPCVerbose(List: TStrings; out ConfigFiles: TSTrings;
1336
 
  out CompilerFilename: string; out UnitPaths: TStrings;
 
1355
  out RealCompilerFilename: string; out UnitPaths: TStrings;
1337
1356
  out Defines, Undefines: TStringToStringTree): boolean;
1338
1357
 
1339
1358
  procedure UndefineSymbol(const MacroName: string);
1428
1447
      end else if StrLComp(@UpLine[CurPos], 'COMPILER: ', 10) = 0 then begin
1429
1448
        // skip keywords
1430
1449
        Inc(CurPos, 10);
1431
 
        CompilerFilename:=copy(Line,CurPos,length(Line));
 
1450
        RealCompilerFilename:=copy(Line,CurPos,length(Line));
1432
1451
      end;
1433
1452
    'R':
1434
1453
      if StrLComp(@UpLine[CurPos], 'READING OPTIONS FROM FILE ', 26) = 0 then
1449
1468
begin
1450
1469
  Result:=false;
1451
1470
  ConfigFiles:=TStringList.Create;
1452
 
  CompilerFilename:='';
 
1471
  RealCompilerFilename:='';
1453
1472
  UnitPaths:=TStringList.Create;
1454
1473
  Defines:=TStringToStringTree.Create(false);
1455
1474
  Undefines:=TStringToStringTree.Create(false);
1468
1487
end;
1469
1488
 
1470
1489
function RunFPCVerbose(const CompilerFilename, TestFilename: string;
1471
 
  out ConfigFiles: TStrings; out TargetCompilerFilename: string;
 
1490
  out ConfigFiles: TStrings; out RealCompilerFilename: string;
1472
1491
  out UnitPaths: TStrings; out Defines, Undefines: TStringToStringTree;
1473
1492
  const Options: string): boolean;
1474
1493
var
1476
1495
  Filename: String;
1477
1496
  WorkDir: String;
1478
1497
  List: TStringList;
1479
 
  fs: TFileStream;
 
1498
  fs: TFileStreamUTF8;
1480
1499
begin
1481
1500
  Result:=false;
1482
1501
  ConfigFiles:=nil;
1483
 
  TargetCompilerFilename:='';
 
1502
  RealCompilerFilename:='';
1484
1503
  UnitPaths:=nil;
1485
1504
  Defines:=nil;
1486
1505
  Undefines:=nil;
1487
1506
 
1488
1507
  // create empty file
1489
1508
  try
1490
 
    fs:=TFileStream.Create(UTF8ToSys(TestFilename),fmCreate);
 
1509
    fs:=TFileStreamUTF8.Create(TestFilename,fmCreate);
1491
1510
    fs.Free;
1492
1511
  except
1493
 
    debugln(['RunFPCVerbose unable to create test file '+TestFilename]);
 
1512
    debugln(['RunFPCVerbose unable to create test file "'+TestFilename+'"']);
1494
1513
    exit;
1495
1514
  end;
1496
1515
 
1508
1527
      debugln(['RunFPCVerbose failed: ',CompilerFilename,' ',Params]);
1509
1528
      exit;
1510
1529
    end;
1511
 
    Result:=ParseFPCVerbose(List,ConfigFiles,TargetCompilerFilename,
 
1530
    Result:=ParseFPCVerbose(List,ConfigFiles,RealCompilerFilename,
1512
1531
                            UnitPaths,Defines,Undefines);
1513
1532
  finally
1514
1533
    List.Free;
1540
1559
  FileCount:=0;
1541
1560
  Abort:=false;
1542
1561
  for i:=SearchPaths.Count-1 downto 0 do begin
1543
 
    Directory:=CleanAndExpandDirectory(SearchPaths[i]);
 
1562
    Directory:=TrimAndExpandDirectory(SearchPaths[i]);
 
1563
    if (Directory='') then continue;
1544
1564
    if FindFirstUTF8(Directory+FileMask,faAnyFile,FileInfo)=0 then begin
1545
1565
      repeat
1546
1566
        inc(FileCount);
1773
1793
    ctsFreePascalCompilerInitialMacros,'','',da_Block);
1774
1794
 
1775
1795
  // define #TargetOS
1776
 
  TargetOS:=Config.TargetOS;
 
1796
  TargetOS:=Config.RealTargetOS;
 
1797
  if TargetOS='' then
 
1798
    TargetOS:=Config.TargetOS;
 
1799
  if TargetOS='' then
 
1800
    TargetOS:=GetCompiledTargetOS;
1777
1801
  NewDefTempl:=TDefineTemplate.Create('Define TargetOS',
1778
1802
    ctsDefaultFPCTargetOperatingSystem,
1779
1803
    ExternalMacroStart+'TargetOS',TargetOS,da_DefineRecurse);
1793
1817
    ExternalMacroStart+'SrcOS2',SrcOS2,da_DefineRecurse);
1794
1818
  Result.AddChild(NewDefTempl);
1795
1819
  // define #TargetProcessor
1796
 
  TargetCPU:=Config.TargetCPU;
 
1820
  TargetCPU:=Config.RealTargetCPU;
 
1821
  if TargetCPU='' then
 
1822
    TargetCPU:=Config.TargetCPU;
 
1823
  if TargetCPU='' then
 
1824
    TargetCPU:=GetCompiledTargetCPU;
1797
1825
  NewDefTempl:=TDefineTemplate.Create('Define TargetProcessor',
1798
1826
    ctsDefaultFPCTargetProcessor,
1799
1827
    ExternalMacroStart+'TargetProcessor',TargetCPU,
1834
1862
                  UnitSetMacroName,Config.GetUnitSetID,da_DefineRecurse));
1835
1863
end;
1836
1864
 
1837
 
function CreateFPCSrcTemplate(Config: TFPCUnitSetCache; Owner: TObject
 
1865
function CreateFPCSourceTemplate(FPCSrcDir: string; Owner: TObject
1838
1866
  ): TDefineTemplate;
1839
1867
var
1840
1868
  Dir, SrcOS, SrcOS2, TargetProcessor,
1928
1956
  FCLSubSrcDir: TDefineTemplate;
1929
1957
  FCLSubDir: TDefineTemplate;
1930
1958
  Ok: Boolean;
1931
 
  FPCSrcDir: String;
 
1959
  PackagesFCLExtraDir: TDefineTemplate;
1932
1960
begin
1933
 
  FPCSrcDir:=Config.FPCSourceDirectory;
1934
1961
  {$IFDEF VerboseFPCSrcScan}
1935
1962
  DebugLn('CreateFPCSrcTemplate FPCSrcDir="',FPCSrcDir,'"');
1936
1963
  {$ENDIF}
1963
1990
    DefTempl:=TDefineTemplate.Create('Reset UnitPath',
1964
1991
      ctsUnitPathInitialization,ExternalMacroStart+'UnitPath','',da_DefineRecurse);
1965
1992
    MainDir.AddChild(DefTempl);
1966
 
    // turn Nested comments on
1967
 
    DefTempl:=TDefineTemplate.Create('Nested Comments',
1968
 
      ctsNestedCommentsOn,ExternalMacroStart+'NestedComments','',da_DefineRecurse);
1969
 
    MainDir.AddChild(DefTempl);
1970
1993
 
1971
1994
    // rtl
1972
1995
    RTLDir:=TDefineTemplate.Create('RTL',ctsRuntimeLibrary,'','rtl',da_Directory);
1990
2013
      ['objpas, inc,'+TargetProcessor+','+SrcOS]),
1991
2014
      ExternalMacroStart+'IncPath',s,da_DefineRecurse));
1992
2015
 
 
2016
    // if solaris or darwin or beos then define FPC_USE_LIBC
 
2017
    IFTempl:=TDefineTemplate.Create('IF darwin or solaris or beos',
 
2018
      'If Darwin or Solaris or Beos', '', 'defined(darwin) or defined(solaris) or defined(beos)', da_If);
 
2019
      // then define FPC_USE_LIBC
 
2020
      IFTempl.AddChild(TDefineTemplate.Create('define FPC_USE_LIBC',
 
2021
        'define FPC_USE_LIBC','FPC_USE_LIBC','',da_DefineRecurse));
 
2022
    RTLDir.AddChild(IFTempl);
 
2023
 
 
2024
    // rtl: IF SrcOS=win then add include path rtl/win/wininc
 
2025
    IFTempl:=TDefineTemplate.Create('If SrcOS=win','If SrcOS=win',
 
2026
      '',''''+SrcOS+'''=''win''',da_If);
 
2027
    IFTempl.AddChild(TDefineTemplate.Create('Include Path',
 
2028
        Format(ctsIncludeDirectoriesPlusDirs,['wininc']),
 
2029
        ExternalMacroStart+'IncPath',
 
2030
        IncPathMacro
 
2031
        +';'+Dir+'rtl'+DS+'win'+DS+'wininc'
 
2032
        +';'+Dir+'rtl'+DS+'win',
 
2033
        da_DefineRecurse));
 
2034
    RTLDir.AddChild(IFTempl);
 
2035
 
 
2036
    // rtl: IF TargetOS=iphonesim then add include path rtl/unix, rtl/bsd, rtl/darwin
 
2037
    IFTempl:=TDefineTemplate.Create('If TargetOS=iphonesim','If TargetOS=iphonesim',
 
2038
      '',''''+TargetOSMacro+'''=''iphonesim''',da_If);
 
2039
    IFTempl.AddChild(TDefineTemplate.Create('Include Path',
 
2040
        Format(ctsIncludeDirectoriesPlusDirs,['unix,bsd,darwin']),
 
2041
        ExternalMacroStart+'IncPath',
 
2042
        IncPathMacro
 
2043
        +';'+Dir+'rtl'+DS+'unix'
 
2044
        +';'+Dir+'rtl'+DS+'bsd'
 
2045
        +';'+Dir+'rtl'+DS+'darwin',
 
2046
        da_DefineRecurse));
 
2047
    RTLDir.AddChild(IFTempl);
 
2048
 
 
2049
    // add processor and SrcOS alias defines for the RTL
 
2050
    AddProcessorTypeDefine(RTLDir);
 
2051
    AddSrcOSDefines(RTLDir);
 
2052
 
1993
2053
    // rtl/$(#TargetOS)
1994
2054
    RTLOSDir:=TDefineTemplate.Create('TargetOS','Target OS','',
1995
2055
                                     TargetOSMacro,da_Directory);
2008
2068
      ExternalMacroStart+'SrcPath',s,da_DefineRecurse));
2009
2069
    RTLDir.AddChild(RTLOSDir);
2010
2070
 
2011
 
    // rtl: IF SrcOS=win then add include path rtl/win/wininc
2012
 
    IFTempl:=TDefineTemplate.Create('If SrcOS=win','If SrcOS=win',
2013
 
      '',''''+SrcOS+'''=''win''',da_If);
2014
 
    IFTempl.AddChild(TDefineTemplate.Create('Include Path',
2015
 
        Format(ctsIncludeDirectoriesPlusDirs,['wininc']),
2016
 
        ExternalMacroStart+'IncPath',
2017
 
        IncPathMacro
2018
 
        +';'+Dir+'rtl'+DS+'win'+DS+'wininc'
2019
 
        +';'+Dir+'rtl'+DS+'win',
2020
 
        da_DefineRecurse));
2021
 
    RTLDir.AddChild(IFTempl);
2022
 
 
2023
 
    // rtl: IF TargetOS=darwin then add include path rtl/freebsd
2024
 
    IFTempl:=TDefineTemplate.Create('If TargetOS=darwin','If TargetOS=darwin',
2025
 
      '',''''+TargetOSMacro+'''=''darwin''',da_If);
2026
 
    IFTempl.AddChild(TDefineTemplate.Create('Include Path',
2027
 
        Format(ctsIncludeDirectoriesPlusDirs,['rtl'+DS+'freebsd']),
2028
 
        ExternalMacroStart+'IncPath',
2029
 
        IncPathMacro
2030
 
        +';'+Dir+'rtl'+DS+'freebsd',
2031
 
        da_DefineRecurse));
2032
 
    RTLDir.AddChild(IFTempl);
2033
 
 
2034
 
    // add processor and SrcOS alias defines for the RTL
2035
 
    AddProcessorTypeDefine(RTLDir);
2036
 
    AddSrcOSDefines(RTLDir);
2037
 
 
2038
2071
 
2039
2072
    // fcl
2040
2073
    FCLDir:=TDefineTemplate.Create('FCL',ctsFreePascalComponentLibrary,'','fcl',
2116
2149
      +';'+IncPathMacro)
2117
2150
      ,da_DefineRecurse));
2118
2151
 
 
2152
    // packages/fcl-extra
 
2153
    PackagesFCLExtraDir:=TDefineTemplate.Create('fcl-extra','fcl-extra','','fcl-extra',da_Directory);
 
2154
    PackagesDir.AddChild(PackagesFCLExtraDir);
 
2155
 
 
2156
    // packages/fcl-extra/src
 
2157
    PackagesFCLExtraDir.AddChild(TDefineTemplate.Create('Include Path',
 
2158
      Format(ctsIncludeDirectoriesPlusDirs,['packages/fcl-extra/src']),
 
2159
      ExternalMacroStart+'IncPath',
 
2160
      d(   DefinePathMacro+'/src/'+SrcOS
 
2161
      +';'+IncPathMacro)
 
2162
      ,da_DefineRecurse));
 
2163
 
2119
2164
    // packages/extra
2120
2165
    PackagesExtraDir:=TDefineTemplate.Create('extra','extra','','extra',da_Directory);
2121
2166
    PackagesDir.AddChild(PackagesExtraDir);
2193
2238
  end;
2194
2239
end;
2195
2240
 
 
2241
function CreateFPCSourceTemplate(Config: TFPCUnitSetCache; Owner: TObject
 
2242
  ): TDefineTemplate;
 
2243
begin
 
2244
  Result:=CreateFPCSourceTemplate(Config.FPCSourceDirectory,Owner);
 
2245
end;
 
2246
 
2196
2247
procedure CheckPPUSources(PPUFiles, UnitToSource,
2197
2248
  UnitToDuplicates: TStringToStringTree;
2198
2249
  var Duplicates, Missing: TStringToStringTree);
2397
2448
  Params.Free;
2398
2449
end;
2399
2450
 
2400
 
function CompareFPCSourceRulesViaFilenameStart(Rule1, Rule2: Pointer): integer;
 
2451
function CompareFPCSourceRulesViaFilename(Rule1, Rule2: Pointer): integer;
2401
2452
var
2402
2453
  SrcRule1: TFPCSourceRule absolute Rule1;
2403
2454
  SrcRule2: TFPCSourceRule absolute Rule2;
2546
2597
  Result:=lowerCase({$I %FPCTARGETCPU%});
2547
2598
end;
2548
2599
 
2549
 
function GetDefaultCompilerFilename(const TargetCPU: string = ''): string;
 
2600
function GetDefaultCompilerFilename(const TargetCPU: string;
 
2601
  Cross: boolean): string;
2550
2602
begin
 
2603
  if Cross then
 
2604
    {$ifdef darwin}
 
2605
    Result:='ppc' // the mach-o format supports "fat" binaries whereby
 
2606
                  // a single executable contains machine code for several architectures
 
2607
    {$else}
 
2608
    Result:='ppcross'
 
2609
    {$endif}
 
2610
  else
 
2611
    Result:='ppc';
2551
2612
  if TargetCPU='' then
2552
2613
    Result:='fpc'
2553
2614
  else if SysUtils.CompareText(TargetCPU,'i386')=0 then
2554
 
    Result:='ppc386'
 
2615
    Result:=Result+'386'
 
2616
  else if SysUtils.CompareText(TargetCPU,'m68k')=0 then
 
2617
    Result:=Result+'86k'
 
2618
  else if SysUtils.CompareText(TargetCPU,'alpha')=0 then
 
2619
    Result:=Result+'apx'
2555
2620
  else if SysUtils.CompareText(TargetCPU,'powerpc')=0 then
2556
 
    Result:='ppcppc'
 
2621
    Result:=Result+'ppc'
 
2622
  else if SysUtils.CompareText(TargetCPU,'powerpc64')=0 then
 
2623
    Result:=Result+'ppc64'
 
2624
  else if SysUtils.CompareText(TargetCPU,'arm')=0 then
 
2625
    Result:=Result+'arm'
2557
2626
  else if SysUtils.CompareText(TargetCPU,'sparc')=0 then
2558
 
    Result:='ppcsparc'
2559
 
  else if SysUtils.CompareText(TargetCPU,'m68k')=0 then
2560
 
    Result:='ppc86k'
2561
 
  else if SysUtils.CompareText(TargetCPU,'alpha')=0 then
2562
 
    Result:='ppcalpha'
 
2627
    Result:=Result+'sparc'
2563
2628
  else if SysUtils.CompareText(TargetCPU,'x86_64')=0 then
2564
 
    Result:='ppcx64'
2565
 
  else if SysUtils.CompareText(TargetCPU,'arm')=0 then
2566
 
    Result:='ppcarm'
 
2629
    Result:=Result+'x64'
 
2630
  else if SysUtils.CompareText(TargetCPU,'ia64')=0 then
 
2631
    Result:=Result+'ia64'
2567
2632
  else
2568
2633
    Result:='fpc';
2569
2634
  Result:=Result+ExeExt;
3694
3759
constructor TDefineTree.Create;
3695
3760
begin
3696
3761
  inherited Create;
 
3762
  IncreaseChangeStep;
3697
3763
  FFirstDefineTemplate:=nil;
3698
3764
  FCache:=TAVLTree.Create(@CompareDirectoryDefines);
3699
3765
  FDefineStrings:=TStringTree.Create;
3700
3766
 
3701
 
  FMacroFunctions:=TKeyWordFunctionList.Create;
 
3767
  FMacroFunctions:=TKeyWordFunctionList.Create('TDefineTree.Create.MacroFunctions');
3702
3768
  FMacroFunctions.AddExtended('Ext',nil,@MacroFuncExtractFileExt);
3703
3769
  FMacroFunctions.AddExtended('PATH',nil,@MacroFuncExtractFilePath);
3704
3770
  FMacroFunctions.AddExtended('NAME',nil,@MacroFuncExtractFileName);
3705
3771
  FMacroFunctions.AddExtended('NAMEONLY',nil,@MacroFuncExtractFileNameOnly);
3706
3772
  
3707
 
  FMacroVariables:=TKeyWordFunctionList.Create;
 
3773
  FMacroVariables:=TKeyWordFunctionList.Create('TDefineTree.Create.MacroVariables');
3708
3774
end;
3709
3775
 
3710
3776
destructor TDefineTree.Destroy;
4408
4474
 
4409
4475
procedure TDefineTree.IncreaseChangeStep;
4410
4476
begin
4411
 
  if FChangeStep<>$7fffffff then
4412
 
    inc(FChangeStep)
4413
 
  else
4414
 
    FChangeStep:=-$7fffffff;
 
4477
  CTIncreaseChangeStamp(FChangeStep);
4415
4478
  if DirectoryCachePool<>nil then DirectoryCachePool.IncreaseConfigTimeStamp;
4416
4479
end;
4417
4480
 
4418
 
procedure TDefineTree.SetDirectoryCachePool(const AValue: TCTDirectoryCachePool
4419
 
  );
 
4481
procedure TDefineTree.SetDirectoryCachePool(const AValue: TCTDirectoryCachePool);
4420
4482
begin
4421
4483
  if FDirectoryCachePool=AValue then exit;
4422
4484
  FDirectoryCachePool:=AValue;
5088
5150
  UnitLinkListValid: boolean; var UnitLinkList: string;
5089
5151
  Owner: TObject): TDefineTemplate;
5090
5152
var
5091
 
  Dir, SrcOS, SrcOS2, TargetProcessor, UnitLinks,
5092
 
  IncPathMacro: string;
5093
 
  DS: char; // dir separator
 
5153
  Dir, SrcOS, SrcOS2, TargetProcessor, UnitLinks: string;
5094
5154
  UnitTree: TAVLTree; // tree of TDefTemplUnitNameLink
5095
 
  DefaultSrcOS, DefaultSrcOS2: string;
 
5155
  IncPathMacro, DefaultSrcOS, DefaultSrcOS2: string;
5096
5156
  ProgressID: integer;
5097
5157
  
5098
5158
  function d(const Filenames: string): string;
5594
5654
  end;
5595
5655
 
5596
5656
var
5597
 
  DefTempl, MainDir, FCLDir, RTLDir, RTLOSDir, PackagesDir, CompilerDir,
5598
 
  UtilsDir, DebugSvrDir: TDefineTemplate;
5599
 
  s: string;
5600
 
  FCLDBDir: TDefineTemplate;
5601
 
  FCLDBInterbaseDir: TDefineTemplate;
5602
 
  InstallerDir: TDefineTemplate;
5603
 
  IFTempl: TDefineTemplate;
5604
 
  FCLBaseDir: TDefineTemplate;
5605
 
  FCLBaseSrcDir: TDefineTemplate;
5606
 
  PackagesFCLAsyncDir: TDefineTemplate;
5607
 
  PackagesExtraDir: TDefineTemplate;
5608
 
  PkgExtraGraphDir: TDefineTemplate;
5609
 
  PkgExtraAMunitsDir: TDefineTemplate;
5610
 
  FCLSubSrcDir: TDefineTemplate;
5611
 
  FCLSubDir: TDefineTemplate;
 
5657
  DefTempl: TDefineTemplate;
5612
5658
  Ok: Boolean;
5613
5659
begin
5614
5660
  {$IFDEF VerboseFPCSrcScan}
5621
5667
  ProgressID:=0;
5622
5668
  Ok:=false;
5623
5669
  try
5624
 
    if (FPCSrcDir='') or (not DirPathExists(FPCSrcDir)) then begin
5625
 
      DebugLn(['TDefinePool.CreateFPCSrcTemplate FPCSrcDir does not exist: FPCSrcDir="',FPCSrcDir,'"']);
5626
 
      exit;
5627
 
    end;
5628
 
    DS:=PathDelim;
5629
5670
    Dir:=AppendPathDelim(FPCSrcDir);
5630
5671
    SrcOS:='$('+ExternalMacroStart+'SrcOS)';
5631
5672
    SrcOS2:='$('+ExternalMacroStart+'SrcOS2)';
5634
5675
    DefaultSrcOS:=GetDefaultSrcOSForTargetOS(DefaultTargetOS);
5635
5676
    DefaultSrcOS2:=GetDefaultSrcOS2ForTargetOS(DefaultTargetOS);
5636
5677
 
5637
 
    Result:=TDefineTemplate.Create(StdDefTemplFPCSrc,
5638
 
       Format(ctsFreePascalSourcesPlusDesc,['RTL, FCL, Packages, Compiler']),
5639
 
       '','',da_Block);
5640
 
 
 
5678
    if (FPCSrcDir='') or (not DirPathExists(FPCSrcDir)) then begin
 
5679
      DebugLn(['TDefinePool.CreateFPCSrcTemplate FPCSrcDir does not exist: FPCSrcDir="',FPCSrcDir,'"']);
 
5680
      exit;
 
5681
    end;
5641
5682
    // try to find for every reachable ppu file the unit file in the FPC sources
5642
5683
    UnitLinks:=UnitLinksMacroName;
5643
5684
    UnitTree:=nil;
5644
5685
    if not FindStandardPPUSources then exit;
 
5686
 
 
5687
    Result:=CreateFPCSourceTemplate(FPCSrcDir,Owner);
 
5688
 
5645
5689
    DefTempl:=TDefineTemplate.Create('FPC Unit Links',
5646
5690
      ctsSourceFilenamesForStandardFPCUnits,
5647
5691
      UnitLinks,UnitLinkList,da_DefineRecurse);
5648
5692
    Result.AddChild(DefTempl);
5649
5693
 
5650
 
    // The free pascal sources build a world of their own,
5651
 
    // reset search paths
5652
 
    MainDir:=TDefineTemplate.Create('Free Pascal Source Directory',
5653
 
      ctsFreePascalSourceDir,'',FPCSrcDir,da_Directory);
5654
 
    Result.AddChild(MainDir);
5655
 
    DefTempl:=TDefineTemplate.Create('Reset SrcPath',
5656
 
      ctsSrcPathInitialization,ExternalMacroStart+'SrcPath','',da_DefineRecurse);
5657
 
    MainDir.AddChild(DefTempl);
5658
 
    DefTempl:=TDefineTemplate.Create('Reset UnitPath',
5659
 
      ctsUnitPathInitialization,ExternalMacroStart+'UnitPath','',da_DefineRecurse);
5660
 
    MainDir.AddChild(DefTempl);
5661
 
    // turn Nested comments on
5662
 
    DefTempl:=TDefineTemplate.Create('Nested Comments',
5663
 
      ctsNestedCommentsOn,ExternalMacroStart+'NestedComments','',da_DefineRecurse);
5664
 
    MainDir.AddChild(DefTempl);
5665
 
    // enable FPDocSystem to find compiler functions like writeln and readln
5666
 
    {DefTempl:=TDefineTemplate.Create('FPDocSystem',
5667
 
      ctsFPDocSystemOn,'FPDocSystem','',da_DefineRecurse);
5668
 
    MainDir.AddChild(DefTempl);}
5669
 
 
5670
 
    // rtl
5671
 
    RTLDir:=TDefineTemplate.Create('RTL',ctsRuntimeLibrary,'','rtl',da_Directory);
5672
 
    MainDir.AddChild(RTLDir);
5673
 
 
5674
 
    // rtl include paths
5675
 
    s:=IncPathMacro
5676
 
      +';'+Dir+'rtl'+DS+'objpas'+DS
5677
 
      +';'+Dir+'rtl'+DS+'objpas'+DS+'sysutils'
5678
 
      +';'+Dir+'rtl'+DS+'objpas'+DS+'classes'
5679
 
      +';'+Dir+'rtl'+DS+'inc'+DS
5680
 
      +';'+Dir+'rtl'+DS+'inc'+DS+'graph'+DS
5681
 
      +';'+Dir+'rtl'+DS+SrcOS+DS
5682
 
      +';'+Dir+'rtl'+DS+TargetOSMacro+DS
5683
 
      +';'+Dir+'rtl'+DS+SrcOS2+DS
5684
 
      +';'+Dir+'rtl'+DS+SrcOS2+DS+TargetProcessor
5685
 
      +';'+Dir+'rtl'+DS+TargetProcessor+DS
5686
 
      +';'+Dir+'rtl'+DS+TargetOSMacro+DS+TargetProcessor+DS;
5687
 
    RTLDir.AddChild(TDefineTemplate.Create('Include Path',
5688
 
      Format(ctsIncludeDirectoriesPlusDirs,
5689
 
      ['objpas, inc,'+TargetProcessor+','+SrcOS]),
5690
 
      ExternalMacroStart+'IncPath',s,da_DefineRecurse));
5691
 
 
5692
 
    // rtl/$(#TargetOS)
5693
 
    RTLOSDir:=TDefineTemplate.Create('TargetOS','Target OS','',
5694
 
                                     TargetOSMacro,da_Directory);
5695
 
    s:=IncPathMacro
5696
 
      +';'+Dir+'rtl'+DS+TargetOSMacro+DS+SrcOS+'inc' // e.g. rtl/win32/inc/
5697
 
      +';'+Dir+'rtl'+DS+TargetOSMacro+DS+TargetProcessor+DS
5698
 
      ;
5699
 
    RTLOSDir.AddChild(TDefineTemplate.Create('Include Path',
5700
 
      Format(ctsIncludeDirectoriesPlusDirs,[TargetProcessor]),
5701
 
      ExternalMacroStart+'IncPath',
5702
 
      s,da_DefineRecurse));
5703
 
    s:=SrcPathMacro
5704
 
      +';'+Dir+'rtl'+DS+'objpas'+DS;
5705
 
    RTLOSDir.AddChild(TDefineTemplate.Create('Src Path',
5706
 
      Format(ctsAddsDirToSourcePath,[TargetProcessor]),
5707
 
      ExternalMacroStart+'SrcPath',s,da_DefineRecurse));
5708
 
    RTLDir.AddChild(RTLOSDir);
5709
 
 
5710
 
    // rtl: IF SrcOS=win then add include path rtl/win/wininc
5711
 
    IFTempl:=TDefineTemplate.Create('If SrcOS=win','If SrcOS=win',
5712
 
      '',''''+SrcOS+'''=''win''',da_If);
5713
 
    IFTempl.AddChild(TDefineTemplate.Create('Include Path',
5714
 
        Format(ctsIncludeDirectoriesPlusDirs,['wininc']),
5715
 
        ExternalMacroStart+'IncPath',
5716
 
        IncPathMacro
5717
 
        +';'+Dir+'rtl'+DS+'win'+DS+'wininc'
5718
 
        +';'+Dir+'rtl'+DS+'win',
5719
 
        da_DefineRecurse));
5720
 
    RTLDir.AddChild(IFTempl);
5721
 
 
5722
 
    // rtl: IF TargetOS=darwin then add include path rtl/freebsd
5723
 
    IFTempl:=TDefineTemplate.Create('If TargetOS=darwin','If TargetOS=darwin',
5724
 
      '',''''+TargetOSMacro+'''=''darwin''',da_If);
5725
 
    IFTempl.AddChild(TDefineTemplate.Create('Include Path',
5726
 
        Format(ctsIncludeDirectoriesPlusDirs,['rtl'+DS+'freebsd']),
5727
 
        ExternalMacroStart+'IncPath',
5728
 
        IncPathMacro
5729
 
        +';'+Dir+'rtl'+DS+'freebsd',
5730
 
        da_DefineRecurse));
5731
 
    RTLDir.AddChild(IFTempl);
5732
 
 
5733
 
    // add processor and SrcOS alias defines for the RTL
5734
 
    AddProcessorTypeDefine(RTLDir);
5735
 
    AddSrcOSDefines(RTLDir);
5736
 
 
5737
 
 
5738
 
    // fcl
5739
 
    FCLDir:=TDefineTemplate.Create('FCL',ctsFreePascalComponentLibrary,'','fcl',
5740
 
        da_Directory);
5741
 
    MainDir.AddChild(FCLDir);
5742
 
    FCLDir.AddChild(TDefineTemplate.Create('Include Path',
5743
 
      Format(ctsIncludeDirectoriesPlusDirs,['inc,'+SrcOS]),
5744
 
      ExternalMacroStart+'IncPath',
5745
 
      d(   DefinePathMacro+'/inc/'
5746
 
      +';'+DefinePathMacro+'/classes/'
5747
 
      +';'+DefinePathMacro+'/'+TargetOSMacro+DS // TargetOS before SrcOS !
5748
 
      +';'+DefinePathMacro+'/'+SrcOS+DS
5749
 
      +';'+IncPathMacro)
5750
 
      ,da_DefineRecurse));
5751
 
 
5752
 
    // fcl/db
5753
 
    FCLDBDir:=TDefineTemplate.Create('DB','DB','','db',da_Directory);
5754
 
    FCLDir.AddChild(FCLDBDir);
5755
 
    FCLDBInterbaseDir:=TDefineTemplate.Create('interbase','interbase','',
5756
 
      'interbase',da_Directory);
5757
 
    FCLDBDir.AddChild(FCLDBInterbaseDir);
5758
 
    FCLDBInterbaseDir.AddChild(TDefineTemplate.Create('SrcPath',
5759
 
      'SrcPath addition',
5760
 
      ExternalMacroStart+'SrcPath',
5761
 
      d(Dir+'/packages/base/ibase;'+SrcPathMacro)
5762
 
      ,da_Define));
5763
 
 
5764
 
    // packages
5765
 
    PackagesDir:=TDefineTemplate.Create('Packages',ctsPackageDirectories,'',
5766
 
       'packages',da_Directory);
5767
 
    MainDir.AddChild(PackagesDir);
5768
 
 
5769
 
    // packages/fcl-base
5770
 
    FCLBaseDir:=TDefineTemplate.Create('FCL-base',
5771
 
        ctsFreePascalComponentLibrary,'','fcl-base',
5772
 
        da_Directory);
5773
 
    PackagesDir.AddChild(FCLBaseDir);
5774
 
    // packages/fcl-base/src
5775
 
    FCLBaseSrcDir:=TDefineTemplate.Create('src',
5776
 
        'src','','src',
5777
 
        da_Directory);
5778
 
    FCLBaseDir.AddChild(FCLBaseSrcDir);
5779
 
    FCLBaseSrcDir.AddChild(TDefineTemplate.Create('Include Path',
5780
 
      Format(ctsIncludeDirectoriesPlusDirs,['inc,'+SrcOS]),
5781
 
      ExternalMacroStart+'IncPath',
5782
 
      d(   DefinePathMacro+'/inc/'
5783
 
      +';'+DefinePathMacro+'/'+TargetOSMacro+DS // TargetOS before SrcOS !
5784
 
      +';'+DefinePathMacro+'/'+SrcOS+DS
5785
 
      +';'+IncPathMacro)
5786
 
      ,da_DefineRecurse));
5787
 
 
5788
 
    // packages/fcl-process
5789
 
    FCLSubDir:=TDefineTemplate.Create('FCL-process',
5790
 
        'fcl-process','','fcl-process',
5791
 
        da_Directory);
5792
 
    PackagesDir.AddChild(FCLSubDir);
5793
 
    // packages/fcl-process/src
5794
 
    FCLSubSrcDir:=TDefineTemplate.Create('src',
5795
 
        'src','','src',
5796
 
        da_Directory);
5797
 
    FCLSubDir.AddChild(FCLSubSrcDir);
5798
 
    FCLSubSrcDir.AddChild(TDefineTemplate.Create('Include Path',
5799
 
      Format(ctsIncludeDirectoriesPlusDirs,['inc,'+SrcOS]),
5800
 
      ExternalMacroStart+'IncPath',
5801
 
      d(   DefinePathMacro+'/'+TargetOSMacro+DS // TargetOS before SrcOS !
5802
 
      +';'+DefinePathMacro+'/'+SrcOS+DS
5803
 
      +';'+IncPathMacro)
5804
 
      ,da_DefineRecurse));
5805
 
 
5806
 
    // packages/fcl-async
5807
 
    PackagesFCLAsyncDir:=TDefineTemplate.Create('fcl-async','fcl-async','','fcl-async',da_Directory);
5808
 
    PackagesDir.AddChild(PackagesFCLAsyncDir);
5809
 
 
5810
 
    // packages/fcl-async/src
5811
 
    PackagesFCLAsyncDir.AddChild(TDefineTemplate.Create('Include Path',
5812
 
      Format(ctsIncludeDirectoriesPlusDirs,['packages/fcl-async/src']),
5813
 
      ExternalMacroStart+'IncPath',
5814
 
      d(   DefinePathMacro+'/src/'
5815
 
      +';'+IncPathMacro)
5816
 
      ,da_DefineRecurse));
5817
 
 
5818
 
    // packages/extra
5819
 
    PackagesExtraDir:=TDefineTemplate.Create('extra','extra','','extra',da_Directory);
5820
 
    PackagesDir.AddChild(PackagesExtraDir);
5821
 
 
5822
 
    // packages/extra/graph
5823
 
    PkgExtraGraphDir:=TDefineTemplate.Create('graph','graph','','graph',
5824
 
                                             da_Directory);
5825
 
    PackagesExtraDir.AddChild(PkgExtraGraphDir);
5826
 
    PkgExtraGraphDir.AddChild(TDefineTemplate.Create('Include Path',
5827
 
      Format(ctsIncludeDirectoriesPlusDirs,['inc']),
5828
 
      ExternalMacroStart+'IncPath',
5829
 
      d(   DefinePathMacro+'/inc/'
5830
 
      +';'+IncPathMacro)
5831
 
      ,da_DefineRecurse));
5832
 
 
5833
 
    // packages/extra/amunits
5834
 
    PkgExtraAMunitsDir:=TDefineTemplate.Create('amunits','amunits','','amunits',
5835
 
                                             da_Directory);
5836
 
    PackagesExtraDir.AddChild(PkgExtraAMunitsDir);
5837
 
    PkgExtraAMunitsDir.AddChild(TDefineTemplate.Create('Include Path',
5838
 
      Format(ctsIncludeDirectoriesPlusDirs,['inc']),
5839
 
      ExternalMacroStart+'IncPath',
5840
 
      d(   DefinePathMacro+'/inc/'
5841
 
      +';'+IncPathMacro)
5842
 
      ,da_DefineRecurse));
5843
 
 
5844
 
    // utils
5845
 
    UtilsDir:=TDefineTemplate.Create('Utils',ctsUtilsDirectories,'',
5846
 
       'utils',da_Directory);
5847
 
    MainDir.AddChild(UtilsDir);
5848
 
 
5849
 
    // utils/debugsvr
5850
 
    DebugSvrDir:=TDefineTemplate.Create('DebugSvr','Debug Server','',
5851
 
       'debugsvr',da_Directory);
5852
 
    UtilsDir.AddChild(DebugSvrDir);
5853
 
    DebugSvrDir.AddChild(TDefineTemplate.Create('Interface Path',
5854
 
      Format(ctsAddsDirToSourcePath,['..']),ExternalMacroStart+'SrcPath',
5855
 
      '..;'+ExternalMacroStart+'SrcPath',da_DefineRecurse));
5856
 
 
5857
 
    // installer
5858
 
    InstallerDir:=TDefineTemplate.Create('Installer',ctsInstallerDirectories,'',
5859
 
       'installer',da_Directory);
5860
 
    InstallerDir.AddChild(TDefineTemplate.Create('SrcPath','SrcPath addition',
5861
 
      ExternalMacroStart+'SrcPath',
5862
 
      SrcPathMacro+';'+Dir+'ide;'+Dir+'fv',da_Define));
5863
 
    MainDir.AddChild(InstallerDir);
5864
 
 
5865
 
    // compiler
5866
 
    CompilerDir:=TDefineTemplate.Create('Compiler',ctsCompiler,'','compiler',
5867
 
       da_Directory);
5868
 
    AddProcessorTypeDefine(CompilerDir);
5869
 
    CompilerDir.AddChild(TDefineTemplate.Create('SrcPath','SrcPath addition',
5870
 
      ExternalMacroStart+'SrcPath',
5871
 
      SrcPathMacro+';'+Dir+TargetProcessor,da_Define));
5872
 
    CompilerDir.AddChild(TDefineTemplate.Create('IncPath','IncPath addition',
5873
 
      ExternalMacroStart+'IncPath',
5874
 
      IncPathMacro+';'+Dir+'compiler',da_DefineRecurse));
5875
 
    MainDir.AddChild(CompilerDir);
5876
 
 
5877
 
    // compiler/utils
5878
 
    UtilsDir:=TDefineTemplate.Create('utils',ctsUtilsDirectories,'',
5879
 
       'utils',da_Directory);
5880
 
    UtilsDir.AddChild(TDefineTemplate.Create('SrcPath','SrcPath addition',
5881
 
      ExternalMacroStart+'SrcPath',
5882
 
      SrcPathMacro+';..',da_Define));
5883
 
    CompilerDir.AddChild(UtilsDir);
5884
 
 
5885
5694
    // clean up
5886
5695
    if UnitTree<>nil then begin
5887
5696
      UnitTree.FreeAndClear;
5929
5738
  end;
5930
5739
    
5931
5740
var
5932
 
  MainDir, DirTempl, SubDirTempl, IntfDirTemplate, IfTemplate, ElseTemplate,
5933
 
  LCLUnitsDir, LCLUnitsCPUOSDir, LCLUnitsCPUOSWidgetSetDir,
 
5741
  MainDir, DirTempl, SubDirTempl, IfTemplate,
5934
5742
  SubTempl: TDefineTemplate;
5935
 
  TargetOS, SrcOS, SrcPath, IncPath: string;
 
5743
  TargetOS, SrcOS, SrcPath: string;
5936
5744
  i: Integer;
5937
 
  CurCPU, CurOS, CurWidgetSet, ExtraSrcPath: string;
5938
 
  LCLWidgetSetDir: TDefineTemplate;
5939
 
  IDEIntfDir: TDefineTemplate;
 
5745
  CurCPU, CurOS, CurWidgetSet: string;
5940
5746
  ToolsInstallDirTempl: TDefineTemplate;
5941
 
  CurCPUOS: String;
5942
 
  SynEditDirTempl, SynEditUnitsDirTempl: TDefineTemplate;
5943
 
  LazControlsDirTempl, LazControlsUnitsDirTempl: TDefineTemplate;
5944
 
  CodeToolsDirTempl: TDefineTemplate;
5945
 
  CodeToolsUnitsDirTempl: TDefineTemplate;
5946
 
  FPGUIPlatformTempl: TDefineTemplate;
5947
5747
  AllWidgetSets: String;
5948
5748
  p: Integer;
5949
5749
begin
5953
5753
  TargetOS:='$('+ExternalMacroStart+'TargetOS)';
5954
5754
  SrcOS:='$('+ExternalMacroStart+'SrcOS)';
5955
5755
  SrcPath:='$('+ExternalMacroStart+'SrcPath)';
5956
 
  IncPath:='$('+ExternalMacroStart+'IncPath)';
 
5756
  //IncPath:='$('+ExternalMacroStart+'IncPath)';
5957
5757
  
5958
5758
  AllWidgetSets:='';
5959
5759
  for i:=Low(Lazarus_CPU_OS_Widget_Combinations)
5984
5784
      ExternalMacroStart+'SrcPath',
5985
5785
      d(LazarusSrcDir+'/lcl/nonwin32;')+SrcPath,da_DefineRecurse));
5986
5786
  MainDir.AddChild(IfTemplate);
5987
 
  // turn Nested comments on
5988
 
  MainDir.AddChild(TDefineTemplate.Create('Nested Comments',
5989
 
    ctsNestedCommentsOn,ExternalMacroStart+'NestedComments','',da_DefineRecurse));
5990
5787
  // define 'LCL'
5991
5788
  MainDir.AddChild(TDefineTemplate.Create('define LCL',
5992
5789
    ctsDefineLCL,'LCL',WidgetType,da_DefineRecurse));
6020
5817
       +LazarusSrcDir+'/converter;'
6021
5818
       +LazarusSrcDir+'/packager;'
6022
5819
       +LazarusSrcDir+'/packager/registration;'
6023
 
       +LazarusSrcDir+'/components/custom;'
6024
 
       +LazarusSrcDir+'/components/mpaslex;')
6025
 
    ,da_DefineRecurse));
6026
 
  DirTempl.AddChild(TDefineTemplate.Create('IDEIntf path addition',
6027
 
    Format(ctsAddsDirToSourcePath,['ideintf']),
6028
 
    ExternalMacroStart+'SrcPath',
6029
 
      d(LazarusSrcDir+'/ideintf;'
6030
 
       +SrcPath)
6031
 
    ,da_DefineRecurse));
6032
 
  DirTempl.AddChild(TDefineTemplate.Create('SynEdit path addition',
6033
 
    Format(ctsAddsDirToSourcePath,['synedit']),
6034
 
    ExternalMacroStart+'SrcPath',
6035
 
      d(LazarusSrcDir+'/components/synedit;'
6036
 
       +SrcPath)
6037
 
    ,da_DefineRecurse));
6038
 
  DirTempl.AddChild(TDefineTemplate.Create('LazControls path addition',
6039
 
    Format(ctsAddsDirToSourcePath,['lazcontrols']),
6040
 
    ExternalMacroStart+'SrcPath',
6041
 
      d(LazarusSrcDir+'/components/lazcontrols;'
6042
 
       +SrcPath)
6043
 
    ,da_DefineRecurse));
6044
 
  DirTempl.AddChild(TDefineTemplate.Create('CodeTools path addition',
6045
 
    Format(ctsAddsDirToSourcePath,['codetools']),
6046
 
    ExternalMacroStart+'SrcPath',
6047
 
      d(LazarusSrcDir+'/components/codetools;'
6048
 
       +SrcPath)
6049
 
    ,da_DefineRecurse));
6050
 
  DirTempl.AddChild(TDefineTemplate.Create('LCL path addition',
6051
 
    Format(ctsAddsDirToSourcePath,['lcl']),
6052
 
    ExternalMacroStart+'SrcPath',
6053
 
      d(LazarusSrcDir+'/lcl;'
 
5820
       +LazarusSrcDir+'/packager/frames;'
 
5821
       +LazarusSrcDir+'/ideintf;'
 
5822
       +LazarusSrcDir+'/components/lazutils;'
 
5823
       +LazarusSrcDir+'/components/lazcontrols;'
 
5824
       +LazarusSrcDir+'/components/synedit;'
 
5825
       +LazarusSrcDir+'/components/codetools;'
 
5826
       +LazarusSrcDir+'/lcl;'
 
5827
       +LazarusSrcDir+'/lcl/interfaces;'
6054
5828
       +LazarusSrcDir+'/lcl/interfaces/'+WidgetType+';'
6055
 
       +SrcPath)
 
5829
       +LazarusSrcDir+'/components/custom;')
6056
5830
    ,da_DefineRecurse));
6057
5831
  // include path addition
6058
5832
  DirTempl.AddChild(TDefineTemplate.Create('includepath addition',
6067
5841
  // <LazarusSrcDir>/designer
6068
5842
  DirTempl:=TDefineTemplate.Create('Designer',ctsDesignerDirectory,
6069
5843
    '','designer',da_Directory);
6070
 
  DirTempl.AddChild(TDefineTemplate.Create('LCL path addition',
6071
 
    Format(ctsAddsDirToSourcePath,['lcl']),
 
5844
  DirTempl.AddChild(TDefineTemplate.Create('components path addition',
 
5845
    Format(ctsAddsDirToSourcePath,['synedit']),
6072
5846
    SrcPathMacroName,
6073
 
      d('../lcl'
6074
 
       +';../lcl/interfaces/'+WidgetType)
 
5847
      d('../components/lazutils'
 
5848
       +';../components/codetools'
 
5849
       +';../lcl'
 
5850
       +';../lcl/interfaces'
 
5851
       +';../lcl/interfaces/'+WidgetType
 
5852
       +';../ideintf'
 
5853
       +';../components/synedit'
 
5854
       +';../components/codetools'
 
5855
       +';../components/lazcontrols'
 
5856
       +';../components/custom')
6075
5857
       +';'+SrcPath
6076
5858
    ,da_Define));
6077
5859
  DirTempl.AddChild(TDefineTemplate.Create('main path addition',
6079
5861
    SrcPathMacroName,
6080
5862
    d('../ide;../packager;')+SrcPath
6081
5863
    ,da_Define));
6082
 
  DirTempl.AddChild(TDefineTemplate.Create('components path addition',
6083
 
    Format(ctsAddsDirToSourcePath,['synedit']),
6084
 
    ExternalMacroStart+'SrcPath',
6085
 
      d('../ideintf;'
6086
 
       +'../components/synedit;'
6087
 
       +'../components/codetools;'
6088
 
       +'../components/lazcontrols;'
6089
 
       +'../components/custom;'
6090
 
       +'jitform;')
6091
 
       +SrcPath
6092
 
    ,da_Define));
6093
5864
  DirTempl.AddChild(TDefineTemplate.Create('includepath addition',
6094
5865
    Format(ctsIncludeDirectoriesPlusDirs,['include']),
6095
5866
    ExternalMacroStart+'IncPath',
6096
5867
    d('../ide/include;../ide/include/'+TargetOS),
6097
5868
    da_Define));
6098
 
  // <LazarusSrcDir>/designer/jitform
6099
 
  SubDirTempl:=TDefineTemplate.Create('JITForm',ctsJITFormDirectory,
6100
 
    '','jitform',da_Directory);
6101
 
  SubDirTempl.AddChild(TDefineTemplate.Create('LCL path addition',
6102
 
    Format(ctsAddsDirToSourcePath,['lcl']),
6103
 
    SrcPathMacroName,
6104
 
      d('../../lcl'
6105
 
      +';../../lcl/interfaces/'+WidgetType)
6106
 
      +';'+SrcPath
6107
 
    ,da_Define));
6108
 
  DirTempl.AddChild(SubDirTempl);
6109
5869
  // <LazarusSrcDir>/designer/units
6110
 
  SubDirTempl:=TDefineTemplate.Create('Designer Units',
6111
 
    ctsDesignerUnitsDirectory,'','units',da_Directory);
6112
 
  SubDirTempl.AddChild(TDefineTemplate.Create('CompiledSrcPath',
6113
 
    ctsCompiledSrcPath,CompiledSrcPathMacroName,d('../jitform/'),
6114
 
    da_Define));
6115
 
  DirTempl.AddChild(SubDirTempl);
6116
5870
  MainDir.AddChild(DirTempl);
6117
5871
 
6118
5872
 
6129
5883
       +';'+LazarusSrcDir+'/debugger/frames'
6130
5884
       +';'+LazarusSrcDir+'/ide'
6131
5885
       +';'+LazarusSrcDir+'/ideintf'
 
5886
       +';'+LazarusSrcDir+'/components/lazutils'
6132
5887
       +';'+LazarusSrcDir+'/components/codetools'
6133
5888
       +';'+LazarusSrcDir+'/lcl'
 
5889
       +';'+LazarusSrcDir+'/lcl/interfaces'
6134
5890
       +';'+LazarusSrcDir+'/lcl/interfaces/'+WidgetType)
6135
5891
       +';'+SrcPath
6136
5892
    ,da_DefineRecurse));
6145
5901
    ExternalMacroStart+'SrcPath',
6146
5902
      d('../ide'
6147
5903
       +';../ideintf'
 
5904
       +';../components/lazutils'
6148
5905
       +';../components/codetools'
6149
5906
       +';../components/synedit'
6150
5907
       +';../components/lazcontrols'
6152
5909
       +';../debugger'
6153
5910
       +';../designer'
6154
5911
       +';../lcl'
 
5912
       +';../lcl/interfaces'
6155
5913
       +';../lcl/interfaces/'+WidgetType)
6156
5914
       +';'+SrcPath
6157
5915
    ,da_Define));
6165
5923
    Format(ctsAddsDirToSourcePath,['lcl synedit codetools lazcontrols ideintf']),
6166
5924
    SrcPathMacroName,
6167
5925
      d(LazarusSrcDir+'/lcl'
 
5926
      +';'+LazarusSrcDir+'/lcl/interfaces'
6168
5927
      +';'+LazarusSrcDir+'/lcl/interfaces/'+WidgetType
6169
5928
      +';'+LazarusSrcDir+'/ide'
6170
5929
      +';'+LazarusSrcDir+'/ideintf'
6171
5930
      +';'+LazarusSrcDir+'/components/synedit'
6172
5931
      +';'+LazarusSrcDir+'/components/lazcontrols'
 
5932
      +';'+LazarusSrcDir+'/components/lazutils'
6173
5933
      +';'+LazarusSrcDir+'/components/codetools'
6174
5934
      +';'+LazarusSrcDir+'/packager/frames'
6175
5935
      +';'+LazarusSrcDir+'/packager/registration'
6187
5947
  SubDirTempl.AddChild(TDefineTemplate.Create('src path addition',
6188
5948
    Format(ctsAddsDirToSourcePath,['ide']),
6189
5949
    SrcPathMacroName,
6190
 
    d(LazarusSrcDir+'/ide;'+SrcPath)
 
5950
    d(LazarusSrcDir+'/ide;'+LazarusSrcDir+'/packager;'+SrcPath)
6191
5951
    ,da_Define));
6192
5952
  // <LazarusSrcDir>/packager/registration
6193
5953
  SubDirTempl:=TDefineTemplate.Create('Registration',
6204
5964
  MainDir.AddChild(DirTempl);
6205
5965
 
6206
5966
 
6207
 
  // <LazarusSrcDir>/ideintf
6208
 
  IDEIntfDir:=TDefineTemplate.Create('IDEIntf',ctsIDEIntfDirectory,
6209
 
    '','ideintf',da_Directory);
6210
 
  IDEIntfDir.AddChild(TDefineTemplate.Create('LCL path addition',
6211
 
    Format(ctsAddsDirToSourcePath,['lcl']),
6212
 
    SrcPathMacroName,
6213
 
      d('../components/codetools'
6214
 
       +';../packager/registration'
6215
 
       +';../lcl'
6216
 
       +';../lcl/interfaces/'+WidgetType)
6217
 
       +';'+SrcPath
6218
 
    ,da_Define));
6219
 
  IDEIntfDir.AddChild(TDefineTemplate.Create('CompiledSrcPath',
6220
 
    ctsCompiledSrcPath,CompiledSrcPathMacroName,
6221
 
    LazarusSrcDir+d('/ideintf'),
6222
 
    da_DefineRecurse));
6223
 
  MainDir.AddChild(IDEIntfDir);
6224
 
 
6225
5967
  // <LazarusSrcDir>/examples
6226
5968
  DirTempl:=TDefineTemplate.Create('Examples',
6227
5969
    Format(ctsNamedDirectory,['Examples']),
6233
5975
      +';../lcl/interfaces/'+WidgetType+';'+SrcPath)
6234
5976
    ,da_Define));
6235
5977
  MainDir.AddChild(DirTempl);
6236
 
  
6237
 
  // <LazarusSrcDir>/lcl
6238
 
  DirTempl:=TDefineTemplate.Create('LCL',Format(ctsNamedDirectory,['LCL']),
6239
 
    '','lcl',da_Directory);
6240
 
  DirTempl.AddChild(TDefineTemplate.Create('IncludePath',
6241
 
     Format(ctsIncludeDirectoriesPlusDirs,['include']),
6242
 
     ExternalMacroStart+'IncPath',
6243
 
     'include',da_Define));
6244
 
  DirTempl.AddChild(TDefineTemplate.Create('LCL path addition',
6245
 
    Format(ctsAddsDirToSourcePath,['forms']),
6246
 
    ExternalMacroStart+'SrcPath','forms;'+SrcPath,da_Define));
6247
 
  DirTempl.AddChild(TDefineTemplate.Create('LCL path addition',
6248
 
    Format(ctsAddsDirToSourcePath,['widgetset']),
6249
 
    ExternalMacroStart+'SrcPath','widgetset;'+SrcPath,da_Define));
6250
 
    // #FPGUIPlatform
6251
 
    FPGUIPlatformTempl:=TDefineTemplate.Create('Define FPGUIPlatform',
6252
 
                               'Define FPGUIPlatform','','',da_Block);
6253
 
      IfTemplate:=TDefineTemplate.Create('IFDEF windows',
6254
 
        ctsIfDefWindows, 'windows', '', da_IfDef);
6255
 
        // then set #FPGUIPlatform to gdi
6256
 
        IfTemplate.AddChild(TDefineTemplate.Create('#FPGUIPlatform:=gdi',
6257
 
          '#FPGUIPlatform:=gdi',
6258
 
          ExternalMacroStart+'FPGUIPlatform','gdi',da_DefineRecurse));
6259
 
      FPGUIPlatformTempl.AddChild(IfTemplate);
6260
 
      ElseTemplate:=TDefineTemplate.Create('Else',
6261
 
        ctsElse, '', '', da_Else);
6262
 
        // then set #FPGUIPlatform to x11
6263
 
        ElseTemplate.AddChild(TDefineTemplate.Create('#FPGUIPlatform:=x11',
6264
 
          '#FPGUIPlatform:=x11',
6265
 
          ExternalMacroStart+'FPGUIPlatform','x11',da_DefineRecurse));
6266
 
      FPGUIPlatformTempl.AddChild(ElseTemplate);
6267
 
    DirTempl.AddChild(FPGUIPlatformTempl);
6268
 
  MainDir.AddChild(DirTempl);
6269
 
 
6270
 
  // <LazarusSrcDir>/lcl/forms
6271
 
  LCLWidgetSetDir:=TDefineTemplate.Create('forms',Format(ctsNamedDirectory,['WidgetSet']),
6272
 
    '','forms',da_Directory);
6273
 
  LCLWidgetSetDir.AddChild(TDefineTemplate.Create('LCL path addition',
6274
 
    Format(ctsAddsDirToSourcePath,['..']),
6275
 
    ExternalMacroStart+'SrcPath','..;'+SrcPath,da_Define));
6276
 
  DirTempl.AddChild(LCLWidgetSetDir);
6277
 
 
6278
 
  // <LazarusSrcDir>/lcl/widgetset
6279
 
  LCLWidgetSetDir:=TDefineTemplate.Create('widgetset',Format(ctsNamedDirectory,['WidgetSet']),
6280
 
    '','widgetset',da_Directory);
6281
 
  LCLWidgetSetDir.AddChild(TDefineTemplate.Create('LCL path addition',
6282
 
    Format(ctsAddsDirToSourcePath,['..']),
6283
 
    ExternalMacroStart+'SrcPath','..;'+SrcPath,da_Define));
6284
 
  DirTempl.AddChild(LCLWidgetSetDir);
6285
 
 
6286
 
  // <LazarusSrcDir>/lcl/units
6287
 
  LCLUnitsDir:=TDefineTemplate.Create('units',Format(ctsNamedDirectory,['Units']),
6288
 
    '','units',da_Directory);
6289
 
  DirTempl.AddChild(LCLUnitsDir);
6290
 
  for i:=Low(Lazarus_CPU_OS_Widget_Combinations)
6291
 
      to High(Lazarus_CPU_OS_Widget_Combinations) do
6292
 
  begin
6293
 
    SplitLazarusCPUOSWidgetCombo(Lazarus_CPU_OS_Widget_Combinations[i],
6294
 
                                 CurCPU,CurOS,CurWidgetSet);
6295
 
    // <LazarusSrcDir>/lcl/units/<TargetCPU>-<TargetOS>
6296
 
    // these directories contain the output of the LCL (excluding the interfaces)
6297
 
    CurCPUOS:=CurCPU+'-'+CurOS;
6298
 
    LCLUnitsCPUOSDir:=LCLUnitsDir.FindChildByName(CurCPUOS);
6299
 
    if LCLUnitsCPUOSDir=nil then begin
6300
 
      LCLUnitsCPUOSDir:=TDefineTemplate.Create(CurCPUOS,
6301
 
        Format(ctsNamedDirectory,[CurCPUOS]),
6302
 
        '',CurCPUOS,da_Directory);
6303
 
      LCLUnitsDir.AddChild(LCLUnitsCPUOSDir);
6304
 
 
6305
 
      ExtraSrcPath:='../..;../../widgetset';
6306
 
      if CurOS<>'win32' then
6307
 
        ExtraSrcPath:=ExtraSrcPath+';../../nonwin32';
6308
 
      LCLUnitsCPUOSDir.AddChild(TDefineTemplate.Create('CompiledSrcPath',
6309
 
         ctsSrcPathForCompiledUnits,CompiledSrcPathMacroName,
6310
 
         d(ExtraSrcPath),da_Define));
6311
 
    end;
6312
 
    // <LazarusSrcDir>/lcl/units/<TargetCPU>-<TargetOS>/<WidgetSet>
6313
 
    // these directories contain the output of the LCL interfaces
6314
 
    LCLUnitsCPUOSWidgetSetDir:=LCLUnitsCPUOSDir.FindChildByName(CurWidgetSet);
6315
 
    if LCLUnitsCPUOSWidgetSetDir=nil then begin
6316
 
      LCLUnitsCPUOSWidgetSetDir:=TDefineTemplate.Create(CurWidgetSet,
6317
 
        Format(ctsNamedDirectory,[CurWidgetSet]),
6318
 
        '',CurWidgetSet,da_Directory);
6319
 
      LCLUnitsCPUOSDir.AddChild(LCLUnitsCPUOSWidgetSetDir);
6320
 
      ExtraSrcPath:='../../../interfaces/'+CurWidgetSet;
6321
 
      if (CurWidgetSet='carbon') then
6322
 
        ExtraSrcPath:=ExtraSrcPath+';../../../interfaces/carbon/pascocoa/appkit;../../../interfaces/carbon/objc';
6323
 
      if (CurWidgetSet='fpgui') then
6324
 
        ExtraSrcPath:=ExtraSrcPath
6325
 
          +';../../../interfaces/fpgui/corelib'
6326
 
          +';../../../interfaces/fpgui/corelib/$('+ExternalMacroStart+'FPGUIPlatform)'
6327
 
          +';../../../interfaces/fpgui/gui';
6328
 
      LCLUnitsCPUOSWidgetSetDir.AddChild(
6329
 
        TDefineTemplate.Create('CompiledSrcPath',
6330
 
          ctsSrcPathForCompiledUnits,CompiledSrcPathMacroName,
6331
 
          d(ExtraSrcPath),da_Define));
6332
 
    end;
6333
 
  end;
6334
 
 
6335
 
  // <LazarusSrcDir>/lcl/interfaces
6336
 
  SubDirTempl:=TDefineTemplate.Create('interfaces',
6337
 
    ctsWidgetDirectory,'','interfaces',da_Directory);
6338
 
  // add lcl to the source path of all widget set directories
6339
 
  SubDirTempl.AddChild(TDefineTemplate.Create('LCL Path',
6340
 
    Format(ctsAddsDirToSourcePath,['lcl']),ExternalMacroStart+'SrcPath',
6341
 
    LazarusSrcDir+d('/lcl;')
6342
 
    +LazarusSrcDir+d('/lcl/widgetset;')
6343
 
    +SrcPath,
6344
 
    da_DefineRecurse));
6345
 
  DirTempl.AddChild(SubDirTempl);
6346
 
  
6347
 
  // <LazarusSrcDir>/lcl/interfaces/gtk
6348
 
  IntfDirTemplate:=TDefineTemplate.Create('gtk',
6349
 
    ctsIntfDirectory,'','gtk',da_Directory);
6350
 
  SubDirTempl.AddChild(IntfDirTemplate);
6351
 
 
6352
 
  // <LazarusSrcDir>/lcl/interfaces/gtk2
6353
 
  IntfDirTemplate:=TDefineTemplate.Create('gtk2',
6354
 
    ctsGtk2IntfDirectory,'','gtk2',da_Directory);
6355
 
  SubDirTempl.AddChild(IntfDirTemplate);
6356
 
  
6357
 
  // <LazarusSrcDir>/lcl/interfaces/win32
6358
 
  // no special
6359
 
 
6360
 
  // <LazarusSrcDir>/lcl/interfaces/wince
6361
 
  IntfDirTemplate:=TDefineTemplate.Create('wince',
6362
 
    ctsIntfDirectory,'','wince',da_Directory);
6363
 
    // then define wince1
6364
 
    IntfDirTemplate.AddChild(TDefineTemplate.Create('Define wince1',
6365
 
      ctsDefineMacroWinCE1,'wince1','',da_Define));
6366
 
  SubDirTempl.AddChild(IntfDirTemplate);
6367
 
 
6368
 
  // <LazarusSrcDir>/lcl/interfaces/carbon
6369
 
  IntfDirTemplate:=TDefineTemplate.Create('carbon',
6370
 
    ctsIntfDirectory,'','carbon',da_Directory);
6371
 
    // then define carbon1
6372
 
    IntfDirTemplate.AddChild(TDefineTemplate.Create('Define carbon1',
6373
 
      ctsDefineMacroCarbon1,'carbon1','',da_Define));
6374
 
    // add 'pascocoa/appkit' to the SrcPath
6375
 
    IntfDirTemplate.AddChild(TDefineTemplate.Create('SrcPath',
6376
 
      Format(ctsAddsDirToSourcePath,['pascocoa']),ExternalMacroStart+'SrcPath',
6377
 
      d('pascocoa/appkit;pascocoa/foundation;')+SrcPath,da_Define));
6378
 
  SubDirTempl.AddChild(IntfDirTemplate);
6379
 
 
6380
 
  // <LazarusSrcDir>/lcl/interfaces/qt
6381
 
  IntfDirTemplate:=TDefineTemplate.Create('qt',
6382
 
    ctsIntfDirectory,'','qt',da_Directory);
6383
 
    // then define qt1
6384
 
    IntfDirTemplate.AddChild(TDefineTemplate.Create('Define qt1',
6385
 
      ctsDefineMacroQT1,'qt1','',da_Define));
6386
 
  SubDirTempl.AddChild(IntfDirTemplate);
6387
 
 
6388
 
  // <LazarusSrcDir>/lcl/interfaces/fpgui
6389
 
  IntfDirTemplate:=TDefineTemplate.Create('fpgui',
6390
 
    ctsIntfDirectory,'','fpgui',da_Directory);
6391
 
    // add unit paths
6392
 
    IntfDirTemplate.AddChild(TDefineTemplate.Create('Add gui, corelib to SrcPath',
6393
 
    Format(ctsAddsDirToSourcePath,['gui, corelib']),
6394
 
      ExternalMacroStart+'SrcPath',
6395
 
      d(LazarusSrcDir+'/lcl/interfaces/fpgui/gui')
6396
 
      +';'+d(LazarusSrcDir+'/lcl/interfaces/fpgui/corelib')
6397
 
      +';'+d(LazarusSrcDir+'/lcl/interfaces/fpgui/corelib/$('+ExternalMacroStart+'FPGUIPlatform)')
6398
 
      +';'+SrcPath
6399
 
      ,da_DefineRecurse));
6400
 
    // and include path
6401
 
    IntfDirTemplate.AddChild(TDefineTemplate.Create('Add corelib to IncPath',
6402
 
    Format(ctsAddsDirToIncludePath,['corelib']),
6403
 
      ExternalMacroStart+'IncPath',
6404
 
      d(LazarusSrcDir+'/lcl/interfaces/fpgui/corelib')
6405
 
      +';'+d(LazarusSrcDir+'/lcl/interfaces/fpgui/corelib/$('+ExternalMacroStart+'FPGUIPlatform)')
6406
 
      +';'+IncPath
6407
 
      ,da_Define));
6408
 
  SubDirTempl.AddChild(IntfDirTemplate);
6409
5978
 
6410
5979
  // <LazarusSrcDir>/components
6411
5980
  DirTempl:=TDefineTemplate.Create('Components',ctsComponentsDirectory,
6412
5981
    '','components',da_Directory);
6413
 
  DirTempl.AddChild(TDefineTemplate.Create('LCL Path',
6414
 
    Format(ctsAddsDirToSourcePath,['lcl']),
6415
 
    ExternalMacroStart+'SrcPath',
6416
 
    d(LazarusSrcDir+'/lcl'
6417
 
    +';'+LazarusSrcDir+'/lcl/interfaces/'+WidgetType)
6418
 
    +';'+SrcPath
6419
 
    ,da_DefineRecurse));
6420
 
 
6421
 
  // <LazarusSrcDir>/components/synedit
6422
 
  SynEditDirTempl:=TDefineTemplate.Create('synedit',
6423
 
    'SynEdit','','synedit',da_Directory);
6424
 
  SynEditDirTempl.AddChild(TDefineTemplate.Create('IDEIntf Path',
6425
 
    Format(ctsAddsDirToSourcePath,['ideintf']),
6426
 
    ExternalMacroStart+'SrcPath',
6427
 
    d(LazarusSrcDir+'/ideintf')
6428
 
    +';'+SrcPath
6429
 
    ,da_DefineRecurse));
6430
 
  // <LazarusSrcDir>/components/synedit/units
6431
 
  SynEditUnitsDirTempl:=TDefineTemplate.Create('synedit output directory',
6432
 
    'units','','units',da_Directory);
6433
 
  SynEditDirTempl.AddChild(SynEditUnitsDirTempl);
6434
 
  SynEditUnitsDirTempl.AddChild(TDefineTemplate.Create('CompiledSrcPath',
6435
 
     ctsSrcPathForCompiledUnits,
6436
 
     ExternalMacroStart+'CompiledSrcPath',
6437
 
     d(LazarusSrcDir+'components/synedit')
6438
 
     ,da_DefineRecurse));
6439
 
  DirTempl.AddChild(SynEditDirTempl);
6440
 
 
6441
 
  // <LazarusSrcDir>/components/lazcontrols
6442
 
  LazControlsDirTempl:=TDefineTemplate.Create('lazcontrols',
6443
 
    'LazControls','','lazcontrols',da_Directory);
6444
 
  // <LazarusSrcDir>/components/lazcontrols/lib
6445
 
  LazControlsUnitsDirTempl:=TDefineTemplate.Create('lazcontrols output directory',
6446
 
    'lib','','lib',da_Directory);
6447
 
  LazControlsDirTempl.AddChild(LazControlsUnitsDirTempl);
6448
 
  LazControlsUnitsDirTempl.AddChild(TDefineTemplate.Create('CompiledSrcPath',
6449
 
     ctsSrcPathForCompiledUnits,
6450
 
     ExternalMacroStart+'CompiledSrcPath',
6451
 
     d(LazarusSrcDir+'components/lazcontrols')
6452
 
     ,da_DefineRecurse));
6453
 
  DirTempl.AddChild(LazControlsDirTempl);
6454
 
 
6455
 
  // <LazarusSrcDir>/components/codetools/units
6456
 
  CodeToolsDirTempl:=TDefineTemplate.Create('codetools',
6457
 
    'CodeTools','','codetools',da_Directory);
6458
 
  CodeToolsUnitsDirTempl:=TDefineTemplate.Create('codetools output directory',
6459
 
    'units','','units',da_Directory);
6460
 
  CodeToolsDirTempl.AddChild(CodeToolsUnitsDirTempl);
6461
 
  CodeToolsUnitsDirTempl.AddChild(TDefineTemplate.Create('CompiledSrcPath',
6462
 
     ctsSrcPathForCompiledUnits,
6463
 
     ExternalMacroStart+'CompiledSrcPath',
6464
 
     d(LazarusSrcDir+'components/codetools')
6465
 
     ,da_DefineRecurse));
6466
 
  DirTempl.AddChild(CodeToolsDirTempl);
6467
5982
 
6468
5983
  // <LazarusSrcDir>/components/custom
6469
5984
  SubDirTempl:=TDefineTemplate.Create('Custom Components',
6766
6281
  var
6767
6282
    NewAction: TDefineAction;
6768
6283
  begin
 
6284
    //debugln(['AddDefine Name="',AName,'" Var="',AVariable,'" Value="',AValue,'"']);
6769
6285
    if RecursiveDefines then
6770
6286
      NewAction:=da_DefineRecurse
6771
6287
    else
6813
6329
  StartPos, EndPos: Integer;
6814
6330
  s: string;
6815
6331
  CompilerMode: String;
 
6332
  m: Integer;
6816
6333
begin
6817
6334
  Result:=nil;
6818
6335
  if AlwaysCreate then
6860
6377
          CompilerMode:=copy(CmdLine,StartPos,EndPos-StartPos);
6861
6378
        end;
6862
6379
 
 
6380
      'W':
 
6381
        begin
 
6382
          inc(StartPos,2);
 
6383
          if StartPos<EndPos then begin
 
6384
            case CmdLine[StartPos] of
 
6385
            'p':
 
6386
              begin
 
6387
                // controller unit
 
6388
                AddDefine('Define '+MacroControllerUnit,
 
6389
                  ctsDefine+MacroControllerUnit,MacroControllerUnit,
 
6390
                  copy(CmdLine,StartPos+1,EndPos-StartPos-1));
 
6391
              end;
 
6392
            end;
 
6393
          end;
 
6394
        end;
 
6395
 
6863
6396
      end;
6864
6397
    end;
6865
6398
  end;
6866
6399
  if CompilerMode<>'' then begin
6867
 
    AddDefineUndefine('FPC_FPC',SysUtils.CompareText(CompilerMode,'FPC')=0);
6868
 
    AddDefineUndefine('FPC_ObjFPC',SysUtils.CompareText(CompilerMode,'ObjFPC')=0);
6869
 
    AddDefineUndefine('FPC_Delphi',SysUtils.CompareText(CompilerMode,'Delphi')=0);
6870
 
    AddDefineUndefine('FPC_TP',SysUtils.CompareText(CompilerMode,'TP')=0);
6871
 
    AddDefineUndefine('FPC_GPC',SysUtils.CompareText(CompilerMode,'GPC')=0);
6872
 
    AddDefineUndefine('FPC_MACPAS',SysUtils.CompareText(CompilerMode,'MACPAS')=0);
 
6400
    for m:=low(FPCSyntaxModes) to high(FPCSyntaxModes) do
 
6401
      AddDefineUndefine('FPC_'+FPCSyntaxModes[m],SysUtils.CompareText(CompilerMode,FPCSyntaxModes[m])=0);
6873
6402
  end;
6874
6403
 
6875
6404
  Result.SetDefineOwner(Owner,true);
6937
6466
  if FItems.Count=0 then exit;
6938
6467
  for i:=0 to FItems.Count-1 do
6939
6468
    TObject(FItems[i]).Free;
 
6469
  FItems.Clear;
6940
6470
  IncreaseChangeStamp;
6941
6471
end;
6942
6472
 
6963
6493
    SrcRule:=Rules[i];
6964
6494
    Rule:=Add(SrcRule.Filename);
6965
6495
    Rule.Assign(SrcRule);
 
6496
    //debugln(['TFPCSourceRules.Assign ',i,' ',Rule.Targets,' ',Rule.Filename]);
6966
6497
  end;
6967
6498
  IncreaseChangeStamp;
6968
6499
end;
7015
6546
begin
7016
6547
  if RulesSortedForFilenameStart=nil then
7017
6548
    RulesSortedForFilenameStart:=
7018
 
                        TAVLTree.Create(@CompareFPCSourceRulesViaFilenameStart);
 
6549
                             TAVLTree.Create(@CompareFPCSourceRulesViaFilename);
7019
6550
  for i:=0 to Count-1 do
7020
6551
    if Items[i].FitsTargets(Targets) then
7021
6552
      RulesSortedForFilenameStart.Add(Items[i]);
7157
6688
 
7158
6689
constructor TFPCTargetConfigCache.Create(AOwner: TComponent);
7159
6690
begin
7160
 
  FChangeStamp:=CTInvalidChangeStamp;
 
6691
  CTIncreaseChangeStamp(FChangeStamp); // set to not 0
7161
6692
  inherited Create(AOwner);
7162
6693
  ConfigFiles:=TFPCConfigFileStateList.Create;
7163
6694
  if Owner is TFPCTargetConfigCaches then
7180
6711
  RealTargetCPU:='';
7181
6712
  RealTargetOS:='';
7182
6713
  RealCompilerInPath:='';
 
6714
  FullVersion:='';
7183
6715
  HasPPUs:=false;
7184
6716
  ConfigFiles.Clear;
7185
6717
  ErrorMsg:='';
7235
6767
    or (RealTargetOS<>Item.RealTargetOS)
7236
6768
    or (RealTargetCPU<>Item.RealTargetCPU)
7237
6769
    or (RealCompilerInPath<>Item.RealCompilerInPath)
 
6770
    or (FullVersion<>Item.FullVersion)
7238
6771
    or (HasPPUs<>Item.HasPPUs)
7239
6772
    or (not ConfigFiles.Equals(Item.ConfigFiles,true))
7240
6773
  then
7264
6797
    RealTargetOS:=Item.RealTargetOS;
7265
6798
    RealTargetCPU:=Item.RealTargetCPU;
7266
6799
    RealCompilerInPath:=Item.RealCompilerInPath;
 
6800
    FullVersion:=Item.FullVersion;
7267
6801
    HasPPUs:=Item.HasPPUs;
7268
6802
    ConfigFiles.Assign(Item.ConfigFiles);
7269
6803
    if Item.Defines<>nil then begin
7325
6859
  RealTargetOS:=XMLConfig.GetValue(Path+'RealCompiler/OS','');
7326
6860
  RealTargetCPU:=XMLConfig.GetValue(Path+'RealCompiler/CPU','');
7327
6861
  RealCompilerInPath:=XMLConfig.GetValue(Path+'RealCompiler/InPath','');
 
6862
  FullVersion:=XMLConfig.GetValue(Path+'RealCompiler/FullVersion','');
7328
6863
  HasPPUs:=XMLConfig.GetValue(Path+'HasPPUs',true);
7329
6864
  ConfigFiles.LoadFromXMLConfig(XMLConfig,Path+'Configs/');
7330
6865
 
7433
6968
  XMLConfig.SetDeleteValue(Path+'RealCompiler/OS',RealTargetOS,'');
7434
6969
  XMLConfig.SetDeleteValue(Path+'RealCompiler/CPU',RealTargetCPU,'');
7435
6970
  XMLConfig.SetDeleteValue(Path+'RealCompiler/InPath',RealCompilerInPath,'');
 
6971
  XMLConfig.SetDeleteValue(Path+'RealCompiler/FullVersion',FullVersion,'');
7436
6972
  XMLConfig.SetDeleteValue(Path+'HasPPUs',HasPPUs,true);
7437
6973
  ConfigFiles.SaveToXMLConfig(XMLConfig,Path+'Configs/');
7438
6974
 
7553
7089
begin
7554
7090
  Result:=true;
7555
7091
  if (not FileExistsCached(Compiler)) then begin
7556
 
    debugln(['TFPCTargetConfigCache.NeedsUpdate compiler file missing "',Compiler,'"']);
 
7092
    debugln(['TFPCTargetConfigCache.NeedsUpdate TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" compiler file missing "',Compiler,'"']);
7557
7093
    exit;
7558
7094
  end;
7559
7095
  if (FileAgeCached(Compiler)<>CompilerDate) then begin
7560
 
    debugln(['TFPCTargetConfigCache.NeedsUpdate compiler file changed "',Compiler,'" FileAge=',FileAgeCached(Compiler),' StoredAge=',CompilerDate]);
 
7096
    debugln(['TFPCTargetConfigCache.NeedsUpdate TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" compiler file changed "',Compiler,'" FileAge=',FileAgeCached(Compiler),' StoredAge=',CompilerDate]);
7561
7097
    exit;
7562
7098
  end;
7563
7099
  if (RealCompiler<>'') and (CompareFilenames(RealCompiler,Compiler)<>0)
7564
7100
  then begin
7565
7101
    if (not FileExistsCached(RealCompiler))
7566
7102
    or (FileAgeCached(RealCompiler)<>RealCompilerDate) then begin
7567
 
      debugln(['TFPCTargetConfigCache.NeedsUpdate real compiler file changed "',RealCompiler,'"']);
7568
 
      exit;
7569
 
    end;
7570
 
    // fpc searches via PATH for the real compiler, resolves any symlink
7571
 
    // and that is the RealCompiler
7572
 
    // check if PATH
7573
 
    AFilename:=FindRealCompilerInPath(TargetCPU,true);
7574
 
    if RealCompilerInPath<>AFilename then begin
7575
 
      debugln(['TFPCTargetConfigCache.NeedsUpdate real compiler in PATH changed from "',RealCompilerInPath,'" to "',AFilename,'"']);
7576
 
      exit;
7577
 
    end;
 
7103
      debugln(['TFPCTargetConfigCache.NeedsUpdate TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" real compiler file changed "',RealCompiler,'"']);
 
7104
      exit;
 
7105
    end;
 
7106
  end;
 
7107
  // fpc searches via PATH for the real compiler, resolves any symlink
 
7108
  // and that is the RealCompiler
 
7109
  AFilename:=FindRealCompilerInPath(TargetCPU,true);
 
7110
  if RealCompilerInPath<>AFilename then begin
 
7111
    debugln(['TFPCTargetConfigCache.NeedsUpdate TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" real compiler in PATH changed from "',RealCompilerInPath,'" to "',AFilename,'"']);
 
7112
    exit;
7578
7113
  end;
7579
7114
  for i:=0 to ConfigFiles.Count-1 do begin
7580
7115
    Cfg:=ConfigFiles[i];
7581
7116
    if Cfg.Filename='' then continue;
7582
7117
    if FileExistsCached(Cfg.Filename)<>Cfg.FileExists then begin
7583
 
      debugln(['TFPCTargetConfigCache.NeedsUpdate config fileexists changed "',Cfg.Filename,'"']);
 
7118
      debugln(['TFPCTargetConfigCache.NeedsUpdate TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" config fileexists changed "',Cfg.Filename,'"']);
7584
7119
      exit;
7585
7120
    end;
7586
7121
    if Cfg.FileExists and (FileAgeCached(Cfg.Filename)<>Cfg.FileDate) then begin
7587
 
      debugln(['TFPCTargetConfigCache.NeedsUpdate config file changed "',Cfg.Filename,'"']);
 
7122
      debugln(['TFPCTargetConfigCache.NeedsUpdate TargetOS="',TargetOS,'" TargetCPU="',TargetCPU,'" config file changed "',Cfg.Filename,'"']);
7588
7123
      exit;
7589
7124
    end;
7590
7125
  end;
7591
7126
  Result:=false;
7592
7127
end;
7593
7128
 
 
7129
function TFPCTargetConfigCache.GetFPCInfoCmdLineOptions(ExtraOptions: string
 
7130
  ): string;
 
7131
var
 
7132
  CurTargetCPU: String;
 
7133
  CurTargetOS: String;
 
7134
begin
 
7135
  Result:=CompilerOptions;
 
7136
  // Note: always pass the -P and -T options so that the compiler writes the
 
7137
  // target macros with -va
 
7138
  CurTargetCPU:=TargetCPU;
 
7139
  if CurTargetCPU='' then
 
7140
    CurTargetCPU:=GetCompiledTargetCPU;
 
7141
  Result:=Result+' -P'+LowerCase(CurTargetCPU);
 
7142
  CurTargetOS:=TargetOS;
 
7143
  if CurTargetOS='' then
 
7144
    CurTargetOS:=GetCompiledTargetOS;
 
7145
  Result:=Result+' -T'+LowerCase(CurTargetOS);
 
7146
  Result:=Result+' '+ExtraOptions;
 
7147
  Result:=Trim(Result);
 
7148
end;
 
7149
 
7594
7150
procedure TFPCTargetConfigCache.IncreaseChangeStamp;
7595
7151
begin
7596
7152
  CTIncreaseChangeStamp(FChangeStamp);
7609
7165
  CfgFileDate: Integer;
7610
7166
  Info: String;
7611
7167
  Infos: TFPCInfoStrings;
 
7168
  InfoTypes: TFPCInfoTypes;
7612
7169
begin
7613
7170
  OldOptions:=TFPCTargetConfigCache.Create(nil);
7614
7171
  CfgFiles:=nil;
7620
7177
    debugln(['TFPCTargetConfigCache.Update ',Compiler,' TargetOS=',TargetOS,' TargetCPU=',TargetCPU,' CompilerOptions=',CompilerOptions,' ExtraOptions=',ExtraOptions,' PATH=',GetEnvironmentVariableUTF8('PATH')]);
7621
7178
    CompilerDate:=FileAgeCached(Compiler);
7622
7179
    if FileExistsCached(Compiler) then begin
7623
 
 
7624
 
      if CompilerOptions<>'' then
7625
 
        ExtraOptions:=CompilerOptions+' '+ExtraOptions;
7626
 
      if TargetOS<>'' then
7627
 
        ExtraOptions:='-T'+LowerCase(TargetOS)+' '+ExtraOptions;
7628
 
      if TargetCPU<>'' then
7629
 
        ExtraOptions:='-P'+LowerCase(TargetCPU)+' '+ExtraOptions;
7630
 
      ExtraOptions:=Trim(ExtraOptions);
 
7180
      ExtraOptions:=GetFPCInfoCmdLineOptions(ExtraOptions);
7631
7181
 
7632
7182
      // get real OS and CPU
7633
 
      Info:=RunFPCInfo(Compiler,[fpciTargetOS,fpciTargetProcessor],ExtraOptions);
7634
 
      if ParseFPCInfo(Info,[fpciTargetOS,fpciTargetProcessor],Infos) then begin
 
7183
      InfoTypes:=[fpciTargetOS,fpciTargetProcessor,fpciFullVersion];
 
7184
      Info:=RunFPCInfo(Compiler,InfoTypes,ExtraOptions);
 
7185
      if ParseFPCInfo(Info,InfoTypes,Infos) then begin
7635
7186
        RealTargetOS:=Infos[fpciTargetOS];
7636
7187
        RealTargetCPU:=Infos[fpciTargetProcessor];
 
7188
        FullVersion:=Infos[fpciFullVersion];
7637
7189
      end else begin
7638
7190
        RealTargetOS:=TargetOS;
7639
7191
        if RealTargetOS='' then
7652
7204
        for i:=0 to UnitPaths.Count-1 do
7653
7205
          UnitPaths[i]:=ChompPathDelim(TrimFilename(UnitPaths[i]));
7654
7206
      // store the real compiler file and date
7655
 
      if (RealCompiler<>'') and FileExistsCached(RealCompiler) then
 
7207
      if (RealCompiler<>'') and FileExistsCached(RealCompiler) then begin
7656
7208
        RealCompilerDate:=FileAgeCached(RealCompiler);
 
7209
      end else
 
7210
        debugln(['TFPCTargetConfigCache.Update WARNING: compiler is broken: '+Compiler+' '+ExtraOptions]);
7657
7211
      // store the list of tried and read cfg files
7658
 
      if CfgFiles<>nil then begin
 
7212
      if CfgFiles<>nil then
7659
7213
        for i:=0 to CfgFiles.Count-1 do begin
7660
7214
          Filename:=CfgFiles[i];
7661
7215
          if Filename='' then continue;
7666
7220
            CfgFileDate:=FileAgeCached(Filename);
7667
7221
          ConfigFiles.Add(Filename,CfgFileExists,CfgFileDate);
7668
7222
        end;
7669
 
      end;
7670
7223
      // gather all units in all unit search paths
7671
7224
      if (UnitPaths<>nil) and (UnitPaths.Count>0) then
7672
7225
        Units:=GatherUnitsInSearchPaths(UnitPaths,OnProgress)
7691
7244
 
7692
7245
function TFPCTargetConfigCache.FindRealCompilerInPath(aTargetCPU: string;
7693
7246
  ResolveLinks: boolean): string;
 
7247
 
 
7248
  function Search(const ShortFileName: string): string;
 
7249
  begin
 
7250
    // fpc.exe first searches in -XP
 
7251
    // Maybe: extact -XP from extra options
 
7252
 
 
7253
    // then fpc.exe searches in its own directory
 
7254
    if Compiler<>'' then begin
 
7255
      Result:=ExtractFilePath(Compiler);
 
7256
      if FilenameIsAbsolute(Result) then begin
 
7257
        Result+=ShortFileName;
 
7258
        if FileExistsCached(Result) then
 
7259
          exit;
 
7260
      end;
 
7261
    end;
 
7262
    // finally fpc.exe searches in PATH
 
7263
    Result:=SearchFileInPath(ShortFileName,GetCurrentDirUTF8,
 
7264
      GetEnvironmentVariableUTF8('PATH'),PathSeparator,ctsfcDefault);
 
7265
    if (Result<>'') or (Compiler='') then exit;
 
7266
  end;
 
7267
 
7694
7268
var
7695
 
  ShortFileName: String;
 
7269
  CompiledTargetCPU: String;
 
7270
  Cross: Boolean;
7696
7271
begin
7697
7272
  Result:='';
 
7273
  CompiledTargetCPU:=GetCompiledTargetCPU;
7698
7274
  if aTargetCPU='' then
7699
 
    aTargetCPU:=GetCompiledTargetCPU;
7700
 
  ShortFileName:=GetDefaultCompilerFilename(aTargetCPU);
7701
 
  if ShortFileName='' then exit;
7702
 
  // try in PATH
7703
 
  Result:=SearchFileInPath(ShortFileName,GetCurrentDirUTF8,
7704
 
    GetEnvironmentVariableUTF8('PATH'),PathSeparator,ctsfcDefault);
7705
 
  if (Result='') and (Compiler<>'') then
7706
 
  begin
7707
 
    // try in directory of compiler
7708
 
    Result:=ExtractFilePath(Compiler)+ShortFileName;
7709
 
    if not FileExistsCached(Result) then
7710
 
      Result:='';
 
7275
    aTargetCPU:=CompiledTargetCPU;
 
7276
  Cross:=aTargetCPU<>CompiledTargetCPU;
 
7277
  Result:=Search(GetDefaultCompilerFilename(aTargetCPU,Cross));
 
7278
  if (Result='') and Cross then begin
 
7279
    Result:=Search(GetDefaultCompilerFilename(aTargetCPU,false));
 
7280
    if Result='' then exit;
7711
7281
  end;
7712
 
  if Result='' then exit;
7713
7282
  if ResolveLinks then
7714
7283
    Result:=TryReadAllLinks(Result);
7715
7284
end;
7716
7285
 
7717
 
function TFPCTargetConfigCache.GetFPCVer(out FPCVersion, FPCRelease,
 
7286
function TFPCTargetConfigCache.GetUnitPaths: string;
 
7287
begin
 
7288
  if UnitPaths=nil then exit('');
 
7289
  UnitPaths.Delimiter:=';';
 
7290
  UnitPaths.StrictDelimiter:=true;
 
7291
  Result:=UnitPaths.DelimitedText;
 
7292
end;
 
7293
 
 
7294
function TFPCTargetConfigCache.GetFPCVerNumbers(out FPCVersion, FPCRelease,
7718
7295
  FPCPatch: integer): boolean;
7719
7296
var
7720
7297
  v: string;
7728
7305
  end;
7729
7306
end;
7730
7307
 
 
7308
function TFPCTargetConfigCache.GetFPCVer: string;
 
7309
var
 
7310
  FPCVersion: integer;
 
7311
  FPCRelease: integer;
 
7312
  FPCPatch: integer;
 
7313
begin
 
7314
  if GetFPCVerNumbers(FPCVersion,FPCRelease,FPCPatch) then
 
7315
    Result:=IntToStr(FPCVersion)+'.'+IntToStr(FPCRelease)+'.'+IntToStr(FPCPatch)
 
7316
  else
 
7317
    Result:='';
 
7318
end;
 
7319
 
 
7320
function TFPCTargetConfigCache.IndexOfUsedCfgFile: integer;
 
7321
begin
 
7322
  if ConfigFiles=nil then exit(-1);
 
7323
  Result:=0;
 
7324
  while (Result<ConfigFiles.Count) and (not ConfigFiles[Result].FileExists) do
 
7325
    inc(Result);
 
7326
  if Result=ConfigFiles.Count then Result:=-1;
 
7327
end;
 
7328
 
7731
7329
{ TFPCTargetConfigCaches }
7732
7330
 
7733
7331
constructor TFPCTargetConfigCaches.Create(AOwner: TComponent);
7734
7332
begin
7735
 
  FChangeStamp:=CTInvalidChangeStamp;
 
7333
  CTIncreaseChangeStamp(FChangeStamp); // set to not 0
7736
7334
  inherited Create(AOwner);
7737
7335
  fItems:=TAVLTree.Create(@CompareFPCTargetConfigCacheItems);
7738
7336
end;
7890
7488
  end;
7891
7489
end;
7892
7490
 
 
7491
function TFPCTargetConfigCaches.GetListing: string;
 
7492
var
 
7493
  Node: TAVLTreeNode;
 
7494
  CfgCache: TFPCTargetConfigCache;
 
7495
  i: Integer;
 
7496
begin
 
7497
  Result:='TFPCTargetConfigCaches.GetListing Count='+dbgs(fItems.Count)+LineEnding;
 
7498
  i:=0;
 
7499
  Node:=fItems.FindLowest;
 
7500
  while Node<>nil do begin
 
7501
    inc(i);
 
7502
    CfgCache:=TFPCTargetConfigCache(Node.Data);
 
7503
    Result+='  '+dbgs(i)+':'
 
7504
           +' TargetOS="'+CfgCache.TargetOS+'"'
 
7505
           +' TargetCPU="'+CfgCache.TargetCPU+'"'
 
7506
           +' Compiler="'+CfgCache.Compiler+'"'
 
7507
           +' CompilerOptions="'+CfgCache.CompilerOptions+'"'
 
7508
           +LineEnding;
 
7509
    Node:=fItems.FindSuccessor(Node);
 
7510
  end;
 
7511
end;
 
7512
 
7893
7513
{ TFPCConfigFileStateList }
7894
7514
 
7895
7515
function TFPCConfigFileStateList.GetItems(Index: integer): TFPCConfigFileState;
8021
7641
  inherited Create(AOwner);
8022
7642
  Files:=TStringList.Create;
8023
7643
  Valid:=false;
8024
 
  FChangeStamp:=CTInvalidChangeStamp;
 
7644
  CTIncreaseChangeStamp(FChangeStamp); // set to not 0
8025
7645
  if Owner is TFPCSourceCaches then
8026
7646
    Caches:=TFPCSourceCaches(Owner);
8027
7647
end;
8174
7794
 
8175
7795
constructor TFPCSourceCaches.Create(AOwner: TComponent);
8176
7796
begin
8177
 
  FChangeStamp:=CTInvalidChangeStamp;
 
7797
  CTIncreaseChangeStamp(FChangeStamp); // set to not 0
8178
7798
  inherited Create(AOwner);
8179
7799
  fItems:=TAVLTree.Create(@CompareFPCSourceCacheItems);
8180
7800
end;
8325
7945
 
8326
7946
{ TFPCDefinesCache }
8327
7947
 
8328
 
procedure TFPCDefinesCache.SetConfigCaches(const AValue: TFPCTargetConfigCaches
8329
 
  );
 
7948
procedure TFPCDefinesCache.SetConfigCaches(const AValue: TFPCTargetConfigCaches);
8330
7949
begin
8331
7950
  if FConfigCaches=AValue then exit;
8332
7951
  FConfigCaches:=AValue;
8565
8184
var
8566
8185
  NewFilename: String;
8567
8186
begin
8568
 
  NewFilename:=CleanAndExpandFilename(AValue);
 
8187
  NewFilename:=TrimAndExpandFilename(AValue);
8569
8188
  if FCompilerFilename=NewFilename then exit;
8570
8189
  FCompilerFilename:=NewFilename;
8571
8190
  ClearConfigCache;
8582
8201
var
8583
8202
  NewValue: String;
8584
8203
begin
8585
 
  NewValue:=CleanAndExpandDirectory(AValue);
 
8204
  NewValue:=TrimAndExpandDirectory(AValue);
8586
8205
  if FFPCSourceDirectory=NewValue then exit;
8587
8206
  FFPCSourceDirectory:=NewValue;
8588
8207
  ClearSourceCache;
8629
8248
constructor TFPCUnitSetCache.Create(TheOwner: TComponent);
8630
8249
begin
8631
8250
  inherited Create(TheOwner);
8632
 
  FChangeStamp:=CTInvalidChangeStamp;
 
8251
  CTIncreaseChangeStamp(FChangeStamp); // set ot not 0
8633
8252
  FCaches:=TheOwner as TFPCDefinesCache;
8634
8253
  fUnitToSourceTree:=TStringToStringTree.Create(false);
8635
8254
  fSrcDuplicates:=TStringToStringTree.Create(false);
8765
8384
  Result:=fSrcDuplicates;
8766
8385
end;
8767
8386
 
8768
 
function TFPCUnitSetCache.GetUnitSrcFile(const AUnitName: string;
8769
 
  MustHavePPU: boolean; SkipPPUCheckIfNoneExists: boolean): string;
 
8387
function TFPCUnitSetCache.GetUnitSrcFile(const AnUnitName: string;
 
8388
  MustHavePPU: boolean; SkipPPUCheckIfTargetIsSourceOnly: boolean): string;
8770
8389
var
8771
8390
  Tree: TStringToStringTree;
8772
8391
  ConfigCache: TFPCTargetConfigCache;
8773
8392
begin
8774
8393
  Result:='';
 
8394
  {$IFDEF ShowTriedUnits}
 
8395
  debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" MustHavePPU=',MustHavePPU,' SkipPPUCheckIfNoneExists=',SkipPPUCheckIfNoneExists]);
 
8396
  {$ENDIF}
8775
8397
  Tree:=GetUnitToSourceTree(false);
8776
8398
  if MustHavePPU then begin
8777
8399
    ConfigCache:=GetConfigCache(false);
8778
8400
    if (ConfigCache.Units<>nil)
8779
 
      and (CompareFileExt(ConfigCache.Units[AUnitName],'ppu',false)<>0)
 
8401
      and (CompareFileExt(ConfigCache.Units[AnUnitName],'ppu',false)<>0)
8780
8402
    then begin
8781
8403
      // unit has no ppu in the FPC ppu search path
8782
8404
      if ConfigCache.HasPPUs then begin
8783
8405
        // but there are other ppu files
 
8406
        {$IFDEF ShowTriedUnits}
 
8407
        debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" unit has no ppu file in FPC path, but there are other ppu']);
 
8408
        {$ENDIF}
8784
8409
        exit;
8785
8410
      end else begin
8786
8411
        // no ppu exists at all
8787
8412
        // => the fpc is not installed properly for this target
8788
 
        if not SkipPPUCheckIfNoneExists then
 
8413
        {$IFDEF ShowTriedUnits}
 
8414
        debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" there are no ppu files for this target']);
 
8415
        {$ENDIF}
 
8416
        if not SkipPPUCheckIfTargetIsSourceOnly then
8789
8417
          exit;
8790
8418
        // => search directly in the sources
8791
8419
        // this allows cross editing even if FPC is not installed for this target
8793
8421
    end;
8794
8422
  end;
8795
8423
  if Tree<>nil then begin
8796
 
    Result:=Tree[AUnitName];
8797
 
    if Result<>'' then
 
8424
    Result:=Tree[AnUnitName];
 
8425
    if (Result<>'') and (not FilenameIsAbsolute(Result)) then
8798
8426
      Result:=FPCSourceDirectory+Result;
 
8427
    if (Result='') then begin
 
8428
      // maybe the source is in the fpc search path
 
8429
      ConfigCache:=GetConfigCache(false);
 
8430
      if ConfigCache<>nil then begin
 
8431
        Result:=ConfigCache.Units[AnUnitName];
 
8432
        if (CompareFileExt(Result,'ppu',false)=0) then begin
 
8433
          Result:='';
 
8434
          exit;
 
8435
        end;
 
8436
      end;
 
8437
    end;
 
8438
    {$IFDEF ShowTriedUnits}
 
8439
    debugln(['TFPCUnitSetCache.GetUnitSrcFile Unit="',AnUnitName,'" Result=',Result]);
 
8440
    {$ENDIF}
8799
8441
  end;
8800
8442
end;
8801
8443
 
 
8444
function TFPCUnitSetCache.GetCompiledUnitFile(const AUnitName: string): string;
 
8445
var
 
8446
  ConfigCache: TFPCTargetConfigCache;
 
8447
begin
 
8448
  Result:='';
 
8449
  ConfigCache:=GetConfigCache(false);
 
8450
  if ConfigCache.Units=nil then exit;
 
8451
  Result:=ConfigCache.Units[AUnitName];
 
8452
  if Result='' then exit;
 
8453
  if CompareFileExt(Result,'.ppu',false)<>0 then
 
8454
    Result:='';
 
8455
end;
 
8456
 
8802
8457
class function TFPCUnitSetCache.GetInvalidChangeStamp: integer;
8803
8458
begin
8804
8459
  Result:=CTInvalidChangeStamp;
8815
8470
                              CompilerOptions,FPCSourceDirectory,ChangeStamp);
8816
8471
end;
8817
8472
 
 
8473
function TFPCUnitSetCache.GetFirstFPCCfg: string;
 
8474
var
 
8475
  Cfg: TFPCTargetConfigCache;
 
8476
  i: Integer;
 
8477
begin
 
8478
  Result:='';
 
8479
  Cfg:=GetConfigCache(false);
 
8480
  if Cfg=nil then exit;
 
8481
  if Cfg.ConfigFiles=nil then exit;
 
8482
  for i:=0 to Cfg.ConfigFiles.Count-1 do begin
 
8483
    if Cfg.ConfigFiles[i].FileExists then begin
 
8484
      Result:=Cfg.ConfigFiles[i].Filename;
 
8485
      exit;
 
8486
    end;
 
8487
  end;
 
8488
end;
 
8489
 
8818
8490
initialization
8819
8491
  InitDefaultFPCSourceRules;
8820
8492