#
# Makefile generated by fpcmake v0.99.15 [2000/07/02]
#

defaultrule: all

#####################################################################
# Autodetect OS (Linux or Dos or Windows NT)
# define inlinux when running under linux
# 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
inlinux=1
endif
else
PWD:=$(firstword $(PWD))
endif

# Detect NT - NT sets OS to Windows_NT
ifndef inlinux
ifeq ($(OS),Windows_NT)
inWinNT=1
endif
endif

# Detect OS/2 - OS/2 has OS2_SHELL defined
ifndef inlinux
ifndef inWinNT
ifdef OS2_SHELL
inOS2=1
endif
endif
endif

# The extension of executables
ifdef inlinux
EXEEXT=
else
EXEEXT=.exe
endif

# The path which is searched separated by spaces
ifdef inlinux
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
ifdef inOS2
FPC=ppos2
else
FPC=ppc386
endif
endif
endif
override FPC:=$(subst $(EXEEXT),,$(FPC))
override FPC:=$(subst \,/,$(FPC))$(EXEEXT)

# 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 inlinux
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 compiler gdb)

# Clean


# Install

ZIPTARGET=install

# Defaults


# Directories


# Packages


# Libraries




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

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

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

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

ifndef REDIRFILE
REDIRFILE=log
endif

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

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

all: $(addsuffix _all,$(DIROBJECTS))

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

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

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

showinstall: $(addsuffix _showinstall,$(DIROBJECTS))

install: $(addsuffix _install,$(DIROBJECTS))

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

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

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

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

.PHONY:  all debug smart shared showinstall install clean distclean cleanall require

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

OBJECTDIRCOMPILER=1
OBJECTDIRGDB=1

# Dir compiler

ifdef OBJECTDIRCOMPILER
.PHONY:  compiler_all compiler_debug compiler_examples compiler_test compiler_smart compiler_shared compiler_showinstall compiler_install compiler_sourceinstall compiler_exampleinstall compiler_zipinstall compiler_zipsourceinstall compiler_zipexampleinstall compiler_clean compiler_distclean compiler_cleanall compiler_require compiler_info

compiler_all:
	$(MAKE) -C compiler all

compiler_debug:
	$(MAKE) -C compiler debug

compiler_examples:
	$(MAKE) -C compiler examples

compiler_test:
	$(MAKE) -C compiler test

compiler_smart:
	$(MAKE) -C compiler smart

compiler_shared:
	$(MAKE) -C compiler shared

compiler_showinstall:
	$(MAKE) -C compiler showinstall

compiler_install:
	$(MAKE) -C compiler install

compiler_sourceinstall:
	$(MAKE) -C compiler sourceinstall

compiler_exampleinstall:
	$(MAKE) -C compiler exampleinstall

compiler_zipinstall:
	$(MAKE) -C compiler zipinstall

compiler_zipsourceinstall:
	$(MAKE) -C compiler zipsourceinstall

compiler_zipexampleinstall:
	$(MAKE) -C compiler zipexampleinstall

compiler_clean:
	$(MAKE) -C compiler clean

compiler_distclean:
	$(MAKE) -C compiler distclean

compiler_cleanall:
	$(MAKE) -C compiler cleanall

compiler_require:
	$(MAKE) -C compiler require

compiler_info:
	$(MAKE) -C compiler info
endif

# Dir gdb

ifdef OBJECTDIRGDB
.PHONY:  gdb_all gdb_debug gdb_examples gdb_test gdb_smart gdb_shared gdb_showinstall gdb_install gdb_sourceinstall gdb_exampleinstall gdb_zipinstall gdb_zipsourceinstall gdb_zipexampleinstall gdb_clean gdb_distclean gdb_cleanall gdb_require gdb_info

gdb_all:
	$(MAKE) -C gdb all

gdb_debug:
	$(MAKE) -C gdb debug

gdb_examples:
	$(MAKE) -C gdb examples

gdb_test:
	$(MAKE) -C gdb test

gdb_smart:
	$(MAKE) -C gdb smart

gdb_shared:
	$(MAKE) -C gdb shared

gdb_showinstall:
	$(MAKE) -C gdb showinstall

gdb_install:
	$(MAKE) -C gdb install

gdb_sourceinstall:
	$(MAKE) -C gdb sourceinstall

gdb_exampleinstall:
	$(MAKE) -C gdb exampleinstall

gdb_zipinstall:
	$(MAKE) -C gdb zipinstall

gdb_zipsourceinstall:
	$(MAKE) -C gdb zipsourceinstall

gdb_zipexampleinstall:
	$(MAKE) -C gdb zipexampleinstall

gdb_clean:
	$(MAKE) -C gdb clean

gdb_distclean:
	$(MAKE) -C gdb distclean

gdb_cleanall:
	$(MAKE) -C gdb cleanall

gdb_require:
	$(MAKE) -C gdb require

gdb_info:
	$(MAKE) -C gdb info
endif

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

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

