#
#   Makefile.fpc for Free Pascal FreeBSD RTL
#

[package]
main=rtl

[install]
fpcpackage=y

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

rsts=math varutils typinfo classes variants dateutils sysconst

[require]
nortl=y

[install]
fpcpackage=y

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

[compiler]
includedir=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC) $(BSDPROCINC) $(OSPROCINC)
sourcedir=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC) $(COMMON)


[lib]
libname=libfprtl.so
libversion=2.0.0
libunits=$(SYSTEMUNIT) objpas strings \
      unix  \
      dos crt objects printer \
      sysutils typinfo math \
      $(CPU_UNITS) getopts heaptrc \
      errors sockets ipc dynlibs

[prerules]
RTL=..
INC=$(RTL)/inc
COMMON=$(RTL)/common
PROCINC=$(RTL)/$(CPU_TARGET)
OSPROCINC=$(RTL)/freebsd/$(CPU_TARGET)
BSDINC=$(RTL)/bsd
BSDPROCINC=$(BSDINC)/$(CPU_TARGET)
UNIXINC=$(RTL)/unix
UNITPREFIX=rtl
CPU_UNITS=

ifeq ($(findstring 1.0.,$(FPC_VERSION)),)
SYSTEMUNIT=system
override FPCOPT+=-dNOMOUSE
loaders+=gprt0
else
SYSTEMUNIT=sysbsd
override FPCOPT+=-dUNIX -dNOMOUSE
endif

ifeq ($(ARCH),i386)
CPU_UNITS=x86 ports cpu mmx
endif

ifeq ($(ARCH),x86_64)
CPU_UNITS=x86 ports cpu
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

[rules]
.NOTPARALLEL:
# Get the system 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 system unit dependencies together.
SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)


#
# Loaders
#

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

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

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

#
# System Units (System, Objpas, Strings)
#

$(SYSTEMUNIT)$(PPUEXT) : $(BSDINC)/$(SYSTEMUNIT).pp unxconst.inc $(SYSDEPS)
        $(COMPILER) -Us -Sg $(BSDINC)/$(SYSTEMUNIT).pp

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


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


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

#
# System Dependent Units
#

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

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


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

linux$(PPUEXT) : baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)

#
# TP7 Compatible RTL Units
#

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

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

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

printer$(PPUEXT) : $(UNIXINC)/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

rtlconsts$(PPUEXT) : $(OBJPASDIR)/rtlconsts.pp
	$(COMPILER) $(OBJPASDIR)/rtlconsts.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

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

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

fmtbcd$(PPUEXT) : $(OBJPASDIR)/fmtbcd.pp objpas$(PPUEXT) sysutils$(PPUEXT) variants$(PPUEXT) classes$(PPUEXT) system$(PPUEXT)
        $(COMPILER) $(OBJPASDIR)/fmtbcd.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

#
# Mac Pascal Model
#

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

#
# Other system-independent RTL Units
#

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

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 system-dependent RTL Units
#

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

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

ipc$(PPUEXT) : $(UNIXINC)/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)

sysctl$(PPUEXT) : $(BSDINC)/sysctl.pp $(SYSTEMUNIT)$(PPUEXT) syscall$(PPUEXT)

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

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

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

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

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

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

