#
#   Makefile.fpc for Free Pascal GDB Interface
#

[package]
name=gdbint
version=1.0.5

[target]
units=gdbint gdbcon
examples=testgdb symify

[compiler]
objectdir=libgdb/$(OS_TARGET)
librarydir=libgdb/$(OS_TARGET)

[require]
libc=y

[install]
fpcpackage=y

[default]
fpcdir=../..


[rules]
# For unix be sure to use the locally created gdbver
ifdef inUnix
CURRDIR=./
else
CURRDIR=
endif

GDBLIBDIR+=libgdb/$(OS_TARGET)
ifeq ($(OS_TARGET),go32v2)
ifneq ($(DJDIR),)
GDBLIBDIR+=$(DJDIR)/lib
endif
endif
# Detect if libgdb.a is available
override LIBGDB:=$(firstword $(wildcard $(addsuffix /libgdb.a,$(GDBLIBDIR))))
ifeq ($(LIBGDB),)
GDBFOUND=0
else
GDBFOUND=1
endif

ifeq ($(GDBFOUND),1)
# libgdb.a found

$(CURRDIR)getver$(EXEEXT) : gdbver.pp
        $(COMPILER) -o$(CURRDIR)getver$(EXEEXT) gdbver.pp

ifndef GOTGDBVER
# gdbver doesn't exists, build it first
gdbint$(PPUEXT): $(CURRDIR)gdbver$(EXEEXT)
        $(MAKE) gdbint$(PPUEXT) GOTGDBVER=1
else
# gdbver exists
GDBVER:=GDB_V$(strip $(shell $(CURRDIR)gdbver$(EXEEXT) -n))
gdbint$(PPUEXT): gdbint.pp
        @$(ECHO) Using GDB $(GDBVER)
        $(COMPILER) -d$(GDBVER) gdbint.pp
        $(DEL) gdbver$(EXEEXT) gdbver$(OEXT)
endif

else
# libgdb.a not found, default to libgdb v5
GDBVER=GDB_V5
gdbint$(PPUEXT): gdbint.pp
        @$(ECHO) libgdb.a not found, using default GDB $(GDBVER)
        $(COMPILER) -d$(GDBVER) gdbint.pp
endif

gdbcon$(PPUEXT): gdbcon.pp gdbint$(PPUEXT)

ifeq ($(OS_TARGET),go32v2)
DBGCOM=dbgcom$(OEXT)
else
DBGCOM=
endif

ifdef $(COMPILEDBGCOM)
# FPC conditionnal remove the file watching mecanism introduced
# in v2.02 of dbgcom.c because it relies
# on the fact that all files are opened via C lib calls
# which is wrong for FPC !!
$(DBGCOM): ../v4.16/dbgcom.c
        gcc -c -DFPC -Dother_sel -gstabs -o dbgcom.o -I../v4.16 ../v4.16/dbgcom.c
else
$(DBGCOM):
endif

simple: $(DBGCOM)
        -rm gdbint.ppu
        ppc386 -dUSE_LIBGDB gdbint
        ppc386 testgdb

testgdb$(EXEEXT): testgdb.pp gdbint$(PPUEXT) gdbcon$(PPUEXT) $(DBGCOM)

# Allow test for example
.PHONY: test

test: examples

clean: fpc_clean
        $(DEL) gdbver$(EXEEXT) gdbver$(OEXT)

