VPATH = ../../p
# Makefile for GNU Pascal compiler.
#   Copyright (C) 1987, 88, 90-4, 1995, 1997 Free Software Foundation, Inc.

#This file is part of GNU Pascal.

#GNU Pascal is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2, or (at your option)
#any later version.

#GNU Pascal is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with GNU Pascal; see the file COPYING.  If not, write to
#the Free Software Foundation, 59 Temple Place - Suite 330,
#Boston, MA 02111-1307, USA.

# The makefile built from this file lives in the language subdirectory.
# Its purpose is to provide support for:
#
# 1) recursion where necessary, and only then (building .o's), and
# 2) building and debugging gpc1 from the language subdirectory, and
# 3) nothing else.
#
# The parent makefile handles all other chores, with help from the
# language makefile fragment, of course.
#
# The targets for external use are:
# all, TAGS, ???mostlyclean, ???clean.

# Suppress smart makes who think they know how to automake Yacc files
.y.c:

# Variables that exist for you to override.
# See below for how to change them for certain systems.

ALLOCA =

# Various ways of specifying flags for compilations:  
# CFLAGS is for the user to override to, e.g., do a bootstrap with -O2.
# BOOT_CFLAGS is the value of CFLAGS to pass
# to the stage2 and stage3 compilations
# XCFLAGS is used for most compilations but not when using the GCC just built.
XCFLAGS =
CFLAGS = -g
BOOT_CFLAGS = -O $(CFLAGS)
# These exists to be overridden by the x-* and t-* files, respectively.
X_CFLAGS =
T_CFLAGS =

X_CPPFLAGS =
T_CPPFLAGS =

CC = cc
BISON = bison
BISONFLAGS =
LEX = flex
LEXFLAGS =
AR = ar
AR_FLAGS = rc
SHELL = /bin/sh
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi
DIFF = diff
DIFF_FLAGS = -C4

# Define this as & to perform parallel make on a Sequent.
# Note that this has some bugs, and it seems currently necessary 
# to compile all the gen* files first by hand to avoid erroneous results.
P =

# This is used in the definition of SUBDIR_USE_ALLOCA.
# ??? Perhaps it would be better if it just looked for *gcc*.
OLDCC = cc

# This is used instead of ALL_CFLAGS when compiling with GCC_FOR_TARGET.
# It omits XCFLAGS, and specifies -B./.
# It also specifies -B$(tooldir)/ to find as and ld for a cross compiler.
GCC_CFLAGS=$(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS)

# Tools to use when building a cross-compiler.
# These are used because `configure' appends `cross-make'
# to the makefile when making a cross-compiler.

target=i586-pc-msdosdjgpp
xmake_file= ../config/i386/x-go32
tmake_file= ../config/i386/t-go32

# Directory where sources are, from where we are.
srcdir = ../../p

# Additional system libraries to link with.
CLIB=

# Change this to a null string if obstacks are installed in the
# system library.
OBSTACK=obstack.o

# Choose the real default target.
ALL=error

# End of variables for you to override.

# Bomb out
error:
	echo "Invoke make from toplevel only"

# Definition of `all' is here so that new rules inserted by sed
# do not specify the default target.
all: all.indirect

# This tells GNU Make version 3 not to put all variables in the environment.
.NOEXPORT:

# sed inserts variable overrides after the following line.
####target overrides
LIBGCC1 = libgcc1.null
CROSS_LIBGCC1 = libgcc1.null
####host overrides
# translate the version string, so it can be used on DJGPP, where only
# one dot in filename is allowed

# to avoid recursion when redefining $(version)
_version:=$(version)
__version=$(subst ., ,$(_version))
version=

SYSTEM_HEADER_DIR=$(DJDIR)/include
X_CPPFLAGS=-DSTANDARD_INCLUDE_DIR=\"\$$DJDIR/include\" \
	   -DSTANDARD_INCLUDE_COMPONENT=\"\"
FIXINCLUDES=fixinc.djgpp

# when building a native compiler for DJGPP, make the target_alias
# a shorter name, since otherwise it will produce some problems, when
# using the same gcc once with long filenames and once with short (8+3)
# filenames
ifeq ($(findstring -pc-msdosdjgpp,$(target_alias)),-pc-msdosdjgpp)
target_alias=djgpp
endif

# on DJGPP the 'ln -s' does not work correctly
LN = cp -p
LN_S = cp -p

EXTRA_GCC_OBJS += djgcc-mktemp.o
EXTRA_COLLECT2_OBJS += pexecute.o
#
#   Replacement for DJGPP libc.a function mktemp() that excludes 
#   possibility of filename conflicts between 2 or more copies of
#   gcc running simultanously. I added -I$(DJDIR)/include before
#   $(INCLUDES) to get DJGPP specific headers included before gcc
#   specific ones (the problem is with go32.h)
#
djgcc-mktemp.o: $(srcdir)/config/i386/djgcc-mktemp.c $(CONFIG_H) 
	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) \
  -I$(DJDIR)/include \
  $(INCLUDES) \
  $(DRIVER_DEFINES) \
  -o djgcc-mktemp.o -c $(srcdir)/config/i386/djgcc-mktemp.c

####cross overrides
####build overrides

# Now figure out from those variables how to compile and link.

all.indirect: Makefile ../gpc1$(exeext) ../gpc-cpp$(exeext) ../libgpc.a

# IN_GCC tells obstack.h that we are using gcc's <stddef.h> file.
INTERNAL_CFLAGS = $(CROSS) -DIN_GCC -DGPC $(GPC_EGCS_FLAG)

# This is the variable actually used when we compile.
ALL_CFLAGS = $(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS) $(XCFLAGS) \
	$(SCHED_CFLAGS)

# Likewise.
ALL_CPPFLAGS = $(CPPFLAGS) $(X_CPPFLAGS) $(T_CPPFLAGS)

# Extra warnings for GPC
ALL_WARNINGS = -Wall
#ALL_WARNINGS = -ansi -pedantic -Wall -Wpointer-arith \
#	-Wmissing-prototypes # -Wwrite-strings

# Even if ALLOCA is set, don't use it if compiling with GCC.

SUBDIR_OBSTACK = `if [ x$(OBSTACK) != x ]; then echo ../$(OBSTACK); else true; fi`
SUBDIR_USE_ALLOCA = `case "${CC}" in "${OLDCC}") if [ x$(ALLOCA) != x ]; then echo ../$(ALLOCA); else true; fi ;; esac`
SUBDIR_MALLOC = `if [ x$(MALLOC) != x ]; then echo ../$(MALLOC); else true; fi`

# How to link with both our special library facilities
# and the system's installed libraries.
LIBS = $(SUBDIR_OBSTACK) $(SUBDIR_USE_ALLOCA) $(SUBDIR_MALLOC) $(CLIB)

# Specify the directories to be searched for header files.
# Both . and srcdir are used, in that order,
# so that tm.h and config.h will be found in the compilation
# subdirectory rather than in the source directory.
INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config -I$(srcdir)/../../include

# Flags_to_pass to recursive makes.
# Note that we don't need to distinguish the `_FOR_TARGET' cross tools
# as AR and RANLIB are set appropriately by configure iff cross compiling.
FLAGS_TO_PASS = \
	"CROSS=$(CROSS)" \
	"AR_FLAGS=$(AR_FLAGS)" \
	"AR=$(AR)" \
	"BISON=$(BISON)" \
	"BISONFLAGS=$(BISONFLAGS)" \
	"CC=$(CC)" \
	"CFLAGS=$(CFLAGS)" \
	"GCCFLAGS=$(GCCFLAGS)" \
	"GCC_FOR_TARGET=$(GCC_FOR_TARGET)" \
	"GPC_FOR_TARGET=$(GPC_FOR_TARGET)" \
	"LDFLAGS=$(LDFLAGS)" \
	"LEX=$(LEX)" \
	"LEXFLAGS=$(LEXFLAGS)" \
	"MAKEINFO=$(MAKEINFO)" \
	"MAKEINFOFLAGS=$(MAKEINFOFLAGS)" \
	"RANLIB=$(RANLIB)" \
	"RANLIB_TEST=$(RANLIB_TEST)" \
	"SCHED_CFLAGS=$(SCHED_CFLAGS)" \
	"SHELL=$(SHELL)" \
	"exec_prefix=`echo '$(exec_prefix)'|sed -e 's/\\$$/\\\\&&/g'`" \
	"prefix=`echo '$(prefix)'|sed -e 's/\\$$/\\\\&&/g'`" \
	"tooldir=`echo '$(tooldir)'|sed -e 's/\\$$/\\\\&&/g'`" \
	"bindir=`echo '$(bindir)'|sed -e 's/\\$$/\\\\&&/g'`" \
	"libsubdir=`echo '$(libsubdir)'|sed -e 's/\\$$/\\\\&&/g'`"

# Always use -I$(srcdir)/config when compiling.
.c.o:
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

# Lists of files for various purposes.

# (1) The GNU back end (GBE). Supposed to be language independent and reused
#     unmodified by all members of the GNU compiler family. Some parts of
#     the GBE require GPC specific patches though.

# Remove patched files from language-independent object file list.
# `version.c' is replaced by `p/version.c'
GCC_OBJDEPS = ../stamp-objlist
GCC_OBJS = `cat ../stamp-objlist | sed -e 's:  : :g' \
        -e 's:../convert.o::g' \
        -e 's:../dbxout.o::g' \
        -e 's:../expr.o::g' \
        -e 's:../fold-const.o::g' \
        -e 's:../function.o::g' \
        -e 's:../optabs.o::g' \
        -e 's:../stor-layout.o::g' \
        -e 's:../toplev.o::g' \
        -e 's:../tree.o::g' \
        -e 's:../version.o::g'`

# GBE files patched for GPC.
# Rebuild these with -DGPC
GCC_PATCHED = convert.o dbxout.o expr.o fold-const.o \
	function.o optabs.o stor-layout.o toplev.o tree.o

stamp-gbe: Makefile $(GCC_OBJDEPS) $(GCC_PATCHED)
	echo " $(GCC_OBJS) $(GCC_PATCHED)" >stamp-gbe

GBE_OBJS = `cat stamp-gbe`
GBE_OBJDEPS = stamp-gbe

# (2) Language-specific object files for gpc
#     Currently the (c-aux-info.c,c-iterate.c) file is not modified
#     so we use the original C-compiler file
GPC_OBJDEPS = stamp-gpc1
GPC_OBJS = ../c-aux-info.o ../c-iterate.o ../c-pragma.o \
	../choose-temp.o ../pexecute.o mkstemp.o \
	gpc-common.o gpc-convert.o gpc-decl.o gpc-lang.o gpc-lex.o \
	gpc-typeck.o module.o gpi-hash.o circle-buf.o objects.o \
	parse.o rts.o types.o util.o setop.o version.o

stamp-gpc1: Makefile $(GPC_OBJS)
	echo " $(GPC_OBJS)" >stamp-gpc1

compiler: ../gpc1$(exeext)
../gpc1$(exeext): $(P) $(GBE_OBJDEPS) $(GPC_OBJDEPS) $(LIBDEPS)
	rm -f ../gpc1$(exeext)
	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
	      $(GBE_OBJS) $(GPC_OBJS) $(LIBS) $(EXTRA_LIBS)

preprocessor: ../gpc-cpp$(exeext)
../gpc-cpp$(exeext): $(P) gpc-cccp.o ../cexp.o ../mbchar.o version.o $(LIBDEPS)
	rm -f ../gpc-cpp$(exeext)
	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
	      gpc-cccp.o ../cexp.o ../mbchar.o version.o $(LIBS) $(EXTRA_LIBS)

Makefile: $(srcdir)/Makefile.in $(srcdir)/../configure
	cd ..; $(SHELL) config.status

native: ../gpc1$(exeext) ../gpc-cpp$(exeext)

# Compiling object files from source files.

# Note that dependencies on obstack.h are not written
# because that file is not part of GCC.

# Pascal language specific files.

RTL_H = $(srcdir)/../rtl.h $(srcdir)/../rtl.def \
	$(srcdir)/../machmode.h $(srcdir)/../machmode.def
TREE_H = $(srcdir)/../tree.h $(srcdir)/../real.h $(srcdir)/../tree.def \
	$(srcdir)/../machmode.h $(srcdir)/../machmode.def
FLAGS_H = $(srcdir)/../flags.h
INPUT_H = $(srcdir)/../input.h
CONVERT_H = $(srcdir)/../convert.h
GPC_TREE_H = $(TREE_H) # gpc-tree.h tree.def

PARSE_H = $(srcdir)/parse.h
PARSE_C = $(srcdir)/parse.c

parse.o: $(PARSE_C) $(CONFIG_H) $(GPC_TREE_H) $(INPUT_H) \
 $(srcdir)/../c-tree.h $(FLAGS_H) gpc-defs.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) \
  $(INCLUDES) $(BIG_SWITCHFLAG) \
  `echo $(PARSE_C) | sed 's,^\./,,'`

CONFLICTS =

$(PARSE_H) : $(PARSE_C)
$(PARSE_C) : $(srcdir)/parse.y
#	@echo $(CONFLICTS)
	cd $(srcdir); $(BISON) $(BISONFLAGS) -d -o parse.c parse.y
	cd $(srcdir); grep '^#define[ 	]*YYEMPTY' parse.c >>parse.h

# hash.h really depends on $(srcdir)/gpc.gperf.
# But this would screw things for people that don't have gperf,
# if gpc.gperf got touched, say.
# Thus you have to remove hash.h to force it to be re-made.
$(srcdir)/hash.h:
	gperf -p -j1 -g -G -o -t -N is_reserved_word \
		$(srcdir)/gpc.gperf > $(srcdir)/hash.h

# Compiling object files from source files.

# Note that dependencies on obstack.h are not written
# because that file is not part of GCC.

# Pascal language specific files.
# Use maximum warnings for them.

circle-buf.o: circle-buf.c circle-buf.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) $(INCLUDES) $<

gpi-hash.o: gpi-hash.c gpi-hash.h $(CONFIG_H) $(GBE_H) gpc-defs.h \
 util.h module.h util.h circle-buf.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) $(INCLUDES) $<

module.o: module.c module.h $(CONFIG_H) $(GBE_H) gpc-defs.h \
 gpc-nodes.def util.h module.h circle-buf.h gpi-hash.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) $(INCLUDES) $<

objects.o: objects.c objects.h $(CONFIG_H) $(GBE_H) gpc-defs.h \
 types.h util.h $(srcdir)/rts/types.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) $(INCLUDES) $<

rts.o: rts.c rts.h $(CONFIG_H) gpc-defs.h module.h \
 $(PARSE_H) types.h util.h $(srcdir)/rts/types.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) $(INCLUDES) $<

setop.o: setop.c setop.h $(CONFIG_H) $(GBE_H) ../insn-flags.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) $(INCLUDES) $<

types.o: types.c types.h $(CONFIG_H) $(GBE_H) gpc-defs.h objects.h \
 util.h types.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) $(INCLUDES) $<

util.o: util.c util.h $(CONFIG_H) $(GBE_H) gpc-defs.h module.h \
 $(PARSE_H) rts.h types.h $(srcdir)/rts/types.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(ALL_WARNINGS) $(INCLUDES) $<

# Modified GCC files.
# Don't even think of using -Wall on these :-(

gpc-common.o: gpc-common.c $(CONFIG_H) $(GPC_TREE_H) $(FLAGS_H) \
 $(PARSE_H) $(srcdir)/../c-lex.h $(srcdir)/../rtl.h gpc-defs.h \
 types.h parse.h rts.h util.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

gpc-convert.o: gpc-convert.c $(CONFIG_H) $(GPC_TREE_H) $(FLAGS_H) \
 $(CONVERT_H) gpc-defs.h types.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

gpc-decl.o: gpc-decl.c $(CONFIG_H) $(GPC_TREE_H) $(FLAGS_H) \
 $(srcdir)/../output.h $(srcdir)/../c-lex.h gpc-defs.h module.h \
 objects.h util.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

gpc-lang.o: gpc-lang.c $(CONFIG_H) $(GPC_TREE_H) $(INPUT_H) ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

gpc-lex.o: gpc-lex.c $(CONFIG_H) $(GPC_TREE_H) $(INPUT_H) \
 $(FLAGS_H) gpc-defs.h $(PARSE_H) hash.h gpc-defs.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

gpc-typeck.o: gpc-typeck.c $(CONFIG_H) $(GPC_TREE_H) $(srcdir)/../c-tree.h \
 $(FLAGS_H) gpc-defs.h $(srcdir)/../output.h module.h types.h util.h ../gansidecl.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

# Language Independent files that need to be patched for GPC
#
# For EGCS support, we dropped the dependency of the bytecode-related files:
# $(srcdir)/../bytecode.h $(srcdir)/../modemap.def ../bc-opcode.h \
# $(srcdir)/../bc-typecd.h $(srcdir)/../bc-typecd.def
# $(srcdir)/../bc-optab.h $(srcdir)/../bc-emit.h
# We do not change those files for Pascal anyway.

convert.o: $(srcdir)/../convert.c $(CONFIG_H) $(TREE_H) $(FLAGS_H) \
 $(CONVERT_H)
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/../convert.c

dbxout.o: $(srcdir)/../dbxout.c $(CONFIG_H) $(TREE_H) $(RTL_H) \
 $(FLAGS_H) $(srcdir)/../regs.h ../insn-config.h $(srcdir)/../reload.h \
 $(srcdir)/../gstab.h $(srcdir)/../xcoffout.h $(srcdir)/../defaults.h \
 $(srcdir)/../output.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/../dbxout.c

expr.o: $(srcdir)/../expr.c $(CONFIG_H) $(RTL_H) $(TREE_H) $(FLAGS_H) \
 $(srcdir)/../function.h $(srcdir)/../regs.h ../insn-flags.h \
 ../insn-codes.h $(srcdir)/../expr.h ../insn-config.h $(srcdir)/../recog.h \
 $(srcdir)/../output.h $(srcdir)/../typeclass.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/../expr.c

fold-const.o: $(srcdir)/../fold-const.c $(CONFIG_H) $(TREE_H) $(FLAGS_H)
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/../fold-const.c

function.o: $(srcdir)/../function.c $(CONFIG_H) $(RTL_H) $(TREE_H) \
 $(FLAGS_H) $(srcdir)/../function.h ../insn-flags.h ../insn-codes.h \
 $(srcdir)/../expr.h $(srcdir)/../regs.h $(srcdir)/../hard-reg-set.h \
 ../insn-config.h $(srcdir)/../recog.h $(srcdir)/../output.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/../function.c

optabs.o: $(srcdir)/../optabs.c $(CONFIG_H) $(RTL_H) $(TREE_H) \
 $(FLAGS_H) ../insn-flags.h ../insn-config.h ../insn-codes.h \
 $(srcdir)/../expr.h $(srcdir)/../recog.h $(srcdir)/../reload.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/../optabs.c

stor-layout.o: $(srcdir)/../stor-layout.c $(CONFIG_H) $(TREE_H) \
 $(FLAGS_H) $(srcdir)/../function.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/../stor-layout.c

toplev.o : $(srcdir)/../toplev.c $(CONFIG_H) $(TREE_H) $(RTL_H) \
 $(FLAGS_H) $(INPUT_H) \
 ../insn-attr.h $(srcdir)/../xcoffout.h $(srcdir)/../defaults.h \
 $(srcdir)/../output.h lang-options.h
	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
	  $(MAYBE_TARGET_DEFAULT) $(MAYBE_USE_COLLECT2) \
	  -DTARGET_NAME=\"$(target_alias)\" \
	  -c `echo $(srcdir)/../toplev.c | sed 's,^\./,,'`

tree.o: $(srcdir)/../tree.c $(CONFIG_H) $(TREE_H) \
 $(FLAGS_H) $(srcdir)/../function.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/../tree.c

gpc-cccp.o: gpc-cccp.c version.c $(CONFIG_H) ../pcp.h ../config.status
# The reason we use $(libdir)/g++-include rather than using libsubdir
# is for compatibility with the current version of libg++.
	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
	  -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \
	  -DGPLUSPLUS_INCLUDE_DIR=\"$(gxx_include_dir)\" \
	  -DOLD_GPLUSPLUS_INCLUDE_DIR=\"$(old_gxx_include_dir)\" \
	  -DLOCAL_INCLUDE_DIR=\"$(includedir)\" \
	  -DCROSS_INCLUDE_DIR=\"$(libsubdir)/sys-include\" \
	  -DTOOL_INCLUDE_DIR=\"$(tooldir)/include\" \
	  -c `echo $(srcdir)/gpc-cccp.c | sed 's,^\./,,'`

# These exist for maintenance purposes.

# Build diffs for Pascal language implementation files inherited
# from GCC source.
$(srcdir)/gpc-cccp.c.diff: $(srcdir)/gpc-cccp.c $(srcdir)/../cccp.c
	$(DIFF) $(DIFF_FLAGS) $(srcdir)/../cccp.c $(srcdir)/gpc-cccp.c > $@ ; \
	touch $@

$(srcdir)/gpc-common.c.diff: $(srcdir)/gpc-common.c $(srcdir)/../c-common.c
	$(DIFF) $(DIFF_FLAGS) $(srcdir)/../c-common.c $(srcdir)/gpc-common.c > $@ ; \
	touch $@

$(srcdir)/gpc-convert.c.diff: $(srcdir)/gpc-convert.c $(srcdir)/../c-convert.c
	$(DIFF) $(DIFF_FLAGS) $(srcdir)/../c-convert.c $(srcdir)/gpc-convert.c > $@ ; \
	touch $@

$(srcdir)/gpc-decl.c.diff: $(srcdir)/gpc-decl.c $(srcdir)/../c-decl.c
	$(DIFF) $(DIFF_FLAGS) $(srcdir)/../c-decl.c $(srcdir)/gpc-decl.c > $@ ; \
	touch $@

$(srcdir)/gpc-lang.c.diff: $(srcdir)/gpc-lang.c $(srcdir)/../c-lang.c
	$(DIFF) $(DIFF_FLAGS) $(srcdir)/../c-lang.c $(srcdir)/gpc-lang.c > $@ ; \
	touch $@

$(srcdir)/gpc-lex.c.diff: $(srcdir)/gpc-lex.c $(srcdir)/../c-lex.c
	$(DIFF) $(DIFF_FLAGS) $(srcdir)/../c-lex.c $(srcdir)/gpc-lex.c > $@ ; \
	touch $@

$(srcdir)/gpc-typeck.c.diff: $(srcdir)/../c-typeck.c $(srcdir)/gpc-typeck.c
	$(DIFF) $(DIFF_FLAGS) $(srcdir)/../c-typeck.c $(srcdir)/gpc-typeck.c > $@ ; \
	touch $@

# Rebuild Pascal language implementation files inherited from GCC source.
$(srcdir)/gpc-cccp.c:
	cd $(srcdir) ; \
	patch -s -p0 ../cccp.c -o gpc-cccp.c < gpc-cccp.c.diff ; \

$(srcdir)/gpc-common.c:
	cd $(srcdir) ; \
	patch -s -p0 ../c-common.c -o gpc-common.c < gpc-common.c.diff

$(srcdir)/gpc-convert.c:
	cd $(srcdir) ; \
	patch -s -p0 ../c-convert.c -o gpc-convert.c < gpc-convert.c.diff

$(srcdir)/gpc-decl.c:
	cd $(srcdir) ; \
	patch -s -p0 ../c-decl.c -o gpc-decl.c < gpc-decl.c.diff

$(srcdir)/gpc-lang.c:
	cd $(srcdir) ; \
	patch -s -p0 ../c-lang.c -o gpc-lang.c < gpc-lang.c.diff

$(srcdir)/gpc-lex.c:
	cd $(srcdir) ; \
	patch -s -p0 ../c-lex.c -o gpc-lex.c < gpc-lex.c.diff

$(srcdir)/gpc-typeck.c:
	cd $(srcdir) ; \
	patch -s -p0 ../c-typeck.c -o gpc-typeck.c < gpc-typeck.c.diff

# GBE source files changed for GPC.
GBE_GPC_SRC = convert.c dbxout.c expr.c fold-const.c function.c \
	optabs.c stor-layout.c toplev.c tree.c

# Pascal language implementation files inherited from GCC source.
GCCLANG_SRC = gpc-cccp.c gpc-common.c gpc-convert.c gpc-decl.c \
	gpc-lang.c gpc-lex.c gpc-typeck.c

GCCLANG_SRC_DIFF = gpc-cccp.c.diff gpc-common.c.diff gpc-convert.c.diff \
	gpc-decl.c.diff gpc-lang.c.diff gpc-lex.c.diff gpc-typeck.c.diff


gpc-all.diff : $(GCCLANG_SRC_DIFF)
	rm -f gpc-all.diff ;		\
	for f in $(GCCLANG_SRC_DIFF) ;	\
	do				\
	  cat $$f >> gpc-all.diff ;	\
	done


# (JJ) Change path depth?
gbe-diff: force
	cd $(srcdir)/../ ;		\
	rm -f gbe.diff ;		\
	for f in $(GBE_GPC_SRC) ; do	\
	  $(DIFF) $(DIFF_FLAGS) $$f.orig $$f >> gbe.diff ; \
	  echo "$$f" ;			\
	done ;				\
	mv -f gbe.diff $(srcdir)/patches

# take diffs of language dependent files
lang-diff: force
	cd $(srcdir) ;			\
	for i in $(GCCLANG_SRC) ; do	\
	  $(DIFF) $(DIFF_FLAGS) ../`echo $$i | sed -e "s/gpc-/c-/"` $$i > $${i}.diff ; \
	  echo "$$i" ;			\
	done

# Upgrading GPC to a different GCC release.
# (1) Run `make prepare-upgrade' in the "old" gcc-x.y.z/p/ subdirectory.
# (2) Move the "p" subdirectory to the new GCC distribution.
# (3) Run `make upgrade' in the new gcc-a.b.c/p/ subdirectory.
# (4) Resolve .rej files manually and debug thoroughly ;-)
# (5) Rebuild GBE patches for new GCC.
prepare-upgrade: $(GCCLANG_SRC_DIFF)
	cd $(srcdir) ;			\
	for f in $(GCCLANG_SRC) ; do	\
	  mv $$f $$f.old ;		\
	  echo "$$f -> $$f.old" ;	\
	done ;				\
	touch stamp-prepare

stamp-prepare:
	echo "Run 'make prepare-upgrade' with the old gcc dist first"
	error_forced_here

upgrade: stamp-prepare $(GCCLANG_SRC)
	cd $(srcdir) ;			\
	for f in $(GCCLANG_SRC) ; do	\
	  echo "$$f" ;			\
	  cp -v -f ../`echo $$f | sed -e "s/gpc-/c-/"` $$f ; \
	  echo "patch -p0 < $${f}.diff" ; \
	  patch -p0 < $${f}.diff ;	\
	  echo "$$f" ;			\
	done ;				\

# dejagnu
# Setup the testing framework, if you have one
EXPECT = `if [ -f $${rootme}/../expect/expect ] ; then \
            echo $${rootme}/../expect/expect ; \
          else echo expect ; fi`

RUNTEST = `if [ -f $${srcdir}/../dejagnu/runtest ] ; then \
	       echo $${srcdir}/../dejagnu/runtest ; \
	    else echo runtest; fi`

RUNTESTFLAGS =

# These targets are for the dejagnu testsuites. The file site.exp 
# contains global variables that all the testsuites will use.

site.exp: ../config.status Makefile
	@echo "Making a new config file..."
	-@rm -f ./tmp?
	@touch site.exp
	-@mv site.exp site.bak
	@echo "## these variables are automatically generated by make ##" > ./tmp0
	@echo "# Do not edit here. If you wish to override these values" >> ./tmp0
	@echo "# add them to the last section" >> ./tmp0
	@echo "set rootme \"`pwd`\"" >> ./tmp0
	@echo "set srcdir \"`cd ${srcdir}; pwd`\"" >> ./tmp0
	@echo "set host_triplet $(host_canonical)" >> ./tmp0
	@echo "set build_triplet $(build_canonical)" >> ./tmp0
	@echo "set target_triplet $(target)" >> ./tmp0
	@echo "set target_alias $(target_alias)" >> ./tmp0
# PFLAGS is set even though it's empty to show we reserve the right to set it.
	@echo "set PFLAGS \"\"" >> ./tmp0
	@echo "set srcdir \"\$${srcdir}/testsuite\"" >> ./tmp0
	@echo "## All variables above are generated by configure. Do Not Edit ##" >> ./tmp0
	@cat ./tmp0 > site.exp
	@cat site.bak | sed \
		-e '1,/^## All variables above are.*##/ d' >> site.exp
	-@rm -f ./tmp?

test/Makefile: $(srcdir)/test/Makefile
	if [ ! -d test ]; then \
	   mkdir test; \
	fi; \
	cp $(srcdir)/test/Makefile  test/Makefile

check2-gpc: test/Makefile
	if [ ! -d test ]; then \
	   mkdir test; \
	fi; \
	if [ ! -f test/Makefile ]; then \
	   cp $(srcdir)/test/Makefile test/Makefile; \
	fi; \
	srcdir=`cd $(srcdir)/test; pwd`; \
	builddir=`cd ..; pwd`; \
	cd test && $(MAKE) PC="$$builddir/xgpc -B$$builddir/" \
		EXTRA_PFLAGS="--unit-path=$$builddir/p/units --object-path=$$builddir/p/units" \
		srcdir=$$srcdir test

CHECK_TARGETS = check-gpc

check: $(CHECK_TARGETS)

check-gpc: site.exp
	if [ -d testsuite ]; then \
	  true; \
	else \
	  mkdir testsuite; \
	fi
	rm -rf testsuite/site.exp
	cp site.exp testsuite/site.exp
	rootme=`pwd`; export rootme; \
	srcdir=`cd ${srcdir}; pwd` ; export srcdir ; \
	cd testsuite; \
	EXPECT=${EXPECT} ; export EXPECT ; \
	if [ -f $${rootme}/../expect/expect ] ; then  \
	   TCL_LIBRARY=$${srcdir}/../tcl/library ; \
	   export TCL_LIBRARY ; fi ; \
	$(RUNTEST) --tool gpc $(RUNTESTFLAGS)

# Update the tags table.
TAGS: force
	cd $(srcdir) ;				\
	etags *.c *.h ;				\
	echo 'l' | tr 'l' '\f' >> TAGS ;	\
	echo 'parse.y,0' >> TAGS ; 		\
	etags -a ../*.h ../*.c;

.PHONY: TAGS lang-diff

force:
