#
#   Makefile.fpc for Free Pascal Linux RTL
#

[package]
main=rtl

[target]
loaders=prt0 dllprt0 cprt0 gprt0 cprt21 gprt21
units=$(SYSTEMUNIT) baseunix systhrds objpas strings \
      heaptrc lineinfo \
      $(LINUXUNIT) unix initc $(CPU_UNITS) \
      dos crt objects printer ggigraph \
      sysutils typinfo math varutils \
      charset ucomplex getopts \
      errors sockets gpm ipc serial terminfo dl dynlibs \
      video mouse keyboard variants types
rsts=math varutils typinfo variants

[require]
nortl=y

[clean]
units=syslinux linux

[install]
fpcpackage=y

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

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

[lib]
libname=libfprtl.so
libversion=1.0
libunits=$(SYSTEMUNIT) objpas strings \
      unix ports \
      dos crt objects printer \
      sysutils typinfo math \
      cpu mmx getopts heaptrc \
      errors sockets ipc dl dynlibs varutils

[prerules]
RTL=..
INC=$(RTL)/inc
PROCINC=$(RTL)/$(CPU_TARGET)
UNIXINC=$(RTL)/unix

ifeq ($(CPU_TARGET),i386)
CPU_UNITS=ports cpu mmx graph
else
CPU_UNITS=
endif

UNITPREFIX=rtl

ifeq ($(findstring 1.0.,$(FPC_VERSION)),)
SYSTEMUNIT=system
LINUXUNIT=
PRT0=prt0
else
SYSTEMUNIT=syslinux
LINUXUNIT=linux
PRT0=prt0_10
override FPCOPT+=-dUNIX
endif

# Use new feature from 1.0.5 version
# that generates release PPU files
# which will not be recompiled
ifdef RELEASE
override FPCOPT+=-Ur
endif

# Paths
OBJPASDIR=$(RTL)/objpas
GRAPHDIR=$(INC)/graph

# Use new graph unit ?
# NEWGRAPH=YES
# Use LibGGI ?
# Use
#
ifndef USELIBGGI
USELIBGGI=NO
endif

[rules]
# 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)


#
# Loaders
#

prt0$(OEXT) : $(CPU_TARGET)/$(PRT0).as
        $(AS) -o prt0$(OEXT) $(CPU_TARGET)/$(PRT0).as

dllprt0$(OEXT) : $(CPU_TARGET)/dllprt0.as
        $(AS) -o dllprt0$(OEXT) $(CPU_TARGET)/dllprt0.as

gprt0$(OEXT) : $(CPU_TARGET)/gprt0.as
        $(AS) -o gprt0$(OEXT) $(CPU_TARGET)/gprt0.as

cprt0$(OEXT) : $(CPU_TARGET)/cprt0.as
        $(AS) -o cprt0$(OEXT) $(CPU_TARGET)/cprt0.as

cprt21$(OEXT) : $(CPU_TARGET)/cprt21.as
        $(AS) -o cprt21$(OEXT) $(CPU_TARGET)/cprt21.as

# still need to use gprt1, because gprt21 crashes
gprt21$(OEXT) : $(CPU_TARGET)/gprt0.as
        $(AS) -o gprt21$(OEXT) $(CPU_TARGET)/gprt0.as


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

$(SYSTEMUNIT)$(PPUEXT) : $(SYSTEMUNIT).pp sysconst.inc systypes.inc syscalls.inc $(SYSDEPS)
        $(COMPILER) -Us -Sg $(SYSTEMUNIT).pp

systhrds$(PPUEXT): systhrds.pp $(INC)/threadh.inc $(SYSTEMUNIT)$(PPUEXT)

objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc $(SYSTEMUNIT)$(PPUEXT)
        $(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/objpas.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) $(INC)/textrec.inc $(INC)/filerec.inc \
                 syscalls.inc systypes.inc sysconst.inc $(UNIXINC)/timezone.inc $(SYSTEMUNIT)$(PPUEXT) \
                 unixsysc.inc

baseunix$(PPUEXT) : errno.inc bunxtype.inc ptypes.inc ctypes.inc \
	signal.inc $(UNIXINC)/bunxh.inc bunxmain.inc ostypes.inc \
	bunxfunc.inc $(CPU_TARGET)/syscallh.inc sysnr.inc \
	ostypes.inc ossysch.inc bunxmacr.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.pp $(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)

#
# Graph
#
include $(GRAPHDIR)/makefile.inc
GRAPHINCDEPS=$(addprefix $(GRAPHDIR)/,$(GRAPHINCNAMES))

graph$(PPUEXT) : graph.pp unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
                 $(GRAPHINCDEPS) $(UNIXINC)/graph16.inc
        $(COMPILER) -I$(GRAPHDIR) $(UNIXINC)/graph.pp

ggigraph$(PPUEXT) : $(UNIXINC)/ggigraph.pp unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
                 $(GRAPHINCDEPS)
        $(COMPILER) -I$(GRAPHDIR) $(UNIXINC)/ggigraph.pp

#
# Delphi Compatible Units
#

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

typinfo$(PPUEXT): $(OBJPASDIR)/typinfo.pp objpas$(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
        $(COMPILER) -I$(OBJPASDIR) $(UNIXINC)/varutils.pp

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

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

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

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)

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)


