#
# Makefile generated by fpcmake v1.00 [2000/10/27]
#

defaultrule: all

#####################################################################
# Autodetect OS (Linux or Dos or Windows NT)
# define inUnix when running under Unix (Linux,FreeBSD)
# define inWinNT when running under WinNT
#####################################################################

# We need only / in the path
override PATH:=$(subst \,/,$(PATH))

# Search for PWD and determine also if we are under linux
PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(subst ;, ,$(PATH)))))
ifeq ($(PWD),)
PWD:=$(strip $(wildcard $(addsuffix /pwd,$(subst :, ,$(PATH)))))
ifeq ($(PWD),)
nopwd:
	@echo You need the GNU utils package to use this Makefile!
	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
	@exit
else
inUnix=1
endif
else
PWD:=$(firstword $(PWD))
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
endif

# The extension of executables
ifdef inUnix
SRCEXEEXT=
else
SRCEXEEXT=.exe
endif

# The path which is searched separated by spaces
ifdef inUnix
SEARCHPATH=$(subst :, ,$(PATH))
else
SEARCHPATH=$(subst ;, ,$(PATH))
endif

# Base dir
ifdef PWD
BASEDIR:=$(shell $(PWD))
else
BASEDIR=.
endif

#####################################################################
# FPC version/target Detection
#####################################################################

# What compiler to use ?
ifndef FPC
# Compatibility with old makefiles
ifdef PP
FPC=$(PP)
else
FPC=ppc386
endif
endif
override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)

# Target OS
ifndef OS_TARGET
OS_TARGET:=$(shell $(FPC) -iTO)
endif

# Source OS
ifndef OS_SOURCE
OS_SOURCE:=$(shell $(FPC) -iSO)
endif

# Target CPU
ifndef CPU_TARGET
CPU_TARGET:=$(shell $(FPC) -iTP)
endif

# Source CPU
ifndef CPU_SOURCE
CPU_SOURCE:=$(shell $(FPC) -iSP)
endif

# FPC version
ifndef FPC_VERSION
FPC_VERSION:=$(shell $(FPC) -iV)
endif

export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION

#####################################################################
# FPCDIR Setting
#####################################################################

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

# 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 $(FPCDIR)/rtl),)
ifeq ($(wildcard $(FPCDIR)/units),)
override FPCDIR:=$(FPCDIR)/..
ifeq ($(wildcard $(FPCDIR)/rtl),)
ifeq ($(wildcard $(FPCDIR)/units),)
override FPCDIR=c:/pp
endif
endif
endif
endif
endif
endif

#####################################################################
# User Settings
#####################################################################


# Targets

override DIROBJECTS+=$(wildcard fake text)

# Clean


# Install

PACKAGENAME=ide
ZIPTARGET=install

# Defaults


# Directories


# Packages


# Libraries


#####################################################################
# Shell tools
#####################################################################

# echo
ifndef ECHO
ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
ifeq ($(ECHO),)
ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
ifeq ($(ECHO),)
ECHO:=echo
ECHOE:=echo
else
ECHO:=$(firstword $(ECHO))
ECHOE=$(ECHO) -E
endif
else
ECHO:=$(firstword $(ECHO))
ECHOE=$(ECHO) -E
endif
endif

# To copy pograms
ifndef COPY
COPY:=cp -fp
endif

# Copy a whole tree
ifndef COPYTREE
COPYTREE:=cp -rfp
endif

# To move pograms
ifndef MOVE
MOVE:=mv -f
endif

# Check delete program
ifndef DEL
DEL:=rm -f
endif

# Check deltree program
ifndef DELTREE
DELTREE:=rm -rf
endif

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

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

# To make a directory.
ifndef MKDIR
ifdef inUnix
MKDIR:=install -m 755 -d
else
MKDIR:=ginstall -m 755 -d
endif
endif

export ECHO ECHOE COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR

#####################################################################
# Default Tools
#####################################################################

# assembler, redefine it if cross compiling
ifndef AS
AS=as
endif

# linker, but probably not used
ifndef LD
LD=ld
endif

# ppas.bat / ppas.sh
ifdef inUnix
PPAS=ppas.sh
else
ifdef inOS2
PPAS=ppas.cmd
else
PPAS=ppas.bat
endif
endif

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

# ZipProg, you can't use Zip as the var name (PFV)
ifndef ZIPPROG
ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
ifeq ($(ZIPPROG),)
ZIPPROG=
else
ZIPPROG:=$(firstword $(ZIPPROG))
endif
endif
export ZIPPROG

ZIPOPT=-9
ZIPEXT=.zip

# Tar
ifndef TARPROG
TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
ifeq ($(TARPROG),)
TARPROG=
else
TARPROG:=$(firstword $(TARPROG))
endif
endif
export TARPROG

ifeq ($(USETAR),bz2)
TAROPT=vI
TAREXT=.tar.bz2
else
TAROPT=vz
TAREXT=.tar.gz
endif



#####################################################################
# Default Directories
#####################################################################

# Linux and freebsd use unix dirs with /usr/bin, /usr/lib
# When zipping use the target as default, when normal install then
# use the source os as default
ifdef ZIPNAME
# Zipinstall
ifeq ($(OS_TARGET),linux)
UNIXINSTALLDIR=1
endif
ifeq ($(OS_TARGET),freebsd)
UNIXINSTALLDIR=1
endif
else
# Normal install
ifeq ($(OS_SOURCE),linux)
UNIXINSTALLDIR=1
endif
ifeq ($(OS_SOURCE),freebsd)
UNIXINSTALLDIR=1
endif
endif

# set the prefix directory where to install everything
ifndef PREFIXINSTALLDIR
ifdef UNIXINSTALLDIR
PREFIXINSTALLDIR=/usr
else
PREFIXINSTALLDIR=/pp
endif
endif
export PREFIXINSTALLDIR

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

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

# set the base directory where to install everything
ifndef BASEINSTALLDIR
ifdef UNIXINSTALLDIR
BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(FPC_VERSION)
else
BASEINSTALLDIR=$(PREFIXINSTALLDIR)
endif
endif

# set the directory where to install the binaries
ifndef BININSTALLDIR
ifdef UNIXINSTALLDIR
BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
else
BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
endif
endif

# set the directory where to install the units.
ifndef UNITINSTALLDIR
UNITINSTALLDIR=$(BASEINSTALLDIR)/units/$(OS_TARGET)
ifdef UNITSUBDIR
UNITINSTALLDIR:=$(UNITINSTALLDIR)/$(UNITSUBDIR)
endif
endif

# Where to install shared libraries
ifndef LIBINSTALLDIR
ifdef UNIXINSTALLDIR
LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
else
LIBINSTALLDIR=$(UNITINSTALLDIR)
endif
endif

# Where the source files will be stored
ifndef SOURCEINSTALLDIR
ifdef UNIXINSTALLDIR
SOURCEINSTALLDIR=$(PREFIXINSTALLDIR)/src/fpc-$(FPC_VERSION)
else
SOURCEINSTALLDIR=$(BASEINSTALLDIR)/source
endif
ifdef SOURCESUBDIR
SOURCEINSTALLDIR:=$(SOURCEINSTALLDIR)/$(SOURCESUBDIR)
endif
endif

# Where the doc files will be stored
ifndef DOCINSTALLDIR
ifdef UNIXINSTALLDIR
DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc-$(FPC_VERSION)
else
DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
endif
endif

# Where to install the examples, under linux we use the doc dir
# because the copytree command will create a subdir itself
ifndef EXAMPLEINSTALLDIR
ifdef UNIXINSTALLDIR
EXAMPLEINSTALLDIR=$(DOCINSTALLDIR)/examples
else
EXAMPLEINSTALLDIR=$(BASEINSTALLDIR)/examples
endif
ifdef EXAMPLESUBDIR
EXAMPLEINSTALLDIR:=$(EXAMPLEINSTALLDIR)/$(EXAMPLESUBDIR)
endif
endif

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

#####################################################################
# Redirection
#####################################################################

ifndef REDIRFILE
REDIRFILE=log
endif

ifdef REDIR
ifndef inUnix
override FPC=redir -eo $(FPC)
endif
# set the verbosity to max
override FPCOPT+=-va
override REDIR:= >> $(REDIRFILE)
endif

#####################################################################
# Standard rules
#####################################################################

debug: $(addsuffix _debug,$(DIROBJECTS))

smart: $(addsuffix _smart,$(DIROBJECTS))

shared: $(addsuffix _shared,$(DIROBJECTS))

showinstall: $(addsuffix _showinstall,text)

install: $(addsuffix _install,text)

sourceinstall: fpc_sourceinstall

zipinstall: fpc_zipinstall

zipsourceinstall: fpc_zipsourceinstall

clean: $(addsuffix _clean,$(DIROBJECTS))

distclean: $(addsuffix _distclean,$(DIROBJECTS))

cleanall: $(addsuffix _cleanall,$(DIROBJECTS))

require: $(addsuffix _require,$(DIROBJECTS))

.PHONY:  debug smart shared showinstall install sourceinstall zipinstall zipsourceinstall clean distclean cleanall require

#####################################################################
# SourceInstall rules
#####################################################################

.PHONY: fpc_sourceinstall

ifndef SOURCETOPDIR
SOURCETOPDIR=$(BASEDIR)
endif

fpc_sourceinstall: clean
	$(MKDIR) $(SOURCEINSTALLDIR)
	$(COPYTREE) $(SOURCETOPDIR) $(SOURCEINSTALLDIR)

#####################################################################
# Zip
#####################################################################

.PHONY: fpc_zipinstall

# Create suffix to add
ifndef PACKAGESUFFIX
PACKAGESUFFIX=$(OS_TARGET)
ifeq ($(OS_TARGET),go32v2)
PACKAGESUFFIX=go32
endif
ifeq ($(OS_TARGET),win32)
PACKAGESUFFIX=w32
endif
endif

# Temporary path to pack a file
ifndef PACKDIR
ifndef inUnix
PACKDIR=$(BASEDIR)/pack_tmp
else
PACKDIR=/tmp/fpc-pack
endif
endif

# Maybe create default zipname from packagename
ifndef ZIPNAME
ifdef PACKAGENAME
ZIPNAME=$(PACKAGEPREFIX)$(PACKAGENAME)$(PACKAGESUFFIX)
endif
endif

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

fpc_zipinstall:
ifndef ZIPNAME
	@$(ECHO) "Please specify ZIPNAME!"
	@exit 1
else
	$(MAKE) $(ZIPTARGET) PREFIXINSTALLDIR=$(PACKDIR)
ifdef USETAR
	$(DEL) $(DESTZIPDIR)/$(ZIPNAME)$(TAREXT)
	cd $(PACKDIR) ; $(TARPROG) cf$(TAROPT) $(DESTZIPDIR)/$(ZIPNAME)$(TAREXT) * ; cd $(BASEDIR)
else
	$(DEL) $(DESTZIPDIR)/$(ZIPNAME)$(ZIPEXT)
	cd $(PACKDIR) ; $(ZIPPROG) -Dr $(ZIPOPT) $(DESTZIPDIR)/$(ZIPNAME)$(ZIPEXT) * ; cd $(BASEDIR)
endif
	$(DELTREE) $(PACKDIR)
endif

.PHONY:  fpc_zipsourceinstall

fpc_zipsourceinstall:
	$(MAKE) fpc_zipinstall ZIPTARGET=sourceinstall PACKAGESUFFIX=src

#####################################################################
# Directories
#####################################################################

OBJECTDIRFAKE=1
OBJECTDIRTEXT=1

# Dir fake

ifdef OBJECTDIRFAKE
.PHONY:  fake_all fake_debug fake_examples fake_test fake_smart fake_shared fake_showinstall fake_install fake_sourceinstall fake_exampleinstall fake_zipinstall fake_zipsourceinstall fake_zipexampleinstall fake_clean fake_distclean fake_cleanall fake_require fake_info

fake_all:
	$(MAKE) -C fake all

fake_debug:
	$(MAKE) -C fake debug

fake_examples:
	$(MAKE) -C fake examples

fake_test:
	$(MAKE) -C fake test

fake_smart:
	$(MAKE) -C fake smart

fake_shared:
	$(MAKE) -C fake shared

fake_showinstall:
	$(MAKE) -C fake showinstall

fake_install:
	$(MAKE) -C fake install

fake_sourceinstall:
	$(MAKE) -C fake sourceinstall

fake_exampleinstall:
	$(MAKE) -C fake exampleinstall

fake_zipinstall:
	$(MAKE) -C fake zipinstall

fake_zipsourceinstall:
	$(MAKE) -C fake zipsourceinstall

fake_zipexampleinstall:
	$(MAKE) -C fake zipexampleinstall

fake_clean:
	$(MAKE) -C fake clean

fake_distclean:
	$(MAKE) -C fake distclean

fake_cleanall:
	$(MAKE) -C fake cleanall

fake_require:
	$(MAKE) -C fake require

fake_info:
	$(MAKE) -C fake info
endif

# Dir text

ifdef OBJECTDIRTEXT
.PHONY:  text_all text_debug text_examples text_test text_smart text_shared text_showinstall text_install text_sourceinstall text_exampleinstall text_zipinstall text_zipsourceinstall text_zipexampleinstall text_clean text_distclean text_cleanall text_require text_info

text_all:
	$(MAKE) -C text all

text_debug:
	$(MAKE) -C text debug

text_examples:
	$(MAKE) -C text examples

text_test:
	$(MAKE) -C text test

text_smart:
	$(MAKE) -C text smart

text_shared:
	$(MAKE) -C text shared

text_showinstall:
	$(MAKE) -C text showinstall

text_install:
	$(MAKE) -C text install

text_sourceinstall:
	$(MAKE) -C text sourceinstall

text_exampleinstall:
	$(MAKE) -C text exampleinstall

text_zipinstall:
	$(MAKE) -C text zipinstall

text_zipsourceinstall:
	$(MAKE) -C text zipsourceinstall

text_zipexampleinstall:
	$(MAKE) -C text zipexampleinstall

text_clean:
	$(MAKE) -C text clean

text_distclean:
	$(MAKE) -C text distclean

text_cleanall:
	$(MAKE) -C text cleanall

text_require:
	$(MAKE) -C text require

text_info:
	$(MAKE) -C text info
endif

#####################################################################
# Local Makefile
#####################################################################

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

#####################################################################
# Users rules
#####################################################################

.PHONY: gdb full fullgdb clean_compiler

all:
	$(MAKE) -C text all

gdb:
	$(MAKE) -C text all GDB=1

full:
	$(MAKE) -C text all FULL=1 "NEEDOPT+=-Sg -dGDB -dBROWSERCOL"

fullgdb:
	$(MAKE) -C text all FULL=1 GDB=1 "NEEDOPT+=-Sg -dGDB -dBROWSERCOL"

#
# Misc
#
clean_compiler:
	$(MAKE) -C ../compiler clean
