PUB_HEADERS = 	pub/libvex_basictypes.h 		\
		pub/libvex_ir.h				\
		pub/libvex.h				\
		pub/libvex_trc_values.h			\
		pub/libvex_emnote.h			\
		pub/libvex_guest_x86.h			\
		pub/libvex_guest_amd64.h		\
		pub/libvex_guest_arm.h			\
		pub/libvex_guest_ppc32.h		\
		pub/libvex_guest_ppc64.h		\
		pub/libvex_guest_s390x.h		\
		pub/libvex_s390x_common.h		\
		pub/libvex_guest_mips32.h		\
		pub/libvex_guest_offsets.h

PRIV_HEADERS = 	priv/host_x86_defs.h			\
		priv/host_amd64_defs.h			\
		priv/host_arm_defs.h			\
		priv/host_ppc_defs.h			\
		priv/host_s390_defs.h			\
		priv/host_mips_defs.h			\
		priv/host_generic_maddf.h	        \
		priv/host_generic_regs.h	        \
		priv/host_generic_simd64.h	        \
		priv/host_generic_simd128.h	        \
		priv/host_generic_simd256.h	        \
		priv/main_globals.h			\
		priv/main_util.h			\
		priv/guest_generic_x87.h               	\
		priv/guest_generic_bb_to_IR.h		\
		priv/guest_x86_defs.h			\
		priv/guest_amd64_defs.h	               	\
		priv/guest_arm_defs.h			\
		priv/guest_ppc_defs.h			\
		priv/guest_mips_defs.h			\
		priv/s390_disasm.h		        \
		priv/s390_defs.h		        \
		priv/ir_match.h			        \
		priv/ir_opt.h

LIB_OBJS = 	priv/ir_defs.o                          \
		priv/ir_match.o			        \
		priv/ir_opt.o				\
		priv/ir_inject.o			\
		priv/main_main.o			\
		priv/main_globals.o			\
		priv/main_util.o			\
		priv/s390_disasm.o			\
		priv/host_x86_defs.o			\
		priv/host_amd64_defs.o			\
		priv/host_arm_defs.o			\
		priv/host_arm64_defs.o			\
		priv/host_ppc_defs.o			\
		priv/host_s390_defs.o			\
		priv/host_mips_defs.o			\
		priv/host_x86_isel.o			\
		priv/host_amd64_isel.o			\
		priv/host_arm_isel.o			\
		priv/host_arm64_isel.o			\
		priv/host_ppc_isel.o			\
		priv/host_s390_isel.o			\
		priv/host_mips_isel.o			\
		priv/host_generic_maddf.o	        \
		priv/host_generic_regs.o	        \
		priv/host_generic_simd64.o	        \
		priv/host_generic_simd128.o	        \
		priv/host_generic_simd256.o	        \
		priv/host_generic_reg_alloc2.o		\
		priv/guest_generic_x87.o	        \
		priv/guest_generic_bb_to_IR.o		\
		priv/guest_x86_helpers.o		\
		priv/guest_amd64_helpers.o		\
		priv/guest_arm_helpers.o		\
		priv/guest_arm64_helpers.o		\
		priv/guest_ppc_helpers.o		\
		priv/guest_s390_helpers.o		\
		priv/guest_mips_helpers.o		\
		priv/guest_x86_toIR.o			\
		priv/guest_amd64_toIR.o			\
		priv/guest_arm_toIR.o			\
		priv/guest_arm64_toIR.o			\
		priv/guest_ppc_toIR.o                   \
		priv/guest_s390_toIR.o			\
		priv/guest_mips_toIR.o

PUB_INCLUDES = -Ipub

# Do not add any priv/host-ARCH or priv/guest-ARCH directories to this
# list, as they contain duplicate file names (each host has a hdefs.h,
# for example).
PRIV_INCLUDES = -Ipriv


ifndef CC
   CC = gcc 
endif 
ifndef AR
   AR = ar 
endif

# Put -g -O2 after any flags we inherit from V.  -O2 vs -O
# makes a significant difference, at least with gcc4.
CCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow \
		-Wpointer-arith -Wbad-function-cast -Wcast-qual \
		-Wcast-align -Wmissing-declarations \
		-Wwrite-strings -Wformat -Wformat-security \
		-std=gnu99 \
		$(EXTRA_CFLAGS) -g -O2 -fstrict-aliasing

#CC = icc
#CCFLAGS = -g -Wall -wd981 -wd279 -wd1287 -wd869 -wd111 -wd188 -wd186
# 981: operands are evaluated in unspecified order
# 279: controlling expression is constant
# 1287: invalid attribute for parameter
# 869: parameter "..." was never referenced
# 111: statement is unreachable
# 188: enumerated type mixed with another type
# (the above are for icc 8.0 -- 8.0.0.55 I think)
# 186: pointless comparison of unsigned integer with zero

# kludge: stops V biarch builds screwing up at -j 2 or above
# The Right fix is to autoconf/automake-ise vex.
.NOTPARALLEL:

all: vex

# Empty, needed for Valgrind
install:

scratch: clean all

vex: libvex.a

libvex.a: $(LIB_OBJS)
	rm -f libvex.a
	$(AR) crus libvex.a $(LIB_OBJS)


# The idea with these TAG-s is to mark the flavour of libvex.a 
# most recently built, so if the same target is re-requested, we
# don't rebuild everything, but if a different one is requested
# then we scrub everything and start over.

libvex-x86-linux.a: TAG-x86-linux libvex.a
	mv -f libvex.a libvex-x86-linux.a
TAG-x86-linux:
	if [ ! -f TAG-x86-linux ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-x86-linux

libvex-amd64-linux.a: TAG-amd64-linux libvex.a
	mv -f libvex.a libvex-amd64-linux.a
TAG-amd64-linux:
	if [ ! -f TAG-amd64-linux ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-amd64-linux

libvex-ppc32-linux.a: TAG-ppc32-linux libvex.a
	mv -f libvex.a libvex-ppc32-linux.a
TAG-ppc32-linux:
	if [ ! -f TAG-ppc32-linux ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-ppc32-linux

libvex-ppc64-linux.a: TAG-ppc64-linux libvex.a
	mv -f libvex.a libvex-ppc64-linux.a
TAG-ppc64-linux:
	if [ ! -f TAG-ppc64-linux ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-ppc64-linux

libvex-mips-linux.a: TAG-mips32-linux libvex.a
	mv -f libvex.a libvex-mips32-linux.a
TAG-mips-linux:
	if [ ! -f TAG-mips32-linux ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-mips32-linux

libvex-ppc32-aix5.a: TAG-ppc32-aix5 libvex.a
	mv -f libvex.a libvex-ppc32-aix5.a
TAG-ppc32-aix5:
	if [ ! -f TAG-ppc32-aix5 ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-ppc32-aix5

libvex-ppc64-aix5.a: TAG-ppc64-aix5 libvex.a
	mv -f libvex.a libvex-ppc64-aix5.a
TAG-ppc64-aix5:
	if [ ! -f TAG-ppc64-aix5 ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-ppc64-aix5

libvex-x86-darwin.a: TAG-x86-darwin libvex.a
	mv -f libvex.a libvex-x86-darwin.a
TAG-x86-darwin:
	if [ ! -f TAG-x86-darwin ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-x86-darwin

libvex-amd64-darwin.a: TAG-amd64-darwin libvex.a
	mv -f libvex.a libvex-amd64-darwin.a
TAG-amd64-darwin:
	if [ ! -f TAG-amd64-darwin ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-amd64-darwin

libvex-arm64-linux.a: TAG-arm64-linux libvex.a
	mv -f libvex.a libvex-arm64-linux.a
TAG-arm64-linux:
	if [ ! -f TAG-arm64-linux ] ; then rm -f $(LIB_OBJS) TAG-* libvex.a ; fi
	touch TAG-arm64-linux


clean:
	rm -f $(LIB_OBJS) *.a TAG-* \
		pub/libvex_guest_offsets.h \
		auxprogs/genoffsets.s

minidist:
	rm -f vex--minidist-2005MMDD.tar
	tar cf vex--minidist-2005MMDD.tar $(PUB_HEADERS) $(PRIV_HEADERS) \
		Makefile-gcc					\
		`echo $(LIB_OBJS) | sed "s/\.o/\.c/g"`
	@echo 
	@echo minidist done, size follows:
	@ls -l vex--minidist-2005MMDD.tar
	@echo

# This is very uggerly.  Need to sed out both "xyzzyN" and
# "xyzzy$N" since gcc on different targets emits the constants
# differently -- with a leading $ on x86/amd64 but none on ppc32/64.
# ICC also emits the constants differently with a leading # #define
pub/libvex_guest_offsets.h:
	rm -f auxprogs/genoffsets.s
	$(CC) $(CCFLAGS) -O -S -o auxprogs/genoffsets.s \
				auxprogs/genoffsets.c
	grep xyzzy auxprogs/genoffsets.s | grep "^[# ]*#define" \
	   | sed "s/# #define/#define/g" \
	   | sed "s/xyzzy\\$$//g" \
	   | sed "s/xyzzy#//g" \
	   | sed "s/xyzzy//g" \
	   > pub/libvex_guest_offsets.h
	rm -f auxprogs/genoffsets.s


ALL_HEADERS  = $(PUB_HEADERS) $(PRIV_HEADERS)
ALL_INCLUDES = $(PUB_INCLUDES) $(PRIV_INCLUDES)

priv/ir_defs.o: $(ALL_HEADERS) priv/ir_defs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/ir_defs.o \
					 -c priv/ir_defs.c

priv/ir_inject.o: $(ALL_HEADERS) priv/ir_inject.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/ir_inject.o \
					 -c priv/ir_inject.c

priv/ir_match.o: $(ALL_HEADERS) priv/ir_match.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/ir_match.o \
					 -c priv/ir_match.c

priv/ir_opt.o: $(ALL_HEADERS) priv/ir_opt.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/ir_opt.o \
					 -c priv/ir_opt.c

priv/main_main.o: $(ALL_HEADERS) priv/main_main.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/main_main.o \
					 -c priv/main_main.c

priv/main_globals.o: $(ALL_HEADERS) priv/main_globals.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/main_globals.o \
					 -c priv/main_globals.c

priv/main_util.o: $(ALL_HEADERS) priv/main_util.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/main_util.o \
					 -c priv/main_util.c

priv/host_x86_defs.o: $(ALL_HEADERS) priv/host_x86_defs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_x86_defs.o \
					 -c priv/host_x86_defs.c

priv/host_amd64_defs.o: $(ALL_HEADERS) priv/host_amd64_defs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_amd64_defs.o \
					 -c priv/host_amd64_defs.c

priv/host_arm_defs.o: $(ALL_HEADERS) priv/host_arm_defs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_arm_defs.o \
					 -c priv/host_arm_defs.c

priv/host_arm64_defs.o: $(ALL_HEADERS) priv/host_arm64_defs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_arm64_defs.o \
					 -c priv/host_arm64_defs.c

priv/host_ppc_defs.o: $(ALL_HEADERS) priv/host_ppc_defs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_ppc_defs.o \
					 -c priv/host_ppc_defs.c

priv/host_s390_defs.o: $(ALL_HEADERS) priv/host_s390_defs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_s390_defs.o \
					 -c priv/host_s390_defs.c

priv/host_mips_defs.o: $(ALL_HEADERS) priv/host_mips_defs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_mips_defs.o \
					 -c priv/host_mips_defs.c

priv/host_x86_isel.o: $(ALL_HEADERS) priv/host_x86_isel.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_x86_isel.o \
					 -c priv/host_x86_isel.c

priv/host_amd64_isel.o: $(ALL_HEADERS) priv/host_amd64_isel.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_amd64_isel.o \
					 -c priv/host_amd64_isel.c

priv/host_arm_isel.o: $(ALL_HEADERS) priv/host_arm_isel.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_arm_isel.o \
					 -c priv/host_arm_isel.c

priv/host_arm64_isel.o: $(ALL_HEADERS) priv/host_arm64_isel.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_arm64_isel.o \
					 -c priv/host_arm64_isel.c

priv/host_ppc_isel.o: $(ALL_HEADERS) priv/host_ppc_isel.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_ppc_isel.o \
					 -c priv/host_ppc_isel.c

priv/host_s390_isel.o: $(ALL_HEADERS) priv/host_s390_isel.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_s390_isel.o \
					 -c priv/host_s390_isel.c

priv/host_mips_isel.o: $(ALL_HEADERS) priv/host_mips_isel.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_mips_isel.o \
					 -c priv/host_mips_isel.c

priv/host_generic_maddf.o: $(ALL_HEADERS) priv/host_generic_maddf.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_generic_maddf.o \
					 -c priv/host_generic_maddf.c

priv/host_generic_regs.o: $(ALL_HEADERS) priv/host_generic_regs.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_generic_regs.o \
					 -c priv/host_generic_regs.c

priv/host_generic_simd64.o: $(ALL_HEADERS) priv/host_generic_simd64.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_generic_simd64.o \
					 -c priv/host_generic_simd64.c

priv/host_generic_simd128.o: $(ALL_HEADERS) priv/host_generic_simd128.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_generic_simd128.o \
					 -c priv/host_generic_simd128.c

priv/host_generic_simd256.o: $(ALL_HEADERS) priv/host_generic_simd256.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_generic_simd256.o \
					 -c priv/host_generic_simd256.c

priv/host_generic_reg_alloc2.o: $(ALL_HEADERS) priv/host_generic_reg_alloc2.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/host_generic_reg_alloc2.o \
					 -c priv/host_generic_reg_alloc2.c

priv/guest_x86_toIR.o: $(ALL_HEADERS) priv/guest_x86_toIR.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_x86_toIR.o \
					 -c priv/guest_x86_toIR.c

priv/guest_generic_x87.o: $(ALL_HEADERS) priv/guest_generic_x87.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_generic_x87.o \
					 -c priv/guest_generic_x87.c

priv/guest_generic_bb_to_IR.o: $(ALL_HEADERS) priv/guest_generic_bb_to_IR.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_generic_bb_to_IR.o \
					 -c priv/guest_generic_bb_to_IR.c

priv/guest_x86_helpers.o: $(ALL_HEADERS) priv/guest_x86_helpers.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_x86_helpers.o \
					 -c priv/guest_x86_helpers.c

priv/guest_amd64_helpers.o: $(ALL_HEADERS) priv/guest_amd64_helpers.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_amd64_helpers.o \
					 -c priv/guest_amd64_helpers.c

priv/guest_amd64_toIR.o: $(ALL_HEADERS) priv/guest_amd64_toIR.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_amd64_toIR.o \
					 -c priv/guest_amd64_toIR.c

priv/guest_arm_helpers.o: $(ALL_HEADERS) priv/guest_arm_helpers.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_arm_helpers.o \
					 -c priv/guest_arm_helpers.c

priv/guest_arm64_helpers.o: $(ALL_HEADERS) priv/guest_arm64_helpers.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_arm64_helpers.o \
					 -c priv/guest_arm64_helpers.c

priv/guest_arm_toIR.o: $(ALL_HEADERS) priv/guest_arm_toIR.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_arm_toIR.o \
					 -c priv/guest_arm_toIR.c

priv/guest_arm64_toIR.o: $(ALL_HEADERS) priv/guest_arm64_toIR.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_arm64_toIR.o \
					 -c priv/guest_arm64_toIR.c

priv/guest_ppc_helpers.o: $(ALL_HEADERS) priv/guest_ppc_helpers.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_ppc_helpers.o \
					 -c priv/guest_ppc_helpers.c

priv/guest_s390_helpers.o: $(ALL_HEADERS) priv/guest_s390_helpers.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_s390_helpers.o \
					 -c priv/guest_s390_helpers.c

priv/guest_ppc_toIR.o: $(ALL_HEADERS) priv/guest_ppc_toIR.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_ppc_toIR.o \
					 -c priv/guest_ppc_toIR.c

priv/guest_s390_toIR.o: $(ALL_HEADERS) priv/guest_s390_toIR.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_s390_toIR.o \
					 -c priv/guest_s390_toIR.c

priv/s390_disasm.o: $(ALL_HEADERS) priv/s390_disasm.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/s390_disasm.o \
					 -c priv/s390_disasm.c

priv/guest_mips_helpers.o: $(ALL_HEADERS) priv/guest_mips_helpers.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_mips_helpers.o \
					 -c priv/guest_mips_helpers.c

priv/guest_mips_toIR.o: $(ALL_HEADERS) priv/guest_mips_toIR.c
	$(CC) $(CCFLAGS) $(ALL_INCLUDES) -o priv/guest_mips_toIR.o \
					 -c priv/guest_mips_toIR.c