#
#   Makefile.fpc for Free Pascal Linux RTL
#

[package]
main=rtl

[target]
loaders=$(LOADERS)
units=$(SYSTEMUNIT) $(SYSINIT_UNITS) \
      unixtype ctypes baseunix strings objpas macpas iso7185 syscall unixutil \
      fpintres heaptrc lineinfo lnfodwrf \
      termio unix linux initc cmem $(CPU_UNITS) \
      crt printer linuxvcs \
      sysutils typinfo math matrix varutils \
      charset ucomplex getopts \
      errors sockets gpm ipc serial terminfo dl dynlibs \
      video mouse keyboard variants types dateutils sysconst fmtbcd \
      cthreads classes fgl convutils stdconvs strutils rtlconsts dos objects cwstring fpcylix clocale
implicitunits=exeinfo

rsts=math varutils typinfo variants sysconst rtlconsts stdconvs

[require]
nortl=y

[clean]
units=syslinux linux

[install]
fpcpackage=y

[default]
fpcdir=../..
target=linux

[compiler]
includedir=$(INC) $(PROCINC) $(UNIXINC) $(ARCH)
sourcedir=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
targetdir=.

[shared]
libunits=$(SYSTEMUNIT) objpas strings dos \
      unix baseunix unixtype unixutil \
      sysutils typinfo math \
      $(CPU_UNITS) getopts \
      errors sockets varutils \
      classes fgl variants sysconst rtlconsts \

[prerules]
RTL=..
INC=$(RTL)/inc
COMMON=$(RTL)/common
PROCINC=$(RTL)/$(ARCH)
UNIXINC=$(RTL)/unix

UNITPREFIX=rtl

CPU_UNITS=
SYSINIT_UNITS=

LOADERS=prt0 dllprt0 cprt0 gprt0

ifeq ($(ARCH),i386)
ifeq ($(findstring 2.0.,$(FPC_VERSION)),)
override LOADERS=
else
override LOADERS+=cprt21 gprt21
endif
CPU_UNITS=x86 ports cpu mmx
SYSINIT_UNITS=si_prc si_c21g si_c21 si_c si_dll si_uc
endif

ifeq ($(ARCH),x86_64)
CPU_UNITS=x86 ports cpu
SYSINIT_UNITS=   # si_prc si_c si_dll
endif

ifeq ($(ARCH),arm)
override LOADERS+=ucprt0
endif

SYSTEMUNIT=system

# Causes release PPU files not to be recompiled
ifdef RELEASE
override FPCOPT+=-Ur
endif

# Paths
OBJPASDIR=$(RTL)/objpas

[rules]
.NOTPARALLEL:
# Get the $(SYSTEMUNIT) independent include file names.
# This will set the following variables :
# SYSINCNAMES
include $(INC)/makefile.inc
SYSINCDEPS=$(addprefix $(INC)/,$(SYSINCNAMES))

# Get the processor dependent include file names.
# This will set the following variables :
# CPUINCNAMES
include $(PROCINC)/makefile.cpu
SYSCPUDEPS=$(addprefix $(PROCINC)/,$(CPUINCNAMES))

# Put $(SYSTEMUNIT) unit dependencies together.
SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)

# Select 32/64 mode
ifeq ($(ARCH),i386)
  ASTARGET=--32
endif
ifeq ($(ARCH),x86_64)
  ASTARGET=--64
endif
ifeq ($(ARCH),powerpc64)
  ASTARGET=-a64
endif

#
# Loaders
#

prt0$(OEXT) : $(ARCH)/prt0.as
        $(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)prt0$(OEXT) $(ARCH)/prt0.as

dllprt0$(OEXT) : $(ARCH)/dllprt0.as
        $(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)dllprt0$(OEXT) $(ARCH)/dllprt0.as

gprt0$(OEXT) : $(ARCH)/gprt0.as
        $(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)gprt0$(OEXT) $(ARCH)/gprt0.as

cprt0$(OEXT) : $(ARCH)/cprt0.as
        $(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)cprt0$(OEXT) $(ARCH)/cprt0.as

cprt21$(OEXT) : $(ARCH)/cprt21.as
        $(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)cprt21$(OEXT) $(ARCH)/cprt21.as

gprt21$(OEXT) : $(ARCH)/gprt21.as
        $(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)gprt21$(OEXT) $(ARCH)/gprt21.as

ucprt0$(OEXT) : $(ARCH)/ucprt0.as
        $(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)$@ $<


#
# $(SYSTEMUNIT) Units ($(SYSTEMUNIT), Objpas, Strings)
#

$(SYSTEMUNIT)$(PPUEXT) : $(SYSTEMUNIT).pp $(SYSDEPS)
        $(COMPILER) -Us -Sg $(SYSTEMUNIT).pp

objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc $(SYSTEMUNIT)$(PPUEXT)
        $(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/objpas.pp

dateutils$(PPUEXT): $(OBJPASDIR)/dateutils.pp $(SYSTEMUNIT)$(PPUEXT)
        $(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/dateutils.pp

strings$(PPUEXT) : $(INC)/strings.pp $(INC)/stringsi.inc\
                   $(PROCINC)/strings.inc $(PROCINC)/stringss.inc\
                   $(SYSTEMUNIT)$(PPUEXT)

#
# $(SYSTEMUNIT) Dependent Units
#

unix$(PPUEXT) : unix.pp strings$(PPUEXT) baseunix$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc \
                 unxconst.inc $(UNIXINC)/timezone.inc $(SYSTEMUNIT)$(PPUEXT) \
                 unxfunc.inc

unixtype$(PPUEXT) : $(UNIXINC)/unixtype.pp ptypes.inc $(UNIXINC)/ctypes.inc $(SYSTEMUNIT)$(PPUEXT)

baseunix$(PPUEXT) : errno.inc ptypes.inc $(UNIXINC)/ctypes.inc \
  $(UNIXINC)/bunxh.inc \
  bunxsysc.inc $(ARCH)/syscallh.inc $(ARCH)/sysnr.inc \
  ostypes.inc osmacro.inc $(UNIXINC)/gensigset.inc \
  $(UNIXINC)/genfuncs.inc $(SYSTEMUNIT)$(PPUEXT)

ports$(PPUEXT) : ports.pp unix$(PPUEXT) objpas$(PPUEXT)

dl$(PPUEXT) : $(UNIXINC)/dl.pp $(SYSTEMUNIT)$(PPUEXT)

dynlibs$(PPUEXT) : $(INC)/dynlibs.pas $(UNIXINC)/dynlibs.inc dl$(PPUEXT) objpas$(PPUEXT)

#
# TP7 Compatible RTL Units
#

dos$(PPUEXT) : dos.pp $(INC)/filerec.inc $(INC)/textrec.inc strings$(PPUEXT) \
               unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

crt$(PPUEXT) : crt.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

objects$(PPUEXT) : $(INC)/objects.pp $(SYSTEMUNIT)$(PPUEXT)

printer$(PPUEXT) : printer.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

#
# Delphi Compatible Units
#

sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
                    objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT)
        $(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp

classes$(PPUEXT) : $(UNIXINC)/classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
                   sysutils$(PPUEXT) typinfo$(PPUEXT) rtlconsts$(PPUEXT) fgl$(PPUEXT)
        $(COMPILER) -Fi$(OBJPASDIR)/classes $(UNIXINC)/classes.pp

typinfo$(PPUEXT): $(OBJPASDIR)/typinfo.pp objpas$(PPUEXT) sysutils$(PPUEXT) rtlconsts$(PPUEXT)
        $(COMPILER) -Sg $(OBJPASDIR)/typinfo.pp

math$(PPUEXT): $(OBJPASDIR)/math.pp objpas$(PPUEXT) sysutils$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/math.pp

gettext$(PPUEXT): $(OBJPASDIR)/gettext.pp objpas$(PPUEXT) sysutils$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/gettext.pp

varutils$(PPUEXT) : $(OBJPASDIR)/cvarutil.inc $(OBJPASDIR)/varutils.inc \
                    $(OBJPASDIR)/varutilh.inc varutils.pp sysutils$(PPUEXT)
        $(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/varutils.pp

variants$(PPUEXT) : $(INC)/variants.pp sysutils$(PPUEXT) sysconst$(PPUEXT) varutils$(PPUEXT) typinfo$(PPUEXT) rtlconsts$(PPUEXT)
        $(COMPILER) -Fi$(INC) $(INC)/variants.pp

fmtbcd$(PPUEXT) : $(OBJPASDIR)/fmtbcd.pp objpas$(PPUEXT) sysutils$(PPUEXT) variants$(PPUEXT) classes$(PPUEXT) system$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/fmtbcd.pp

fgl$(PPUEXT) : $(OBJPASDIR)/fgl.pp objpas$(PPUEXT) types$(PPUEXT) system$(PPUEXT) sysutils$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/fgl.pp

types$(PPUEXT) : $(OBJPASDIR)/types.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/types.pp

sysconst$(PPUEXT) : $(OBJPASDIR)/sysconst.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/sysconst.pp

rtlconsts$(PPUEXT) : $(OBJPASDIR)/rtlconsts.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/rtlconsts.pp

strutils$(PPUEXT) : $(OBJPASDIR)/strutils.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
                    sysutils$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/strutils.pp

convutils$(PPUEXT) : $(OBJPASDIR)/convutils.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
                    sysutils$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/convutils.pp

stdconvs$(PPUEXT) : $(OBJPASDIR)/stdconvs.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
                    sysutils$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/stdconvs.pp

#
# Mac Pascal Model
#

macpas$(PPUEXT) : $(INC)/macpas.pp objpas$(PPUEXT) math$(PPUEXT)
        $(COMPILER) $(INC)/macpas.pp $(REDIR)

#
# Other $(SYSTEMUNIT)-independent RTL Units
#

ifeq ($(ARCH),x86_64)
cpu$(PPUEXT) : $(PROCINC)/cpu.pp $(SYSTEMUNIT)$(PPUEXT) sysutils$(PPUEXT)
else
cpu$(PPUEXT) : $(PROCINC)/cpu.pp $(SYSTEMUNIT)$(PPUEXT)
endif

mmx$(PPUEXT) : $(PROCINC)/mmx.pp cpu$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

getopts$(PPUEXT) : $(INC)/getopts.pp $(SYSTEMUNIT)$(PPUEXT)

heaptrc$(PPUEXT) : $(INC)/heaptrc.pp $(SYSTEMUNIT)$(PPUEXT)
        $(COMPILER) -Sg $(INC)/heaptrc.pp

lineinfo$(PPUEXT) : $(INC)/lineinfo.pp $(SYSTEMUNIT)$(PPUEXT)

lnfodwrf$(PPUEXT) : $(INC)/lnfodwrf.pp $(SYSTEMUNIT)$(PPUEXT)

charset$(PPUEXT) : $(INC)/charset.pp $(SYSTEMUNIT)$(PPUEXT)

ucomplex$(PPUEXT) : $(INC)/ucomplex.pp math$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)


#
# Other $(SYSTEMUNIT)-dependent RTL Units
#

sockets$(PPUEXT) : sockets.pp $(INC)/textrec.inc $(INC)/filerec.inc \
                   unixsock.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

errors$(PPUEXT) : errors.pp strings$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

ipc$(PPUEXT) : ipc.pp unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

terminfo$(PPUEXT) : terminfo.pp unix$(PPUEXT)

callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)

cmem$(PPUEXT) : $(INC)/cmem.pp $(SYSTEMUNIT)$(PPUEXT)

cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp $(SYSTEMUNIT)$(PPUEXT)

cwstring$(PPUEXT) : $(UNIXINC)/cwstring.pp $(SYSTEMUNIT)$(PPUEXT) sysutils$(PPUEXT) baseunix$(PPUEXT) unix$(PPUEXT) unixtype$(PPUEXT) ctypes$(PPUEXT)

gpm$(PPUEXT): gpm.pp unix$(PPUEXT) baseunix$(PPUEXT) sockets$(PPUEXT)

ctypes$(PPUEXT) :  $(INC)/ctypes.pp $(SYSTEMUNIT)$(PPUEXT)

fpcylix$(PPUEXT) :  fpcylix.pp $(SYSTEMUNIT)$(PPUEXT) dynlibs$(PPUEXT) objpas$(PPUEXT)
