;
; Templates used by fpcmake to create a Makefile from Makefile.fpc
;

[defines]
#####################################################################
# Misc defines to be used by anyone
#####################################################################

# OS categories
BSDs = freebsd netbsd openbsd darwin
UNIXs = linux $(BSDs) solaris qnx haiku
LIMIT83fs = go32v2 os2 emx watcom
OSNeedsComspecToRunBatch = go32v2 watcom

#Empty target for rules that always should run. Needed if
#the target is non-phoney, and there is non-phony prereqisites.
#Then add FORCE as an prerequisite
#See gnu make manual: 4.7 Rules without Commands or Prerequisites
FORCE:
.PHONY: FORCE

[osdetect]
#####################################################################
# Autodetect source OS (Linux or Dos or Windows NT or OS/2 or other)
# define inUnix when running under Unix like environment
#               (Linux,FreeBSD,NetBSD,OpenBSD,Darwin,Cygwin)
# define inWinNT when running under WinNT
# define inOS2 when running under OS/2
# define inCygwin when running under Cygwin32
#####################################################################

# We need only / in the path also remove the current dir,
# also remove trailing /'s
override PATH:=$(patsubst %/,%,$(subst \,/,$(PATH)))

# Detect unix
# Darwin is handled specially
ifneq ($(findstring darwin,$(OSTYPE)),)
inUnix=1 #darwin
SEARCHPATH:=$(filter-out .,$(subst :, ,$(PATH)))
else
# Determine if we've a unix searchpath by looking for a ;
# that normally doesn't exists in the unix PATH var.
ifeq ($(findstring ;,$(PATH)),)
inUnix=1
SEARCHPATH:=$(filter-out .,$(subst :, ,$(PATH)))
else
SEARCHPATH:=$(subst ;, ,$(PATH))
endif
endif

# Add path were make is located
SEARCHPATH+=$(patsubst %/,%,$(subst \,/,$(dir $(MAKE))))

# Search for PWD
PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
ifeq ($(PWD),)
PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
ifeq ($(PWD),)
$(error You need the GNU utils package to use this Makefile)
else
PWD:=$(firstword $(PWD))
SRCEXEEXT=
endif
else
PWD:=$(firstword $(PWD))
SRCEXEEXT=.exe
endif

# Detect NT - NT sets OS to Windows_NT
# Detect OS/2 - OS/2 has OS2_SHELL defined
ifndef inUnix
ifeq ($(OS),Windows_NT)
inWinNT=1
else
ifdef OS2_SHELL
inOS2=1
endif
endif
else
ifneq ($(findstring cygdrive,$(PATH)),)
inCygWin=1
endif
endif

# The extension of batch files / scripts
ifdef inUnix
SRCBATCHEXT=.sh
else
ifdef inOS2
SRCBATCHEXT=.cmd
else
SRCBATCHEXT=.bat
endif
endif

ifdef COMSPEC
ifneq ($(findstring $(OS_SOURCE),$(OSNeedsComspecToRunBatch)),)
ifndef RUNBATCH
RUNBATCH=$(COMSPEC) /C
endif
endif
endif

# Path Separator, the subst trick is necessary for the \ that can't exists
# at the end of a line
ifdef inUnix
PATHSEP=/
else
PATHSEP:=$(subst /,\,/)
# cygwin bash or sh can not handle backslashs
ifdef inCygWin
PATHSEP=/
endif
endif

# Base dir
ifdef PWD
BASEDIR:=$(subst \,/,$(shell $(PWD)))
# For Cygwin we need to replace /cygdrive/c/ with c:/
ifdef inCygWin
ifneq ($(findstring /cygdrive/,$(BASEDIR)),)
BASENODIR:=$(patsubst /cygdrive%,%,$(BASEDIR))
BASEDRIVE:=$(firstword $(subst /, ,$(BASENODIR)))
BASEDIR:=$(subst /cygdrive/$(BASEDRIVE)/,$(BASEDRIVE):/,$(BASEDIR))
endif
endif
else
BASEDIR=.
endif

# Echo is an internal command under OS/2 (and others), so it's always found
ifdef inOS2
ifndef ECHO
ECHO:=$(strip $(wildcard $(addsuffix /gecho$(SRCEXEEXT),$(SEARCHPATH))))
ifeq ($(ECHO),)
ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
ifeq ($(ECHO),)
ECHO=echo
else
ECHO:=$(firstword $(ECHO))
endif
else
ECHO:=$(firstword $(ECHO))
endif
endif
export ECHO
endif

[fpcdetect]
#####################################################################
# FPC Binary and Version Detection
#####################################################################

# Compatibility with old makefiles
ifndef FPC
ifdef PP
FPC=$(PP)
endif
endif

# Try to detect the ppcXXX file to use by using "fpc -PB" option
# to query for the default ppcXXX the fpc executable tries. When
# fpc is not found use ppc386 by default. Also when fpc -PB gives
# an error ppc386 will be used.
ifndef FPC
# check if fpc exists
FPCPROG:=$(strip $(wildcard $(addsuffix /fpc$(SRCEXEEXT),$(SEARCHPATH))))
ifneq ($(FPCPROG),)
FPCPROG:=$(firstword $(FPCPROG))
ifneq ($(CPU_TARGET),)
FPC:=$(shell $(FPCPROG) -P$(CPU_TARGET) -PB)
else
FPC:=$(shell $(FPCPROG) -PB)
endif
# Older fpc executables didn't support it and return
# Error: Illegal processor... If found then fallback to ppc386
ifneq ($(findstring Error,$(FPC)),)
override FPC=$(firstword $(strip $(wildcard $(addsuffix /ppc386$(SRCEXEEXT),$(SEARCHPATH)))))
else
# if the cross compiler is not found, fall back to fpc
ifeq ($(strip $(wildcard $(FPC))),)
FPC:=$(firstword $(FPCPROG))
endif
endif
else
# fpc binary not found, fallback to ppc386
override FPC=$(firstword $(strip $(wildcard $(addsuffix /ppc386$(SRCEXEEXT),$(SEARCHPATH)))))
endif
endif

# Get a clean executable name
override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)

# Try to find the binary direct first, otherwise in the path,
# if not found give an error
FOUNDFPC:=$(strip $(wildcard $(FPC)))
ifeq ($(FOUNDFPC),)
FOUNDFPC=$(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))
ifeq ($(FOUNDFPC),)
$(error Compiler $(FPC) not found)
endif
endif

# For 1.1 and up we can use a single compiler call to retrieve
# all needed information
ifndef FPC_COMPILERINFO
FPC_COMPILERINFO:=$(shell $(FPC) -iVSPTPSOTO)
endif

# FPC version
ifndef FPC_VERSION
FPC_VERSION:=$(word 1,$(FPC_COMPILERINFO))
endif

export FPC FPC_VERSION FPC_COMPILERINFO
# CHECKDEPEND should not be exported
# This should limit multiple checks
unexport CHECKDEPEND ALLDEPENDENCIES

#####################################################################
# FPC Target Detection
#####################################################################

# Fall back to default values if needed
ifndef CPU_TARGET
ifdef CPU_TARGET_DEFAULT
CPU_TARGET=$(CPU_TARGET_DEFAULT)
endif
endif
ifndef OS_TARGET
ifdef OS_TARGET_DEFAULT
OS_TARGET=$(OS_TARGET_DEFAULT)
endif
endif

# Retrieve Target/Source CPU and Target/Source OS
ifndef CPU_SOURCE
CPU_SOURCE:=$(word 2,$(FPC_COMPILERINFO))
endif
ifndef CPU_TARGET
CPU_TARGET:=$(word 3,$(FPC_COMPILERINFO))
endif
ifndef OS_SOURCE
OS_SOURCE:=$(word 4,$(FPC_COMPILERINFO))
endif
ifndef OS_TARGET
OS_TARGET:=$(word 5,$(FPC_COMPILERINFO))
endif
FULL_TARGET=$(CPU_TARGET)-$(OS_TARGET)
FULL_SOURCE=$(CPU_SOURCE)-$(OS_SOURCE)

ifeq ($(CPU_TARGET),armeb)
ARCH=arm
override FPCOPT+=-Cb
else
ifeq ($(CPU_TARGET),armel)
ARCH=arm
override FPCOPT+=-CaEABI
else
ARCH=$(CPU_TARGET)
endif
endif

# Full name of the target, including CPU and OS. For OSs limited
# to 8.3 we only use the target OS
ifneq ($(findstring $(OS_SOURCE),$(LIMIT83fs)),)
TARGETSUFFIX=$(OS_TARGET)
SOURCESUFFIX=$(OS_SOURCE)
else
ifneq ($(findstring $(OS_TARGET),$(LIMIT83fs)),)
TARGETSUFFIX=$(OS_TARGET)
else
TARGETSUFFIX=$(FULL_TARGET)
endif
SOURCESUFFIX=$(FULL_SOURCE)
endif

# Cross compile flag
ifneq ($(FULL_TARGET),$(FULL_SOURCE))
CROSSCOMPILE=1
endif

# Check if the Makefile supports this target, but not
# when the make target is to rebuild the makefile
ifeq ($(findstring makefile,$(MAKECMDGOALS)),)
ifeq ($(findstring $(FULL_TARGET),$(MAKEFILETARGETS)),)
$(error The Makefile doesn't support target $(FULL_TARGET), please run fpcmake first)
endif
endif


# Detect BSD, since BSD uses a slightly different directory hierarchy.
ifneq ($(findstring $(OS_TARGET),$(BSDs)),)
BSDhier=1
endif

# Detect Linux, will also use its own directory hierarchy.
ifeq ($(OS_TARGET),linux)
linuxHier=1
endif

export OS_TARGET OS_SOURCE ARCH CPU_TARGET CPU_SOURCE FULL_TARGET FULL_SOURCE TARGETSUFFIX SOURCESUFFIX CROSSCOMPILE

[fpmakefpcdetect]
#####################################################################
# FPC Binary and Version Detection
#####################################################################
# If FPCFPMAKE is not set and we're cross-compiling, try to find a
# native compiler.
ifndef FPCFPMAKE

ifdef CROSSCOMPILE
# Search for the (native) ppc compiler which is used to do the latest build
# of the native rtl

ifeq ($(strip $(wildcard $(addsuffix /compiler/ppc$(SRCEXEEXT),$(FPCDIR)))),)
# If that compiler is not found, use the common, installed native compiler
# Note that in this case FPCFPMAKE is not exported, because it could be that
# a more suitable compiler is compiled later on
# check if fpc exists
FPCPROG:=$(strip $(wildcard $(addsuffix /fpc$(SRCEXEEXT),$(SEARCHPATH))))
ifneq ($(FPCPROG),)
FPCPROG:=$(firstword $(FPCPROG))
FPCFPMAKE:=$(shell $(FPCPROG) -PB)
# if a native compiler is not found, fall back to fpc
ifeq ($(strip $(wildcard $(FPCFPMAKE))),)
FPCFPMAKE:=$(firstword $(FPCPROG))
endif
else
# fpc binary not found, fallback to ppc386
override FPCFPMAKE=$(firstword $(strip $(wildcard $(addsuffix /ppc386$(SRCEXEEXT),$(SEARCHPATH)))))
endif
else
# Use the ppc compiler. Because the path to the compiler is relative, do not
# evaluate the variable here, but do that on the fly.
FPCFPMAKE=$(strip $(wildcard $(addsuffix /compiler/ppc$(SRCEXEEXT),$(FPCDIR))))
FPMAKE_SKIP_CONFIG=-n
export FPCFPMAKE
export FPMAKE_SKIP_CONFIG
endif

else
FPMAKE_SKIP_CONFIG=-n
FPCFPMAKE=$(FPC)
endif

endif


[fpcdircheckenv]
#####################################################################
# FPCDIR Setting
#####################################################################

# Test FPCDIR to look if the RTL dir exists
ifdef FPCDIR
override FPCDIR:=$(subst \,/,$(FPCDIR))
ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
override FPCDIR=wrong
endif
else
override FPCDIR=wrong
endif

# Default FPCDIR from Makefile.fpc
ifdef DEFAULT_FPCDIR
ifeq ($(FPCDIR),wrong)
override FPCDIR:=$(subst \,/,$(DEFAULT_FPCDIR))
ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
override FPCDIR=wrong
endif
endif
endif

[fpcdirdetect]
# Detect FPCDIR
ifeq ($(FPCDIR),wrong)
ifdef inUnix
override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
ifeq ($(wildcard $(FPCDIR)/units),)
override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
endif
else
override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
override FPCDIR:=$(FPCDIR)/..
ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
override FPCDIR:=$(FPCDIR)/..
ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
override FPCDIR:=$(BASEDIR)
ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
override FPCDIR=c:/pp
endif
endif
endif
endif
endif

# Cross binaries dir
ifndef CROSSBINDIR
CROSSBINDIR:=$(wildcard $(FPCDIR)/bin/$(TARGETSUFFIX))
endif

# Default binutils prefix for cross compile when the
# crossbindir is not set (except for Darwin)
ifneq ($(findstring $(OS_TARGET),darwin iphonesim),)
ifeq ($(OS_SOURCE),darwin)
DARWIN2DARWIN=1
endif
endif

ifndef BINUTILSPREFIX
ifndef CROSSBINDIR
ifdef CROSSCOMPILE
ifndef DARWIN2DARWIN
BINUTILSPREFIX=$(CPU_TARGET)-$(OS_TARGET)-
endif
endif
endif
endif

# Try first the full target name, otherwise try only
# the OS for backwards compatibility
UNITSDIR:=$(wildcard $(FPCDIR)/units/$(TARGETSUFFIX))
ifeq ($(UNITSDIR),)
UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
endif

# Packages dir
PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(FPCDIR)/packages/extra)


[shelltools]
#####################################################################
# Shell tools
#####################################################################

# Echo that can redir (must be able run in the default OS shell)
ifndef ECHOREDIR
ifndef inUnix
ECHOREDIR=echo
else
ECHOREDIR=$(ECHO)
endif
endif

# To copy pograms
ifndef COPY
COPY:=$(CPPROG) -fp
endif

# Copy a whole tree
ifndef COPYTREE
COPYTREE:=$(CPPROG) -Rfp
endif

# Copy a whole tree
ifndef MKDIRTREE
MKDIRTREE:=$(MKDIRPROG) -p
endif

# To move pograms
ifndef MOVE
MOVE:=$(MVPROG) -f
endif

# Check delete program
ifndef DEL
DEL:=$(RMPROG) -f
endif

# Check deltree program
ifndef DELTREE
DELTREE:=$(RMPROG) -rf
endif

# To install files
ifndef INSTALL
ifdef inUnix
INSTALL:=$(GINSTALL) -c -m 644
else
INSTALL:=$(COPY)
endif
endif

# To install programs
ifndef INSTALLEXE
ifdef inUnix
INSTALLEXE:=$(GINSTALL) -c -m 755
else
INSTALLEXE:=$(COPY)
endif
endif

# To make a directory.
ifndef MKDIR
MKDIR:=$(GINSTALL) -m 755 -d
endif

export ECHOREDIR COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR


[defaultdirs]
#####################################################################
# Default Directories
#####################################################################

# Units dir
ifdef REQUIRE_UNITSDIR
override UNITSDIR+=$(REQUIRE_UNITSDIR)
endif

# Units dir
ifdef REQUIRE_PACKAGESDIR
override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
endif


# Unixes use unix dirs with /usr/bin, /usr/lib
# When zipping use the target os default, when normal install then
# use the source os as default
ifdef ZIPINSTALL
# Zipinstall
ifneq ($(findstring $(OS_TARGET),$(UNIXs)),)
UNIXHier=1
endif
else
# Normal install
ifneq ($(findstring $(OS_SOURCE),$(UNIXs)),)
UNIXHier=1
endif
endif

# When install prefix is not set try to use prefix
ifndef INSTALL_PREFIX
ifdef PREFIX
INSTALL_PREFIX=$(PREFIX)
endif
endif

# set the prefix directory where to install everything
ifndef INSTALL_PREFIX
ifdef UNIXHier
INSTALL_PREFIX=/usr/local
else
ifdef INSTALL_FPCPACKAGE
INSTALL_BASEDIR:=/pp
else
INSTALL_BASEDIR:=/$(PACKAGE_NAME)
endif
endif
endif
export INSTALL_PREFIX

# Export also INSTALL_SOURCESUBDIR set so it will be
# used recursively for all subdirs
ifdef INSTALL_FPCSUBDIR
export INSTALL_FPCSUBDIR
endif

# Where to place the resulting zip files
ifndef DIST_DESTDIR
DIST_DESTDIR:=$(BASEDIR)
endif
export DIST_DESTDIR

# EXE/PPU Target directories
ifndef COMPILER_UNITTARGETDIR
ifdef PACKAGEDIR_MAIN
COMPILER_UNITTARGETDIR=$(PACKAGEDIR_MAIN)/units/$(TARGETSUFFIX)
else
COMPILER_UNITTARGETDIR=units/$(TARGETSUFFIX)
endif
endif
ifndef COMPILER_TARGETDIR
COMPILER_TARGETDIR=.
endif


#####################################################################
# Install Directories
#####################################################################

# set the base directory where to install everything
ifndef INSTALL_BASEDIR
ifdef UNIXHier
ifdef INSTALL_FPCPACKAGE
INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
else
INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
endif
else
INSTALL_BASEDIR:=$(INSTALL_PREFIX)
endif
endif

# set the directory where to install the binaries
ifndef INSTALL_BINDIR
ifdef UNIXHier
INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
else
INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
# for FPC packages install the binaries under their target subdir
ifdef INSTALL_FPCPACKAGE
ifdef CROSSCOMPILE
ifdef CROSSINSTALL
INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(SOURCESUFFIX)
else
INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(TARGETSUFFIX)
endif
else
INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(TARGETSUFFIX)
endif
endif
endif
endif

# set the directory where to install the units.
ifndef INSTALL_UNITDIR
INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(TARGETSUFFIX)
ifdef INSTALL_FPCPACKAGE
ifdef PACKAGE_NAME
INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
endif
endif
endif

# Where to install shared libraries
ifndef INSTALL_LIBDIR
ifdef UNIXHier
INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
else
INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
endif
endif

# Where the source files will be stored
ifndef INSTALL_SOURCEDIR
ifdef UNIXHier
ifdef BSDhier
SRCPREFIXDIR=share/src
else
ifdef linuxHier
SRCPREFIXDIR=share/src
else
SRCPREFIXDIR=src
endif
endif
ifdef INSTALL_FPCPACKAGE
ifdef INSTALL_FPCSUBDIR
INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/$(SRCPREFIXDIR)/fpc-$(FPC_VERSION)/$(INSTALL_FPCSUBDIR)/$(PACKAGE_NAME)
else
INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/$(SRCPREFIXDIR)/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
endif
else
INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/$(SRCPREFIXDIR)/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
endif
else
ifdef INSTALL_FPCPACKAGE
ifdef INSTALL_FPCSUBDIR
INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(INSTALL_FPCSUBDIR)/$(PACKAGE_NAME)
else
INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
endif
else
INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source
endif
endif
endif

# Where the doc files will be stored
ifndef INSTALL_DOCDIR
ifdef UNIXHier
ifdef BSDhier
DOCPREFIXDIR=share/doc
else
ifdef linuxHier
DOCPREFIXDIR=share/doc
else
DOCPREFIXDIR=doc
endif
endif
ifdef INSTALL_FPCPACKAGE
INSTALL_DOCDIR:=$(INSTALL_PREFIX)/$(DOCPREFIXDIR)/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
else
INSTALL_DOCDIR:=$(INSTALL_PREFIX)/$(DOCPREFIXDIR)/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
endif
else
ifdef INSTALL_FPCPACKAGE
INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
else
INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
endif
endif
endif

# Where to install the examples, under linux we use the doc dir
# because the copytree command will create a subdir itself
ifndef INSTALL_EXAMPLEDIR
ifdef UNIXHier
ifdef INSTALL_FPCPACKAGE

ifdef BSDhier
INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/share/examples/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
else
ifdef linuxHier
INSTALL_EXAMPLEDIR:=$(INSTALL_DOCDIR)/examples
else
INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
endif
endif

else

ifdef BSDhier
INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/share/examples/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
else
ifdef linuxHier
INSTALL_EXAMPLEDIR:=$(INSTALL_DOCDIR)/examples/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
else
INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
endif

endif
endif
else
ifdef INSTALL_FPCPACKAGE
INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
else
INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
endif
endif
endif

# Where the some extra (data)files will be stored
ifndef INSTALL_DATADIR
INSTALL_DATADIR=$(INSTALL_BASEDIR)
endif

ifndef INSTALL_SHAREDDIR
INSTALL_SHAREDDIR=$(INSTALL_PREFIX)/lib
endif

#####################################################################
# Cross compile dirs
#####################################################################

ifdef CROSSCOMPILE
# Directory where the cross compile tools are stored.
# First check if they are available in FPCDIR. If no targets/ subdir
# is found use the targets/ subdir in INSTALL_BASEDIR.
ifndef CROSSBINDIR
CROSSBINDIR:=$(wildcard $(CROSSTARGETDIR)/bin/$(SOURCESUFFIX))
ifeq ($(CROSSBINDIR),)
CROSSBINDIR:=$(wildcard $(INSTALL_BASEDIR)/cross/$(TARGETSUFFIX)/bin/$(FULL_SOURCE))
endif
endif
else
CROSSBINDIR=
endif


[dirlibc]
# On linux, try to find where libgcc.a is.
ifeq ($(OS_SOURCE),linux)

# Amd64 to i386?
ifndef GCCLIBDIR
ifeq ($(CPU_TARGET),i386)
ifneq ($(findstring x86_64,$(shell uname -a)),)
ifeq ($(BINUTILSPREFIX),)
GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
endif
endif
endif
ifeq ($(CPU_TARGET),powerpc64)
ifeq ($(BINUTILSPREFIX),)
GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
endif
endif
endif

# Try cross gcc
ifndef GCCLIBDIR
CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
ifneq ($(CROSSGCC),)
GCCLIBDIR:=$(shell dirname `$(CROSSGCC) -print-libgcc-file-name`)
endif
endif

# Other libraries from ld.so.conf
ifndef OTHERLIBDIR
OTHERLIBDIR:=$(shell grep -v "^\#" /etc/ld.so.conf | awk '{ ORS=" "; print $1 }')
endif
endif

ifdef inUnix
ifeq ($(OS_SOURCE),netbsd)
OTHERLIBDIR+=/usr/pkg/lib
endif
export GCCLIBDIR OTHERLIB
endif


[extensions]
#####################################################################
# Default extensions
#####################################################################

# Default needed extensions (Go32v2,Linux)
BATCHEXT=.bat
LOADEREXT=.as
EXEEXT=.exe
PPLEXT=.ppl
PPUEXT=.ppu
OEXT=.o
ASMEXT=.s
SMARTEXT=.sl
STATICLIBEXT=.a
SHAREDLIBEXT=.so
SHAREDLIBPREFIX=libfp
STATICLIBPREFIX=libp
IMPORTLIBPREFIX=libimp
RSTEXT=.rst
# external debug info for executable
EXEDBGEXT=.dbg
#DEBUGSYMEXT #for debugger symbol files, define only for targets which has this

# Go32v1
ifeq ($(OS_TARGET),go32v1)
STATICLIBPREFIX=
SHORTSUFFIX=v1
endif

# Go32v2
ifeq ($(OS_TARGET),go32v2)
STATICLIBPREFIX=
SHORTSUFFIX=dos
IMPORTLIBPREFIX=
endif

# watcom
ifeq ($(OS_TARGET),watcom)
STATICLIBPREFIX=
OEXT=.obj
ASMEXT=.asm
SHAREDLIBEXT=.dll
SHORTSUFFIX=wat
IMPORTLIBPREFIX=
endif

# Linux
ifeq ($(OS_TARGET),linux)
BATCHEXT=.sh
EXEEXT=
HASSHAREDLIB=1
SHORTSUFFIX=lnx
endif

# FreeBSD
ifeq ($(OS_TARGET),freebsd)
BATCHEXT=.sh
EXEEXT=
HASSHAREDLIB=1
SHORTSUFFIX=fbs
endif

# NetBSD
ifeq ($(OS_TARGET),netbsd)
BATCHEXT=.sh
EXEEXT=
HASSHAREDLIB=1
SHORTSUFFIX=nbs
endif

# OpenBSD
ifeq ($(OS_TARGET),openbsd)
BATCHEXT=.sh
EXEEXT=
HASSHAREDLIB=1
SHORTSUFFIX=obs
endif

# Win32
ifeq ($(OS_TARGET),win32)
SHAREDLIBEXT=.dll
SHORTSUFFIX=w32
endif

# OS/2
ifeq ($(OS_TARGET),os2)
BATCHEXT=.cmd
AOUTEXT=.out
STATICLIBPREFIX=
SHAREDLIBEXT=.dll
SHORTSUFFIX=os2
ECHO=echo
IMPORTLIBPREFIX=
endif

# EMX
ifeq ($(OS_TARGET),emx)
BATCHEXT=.cmd
AOUTEXT=.out
STATICLIBPREFIX=
SHAREDLIBEXT=.dll
SHORTSUFFIX=emx
ECHO=echo
IMPORTLIBPREFIX=
endif

# Amiga
ifeq ($(OS_TARGET),amiga)
EXEEXT=
SHAREDLIBEXT=.library
SHORTSUFFIX=amg
endif

# MorphOS
ifeq ($(OS_TARGET),morphos)
EXEEXT=
SHAREDLIBEXT=.library
SHORTSUFFIX=mos
endif

# Atari
ifeq ($(OS_TARGET),atari)
EXEEXT=.ttp
SHORTSUFFIX=ata
endif

# BeOS
ifeq ($(OS_TARGET),beos)
BATCHEXT=.sh
EXEEXT=
SHORTSUFFIX=be
endif

# Haiku
ifeq ($(OS_TARGET),haiku)
BATCHEXT=.sh
EXEEXT=
SHORTSUFFIX=hai
endif

# Solaris
ifeq ($(OS_TARGET),solaris)
BATCHEXT=.sh
EXEEXT=
SHORTSUFFIX=sun
endif

# QNX
ifeq ($(OS_TARGET),qnx)
BATCHEXT=.sh
EXEEXT=
SHORTSUFFIX=qnx
endif

# Netware clib
ifeq ($(OS_TARGET),netware)
EXEEXT=.nlm
STATICLIBPREFIX=
SHORTSUFFIX=nw
IMPORTLIBPREFIX=imp
endif

# Netware libc
ifeq ($(OS_TARGET),netwlibc)
EXEEXT=.nlm
STATICLIBPREFIX=
SHORTSUFFIX=nwl
IMPORTLIBPREFIX=imp
endif

# MacOS
ifeq ($(OS_TARGET),macos)
BATCHEXT=
EXEEXT=
DEBUGSYMEXT=.xcoff
SHORTSUFFIX=mac
IMPORTLIBPREFIX=imp
endif

# Darwin
ifneq ($(findstring $(OS_TARGET),darwin iphonesim),)
BATCHEXT=.sh
EXEEXT=
HASSHAREDLIB=1
SHORTSUFFIX=dwn
EXEDBGEXT=.dSYM
endif

# gba
ifeq ($(OS_TARGET),gba)
EXEEXT=.gba
SHAREDLIBEXT=.so
SHORTSUFFIX=gba
endif

# Symbian OS
ifeq ($(OS_TARGET),symbian)
SHAREDLIBEXT=.dll
SHORTSUFFIX=symbian
endif

# NativeNT
ifeq ($(OS_TARGET),NativeNT)
SHAREDLIBEXT=.dll
SHORTSUFFIX=nativent
endif

# wii
ifeq ($(OS_TARGET),wii)
EXEEXT=.dol
SHAREDLIBEXT=.so
SHORTSUFFIX=wii
endif

# For 8.3 limited OS's the short suffixes
# Otherwise use the full source/target names
ifneq ($(findstring $(OS_SOURCE),$(LIMIT83fs)),)
FPCMADE=fpcmade.$(SHORTSUFFIX)
ZIPSUFFIX=$(SHORTSUFFIX)
ZIPCROSSPREFIX=
ZIPSOURCESUFFIX=src
ZIPEXAMPLESUFFIX=exm
else
FPCMADE=fpcmade.$(TARGETSUFFIX)
ZIPSOURCESUFFIX=.source
ZIPEXAMPLESUFFIX=.examples
ifdef CROSSCOMPILE
ZIPSUFFIX=.$(SOURCESUFFIX)
ZIPCROSSPREFIX=$(TARGETSUFFIX)-
else
ZIPSUFFIX=.$(TARGETSUFFIX)
ZIPCROSSPREFIX=
endif
endif

[defaulttools]
#####################################################################
# Default Tools
#####################################################################

# Names of the binutils tools
ASNAME=$(BINUTILSPREFIX)as
LDNAME=$(BINUTILSPREFIX)ld
ARNAME=$(BINUTILSPREFIX)ar
RCNAME=$(BINUTILSPREFIX)rc

# assembler, redefine it if cross compiling
ifndef ASPROG
ifdef CROSSBINDIR
ASPROG=$(CROSSBINDIR)/$(ASNAME)$(SRCEXEEXT)
else
ASPROG=$(ASNAME)
endif
endif

# linker, but probably not used
ifndef LDPROG
ifdef CROSSBINDIR
LDPROG=$(CROSSBINDIR)/$(LDNAME)$(SRCEXEEXT)
else
LDPROG=$(LDNAME)
endif
endif

# Resource compiler
ifndef RCPROG
ifdef CROSSBINDIR
RCPROG=$(CROSSBINDIR)/$(RCNAME)$(SRCEXEEXT)
else
RCPROG=$(RCNAME)
endif
endif

# Archiver
ifndef ARPROG
ifdef CROSSBINDIR
ARPROG=$(CROSSBINDIR)/$(ARNAME)$(SRCEXEEXT)
else
ARPROG=$(ARNAME)
endif
endif

# Override defaults
AS=$(ASPROG)
LD=$(LDPROG)
RC=$(RCPROG)
AR=$(ARPROG)

# ppas.bat / ppas.sh
PPAS=ppas$(SRCBATCHEXT)

# ldconfig to rebuild .so cache
ifdef inUnix
LDCONFIG=ldconfig
else
LDCONFIG=
endif

ifdef DATE
DATESTR:=$(shell $(DATE) +%Y%m%d)
else
DATESTR=
endif

# Look if UPX is found for go32v2 and win32. We can't use $UPX because
# upx uses that one itself (PFV)
ifndef UPXPROG
ifeq ($(OS_TARGET),go32v2)
UPXPROG:=1
endif
# today's harddisks are large enough so using upx
# makes no sense especially because it causes
# some trouble, see e.g. #20772
ifeq ($(OS_TARGET),win32)
UPXPROG:=
endif
ifdef UPXPROG
UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
ifeq ($(UPXPROG),)
UPXPROG=
else
UPXPROG:=$(firstword $(UPXPROG))
endif
else
UPXPROG=
endif
endif
export UPXPROG

# Zip options
ZIPOPT=-9
ZIPEXT=.zip

# Tar options
ifeq ($(USETAR),bz2)
TAROPT=vj
TAREXT=.tar.bz2
else
TAROPT=vz
TAREXT=.tar.gz
endif


[command_begin]
#####################################################################
# Compiler Command Line
#####################################################################

# Load commandline OPTDEF and add FPC_CPU define, for compiling the
# compiler this needs to be turned off
ifndef NOCPUDEF
override FPCOPTDEF=$(ARCH)
endif


# Load commandline OPT and add target and unit dir to be sure
ifneq ($(OS_TARGET),$(OS_SOURCE))
override FPCOPT+=-T$(OS_TARGET)
endif

ifneq ($(CPU_TARGET),$(CPU_SOURCE))
override FPCOPT+=-P$(ARCH)
endif

ifeq ($(OS_SOURCE),openbsd)
override FPCOPT+=-FD$(NEW_BINUTILS_PATH)
endif

ifndef CROSSBOOTSTRAP
ifneq ($(BINUTILSPREFIX),)
override FPCOPT+=-XP$(BINUTILSPREFIX)
endif
ifneq ($(BINUTILSPREFIX),)
override FPCOPT+=-Xr$(RLINKPATH)
endif
endif

# User dirs should be first, so they are looked at first
ifdef UNITDIR
override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
endif
ifdef LIBDIR
override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
endif
ifdef OBJDIR
override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
endif
ifdef INCDIR
override FPCOPT+=$(addprefix -Fi,$(INCDIR))
endif

# Smartlinking
ifdef LINKSMART
override FPCOPT+=-XX
endif

# Smartlinking creation
ifdef CREATESMART
override FPCOPT+=-CX
endif

# Debug
ifdef DEBUG
override FPCOPT+=-gl
override FPCOPTDEF+=DEBUG
endif

# Release mode
# (strip, optimize and don't load fpc.cfg)
# fpc 2.1 has -O2 for all targets
ifdef RELEASE
ifneq ($(findstring 2.0.,$(FPC_VERSION)),)
ifeq ($(CPU_TARGET),i386)
FPCCPUOPT:=-OG2p3
endif
ifeq ($(CPU_TARGET),powerpc)
FPCCPUOPT:=-O1r
endif
else
FPCCPUOPT:=-O2
endif
override FPCOPT+=-Ur -Xs $(FPCCPUOPT) -n
override FPCOPTDEF+=RELEASE
endif

# Strip
ifdef STRIP
override FPCOPT+=-Xs
endif

# Optimizer
ifdef OPTIMIZE
override FPCOPT+=-O2
endif

# Verbose settings (warning,note,info)
ifdef VERBOSE
override FPCOPT+=-vwni
endif

# Needed compiler options
ifdef COMPILER_OPTIONS
override FPCOPT+=$(COMPILER_OPTIONS)
endif
ifdef COMPILER_UNITDIR
override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
endif
ifdef COMPILER_LIBRARYDIR
override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
endif
ifdef COMPILER_OBJECTDIR
override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
endif
ifdef COMPILER_INCLUDEDIR
override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
endif

# Cross compiler utils
ifdef CROSSBINDIR
override FPCOPT+=-FD$(CROSSBINDIR)
endif

# Target dirs and the prefix to use for clean/install
ifdef COMPILER_TARGETDIR
override FPCOPT+=-FE$(COMPILER_TARGETDIR)
ifeq ($(COMPILER_TARGETDIR),.)
override TARGETDIRPREFIX=
else
override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
endif
endif

# Unit target dir (default is units/<cpu>-<os>/
ifdef COMPILER_UNITTARGETDIR
override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
ifeq ($(COMPILER_UNITTARGETDIR),.)
override UNITTARGETDIRPREFIX=
else
override UNITTARGETDIRPREFIX=$(COMPILER_UNITTARGETDIR)/
endif
else
ifdef COMPILER_TARGETDIR
override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
endif
endif

ifdef CREATESHARED
override FPCOPT+=-Cg

ifeq ($(CPU_TARGET),i386)
override FPCOPT+=-Aas
endif

endif

# create always pic'ed code on x86_64
ifeq ($(findstring 2.0.,$(FPC_VERSION)),)
ifneq ($(findstring $(OS_TARGET),freebsd openbsd netbsd linux solaris),)
ifeq ($(CPU_TARGET),x86_64)
override FPCOPT+=-Cg
endif
endif
endif

ifdef LINKSHARED
#!!! deactived for testing override FPCOPT+=-XD
endif


[command_libc]
# Add GCC lib path if asked
ifdef GCCLIBDIR
override FPCOPT+=-Fl$(GCCLIBDIR)
endif
ifdef OTHERLIBDIR
override FPCOPT+=$(addprefix -Fl,$(OTHERLIBDIR))
endif


[command_end]
# Add commandline options last so they can override
ifdef OPT
override FPCOPT+=$(OPT)
endif

# Add defines from FPCOPTDEF to FPCOPT
ifdef FPCOPTDEF
override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
endif

# Was a config file specified ?
ifdef CFGFILE
override FPCOPT+=@$(CFGFILE)
endif

# Use the environment to pass commandline options?
ifdef USEENV
override FPCEXTCMD:=$(FPCOPT)
override FPCOPT:=!FPCEXTCMD
export FPCEXTCMD
endif

override AFULL_TARGET=$(CPU_TARGET)-$(OS_TARGET)
override AFULL_SOURCE=$(CPU_SOURCE)-$(OS_SOURCE)

ifneq ($(AFULL_TARGET),$(AFULL_SOURCE))
override ACROSSCOMPILE=1
endif

ifdef ACROSSCOMPILE
override FPCOPT+=$(CROSSOPT)
endif

# Compiler commandline
override COMPILER:=$(FPC) $(FPCOPT)

# also call ppas if with command option -s
# but only if the FULL_SOURCE and FULL_TARGET are equal
ifeq (,$(findstring -s ,$(COMPILER)))
EXECPPAS=
else
ifeq ($(FULL_SOURCE),$(FULL_TARGET))
ifdef RUNBATCH
EXECPPAS:=@$(RUNBATCH) $(PPAS)
else
EXECPPAS:=@$(PPAS)
endif
endif
endif


[loaderrules]
#####################################################################
# Loaders
#####################################################################

.PHONY: fpc_loaders

ifneq ($(TARGET_LOADERS),)
override ALLTARGET+=fpc_loaders
override CLEANTARGET+=fpc_loaders_clean
override INSTALLTARGET+=fpc_loaders_install

override LOADEROFILES:=$(addsuffix $(OEXT),$(TARGET_LOADERS))
endif

%$(OEXT): %$(LOADEREXT)
ifdef COMPILER_UNITTARGETDIR
        $(AS) -o $(COMPILER_UNITTARGETDIR)/$*$(OEXT) $<
else
        $(AS) -o $*$(OEXT) $<
endif

fpc_loaders: $(COMPILER_UNITTARGETDIR) $(LOADEROFILES)

fpc_loaders_clean:
ifdef COMPILER_UNITTARGETDIR
        -$(DEL) $(addprefix $(COMPILER_UNITTARGETDIR)/,$(LOADEROFILES))
else
        -$(DEL) $(LOADEROFILES)
endif

fpc_loaders_install:
        $(MKDIR) $(INSTALL_UNITDIR)
ifdef COMPILER_UNITTARGETDIR
        $(INSTALL) $(addprefix $(COMPILER_UNITTARGETDIR)/,$(LOADEROFILES)) $(INSTALL_UNITDIR)
else
        $(INSTALL) $(LOADEROFILES) $(INSTALL_UNITDIR)
endif


[unitrules]
#####################################################################
# Units
#####################################################################

.PHONY: fpc_units

ifneq ($(TARGET_UNITS)$(TARGET_IMPLICITUNITS),)
override ALLTARGET+=fpc_units

override UNITPPUFILES=$(addsuffix $(PPUEXT),$(TARGET_UNITS))
override IMPLICITUNITPPUFILES=$(addsuffix $(PPUEXT),$(TARGET_IMPLICITUNITS))
override INSTALLPPUFILES+=$(UNITPPUFILES) $(IMPLICITUNITPPUFILES)
override CLEANPPUFILES+=$(UNITPPUFILES) $(IMPLICITUNITPPUFILES)
endif

fpc_units: $(COMPILER_UNITTARGETDIR) $(UNITPPUFILES)


[exerules]
#####################################################################
# Exes
#####################################################################

.PHONY: fpc_exes

# Programs are not needed for a cross installation
ifndef CROSSINSTALL
ifneq ($(TARGET_PROGRAMS),)
override EXEFILES=$(addsuffix $(EXEEXT),$(TARGET_PROGRAMS))
override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefix $(STATICLIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS))) $(addprefix $(IMPORTLIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS)))
override EXEDBGFILES:=$(addsuffix $(EXEDBGEXT),$(TARGET_PROGRAMS))

override ALLTARGET+=fpc_exes
override INSTALLEXEFILES+=$(EXEFILES)
override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
override CLEANEXEDBGFILES+=$(EXEDBGFILES)
ifeq ($(OS_TARGET),os2)
override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_PROGRAMS))
endif
ifeq ($(OS_TARGET),emx)
override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_PROGRAMS))
endif
endif
endif

fpc_exes: $(COMPILER_TARGETDIR) $(COMPILER_UNITTARGETDIR) $(EXEFILES)


[rstrules]
#####################################################################
# Resource strings
#####################################################################

ifdef TARGET_RSTS
override RSTFILES=$(addsuffix $(RSTEXT),$(TARGET_RSTS))

override CLEANRSTFILES+=$(RSTFILES)
endif


[examplerules]
#####################################################################
# Examples
#####################################################################

.PHONY: fpc_examples

ifneq ($(TARGET_EXAMPLES),)
HASEXAMPLES=1
override EXAMPLESOURCEFILES:=$(wildcard $(addsuffix .pp,$(TARGET_EXAMPLES)) $(addsuffix .pas,$(TARGET_EXAMPLES)) $(addsuffix .lpr,$(TARGET_EXAMPLES)) $(addsuffix .dpr,$(TARGET_EXAMPLES)))
override EXAMPLEFILES:=$(addsuffix $(EXEEXT),$(TARGET_EXAMPLES))
override EXAMPLEOFILES:=$(addsuffix $(OEXT),$(TARGET_EXAMPLES)) $(addprefix $(STATICLIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_EXAMPLES))) $(addprefix $(IMPORTLIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_EXAMPLES)))
override EXAMPLEDBGFILES:=$(addsuffix $(EXEDBGEXT),$(TARGET_EXAMPLES))

override CLEANEXEFILES+=$(EXAMPLEFILES) $(EXAMPLEOFILES)
override CLEANEXEDBGFILES+=$(EXAMPLEDBGFILES)
ifeq ($(OS_TARGET),os2)
override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_EXAMPLES))
endif
ifeq ($(OS_TARGET),emx)
override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_EXAMPLES))
endif
endif
ifneq ($(TARGET_EXAMPLEDIRS),)
HASEXAMPLES=1
endif

fpc_examples: all $(EXAMPLEFILES) $(addsuffix _all,$(TARGET_EXAMPLEDIRS))


[compilerules]
#####################################################################
# General compile rules
#####################################################################

.PHONY: fpc_all fpc_smart fpc_debug fpc_release fpc_shared

$(FPCMADE): $(ALLDEPENDENCIES) $(ALLTARGET)
        @$(ECHOREDIR) Compiled > $(FPCMADE)

fpc_all: $(FPCMADE)

fpc_smart:
        $(MAKE) all LINKSMART=1 CREATESMART=1

fpc_debug:
        $(MAKE) all DEBUG=1

fpc_release:
        $(MAKE) all RELEASE=1

# General compile rules, available for both possible .pp and .pas extensions

.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .lpr .dpr .pp .rc .res

$(COMPILER_UNITTARGETDIR):
        $(MKDIRTREE) $(COMPILER_UNITTARGETDIR)

$(COMPILER_TARGETDIR):
        $(MKDIRTREE) $(COMPILER_TARGETDIR)

%$(PPUEXT): %.pp
        $(COMPILER) $<
        $(EXECPPAS)

%$(PPUEXT): %.pas
        $(COMPILER) $<
        $(EXECPPAS)

%$(EXEEXT): %.pp
        $(COMPILER) $<
        $(EXECPPAS)

%$(EXEEXT): %.pas
        $(COMPILER) $<
        $(EXECPPAS)

%$(EXEEXT): %.lpr
        $(COMPILER) $<
        $(EXECPPAS)

%$(EXEEXT): %.dpr
        $(COMPILER) $<
        $(EXECPPAS)

%.res: %.rc
        windres -i $< -o $@

# Search paths for .ppu, .pp, .pas, .lpr, .dpr
vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
vpath %.lpr $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
vpath %.dpr $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
vpath %.inc $(COMPILER_INCLUDEDIR)
vpath %$(OEXT) $(COMPILER_UNITTARGETDIR)
vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)

[sharedrules]
#####################################################################
# Library
#####################################################################

.PHONY: fpc_shared

override INSTALLTARGET+=fpc_shared_install

ifndef SHARED_LIBVERSION
SHARED_LIBVERSION=$(FPC_VERSION)
endif

ifndef SHARED_LIBNAME
SHARED_LIBNAME=$(PACKAGE_NAME)
endif

ifndef SHARED_FULLNAME
SHARED_FULLNAME=$(SHAREDLIBPREFIX)$(SHARED_LIBNAME)-$(SHARED_LIBVERSION)$(SHAREDLIBEXT)
endif

# Default sharedlib units are all unit objects
ifndef SHARED_LIBUNITS
SHARED_LIBUNITS:=$(TARGET_UNITS) $(TARGET_IMPLICITUNITS)
override SHARED_LIBUNITS:=$(filter-out $(INSTALL_BUILDUNIT),$(SHARED_LIBUNITS))
endif

fpc_shared:
ifdef HASSHAREDLIB
        $(MAKE) all CREATESHARED=1 LINKSHARED=1 CREATESMART=1
ifneq ($(SHARED_BUILD),n)
        $(PPUMOVE) -q $(SHARED_LIBUNITS) -i$(COMPILER_UNITTARGETDIR) -o$(SHARED_FULLNAME) -d$(COMPILER_UNITTARGETDIR)
endif
else
        @$(ECHO) Shared Libraries not supported
endif

fpc_shared_install:
ifneq ($(SHARED_BUILD),n)
ifneq ($(SHARED_LIBUNITS),)
ifneq ($(wildcard $(COMPILER_UNITTARGETDIR)/$(SHARED_FULLNAME)),)
        $(INSTALL) $(COMPILER_UNITTARGETDIR)/$(SHARED_FULLNAME) $(INSTALL_SHAREDDIR)
endif
endif
endif

[installrules]
#####################################################################
# Install rules
#####################################################################

.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall

ifdef INSTALL_UNITS
override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
endif

ifdef INSTALL_BUILDUNIT
override INSTALLPPUFILES:=$(filter-out $(INSTALL_BUILDUNIT)$(PPUEXT),$(INSTALLPPUFILES))
endif

ifdef INSTALLPPUFILES
override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(STATICLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES))) $(addprefix $(IMPORTLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
ifneq ($(UNITTARGETDIRPREFIX),)
override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(notdir $(INSTALLPPUFILES)))
override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(notdir $(INSTALLPPULINKFILES))))
endif
# Implicitly install Package.fpc
override INSTALL_CREATEPACKAGEFPC=1
endif

ifdef INSTALLEXEFILES
ifneq ($(TARGETDIRPREFIX),)
override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(notdir $(INSTALLEXEFILES)))
endif
endif

fpc_install: all $(INSTALLTARGET)
ifdef INSTALLEXEFILES
        $(MKDIR) $(INSTALL_BINDIR)
# Compress the exes if upx is defined
ifdef UPXPROG
        -$(UPXPROG) $(INSTALLEXEFILES)
endif
        $(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
endif
ifdef INSTALL_CREATEPACKAGEFPC
ifdef FPCMAKE
# If the fpcpackage variable is set then create and install Package.fpc,
# a safety check is done if Makefile.fpc is available
ifdef PACKAGE_VERSION
ifneq ($(wildcard Makefile.fpc),)
        $(FPCMAKE) -p -T$(CPU_TARGET)-$(OS_TARGET) Makefile.fpc
        $(MKDIR) $(INSTALL_UNITDIR)
        $(INSTALL) Package.fpc $(INSTALL_UNITDIR)
endif
endif
endif
endif
ifdef INSTALLPPUFILES
        $(MKDIR) $(INSTALL_UNITDIR)
        $(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
ifneq ($(INSTALLPPULINKFILES),)
        $(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
endif
ifneq ($(wildcard $(LIB_FULLNAME)),)
        $(MKDIR) $(INSTALL_LIBDIR)
        $(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
ifdef inUnix
        ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
endif
endif
endif
ifdef INSTALL_FILES
        $(MKDIR) $(INSTALL_DATADIR)
        $(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
endif

fpc_sourceinstall: distclean
        $(MKDIR) $(INSTALL_SOURCEDIR)
        $(COPYTREE) $(BASEDIR)/* $(INSTALL_SOURCEDIR)

fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
ifdef HASEXAMPLES
        $(MKDIR) $(INSTALL_EXAMPLEDIR)
endif
ifdef EXAMPLESOURCEFILES
        $(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
endif
ifdef TARGET_EXAMPLEDIRS
        $(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
endif

[distinstallrules]
#####################################################################
# Dist Install
#####################################################################

.PHONY: fpc_distinstall

fpc_distinstall: install exampleinstall


[zipinstallrules]
#####################################################################
# Zip
#####################################################################

.PHONY: fpc_zipinstall fpc_zipsourceinstall fpc_zipexampleinstall

# Temporary path to pack a file, can only use a single deep
# subdir, because the deltree can't see the whole tree to remove
ifndef PACKDIR
ifndef inUnix
PACKDIR=$(BASEDIR)/../fpc-pack
else
PACKDIR=/tmp/fpc-pack
endif
endif

# Maybe create default zipname from packagename
ifndef ZIPNAME
ifdef DIST_ZIPNAME
ZIPNAME=$(DIST_ZIPNAME)
else
ZIPNAME=$(PACKAGE_NAME)
endif
endif

ifndef FULLZIPNAME
FULLZIPNAME=$(ZIPCROSSPREFIX)$(ZIPPREFIX)$(ZIPNAME)$(ZIPSUFFIX)
endif

# ZipTarget
ifndef ZIPTARGET
ifdef DIST_ZIPTARGET
ZIPTARGET=DIST_ZIPTARGET
else
ZIPTARGET=install
endif
endif

# Use tar by default under linux
ifndef USEZIP
ifdef inUnix
USETAR=1
endif
endif

# Use a wrapper script by default for Os/2
ifndef inUnix
USEZIPWRAPPER=1
endif

# We need to be able to run in the current OS so fix
# the path separator
ifdef USEZIPWRAPPER
ZIPPATHSEP=$(PATHSEP)
ZIPWRAPPER=$(subst /,$(PATHSEP),$(DIST_DESTDIR)/fpczip$(SRCBATCHEXT))
else
ZIPPATHSEP=/
endif

# Create commands to create the zip/tar file
ZIPCMD_CDPACK:=cd $(subst /,$(ZIPPATHSEP),$(PACKDIR))
ZIPCMD_CDBASE:=cd $(subst /,$(ZIPPATHSEP),$(BASEDIR))
ifdef USETAR
ZIPDESTFILE:=$(DIST_DESTDIR)/$(FULLZIPNAME)$(TAREXT)
ZIPCMD_ZIP:=$(TARPROG) c$(TAROPT)f $(ZIPDESTFILE) *
else
ZIPDESTFILE:=$(DIST_DESTDIR)/$(FULLZIPNAME)$(ZIPEXT)
ZIPCMD_ZIP:=$(subst /,$(ZIPPATHSEP),$(ZIPPROG)) -Dr $(ZIPOPT) $(ZIPDESTFILE) *
endif

fpc_zipinstall:
        $(MAKE) $(ZIPTARGET) INSTALL_PREFIX=$(PACKDIR) ZIPINSTALL=1
        $(MKDIR) $(DIST_DESTDIR)
        $(DEL) $(ZIPDESTFILE)
ifdef USEZIPWRAPPER
# Handle gecho separate as we need to espace \ with \\
ifneq ($(ECHOREDIR),echo)
        $(ECHOREDIR) -e "$(subst \,\\,$(ZIPCMD_CDPACK))" > $(ZIPWRAPPER)
        $(ECHOREDIR) -e "$(subst \,\\,$(ZIPCMD_ZIP))" >> $(ZIPWRAPPER)
        $(ECHOREDIR) -e "$(subst \,\\,$(ZIPCMD_CDBASE))" >> $(ZIPWRAPPER)
else
        echo $(ZIPCMD_CDPACK) > $(ZIPWRAPPER)
        echo $(ZIPCMD_ZIP) >> $(ZIPWRAPPER)
        echo $(ZIPCMD_CDBASE) >> $(ZIPWRAPPER)
endif
ifdef inUnix
        /bin/sh $(ZIPWRAPPER)
else
ifdef RUNBATCH
        $(RUNBATCH) $(ZIPWRAPPER)
else
        $(ZIPWRAPPER)
endif
endif
        $(DEL) $(ZIPWRAPPER)
else
        $(ZIPCMD_CDPACK) ; $(ZIPCMD_ZIP) ; $(ZIPCMD_CDBASE)
endif
        $(DELTREE) $(PACKDIR)

fpc_zipsourceinstall:
        $(MAKE) fpc_zipinstall ZIPTARGET=sourceinstall ZIPSUFFIX=$(ZIPSOURCESUFFIX)

fpc_zipexampleinstall:
ifdef HASEXAMPLES
        $(MAKE) fpc_zipinstall ZIPTARGET=exampleinstall ZIPSUFFIX=$(ZIPEXAMPLESUFFIX)
endif

fpc_zipdistinstall:
        $(MAKE) fpc_zipinstall ZIPTARGET=distinstall


[cleanrules]
#####################################################################
# Clean rules
#####################################################################

.PHONY: fpc_clean fpc_cleanall fpc_distclean

ifdef EXEFILES
override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
override CLEANEXEDBGFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEDBGFILES))
endif

ifdef CLEAN_PROGRAMS
override CLEANEXEFILES+=$(addprefix $(TARGETDIRPREFIX),$(addsuffix $(EXEEXT), $(CLEAN_PROGRAMS)))
override CLEANEXEDBGFILES+=$(addprefix $(TARGETDIRPREFIX),$(addsuffix $(EXEDBGEXT), $(CLEAN_PROGRAMS)))
endif

ifdef CLEAN_UNITS
override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
endif

ifdef CLEANPPUFILES
override CLEANPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(STATICLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))) $(addprefix $(IMPORTLIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES)))
ifdef DEBUGSYMEXT
override CLEANPPULINKFILES+=$(subst $(PPUEXT),$(DEBUGSYMEXT),$(CLEANPPUFILES))
endif
override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
override CLEANPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES)))
endif

fpc_clean: $(CLEANTARGET)
ifdef CLEANEXEFILES
        -$(DEL) $(CLEANEXEFILES)
endif
# DELTREE instead of DEL because on Mac OS X these are directories
ifdef CLEANEXEDBGFILES
        -$(DELTREE) $(CLEANEXEDBGFILES)
endif
ifdef CLEANPPUFILES
        -$(DEL) $(CLEANPPUFILES)
endif
ifneq ($(CLEANPPULINKFILES),)
        -$(DEL) $(CLEANPPULINKFILES)
endif
ifdef CLEANRSTFILES
        -$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
endif
ifdef CLEAN_FILES
        -$(DEL) $(CLEAN_FILES)
endif
ifdef LIB_NAME
        -$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
endif
        -$(DEL) $(FPCMADE) Package.fpc $(PPAS) script.res link.res $(FPCEXTFILE) $(REDIRFILE)
        -$(DEL) *$(ASMEXT) *_ppas$(BATCHEXT)

fpc_cleanall: $(CLEANTARGET)
ifdef CLEANEXEFILES
        -$(DEL) $(CLEANEXEFILES)
endif
ifdef COMPILER_UNITTARGETDIR
ifdef CLEANPPUFILES
        -$(DEL) $(CLEANPPUFILES)
endif
ifneq ($(CLEANPPULINKFILES),)
        -$(DEL) $(CLEANPPULINKFILES)
endif
ifdef CLEANRSTFILES
        -$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
endif
endif
ifdef CLEAN_FILES
        -$(DEL) $(CLEAN_FILES)
endif
        -$(DELTREE) units
        -$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
ifneq ($(PPUEXT),.ppu)
        -$(DEL) *.o *.ppu *.a
endif
        -$(DELTREE) *$(SMARTEXT)
        -$(DEL) fpcmade.* Package.fpc $(PPAS) script.res link.res $(FPCEXTFILE) $(REDIRFILE)
        -$(DEL) *_ppas$(BATCHEXT)
ifdef AOUTEXT
        -$(DEL) *$(AOUTEXT)
endif
ifdef DEBUGSYMEXT
        -$(DEL) *$(DEBUGSYMEXT)
endif

fpc_distclean: cleanall


[baseinforules]
#####################################################################
# Base info rules
#####################################################################

.PHONY: fpc_baseinfo

override INFORULES+=fpc_baseinfo

fpc_baseinfo:
        @$(ECHO)
        @$(ECHO)  == Package info ==
        @$(ECHO)  Package Name..... $(PACKAGE_NAME)
        @$(ECHO)  Package Version.. $(PACKAGE_VERSION)
        @$(ECHO)
        @$(ECHO)  == Configuration info ==
        @$(ECHO)
        @$(ECHO)  FPC.......... $(FPC)
        @$(ECHO)  FPC Version.. $(FPC_VERSION)
        @$(ECHO)  Source CPU... $(CPU_SOURCE)
        @$(ECHO)  Target CPU... $(CPU_TARGET)
        @$(ECHO)  Source OS.... $(OS_SOURCE)
        @$(ECHO)  Target OS.... $(OS_TARGET)
        @$(ECHO)  Full Source.. $(FULL_SOURCE)
        @$(ECHO)  Full Target.. $(FULL_TARGET)
        @$(ECHO)  SourceSuffix. $(SOURCESUFFIX)
        @$(ECHO)  TargetSuffix. $(TARGETSUFFIX)
        @$(ECHO)  FPC fpmake... $(FPCFPMAKE)
        @$(ECHO)
        @$(ECHO)  == Directory info ==
        @$(ECHO)
        @$(ECHO)  Required pkgs... $(REQUIRE_PACKAGES)
        @$(ECHO)
        @$(ECHO)  Basedir......... $(BASEDIR)
        @$(ECHO)  FPCDir.......... $(FPCDIR)
        @$(ECHO)  CrossBinDir..... $(CROSSBINDIR)
        @$(ECHO)  UnitsDir........ $(UNITSDIR)
        @$(ECHO)  PackagesDir..... $(PACKAGESDIR)
        @$(ECHO)
        @$(ECHO)  GCC library..... $(GCCLIBDIR)
        @$(ECHO)  Other library... $(OTHERLIBDIR)
        @$(ECHO)
        @$(ECHO)  == Tools info ==
        @$(ECHO)
        @$(ECHO)  As........ $(AS)
        @$(ECHO)  Ld........ $(LD)
        @$(ECHO)  Ar........ $(AR)
        @$(ECHO)  Rc........ $(RC)
        @$(ECHO)
        @$(ECHO)  Mv........ $(MVPROG)
        @$(ECHO)  Cp........ $(CPPROG)
        @$(ECHO)  Rm........ $(RMPROG)
        @$(ECHO)  GInstall.. $(GINSTALL)
        @$(ECHO)  Echo...... $(ECHO)
        @$(ECHO)  Shell..... $(SHELL)
        @$(ECHO)  Date...... $(DATE)
        @$(ECHO)  FPCMake... $(FPCMAKE)
        @$(ECHO)  PPUMove... $(PPUMOVE)
        @$(ECHO)  Upx....... $(UPXPROG)
        @$(ECHO)  Zip....... $(ZIPPROG)
        @$(ECHO)
        @$(ECHO)  == Object info ==
        @$(ECHO)
        @$(ECHO)  Target Loaders........ $(TARGET_LOADERS)
        @$(ECHO)  Target Units.......... $(TARGET_UNITS)
        @$(ECHO)  Target Implicit Units. $(TARGET_IMPLICITUNITS)
        @$(ECHO)  Target Programs....... $(TARGET_PROGRAMS)
        @$(ECHO)  Target Dirs........... $(TARGET_DIRS)
        @$(ECHO)  Target Examples....... $(TARGET_EXAMPLES)
        @$(ECHO)  Target ExampleDirs.... $(TARGET_EXAMPLEDIRS)
        @$(ECHO)
        @$(ECHO)  Clean Units......... $(CLEAN_UNITS)
        @$(ECHO)  Clean Files......... $(CLEAN_FILES)
        @$(ECHO)
        @$(ECHO)  Install Units....... $(INSTALL_UNITS)
        @$(ECHO)  Install Files....... $(INSTALL_FILES)
        @$(ECHO)
        @$(ECHO)  == Install info ==
        @$(ECHO)
        @$(ECHO)  DateStr.............. $(DATESTR)
        @$(ECHO)  ZipName.............. $(ZIPNAME)
        @$(ECHO)  ZipPrefix............ $(ZIPPREFIX)
        @$(ECHO)  ZipCrossPrefix....... $(ZIPCROSSPREFIX)
        @$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)
        @$(ECHO)  FullZipName.......... $(FULLZIPNAME)
        @$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)
        @$(ECHO)
        @$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)
        @$(ECHO)  Install binary dir... $(INSTALL_BINDIR)
        @$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)
        @$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)
        @$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)
        @$(ECHO)  Install doc dir...... $(INSTALL_DOCDIR)
        @$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)
        @$(ECHO)  Install data dir..... $(INSTALL_DATADIR)
        @$(ECHO)
        @$(ECHO)  Dist destination dir. $(DIST_DESTDIR)
        @$(ECHO)  Dist zip name........ $(DIST_ZIPNAME)
        @$(ECHO)

[inforules]
#####################################################################
# Info rules
#####################################################################

.PHONY: fpc_info

fpc_info: $(INFORULES)

[makefilerules]
#####################################################################
# Rebuild Makefile
#####################################################################

.PHONY: fpc_makefile fpc_makefiles fpc_makefile_sub1 fpc_makefile_sub2 \
        fpc_makefile_dirs

fpc_makefile:
        $(FPCMAKE) -w -T$(OS_TARGET) Makefile.fpc

fpc_makefile_sub1:
ifdef TARGET_DIRS
        $(FPCMAKE) -w -T$(OS_TARGET) $(addsuffix /Makefile.fpc,$(TARGET_DIRS))
endif
ifdef TARGET_EXAMPLEDIRS
        $(FPCMAKE) -w -T$(OS_TARGET) $(addsuffix /Makefile.fpc,$(TARGET_EXAMPLEDIRS))
endif

fpc_makefile_sub2: $(addsuffix _makefile_dirs,$(TARGET_DIRS) $(TARGET_EXAMPLEDIRS))

fpc_makefile_dirs: fpc_makefile_sub1 fpc_makefile_sub2

fpc_makefiles: fpc_makefile fpc_makefile_dirs

[localmakefile]
#####################################################################
# Local Makefile
#####################################################################

ifneq ($(wildcard fpcmake.loc),)
include fpcmake.loc
endif


[userrules]
#####################################################################
# Users rules
#####################################################################

[lclrules]
#####################################################################
# LCL Rules
#####################################################################

# LCL Platform
ifndef LCL_PLATFORM
ifneq ($(findstring $(OS_TARGET),win32 win64),)
LCL_PLATFORM=win32
else
LCL_PLATFORM=gtk
endif
endif
export LCL_PLATFORM

# Check if the specified LCLDIR is correct
ifdef LCLDIR
override LCLDIR:=$(subst \,/,$(LCLDIR))
ifeq ($(wildcard $(LCLDIR)/units/$(LCL_PLATFORM)),)
override LCLDIR=wrong
endif
else
override LCLDIR=wrong
endif

# Check if the default LCLDIR is correct
ifdef DEFAULT_LCLDIR
override LCLDIR:=$(subst \,/,$(DEFAULT_LCLDIR))
ifeq ($(wildcard $(LCLDIR)/units/$(LCL_PLATFORM)),)
override LCLDIR=wrong
endif
endif

# Check for development version
ifeq ($(LCLDIR),wrong)
override LCLDIR=$(subst /units/$(LCL_PLATFORM),,$(firstword $(wildcard $(addsuffix /units/$(LCL_PLATFORM),$(BASEDIR)/lcl $(BASEDIR)))))
ifeq ($(LCLDIR),)
override LCLDIR=wrong
endif
endif

# Check for release version
ifeq ($(LCLDIR),wrong)
override LCLDIR=$(subst /units/$(LCL_PLATFORM),,$(firstword $(wildcard $(addsuffix /lib/lazarus/units/$(LCL_PLATFORM),/usr/local /usr))))
ifeq ($(LCLDIR),)
override LCLDIR=wrong
endif
endif

# Generate dirs
override LCLUNITDIR:=$(wildcard $(LCLDIR)/units/$(LCL_PLATFORM) $(LCLDIR)/units)
override LCLCOMPONENTDIR:=$(wildcard $(LCLDIR)/.. $(LCLDIR)/../components $(LCLDIR)/components)
export LCLDIR LCLUNITDIR LCLCOMPONENTDIR

# Add LCL dirs to paths
override REQUIRE_PACKAGESDIR+=$(LCLCOMPONENTDIR)
override COMPILER_UNITDIR+=$(LCLUNITDIR)

[lclinforules]
#####################################################################
# LCL Info rules
#####################################################################
override INFORULES+=lclinfo

.PHONY: lclinfo

lclinfo:
        @$(ECHO)  == LCL info ==
        @$(ECHO)
        @$(ECHO)  Platform............. $(LCL_PLATFORM)
        @$(ECHO)  LCLDIR............... $(LCLDIR)
        @$(ECHO)  LCL Unit dir......... $(LCLUNITDIR)
        @$(ECHO)  LCL Component dir.... $(LCLCOMPONENTDIR)
        @$(ECHO)
