# Makefile for GNU Pascal compiler.
# Patched to work with nmake and emx on a FAT partition (DOS, OS/2)
#
#   Copyright (C) 1987, 1992 Free Software Foundation, Inc.
#
# This file is part of GNU CC.
#
# GNU CC 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 1, or (at your option)
# any later version.
#
# GNU CC 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 CC; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.


# This makefile assumes you have already compiled the correct version
# of GCC $(gccsrc) to the directory $(gccdir), which should contain
# necessary object files

GPCVERSION=1.1

# GPC source directory
srcdir = .

# Directory where GNU-C compiler SOURCES are
# Change it if necessary, but use relative paths! <--
gccsrc = ../gcc-263
gccdossrc = ..\gcc-263

# Directory where GNU-C compiler OBJECTS are
gccdir = $(gccsrc)
gccdosdir = $(gccdossrc)

# Target host: emx
#
target = emx

# GCC version on which the GPC is implemented on.
gccversion=2.6.3

# Your own flags to compile both gpc and the run time system
MY_CFLAGS=
# Your own library specific flags for rts (see rts/Makefile)
MY_LIBFLAGS=

# Define GPC if you wish to compile GPC (obviously)
#
# Flags common to gpc and run time system
COMMON_CFLAGS= -g -DGPC $(MY_CFLAGS)

# compiler flags including the above
CFLAGS = $(COMMON_CFLAGS) -Dabort=fancy_abort
CC = gcc

# For now, it's copy; no real reason.
INSTALL_PROGRAM = copy

# GNU make (gmake) or make or nmake ...
# If your make does not set MAKE variable, set it here
MAKE = nmake

# Some extra checks for run time system compilation
#RTS_WARN=-Wall -Wno-implicit
# but they are not on now
RTS_WARN=
#
# This needs to be GNU C compiler. Otherwise you'll have trouble
# with the run time system. (e.g. complex_type arguments)
#
RTS_GCC=../$(gccdir)/gcc -B../$(gccdir)/ $(RTS_WARN)

# Common prefix for installation directories.
# NOTE: This directory must exist when you start installation.
# ANOTHER NOTE: These directories have a "\", not a "/".
prefix = \emx # <--
# Directory in which to put host dependent programs and libraries
exec_prefix = $(prefix)
# Directory in which to put the executable for the command `gcc'
bindir = $(exec_prefix)\bin
# Directory in which to put the directories used by the compiler.
libdir = $(exec_prefix)\lib
# Directory in which the compiler finds executables, libraries, etc.
libsubdir = /emx/lib # <--

# For cccp.c compilation. See gcc/Makefile.in for more info.
#
# NOTE: local_prefix *should not* default from prefix.
localprefix = /emx # <--
gxx_include_dir = $(libdir)
includedir = $(localprefix)/include
tooldir = $(exec_prefix)

# See GCC Makefile for information about flags needeed
# for various systems, if you want to try to compile
# GPC on such systems.

# Change this to a null string if obstacks are installed in the
# system library.
OBSTACK = $(gccdir)/obstack.o
OBSTACK_SRC= $(gccdir)/obstack.c

# Dependency on obstack, alloca, malloc or whatever library facilities
# are not installed in the system libraries.
LIBDEPS = $(OBSTACK) $(ALLOCA) $(MALLOC)
LINTLIBS = $(OBSTACK_SRC) $(ALLOCA_SRC) $(MALLOC_SRC)

# How to link with both our special library facilities
# and the system's installed libraries.
LIBS = $(OBSTACK) $(GCC_ALLOCA) $(ALLOCA) $(GCC_MALLOC) $(MALLOC) $(CLIB) $(LOADLIBES)

INCLUDES = -I. -I$(srcdir) -I$(gccdir) -I$(gccsrc) -I$(gccsrc)/config \
	-I.. -I../$(srcdir) -I../$(gccdir) -I../$(gccsrc) -I../$(gccsrc)/config

native: gpc.exe pascal preprosessor

# gpc.status deleted. PG

pascal: gpc1.exe

gpc1.exe: gpc1
	emxbind \emx\bin\emxl gpc1

preprosessor: gpc-cpp.exe

gpc-cpp.exe: gpc-cpp
	emxbind \emx\bin\emxl gpc-cpp

.c.o:
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $<

# These object files should be language independent but are currently
# not so.
#
GPC_LANG_IND_OBJS = stor-lay.o dbxout.o expr.o fold-con.o \
		    optabs.o convert.o function.o setop.o toplev.o

#
# Language specific object files for Pascal
#
# Currently the (c-aux-info.c,c-iterate.c) file is not modified
# so I use the original C-compiler file
#
GPC_OBJS_1 = gpc-pars.o gpc-decl.o gpc-type.o gpc-conv.o    \
	gpc-util.o gpc-modu.o gpc-lex.o gpc-comm.o gpc-lang.o \
	$(gccdir)/c-aux-in.o $(gccdir)/c-iterat.o		  \
	$(gccdir)/c-pragma.o					  \
	$(GPC_LANG_IND_OBJS)

# Files specific to the C interpreter bytecode compiler(s).
BC_OBJS = $(gccdir)/bc-emit.o $(gccdir)/bc-optab.o

# Language-independent object files.
#
OBJS = tree.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 \
 aux-outp.o getpwd.o $(EXTRA_OBJS)

# Object files that make up the GNU Pascal compiler
#
GPC_OBJS = version.o $(GPC_OBJS_1) $(OBJS)

# Language specific SOURCE files for Pascal
# The modules on the last line should be
# converted to language independent modules.

# Language independent files that need to be modified
# Setop will be a lang ind source file
GPC_LANG_IND = $(srcdir)/stor-lay.c $(srcdir)/dbxout.c $(srcdir)/expr.c \
	$(srcdir)/fold-con.c $(srcdir)/optabs.c $(srcdir)/convert.c \
	$(srcdir)/function.c $(srcdir)/setop.c $(srcdir)/toplev.c

# Language-independent SOURCE files. For LINT and ETAGS only
#
# See also $(GPC_LANG_IND) They should come back to this
# list when compilers are merged.
# (most of the changes don't affect the C-compiler anyway)
#
SRC =  $(gccsrc)/tree.c $(gccsrc)/print-tr.c \
       $(gccsrc)/stmt.c $(gccsrc)/calls.c $(gccsrc)/expmed.c $(gccsrc)/explow.c \
       $(gccsrc)/varasm.c  \
       $(gccsrc)/rtl.c $(gccsrc)/print-rt.c $(gccsrc)/rtlanal.c $(gccsrc)/emit-rtl.c \
       $(gccsrc)/sdbout.c $(gccsrc)/dwarfout.c $(gccsrc)/xcoffout.c \
       $(gccsrc)/integrat.c $(gccsrc)/jump.c $(gccsrc)/cse.c $(gccsrc)/loop.c \
       $(gccsrc)/unroll.c $(gccsrc)/flow.c $(gccsrc)/stupid.c $(gccsrc)/combine.c \
       $(gccsrc)/regclass.c $(gccsrc)/local-al.c $(gccsrc)/global.c $(gccsrc)/reload.c \
       $(gccsrc)/reload1.c $(gccsrc)/caller-s.c \
       $(gccsrc)/insn-pee.c $(gccsrc)/reorg.c $(gccsrc)/sched.c $(gccsrc)/final.c \
       $(gccsrc)/recog.c $(gccsrc)/reg-stac.c \
       $(gccsrc)/insn-rec.c $(gccsrc)/insn-ext.c $(gccsrc)/insn-out.c \
       $(gccsrc)/insn-emi.c \
       $(gccsrc)/insn-att.c $(gccsrc)/aux-outp.c $(gccsrc)/getpwd.c $(EXTRA_OBJS)

# reversed order / juki
all: prepare copyobj gpc1.exe gpc.exe gpc-cpp.exe

prepare:
	set EMXOPT=-t

copyobj: ./tree.o

# It is necessary to have all the objects in the current directory,
# because otherwise the command line for linking everything becomes
# too large to be handled by DOS or OS/2. :-) PG
#
./tree.o:
	copy $(gccdosdir)\*.o .
	touch *.c

gpc: gcc.o  $(LIBDEPS) version.o # version.c
	$(CC) $(CFLAGS) $(LDFLAGS) -o gpc gcc.o version.o $(LIBS)

gpc.exe: gpc
	emxbind \emx\bin\emxl gpc

# Generate a new edit number
# version.c: must already exist. PG

CONFIG_H = config.h

gcc.o: gcc.c $(gccdir)/$(CONFIG_H) $(gccdir)/multilib.h $(gccdir)/config.sta
	$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) \
  -DSTANDARD_STARTFILE_PREFIX=\"$(libdir)/\" \
  -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc-lib/\" \
  -DDEFAULT_TARGET_VERSION=\"$(version)\" \
  -DDEFAULT_TARGET_MACHINE=\"$(target)\" \
  -DTOOLDIR_BASE_PREFIX=\"$(exec_prefix)/\" \
  $(MAYBE_TARGET_DEFAULT) \
  -c $(srcdir)/gcc.c

#
#  @@@ The necessary$ variables are not initialized!!!!!
#
gpc-cccp.o: gpc-cccp.c
gpc-cccp.o: $(gccdir)/$(CONFIG_H) $(gccsrc)/pcp.h $(gccsrc)/version.c $(gccdir)/config.sta
	$(CC) $(CFLAGS) $(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 $(srcdir)/gpc-cccp.c

gpc-cpp: gpc-cccp.o $(gccdir)/cexp.o $(gccdir)/version.o $(LIBDEPS)
	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o gpc-cpp gpc-cccp.o $(gccdir)/cexp.o $(gccdir)/version.o $(LIBS)

#gpc1: gpc-gper.c $(GPC_OBJS) $(BC_OBJS)
gpc1: $(GPC_OBJS) $(BC_OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o gpc1new $(GPC_OBJS) $(BC_OBJS) $(LIBS)
	copy gpc1new gpc1
	del gpc1new

# Generate this to the source directory
#$(srcdir)/gpc-gper.c: gpc.gperf
#	$(GPERF) $(srcdir)/gpc.gperf > $(srcdir)/gpc-gperf.c
# It must exist. PG

# Circular dependency
#gpc-gperf.c: $(srcdir)/gpc-gperf.c

# rts/Makefile: exists. PG

# Symbolic links removed. PG

# The Pascal runtime library files
#
rts=$(srcdir)/rts

RTSFILES=$(rts)/rts.h       $(rts)/rts-fdr.h     $(rts)/rts-hdr.h \
	$(rts)/rts-type.h   $(rts)/rts-set.h     $(rts)/Version.c    \
	$(rts)/rts-heap.c   $(rts)/rts-math.c    $(rts)/rts-zmat.c   \
	$(rts)/rts-read.c   $(rts)/rts-set.c     $(rts)/rts-setu.c   \
	$(rts)/rts-time.c   $(rts)/rts-writ.c    $(rts)/rts-erro.c   \
	$(rts)/rts-file.c   $(rts)/rts-misc.c    $(rts)/rts-rand.c   \
	$(rts)/rts-rt0.c    $(rts)/rts-stri.c    		      \
	$(rts)/rts-rdsu.c   $(rts)/rts-bind.c

# Pascal language specific files
gpc-pars.o: gpc-pars.c gpc-pars.h

# Bison call removed. PG

gpc-comm.o: gpc-comm.c gpc-pars.h
gpc-lex.o: gpc-lex.c gpc-gper.c gpc-pars.h
gpc-util.o: gpc-util.c $(srcdir)/rts/rts-type.h gpc-pars.h

# Copy the files into directories where they will be run.
install: install-cross

# Install the compiler executables built during cross compilation.
install-gpc1: gpc1.exe
	$(INSTALL_PROGRAM) gpc1.exe $(bindir)\gpc1.exe

install-gpc-cpp: gpc-cpp.exe
	$(INSTALL_PROGRAM) gpc-cpp.exe $(bindir)\gpc-cpp.exe

copy-gpc1:
	$(INSTALL_PROGRAM) gpc1.exe $(bindir)\gpc1.exe

install-gpc: gpc.exe
	$(INSTALL_PROGRAM) gpc.exe $(bindir)\gpc.exe

install-cross: all install-gpc install-gpc1 install-gpc-cpp
#install-cross: native install-dir install-lib install-gpc1
#install-cross: install-gpc install-gpc-cpp

install-lib: library
	$(INSTALL_PROGRAM) rts\libgpc.a $(libdir)\libgpc.a

	done
