# $Id: s.makefile 1.124 04/06/13 05:52:59-04:00 ehallnor@zizzer.eecs.umich.edu $

# the following variables could be defined in the setup files
# TARGET
# FULL_SYSTEM
# DEFINES
# INCLUDES

HOSTNAME=$(shell hostname -s)
OSNAME=$(shell uname -s)
ARCHNAME=$(shell uname -m)

LIBS=-lm -lelf

ifneq ($(CONFIG_OSNAME), $(OSNAME))
$(error This setup was for $(CONFIG_OSNAME) and you are running $(OSNAME))
endif

ifneq ($(CONFIG_ARCHNAME), $(ARCHNAME))
$(error This setup was for $(CONFIG_ARCHNAME) and you are running $(ARCHNAME))
endif

ifneq ($(CONFIG_HOSTNAME), $(HOSTNAME))
$(warning This setup was for $(CONFIG_HOSTNAME) and you are running on $(HOSTNAME))
endif

INSURE?= /usr/opt/insure/bin.linux2/insure

EXT_SRCDIR?= $(SRCDIR)/../ext

VPATH= $(SRCDIR)

ifdef M5_GENDIR
GENDIR= $(BUILDBASE)/gen
VPATH= $(SRCDIR):$(GENDIR)
else
GENDIR= $(SRCDIR)
endif

#
# The "-I-" prevents cpp from searching the specified directories
# for system includes (#include <...>).
#
PIPE?= -pipe
INCLDIRS= -I. -I$(BUILDDIR) -I$(GENDIR) $(INCLUDES) -I- -I$(BUILDDIR)/libelf
COPTS?=
CCFLAGS?= $(PIPE) $(DEFINES) $(INCLDIRS) $(COPTS)
LFLAGS?= $(PIPE) -L$(BUILDBASE)/libelf/lib

ifdef USE_MYSQL
CCFLAGS+=-DUSE_MYSQL
INCLDIRS+= -I/usr/local/include/mysql -I/usr/include/mysql
LIBS+=-lz
ifeq ($(OSNAME), Linux)
LIBS+=/usr/lib/mysql/libmysqlclient.a
else
LFLAGS+=-L/usr/local/lib/mysql/
LIBS+=-lmysqlclient
$(warning Using dynamic mysqlclient library, could not find static library for $(OSNAME))
endif
endif

#
# Base Simulator Sources
# Please maintain a sorted order!
# (And as luck would have it, arch/alpha/decoder.cc is first)
#
SRCS+= arch/alpha/decoder.cc
SRCS+= arch/alpha/fast_cpu_exec.cc
SRCS+= arch/alpha/simple_cpu_exec.cc
SRCS+= arch/alpha/full_cpu_exec.cc
SRCS+= arch/alpha/faults.cc
SRCS+= arch/alpha/isa_traits.cc

SRCS+= base/circlebuf.cc
SRCS+= base/copyright.cc
SRCS+= base/cprintf.cc
SRCS+= base/fast_alloc.cc
SRCS+= base/fifo_buffer.cc
SRCS+= base/hostinfo.cc
SRCS+= base/hybrid_pred.cc
SRCS+= base/inifile.cc
SRCS+= base/intmath.cc
SRCS+= base/misc.cc
ifdef USE_MYSQL
SRCS+= base/mysql.cc
endif
SRCS+= base/pollevent.cc
SRCS+= base/python.cc
SRCS+= base/range.cc
SRCS+= base/sat_counter.cc
SRCS+= base/socket.cc
SRCS+= base/statistics.cc
SRCS+= base/str.cc
SRCS+= base/time.cc
SRCS+= base/trace.cc
SRCS+= base/traceflags.cc
SRCS+= base/userinfo.cc
SRCS+= base/compression/lzss_compression.cc
SRCS+= base/loader/aout_object.cc
SRCS+= base/loader/ecoff_object.cc
SRCS+= base/loader/elf_object.cc
SRCS+= base/loader/object_file.cc
SRCS+= base/loader/symtab.cc
SRCS+= base/stats/events.cc
ifdef USE_MYSQL
SRCS+= base/stats/mysql.cc
endif
SRCS+= base/stats/python.cc
SRCS+= base/stats/statdb.cc
SRCS+= base/stats/visit.cc
SRCS+= base/stats/text.cc

SRCS+= cpu/base_cpu.cc
SRCS+= cpu/exec_context.cc
SRCS+= cpu/exetrace.cc
SRCS+= cpu/pc_event.cc
SRCS+= cpu/static_inst.cc
SRCS+= cpu/fast_cpu/fast_cpu.cc
SRCS+= cpu/full_cpu/bpred.cc
SRCS+= cpu/full_cpu/commit.cc
SRCS+= cpu/full_cpu/create_vector.cc
SRCS+= cpu/full_cpu/cv_spec_state.cc
SRCS+= cpu/full_cpu/dd_queue.cc
SRCS+= cpu/full_cpu/dep_link.cc
SRCS+= cpu/full_cpu/dispatch.cc
SRCS+= cpu/full_cpu/dyn_inst.cc
SRCS+= cpu/full_cpu/execute.cc
SRCS+= cpu/full_cpu/fetch.cc
SRCS+= cpu/full_cpu/floss_reasons.cc
SRCS+= cpu/full_cpu/fu_pool.cc
SRCS+= cpu/full_cpu/full_cpu.cc
SRCS+= cpu/full_cpu/inst_fifo.cc
SRCS+= cpu/full_cpu/instpipe.cc
SRCS+= cpu/full_cpu/issue.cc
SRCS+= cpu/full_cpu/ls_queue.cc
SRCS+= cpu/full_cpu/machine_queue.cc
SRCS+= cpu/full_cpu/pipetrace.cc
SRCS+= cpu/full_cpu/readyq.cc
SRCS+= cpu/full_cpu/reg_info.cc
SRCS+= cpu/full_cpu/rob_station.cc
SRCS+= cpu/full_cpu/spec_memory.cc
SRCS+= cpu/full_cpu/spec_state.cc
SRCS+= cpu/full_cpu/storebuffer.cc
SRCS+= cpu/full_cpu/writeback.cc
SRCS+= cpu/full_cpu/iq/iq_station.cc
SRCS+= cpu/full_cpu/iq/iqueue.cc
SRCS+= cpu/full_cpu/iq/segmented/chain_info.cc
SRCS+= cpu/full_cpu/iq/segmented/chain_wire.cc
SRCS+= cpu/full_cpu/iq/segmented/iq_seg.cc
SRCS+= cpu/full_cpu/iq/segmented/iq_segmented.cc
SRCS+= cpu/full_cpu/iq/segmented/seg_chain.cc
SRCS+= cpu/full_cpu/iq/seznec/iq_seznec.cc
SRCS+= cpu/full_cpu/iq/standard/iq_standard.cc
SRCS+= cpu/sampling_cpu/sampling_cpu.cc
SRCS+= cpu/simple_cpu/simple_cpu.cc
SRCS+= cpu/trace/reader/mem_trace_reader.cc
SRCS+= cpu/trace/reader/ibm_reader.cc
SRCS+= cpu/trace/reader/itx_reader.cc
SRCS+= cpu/trace/reader/m5_reader.cc

SRCS+= mem/base_hier.cc
SRCS+= mem/base_mem.cc
SRCS+= mem/hier_params.cc
SRCS+= mem/mem_cmd.cc
SRCS+= mem/mem_debug.cc
SRCS+= mem/mem_req.hh
SRCS+= mem/memory_interface.cc
SRCS+= mem/bus/base_interface.cc
SRCS+= mem/bus/bus.cc
SRCS+= mem/bus/bus_bridge.cc
SRCS+= mem/bus/bus_bridge_master.cc
SRCS+= mem/bus/bus_bridge_slave.cc
SRCS+= mem/bus/bus_interface.cc
SRCS+= mem/bus/dma_bus_interface.cc
SRCS+= mem/bus/dma_interface.cc
SRCS+= mem/bus/master_interface.cc
SRCS+= mem/bus/slave_interface.cc
SRCS+= mem/cache/base_cache.cc
SRCS+= mem/cache/cache.cc
SRCS+= mem/cache/cache_builder.cc
SRCS+= mem/cache/coherence/coherence_protocol.cc
SRCS+= mem/cache/coherence/uni_coherence.cc
SRCS+= mem/cache/miss/blocking_buffer.cc
SRCS+= mem/cache/miss/miss_queue.cc
SRCS+= mem/cache/miss/mshr.cc
SRCS+= mem/cache/miss/mshr_queue.cc
SRCS+= mem/cache/tags/base_tags.cc
SRCS+= mem/cache/tags/cache_tags.cc
SRCS+= mem/cache/tags/fa_lru.cc
SRCS+= mem/cache/tags/iic.cc
SRCS+= mem/cache/tags/lru.cc
SRCS+= mem/cache/tags/repl/gen.cc
SRCS+= mem/cache/tags/repl/repl.cc
SRCS+= mem/functional_mem/functional_memory.cc
SRCS+= mem/functional_mem/main_memory.cc
SRCS+= mem/timing_mem/base_memory.cc
SRCS+= mem/timing_mem/memory_builder.cc
SRCS+= mem/timing_mem/simple_mem_bank.cc
SRCS+= mem/trace/mem_trace_writer.cc
SRCS+= mem/trace/m5_writer.cc

SRCS+= sim/builder.cc
SRCS+= sim/configfile.cc
SRCS+= sim/debug.cc
SRCS+= sim/eventq.cc
SRCS+= sim/main.cc
SRCS+= sim/param.cc
SRCS+= sim/profile.cc
SRCS+= sim/serialize.cc
SRCS+= sim/sim_events.cc
SRCS+= sim/sim_exit.cc
SRCS+= sim/sim_init.cc
SRCS+= sim/sim_object.cc
SRCS+= sim/stat_context.cc
SRCS+= sim/stat_control.cc
SRCS+= sim/sw_context.cc
SRCS+= sim/trace_context.cc
SRCS+= sim/universe.cc

#
# Full System Sources
# Please maintain a sorted order!
#
ifdef FULL_SYSTEM
SRCS+= arch/alpha/alpha_memory.cc
SRCS+= arch/alpha/arguments.cc
SRCS+= arch/alpha/ev5.cc
SRCS+= arch/alpha/osfpal.cc
SRCS+= arch/alpha/pseudo_inst.cc
SRCS+= arch/alpha/vtophys.cc

SRCS+= base/inet.cc
SRCS+= base/remote_gdb.cc

SRCS+= cpu/intr_control.cc

SRCS+= dev/alpha_console.cc
SRCS+= dev/console.cc
SRCS+= dev/disk_image.cc
SRCS+= dev/dma.cc
SRCS+= dev/etherbus.cc
SRCS+= dev/etherdev.cc
SRCS+= dev/etherdump.cc
SRCS+= dev/etherint.cc
SRCS+= dev/etherlink.cc
SRCS+= dev/etherpkt.cc
SRCS+= dev/ethertap.cc
SRCS+= dev/io_device.cc
SRCS+= dev/scsi.cc
SRCS+= dev/scsi_ctrl.cc
SRCS+= dev/scsi_disk.cc
SRCS+= dev/scsi_none.cc
SRCS+= dev/simple_disk.cc
SRCS+= dev/tlaser_clock.cc
SRCS+= dev/tlaser_ipi.cc
SRCS+= dev/tlaser_mbox.cc
SRCS+= dev/tlaser_mc146818.cc
SRCS+= dev/tlaser_node.cc
SRCS+= dev/tlaser_pcia.cc
SRCS+= dev/tlaser_pcidev.cc
SRCS+= dev/tlaser_serial.cc
SRCS+= dev/tlaser_uart.cc
SRCS+= dev/turbolaser.cc

SRCS+= kern/kernel_stats.cc
SRCS+= kern/system_events.cc
SRCS+= kern/tru64/dump_mbuf.cc
SRCS+= kern/tru64/printf.cc
SRCS+= kern/tru64/tru64_events.cc
SRCS+= kern/tru64/tru64_syscalls.cc
SRCS+= kern/tru64/tru64_system.cc

SRCS+= mem/functional_mem/memory_control.cc
SRCS+= mem/functional_mem/physical_memory.cc

SRCS+= sim/system.cc

#
# Non-Full System Sources
# Please maintain a sorted order!
#
else
SRCS+= arch/alpha/alpha_common_syscall_emul.cc
SRCS+= arch/alpha/alpha_linux_process.cc
SRCS+= arch/alpha/alpha_tru64_process.cc
SRCS+= cpu/memtest/memtest.cc
SRCS+= cpu/trace/trace_cpu.cc
SRCS+= eio/eio.cc
SRCS+= eio/exolex.cc
SRCS+= eio/libexo.cc
SRCS+= sim/process.cc
SRCS+= sim/syscall_emul.cc
endif

#
# Base name of simulator executable
#
SIM?=m5

M5_DEFAULT?= $(SIM).opt
default: $(M5_DEFAULT)

#
# Targets for setting up the build directory.  Called by the setup routine
#

# set up link for #include "targetarch/<foo>"
.setup:
	@echo "Setting up `/bin/pwd` to build"
	@test -L targetarch || ln -sf ../src/arch/$(TARGET) targetarch
	@touch .setup

clean::
	@rm -f .setup targetarch

test:
	@echo testing makefile includes

.PHONY: targetarch setupmsg setup test

#
# complete lists of object files
#
BASES= $(basename $(SRCS))
DEPS= $(addsuffix .d, $(BASES))
OPT_OBJS= $(addsuffix .o, $(BASES))
FAST_OBJS= $(addsuffix .fo, $(BASES))
PROF_OBJS= $(addsuffix .po, $(BASES))
DEBUG_OBJS= $(addsuffix .do, $(BASES))
INSURE_OBJS= $(addsuffix .io, $(BASES))
#VALGRIND_OBJS= $(addsuffix .vo, $(BASES))

cleandepend:
	@rm -f $(DEPS)

justdepend: $(DEPS)

depend: cleandepend justdepend

clobber: clean
clean::	
	@rm -f $(SIM).*
.PHONY: clean clobber cleandepend justdepend depend

all: debug opt fast
opt: $(SIM).opt
fast: $(SIM).fast
debug: $(SIM).debug
insure: $(SIM).insure
prof: $(SIM).prof
valgrind:  $(SIM).valgrind
purify:  $(SIM).purify
.PHONY: all opt debug insure prof valgrind purify

$(SIM).opt: $(OPT_OBJS)  
	$(CXX) $(DEFINES) -c $(SRCDIR)/base/date.cc -o base/date.o
	$(CXX) $(LFLAGS) -o $@ $(OPT_OBJS) base/date.o $(LIBS)

$(SIM).fast: $(FAST_OBJS)
	$(CXX) $(DEFINES) -c $(SRCDIR)/base/date.cc -o base/date.o
	$(CXX) $(LFLAGS) -o $@ $(FAST_OBJS) base/date.o $(LIBS)
	strip $@

$(SIM).prof: $(PROF_OBJS)
	$(CXX) $(DEFINES) -c $(SRCDIR)/base/date.cc -o base/date.o
	$(CXX) -pg $(LFLAGS) -o $@ $(PROF_OBJS) base/date.o $(LIBS)

$(SIM).debug: $(DEBUG_OBJS)
	$(CXX) $(DEFINES) -c $(SRCDIR)/base/date.cc -o base/date.o
	$(CXX) $(LFLAGS) -o $@ $(DEBUG_OBJS) base/date.o $(LIBS)

$(SIM).insure: $(INSURE_OBJS)
	$(INSURE) $(CXX) $(DEFINES) -c $(SRCDIR)/base/date.cc -o base/date.o
	$(INSURE) $(CXX) $(LFLAGS) -o $@ $(INSURE_OBJS) base/date.o $(LIBS)

$(SIM).valgrind: $(DEBUG_OBJS)
	$(CXX) $(DEFINES) -c $(SRCDIR)/base/date.cc -o base/date.o
	$(CXX) $(LFLAGS) -o $@ $(DEBUG_OBJS) base/date.o $(LIBS)

$(SIM).purify: $(DEBUG_OBJS)
	$(CXX) $(DEFINES) -c $(SRCDIR)/base/date.cc -o base/date.o
	purify $(CXX) $(LFLAGS) -o $@ $(DEBUG_OBJS) base/date.o $(LIBS)

# Default compile rules.
#

CC?= gcc
CXX?= g++

ifeq "$(shell uname)" "OSF1"
LEX?= /usr/local/bin/flex

# -O5 doesn't seem to work on alpha
OPT_LEVEL?= -O1
endif

PYTHON?=/usr/bin/env python

OPT_LEVEL?= -O5
LEX?= flex
WARN?= -Wall -Wno-sign-compare -Werror -Wundef

OPT_FLAGS?= $(OPT_LEVEL) -g 
FAST_FLAGS?= $(OPT_LEVEL) -DNDEBUG
PROF_FLAGS?= $(OPT_LEVEL) -g -pg
DEBUG_FLAGS?= -g -gstabs+ -O0 -DDEBUG
INSURE_FLAGS?= -DDEBUG -DINSURE_BUILD -g
CCFLAGS+= -fno-strict-aliasing $(WARN)

clean::
	@for each in *; \
	do if test -d $$each -a ! -h $$each; \
	then rm -rf $$each; \
	fi; \
	done; \
	rm -f *~ *.o *.fo *.do *.po *.io core *.core *.d

.PHONY: clean

# For the targets in this list, don't bother to include all the *.d
# dependence files.  This avoids having make regenerate all the files
# when they're not really needed because we're doing some brute-force
# operation.
NO_DEPEND_TARGETS=clean cleandepend justdepend depend targetarch setupmsg
NO_DEPEND_TARGETS+=setup generate

.SUFFIXES:
.SUFFIXES: .c .cc .d .o .fo .do .io .po .vo

SUFFIXES=.d .o .fo .do .io .po .vo

# Dependency Generation
#
# The code in this rule may look somewhat insane, but here's what it does:
# The VPATH portion of the rule gives you an absolute path like
# /n/ziff/z/binkertn/research/m5/latest/arch/alpha/ev5.cc
#
# the shell variable file is just the file name (ev5.cc)
# the shellvariable dir is the directory portion of the path relative
# to the source directory (arch/alpha)
#
# We create this directory in the build dir and in it make a symlink
# to the real source file.  This source file is used for further
# compilation.  This makes the g++ command line like this:
# g++ <stuff> arch/alpha/ev5.cc -o arch/alpha/ev5.o
#
# The symlink is recreated with every build.  It is also always
# generated because compilation of .cc files depends on .d files
#
# The hope is that by doing this symlink trick and not having an
# absolute path in the debugging info, the compiler and gdb will play
# a bit nicer.
#
%.d:: %.cc
	@dir="$(dir $(subst $(SRCDIR)/,,$<))"; \
	src="$<"; \
	dep="$(BUILDDIR)/$@"; \
	mkdir -p $$dir; \
	echo "$(CXX) -MM -I$(SRCDIR) $(CCFLAGS) $$src > $$dep"; \
	$(CXX) -MM -I$(SRCDIR) $(CCFLAGS) $$src -MT "$(addprefix $*,$(SUFFIXES))" > $$dep; \
	if [ \! -s $$dep ];\
	   then echo Error: empty depend file $$dep; rm -f $$dep; exit 1;\
	fi

%.d:: %.c
	@dir="$(dir $(subst $(SRCDIR)/,,$<))"; \
	src="$<"; \
	dep="$(BUILDDIR)/$@"; \
	mkdir -p $$dir; \
	echo "$(CC) -MM -I$(SRCDIR) $(CCFLAGS) $$src > $$dep"; \
	$(CC) -MM -I$(SRCDIR) $(CCFLAGS) $$src -MT "$(addprefix $*,$(SUFFIXES))" > $$dep; \
	if [ \! -s $$dep ]; \
	   then echo Error: empty depend file $$dep; rm -f $$dep; exit 1;\
	fi

# C++ Compilation
%.o: %.cc
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CXX) $(CCFLAGS) $(OPT_FLAGS) -c $$src -o $$obj"; \
	echo $$cmd; \
	eval $$cmd

%.fo: %.cc
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CXX) $(CCFLAGS) $(FAST_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.po: %.cc
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CXX) $(CCFLAGS) $(PROF_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.do: %.cc
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CXX) $(CCFLAGS) $(DEBUG_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.vo: %.cc
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CXX) $(CCFLAGS) $(DEBUG_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.io: %.cc
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(INSURE) $(CXX) $(CCFLAGS) $(INSURE_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

# C Compilation
%.o: %.c
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CC) $(CCFLAGS) $(OPT_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.fo: %.c
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CC) $(CCFLAGS) $(FAST_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.po: %.c
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CC) $(CCFLAGS) $(PROF_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.do: %.c
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CC) $(CCFLAGS) $(DEBUG_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.vo: %.c
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(CC) $(CCFLAGS) $(DEBUG_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

%.io: %.c
	@cd $(SRCDIR); \
	src="$(subst $(SRCDIR)/,,$<)"; \
	obj="$(BUILDDIR)/$@"; \
	cmd="$(INSURE) $(CC) $(CCFLAGS) $(INSURE_FLAGS) -c $$src -o $$obj"; \
	cd $(SRCDIR); \
	echo $$cmd; \
	eval $$cmd

# Prevent make from doing crap with sfiles
%::SCCS/s.%

#
# Rules for source files generated from other tools/scripts.
#
$(GENDIR)/base/traceflags.cc: $(SRCDIR)/base/traceflags.py
	mkdir -p $(GENDIR)/base; \
	cd $(GENDIR)/base; \
	$(PYTHON) $<

$(GENDIR)/arch/alpha/.isa_desc_parsed: $(SRCDIR)/arch/isa_parser.py $(SRCDIR)/arch/$(TARGET)/isa_desc
	mkdir -p $(GENDIR)/arch/alpha; \
	cd $(GENDIR); \
	env M5_EXT=$(EXT_SRCDIR) $(SRCDIR)/arch/isa_parser.py $(SRCDIR)/arch/$(TARGET)/isa_desc $(GENDIR)/arch/alpha arch/alpha
	@touch $@

clean::
	@rm -f parser.out parsetab.py $(GENDIR)/arch/alpha/.isa_desc_parsed

# Don't treat exolex.cc like other generated files since (1) it
# doesn't build right on some newer versions of flex and (2) we never
# mess with the EIO stuff so in practice it never gets rebuilt.
$(SRCDIR)/eio/exolex.cc: eio/exolex.l eio/libexo.h
	$(LEX) $<
	mv -f lex.yy.c $@

.generate: $(GENDIR)/base/traceflags.cc $(GENDIR)/arch/alpha/.isa_desc_parsed
	@touch .generate

clean::
	@rm -f .generate

# Use libelf.h for libelf dependences since this is the last file
# copied over.  Otherwise a parallel make might start up a dependent
# job before the setup is complete.
libelf/libelf/libelf.h:
	if [ ! -d $(BUILDBASE)/libelf ] ; then mkdir $(BUILDBASE)/libelf; fi
	(cd $(BUILDBASE)/libelf; $(EXTDIR)/libelf/configure --disable-shared --disable-versioning; $(MAKE))
	if [ ! -d libelf/libelf ] ; then mkdir -p libelf/libelf; fi
	cp $(BUILDBASE)/libelf/lib/sys_elf.h libelf/libelf/
	cp $(EXTDIR)/libelf/lib/gelf.h libelf/libelf/
	cp $(EXTDIR)/libelf/lib/elf_repl.h libelf/libelf/
	cp $(EXTDIR)/libelf/lib/nlist.h libelf/libelf/
	cp $(EXTDIR)/libelf/lib/libelf.h libelf/libelf/

clean::
	@rm -rf libelf

# Files that depend on an external package that needs building need an
# explicit dependence from their .d file.  Otherwise, on a clean make
# the .d file will not get properly generatend (because g++ -MM won't
# find the header), and your dependences will be permanently messed up
# (until the bogus .d file is explicitly deleted).
base/loader/elf_object.d: libelf/libelf/libelf.h

ifeq (, $(findstring $(MAKECMDGOALS), $(NO_DEPEND_TARGETS)))
# Be careful here.  when things are included, they are included line
# by line, bit from right to left
-include $(DEPS) .generate .setup
endif
