# Makefile for GNU C compiler.
#   Copyright (C) 1987 Free Software Foundation, Inc.

#This file is part of GNU CC.

#GNU CC is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY.  No author or distributor
#accepts responsibility to anyone for the consequences of using it
#or for whether it serves any particular purpose or works at all,
#unless he says so in writing.  Refer to the GNU CC General Public
#License for full details.

#Everyone is granted permission to copy, modify and redistribute
#GNU CC, but only under the conditions described in the
#GNU CC General Public License.   A copy of this license is
#supposed to have been given to you along with GNU CC so you
#can know your rights and responsibilities.  It should be in a
#file named COPYING.  Among other things, the copyright notice
#and this notice must be preserved on all copies.


O	=.o
CFLAGS	= ${OPTIMIZE}
CC	= ${C_COMPILE}

BISON = yacc
SHELL = /bin/sh

libdir = .

# These are what you would need on HPUX:
# CFLAGS = -Wc,-Ns2000 -Wc,-Ne700
# -g is desirable in CFLAGS, but a compiler bug in HPUX version 5
# bites whenever tree.def, rtl.def or machmode.def is included
# (ie., on every source file).
# CCLIBFLAGS = -Wc,-Ns2000 -Wc,-Ne700
# For CCLIBFLAGS you might want to specify the switch that
# forces only 68000 instructions to be used.

# If you are making gcc for the first time, and if you are compiling it with
# a non-gcc compiler, and if your system doesn't have a working alloca() in any
# of the standard libraries (as is true for HP/UX or Genix),
# then get alloca.c from GNU Emacs and un-comment the following line:
# ALLOCA = alloca$O

# If your system has alloca() in /lib/libPW.a, un-comment the following line:
# CLIB= -lPW
  
# If your system's malloc() routine fails for any reason (as it does on
# certain versions of Genix), try getting the files
# malloc.c and getpagesize.h from GNU Emacs and un-comment the following line:
# MALLOC = malloc$O

# If you are running GCC on an Apollo, you will need this:
# CFLAGS = -g -O -M 3000 -U__STDC__ -DSHORT_ENUM_BUG

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

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

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

# Object files of CC1.
OBJS = toplev$O version$O c-parse.tab$O tree$O print-tree$O \
 c-decl$O c-typeck$O c-convert$O stor-layout$O fold-const$O \
 rtl$O expr$O stmt$O expmed$O explow$O optabs$O varasm$O \
 symout$O dbxout$O sdbout$O emit-rtl$O insn-emit$O \
 integrate$O jump$O cse$O loop$O flow$O stupid$O combine$O \
 regclass$O local-alloc$O global-alloc$O reload$O reload1$O insn-peep$O \
 final$O recog$O insn-recog$O insn-extract$O insn-output$O

# Files to be copied away after each stage in building.
STAGE_GCC=gcc
STAGESTUFF = *.o *.u insn-flags.h insn-config.h insn-codes.h \
 insn-output.c insn-recog.c insn-emit.c insn-extract.c insn-peep.c \
 genemit genoutput genrecog genextract genflags gencodes genconfig genpeep \
 cc1 cpp cccp

# If you want to recompile everything, just do rm *.o.
# CONFIG_H = config.h tm.h
CONFIG_H =
RTL_H = rtl.h rtl.def machmode.def
TREE_H = tree.h tree.def machmode.def

all: gcc cc1 cpp

compilations: ${OBJS}

gcc: gcc$O version$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o gccnew gcc$O version$O $(LIBS)
# Go via `gccnew' to avoid `file busy' if $(CC) is `gcc'.
	mv gccnew gcc

gcc$O: gcc.c $(CONFIG_H)
	$(CC) $(CFLAGS) ${REL} -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc-\" gcc.c

cc1: $(OBJS) $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o cc1 $(OBJS) $(LIBS)

# C-language specific files.

c-parse.tab$O : c-parse.tab.c $(CONFIG_H) $(TREE_H) c-parse.h c-tree.h
c-parse.tab.c : c-parse.y
	$(BISON) -v c-parse.y

c-decl$O : c-decl.c $(CONFIG_H) $(TREE_H) c-tree.h c-parse.h flags.h
c-typeck$O : c-typeck.c $(CONFIG_H) $(TREE_H) c-tree.h flags.h
c-convert$O : c-convert.c $(CONFIG_H) $(TREE_H)

# Language-independent files.

tree$O : tree.c $(CONFIG_H) $(TREE_H)
print-tree$O : print-tree.c $(CONFIG_H) $(TREE_H)
stor-layout$O : stor-layout.c $(CONFIG_H) $(TREE_H)
fold-const$O : fold-const.c $(CONFIG_H) $(TREE_H)
toplev$O : toplev.c $(CONFIG_H) $(TREE_H) flags.h

rtl$O : rtl.c $(CONFIG_H) $(RTL_H)

varasm$O : varasm.c $(CONFIG_H) $(TREE_H) $(RTL_H) flags.h expr.h insn-codes.h
stmt$O : stmt.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h  \
   insn-flags.h expr.h insn-config.h regs.h insn-codes.h
expr$O : expr.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h  \
   insn-flags.h insn-codes.h expr.h insn-config.h recog.h
expmed$O : expmed.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h  \
   insn-flags.h insn-codes.h expr.h insn-config.h recog.h
explow$O : explow.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h expr.h insn-codes.h
optabs$O : optabs.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h  \
   insn-flags.h insn-codes.h expr.h insn-config.h recog.h
symout$O : symout.c $(CONFIG_H) $(TREE_H) $(RTL_H) symseg.h gdbfiles.h
dbxout$O : dbxout.c $(CONFIG_H) $(TREE_H) $(RTL_H) flags.h
sdbout$O : sdbout.c $(CONFIG_H) $(TREE_H) $(RTL_H) c-tree.h

emit-rtl$O : emit-rtl.c $(CONFIG_H) $(RTL_H) regs.h insn-config.h

integrate$O : integrate.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h expr.h \
   insn-flags.h insn-codes.h

jump$O : jump.c $(CONFIG_H) $(RTL_H) flags.h regs.h
stupid$O : stupid.c $(CONFIG_H) $(RTL_H) regs.h hard-reg-set.h

cse$O : cse.c $(CONFIG_H) $(RTL_H) insn-config.h regs.h hard-reg-set.h
loop$O : loop.c $(CONFIG_H) $(RTL_H) insn-config.h regs.h recog.h
flow$O : flow.c $(CONFIG_H) $(RTL_H) basic-block.h regs.h hard-reg-set.h
combine$O : combine.c $(CONFIG_H) $(RTL_H) flags.h  \
   insn-config.h regs.h basic-block.h recog.h
regclass$O : regclass.c $(CONFIG_H) $(RTL_H) flags.h regs.h \
   insn-config.h recog.h hard-reg-set.h
local-alloc$O : local-alloc.c $(CONFIG_H) $(RTL_H) basic-block.h regs.h \
   insn-config.h recog.h hard-reg-set.h
global-alloc$O : global-alloc.c $(CONFIG_H) $(RTL_H) flags.h  \
   basic-block.h regs.h hard-reg-set.h insn-config.h

reload$O : reload.c $(CONFIG_H) $(RTL_H)  \
   reload.h recog.h hard-reg-set.h insn-config.h regs.h
reload1$O : reload1.c $(CONFIG_H) $(RTL_H) flags.h  \
   reload.h regs.h hard-reg-set.h insn-config.h basic-block.h
final$O : final.c $(CONFIG_H) $(RTL_H) regs.h recog.h conditions.h gdbfiles.h \
   insn-config.h
recog$O : recog.c $(CONFIG_H) $(RTL_H)  \
   regs.h recog.h hard-reg-set.h insn-config.h

# Now the source files that are generated from the machine description.

.PRECIOUS: insn-config.h insn-flags.h insn-codes.h \
  insn-emit.c insn-recog.c insn-extract.c insn-output.c insn-peep.c

insn-config.h : md genconfig
	./genconfig md > tmp-insn-config.h
	./move-if-change tmp-insn-config.h insn-config.h

insn-flags.h : md genflags
	./genflags md > tmp-insn-flags.h
	./move-if-change tmp-insn-flags.h insn-flags.h

insn-codes.h : md gencodes
	./gencodes md > tmp-insn-codes.h
	./move-if-change tmp-insn-codes.h insn-codes.h

insn-emit$O : insn-emit.c $(CONFIG_H) $(RTL_H) expr.h insn-config.h
	$(CC) $(CFLAGS) ${REL} insn-emit.c

insn-emit.c : md genemit
	./genemit md > tmp-insn-emit.c
	./move-if-change tmp-insn-emit.c insn-emit.c

insn-recog$O : insn-recog.c $(CONFIG_H) $(RTL_H) insn-config.h
	$(CC) $(CFLAGS) ${REL} insn-recog.c

insn-recog.c : md genrecog
	./genrecog md > tmp-insn-recog.c
	./move-if-change tmp-insn-recog.c insn-recog.c

insn-extract$O : insn-extract.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} insn-extract.c

insn-extract.c : md genextract
	./genextract md > tmp-insn-extract.c
	./move-if-change tmp-insn-extract.c insn-extract.c

insn-peep$O : insn-peep.c $(CONFIG_H) $(RTL_H) regs.h
	$(CC) $(CFLAGS) ${REL} insn-peep.c

insn-peep.c : md genpeep
	./genpeep md > tmp-insn-peep.c
	./move-if-change tmp-insn-peep.c insn-peep.c

insn-output$O : insn-output.c $(CONFIG_H) $(RTL_H) regs.h insn-config.h insn-flags.h conditions.h output.h aux-output.c
	$(CC) $(CFLAGS) ${REL} insn-output.c

insn-output.c : md genoutput
	./genoutput md > tmp-insn-output.c
	./move-if-change tmp-insn-output.c insn-output.c

# Now the programs that generate those files.

genconfig : genconfig$O rtl$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genconfig genconfig$O rtl$O $(LIBS)

genconfig$O : genconfig.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} genconfig.c

genflags : genflags$O rtl$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genflags genflags$O rtl$O $(LIBS)

genflags$O : genflags.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} genflags.c

gencodes : gencodes$O rtl$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o gencodes gencodes$O rtl$O $(LIBS)

gencodes$O : gencodes.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} gencodes.c

genemit : genemit$O rtl$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genemit genemit$O rtl$O $(LIBS)

genemit$O : genemit.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} genemit.c

genrecog : genrecog$O rtl$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genrecog genrecog$O rtl$O $(LIBS)

genrecog$O : genrecog.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} genrecog.c

genextract : genextract$O rtl$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genextract genextract$O rtl$O $(LIBS)

genextract$O : genextract.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} genextract.c

genpeep : genpeep$O rtl$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genpeep genpeep$O rtl$O $(LIBS)

genpeep$O : genpeep.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} genpeep.c

genoutput : genoutput$O rtl$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genoutput genoutput$O rtl$O $(LIBS)

genoutput$O : genoutput.c $(RTL_H)
	$(CC) $(CFLAGS) ${REL} genoutput.c

# Making the preprocessor
cpp: cccp
	-rm -f cpp
	ln cccp cpp
cccp: cccp$O cexp$O version$O $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o cccp cccp$O cexp$O version$O $(LIBS)
cexp$O: cexp.c
cexp.c: cexp.y
	$(BISON) cexp.y
	mv y.tab.c cexp.c
cccp$O: cccp.c
	$(CC) $(CFLAGS) -DGCC_INCLUDE_DIR=\"$(libdir)/gcc-include\" \
          -DGPLUSPLUS_INCLUDE_DIR=\"$(libdir)/g++-include\" ${REL} cccp.c

clean:
	-rm -f $(STAGESTUFF) $(STAGE_GCC)
	-rm -f *.s *.s[0-9] *.co *.greg *.lreg *.combine *.flow *.cse *.jump *.rtl *.tree *.loop
	-rm -f core


# Copy the object files from a particular stage into a subdirectory.
stage1: force
	-mkdir stage1
	mv $(STAGESTUFF) $(STAGE_GCC) stage1
	ln gnulib stage1

stage2: force
	-mkdir stage2
	mv $(STAGESTUFF) $(STAGE_GCC) stage2
	ln gnulib stage2

stage3: force
	-mkdir stage3
	mv $(STAGESTUFF) $(STAGE_GCC) stage3
	ln gnulib stage3

.PHONY: stage1 stage2 stage3 #In GNU Make, ignore whether `stage*' exists.
force:

TAGS: force
	etags *.y *.h *.c
.PHONY: TAGS
