# 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.

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

# Version numbers
gpc_major=2
gpc_minor=0
gpc_release=19990118
gpc_version=$(gpc_release)
rts_version=$(gpc_release)
version=2.8.1  # Hardcoded for EMX

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

ALLOCA =

# Extra flags to pass to recursive makes.
GPC_FLAGS_TO_PASS = \
	"gpc_version=$(gpc_version)" \
	"rts_version=$(rts_version)" \
	"version=$(version)"

# Extra flags to pass when building the RTS.
RTS_FLAGS_TO_PASS = \
	AR="$(AR)" \
	AR_FLAGS="$(AR_FLAGS)" \
	CFLAGS="$(CFLAGS)" \
	LDFLAGS="$(LDFLAGS)" \
	RANLIB="$(RANLIB)" \
	SHELL="$(SHELL)"

# Actual name to use when installing a native compiler.
GPC_INSTALL_NAME = gpc

# 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 = -O2
BOOT_CFLAGS = -O $(CFLAGS)
LDFLAGS = 
# These exists to be overridden by the x-* and t-* files, respectively.
X_CFLAGS =
T_CFLAGS =

X_CPPFLAGS =
T_CPPFLAGS =

CC = gcc
BISON = bison
BISONFLAGS =
LEX = flex
LEXFLAGS =
AR = ar
AR_FLAGS = rc
SHELL = cmd.exe
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi
DIFF = diff
DIFF_FLAGS = -C4

# 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)


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

# 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=all

# End of variables for you to override.

# 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
####host overrides
####cross overrides
####build overrides

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

all.indirect: Makefile ../gpc ../gpc1 ../gpc-cpp
# ../libgpc.a

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

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

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

#Extra warnings for GPC
ALL_WARNINGS = -Wall

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

SUBDIR_OBSTACK = ../$(OBSTACK)
SUBDIR_USE_ALLOCA =
SUBDIR_MALLOC =

# 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

# 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)" \
	"LDFLAGS=$(LDFLAGS)" \
	"LEX=$(LEX)" \
	"LEXFLAGS=$(LEXFLAGS)" \
	"MAKEINFO=$(MAKEINFO)" \
	"MAKEINFOFLAGS=$(MAKEINFOFLAGS)" \
	"RANLIB=$(RANLIB)" \
	"RANLIB_TEST=$(RANLIB_TEST)" \
	"SHELL=$(SHELL)" \
	"exec_prefix=$(exec_prefix)" \
	"prefix=$(prefix)" \
	"tooldir=$(tooldir)" \
	"bindir=$(bindir)" \
	"libsubdir=$(libsubdir)"

# 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.

# Language-independent object files.
GCC_OBJS = ../print-tr.o ../stmt.o ../except.o \
  ../calls.o ../expmed.o ../explow.o ../varasm.o ../rtl.o ../print-rt.o \
  ../rtlanal.o ../emit-rtl.o ../real.o ../sdbout.o ../dwarfout.o \
  ../dwarf2ou.o ../xcoffout.o ../bitmap.o ../integrat.o ../jump.o ../cse.o \
  ../loop.o ../unroll.o ../flow.o ../stupid.o ../combine.o ../regclass.o \
  ../local-al.o ../global.o ../reload.o ../reload1.o ../caller-s.o \
  ../insn-pee.o ../reorg.o ../sched.o ../final.o ../recog.o ../reg-stac.o \
  ../insn-opi.o ../insn-rec.o ../insn-ext.o ../insn-out.o ../insn-emi.o \
  ../profile.o ../insn-att.o ../emx.o ../getpwd.o \
  ../bc-emit.o ../bc-optab.o ../c-bounds.o  #../bc-emit.o ../c-typeck.o

#GCC_OBJS = ../c-bounds.o ../print-tr.o ../stmt.o \
#  ../calls.o ../expmed.o ../explow.o ../varasm.o ../rtl.o \
#  ../print-rt.o ../rtlanal.o ../emit-rtl.o ../real.o \
#  ../sdbout.o ../dwarfout.o ../xcoffout.o ../integrat.o ../jump.o \
#  ../cse.o ../loop.o ../unroll.o ../flow.o ../stupid.o ../combine.o \
#  ../regclass.o ../local-al.o ../global.o ../reload.o ../reload1.o \
#  ../caller-s.o ../insn-pee.o ../reorg.o ../sched.o ../final.o \
#  ../recog.o ../reg-stac.o ../insn-opi.o ../insn-rec.o \
#  ../insn-ext.o ../insn-out.o ../insn-emi.o ../insn-att.o \
#  ../emx.o ../getpwd.o ../bc-emit.o ../bc-optab.o

#GCC_OBJS = 
GCC_OBJDEPS=$(GCC_OBJS)

# 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 = $(GCC_OBJS) $(GCC_PATCHED)
GBE_OBJDEPS = $(GBE_OBJS)

# (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_OBJS = ../c-aux-in.o ../c-iterat.o ../c-pragma.o \
	../choose-t.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 parse.o util.o setop.o version.o types.o rts.o \
	circle-buf.o gpi-hash.o objects.o

GPC_OBJDEPS = $(GPC_OBJS)

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

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

#	del ..\gpc-cpp$(exeext)
preprocessor: ../gpc-cpp
../gpc-cpp: $(P) gpc-cccp.o ../cexp.o version.o $(LIBDEPS)
	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
	      gpc-cccp.o ../cexp.o version.o $(LIBS)

driver: ../gpc
../gpc: $(P) gpc.o version.o ../choose-t.o ../pexecute.o ../prefix.o \
  ../version.o mkstemp.o $(LIBDEPS) $(EXTRA_GCC_OBJS)
	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
	      gpc.o ../prefix.o version.o ../choose-t.o ../pexecute.o \
		mkstemp.o $(EXTRA_GCC_OBJS) $(LIBS) $(EXTRA_LIBS)

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

native: ../gpc1 ../gpc-cpp

# 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) $(INCLUDES) $(BIG_SWITCHFLAG) \
	$(PARSE_C)

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

# 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.

# gpc-cccp.o: gpc-cccp.c $(CONFIG_H) $(srcdir)/../pcp.h

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) $<

mkstemp.o: mkstemp.c
	$(CC) -DGPC $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c $< -o $@

# 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 ../gansidec.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 ../gansidec.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 ../gansidec.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

gpc-lang.o: gpc-lang.c $(CONFIG_H) $(GPC_TREE_H) $(INPUT_H) ../gansidec.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 ../gansidec.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 ../output.h module.h types.h util.h ../gansidec.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<

# Language-independent files.

DRIVER_DEFINES = \
  -DDEFAULT_TARGET_VERSION="\"$(version)\"" \
  -DTOOLDIR_BASE_PREFIX="\"$(exec_prefix)/\""

gpc.o: gpc.c $(CONFIG_H) ../gansidec.h ../multilib.h 
	$(CC) -DGPC $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
  $(DRIVER_DEFINES) \
  -DGPC_MAJOR="\"$(gpc_major)\"" \
  -DGPC_MINOR="\"$(gpc_minor)\"" \
  -DGPC_RELEASE="\"$(gpc_release)\"" \
  -c gpc.c

# Language Independent files that need to be patched for GPC

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

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

expr.o: $(srcdir)/../expr.c $(CONFIG_H) $(RTL_H) $(TREE_H) $(FLAGS_H) \
 ../function.h ../regs.h ../insn-fla.h ../insn-cod.h ../expr.h \
 ../insn-con.h ../recog.h ../output.h ../typeclas.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) ../expr.c

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

function.o: ../function.c $(CONFIG_H) $(RTL_H) $(TREE_H) \
 $(FLAGS_H) ../function.h ../insn-fla.h ../insn-cod.h ../expr.h \
 ../regs.h ../hard-reg.h ../insn-con.h ../recog.h ../output.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) ../function.c

optabs.o: ../optabs.c $(CONFIG_H) $(RTL_H) $(TREE_H) $(FLAGS_H) \
 ../insn-fla.h ../insn-con.h ../insn-cod.h ../expr.h ../recog.h ../reload.h
	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) ../optabs.c

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

toplev.o : ../toplev.c $(CONFIG_H) $(TREE_H) $(RTL_H) $(FLAGS_H) $(INPUT_H) \
 ../insn-att.h ../xcoffout.h ../defaults.h ../output.h lang-options.h
	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
          $(MAYBE_TARGET_DEFAULT) $(MAYBE_USE_COLLECT2) \
          -DTARGET_NAME=\"$(target_alias)\" \
          -c ../toplev.c 

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


gpc-cccp.o: gpc-cccp.c version.c $(CONFIG_H) ../pcp.h ../config.sta
# 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)\" \
	  -DLOCAL_INCLUDE_DIR=\"$(includedir)\" \
	  -DCROSS_INCLUDE_DIR=\"$(libsubdir)/sys-include\" \
	  -DTOOL_INCLUDE_DIR=\"$(tooldir)/include\" \
	  -c gpc-cccp.c

# 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.sta 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?

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:
