# This file is part of MemMXtest
# Copyright (C) 1999, 2000  J.A. Bezemer
# Parts copyright (C) 1996  Chris Brady
# This program is licensed under the GNU General Public License,
# see the top-level README file for details.  


######## NOTE: If you change this, change defines.h also!
######## (You'll get an error...)
# Must match TESTADR from defines.h
TESTADR=0x1000
#
# Must match TESTADR+CODESZ from defines.h
DATAADR=0xF000
########

#
# The source files. In CSSRCS are the .c names of test elements which also
# have _ml.S files.
#
CSSRCS = update_adr.c							\
	 marchel/marchel_wp.c		marchel/marchel_rp.c		\
	 marchel/marchel_rp_wn.c	marchel/marchel_wp_rn.c		\
	 marchel/marchel_rp_rn.c					\
	 marchel/marchel_rp_wn_rn.c	marchel/marchel_rp_rp_wn.c	\
	 marchel/marchel_rp_wn_wp.c	marchel/marchel_wp_wn_rn.c	\
	 marchel/marchel_rp_wn_rn_rn.c	marchel/marchel_rp_wn_rn_wp.c	\
	 marchel/marchel_rp_wn_wp_wn.c					\
	 marchel/marchel_rp_wn_rn_rn_wp.c				\
	 marchel/marchel_rp_wn_wp_wn_rn.c				\
	 marchel/marchel_rp_wn_rn_wp_rp_wn.c				\
	 prmarchel/prmarchel_rp.c	prmarchel/prmarchel_wp.c	\
	 prmarchel/prmarchel_rp_wn.c					\
	 prmarchel/prmarchel_rp_wn_rn.c

#
# In CSRCS are .c files that don't have .S files.
#
CSRCS = mtest.c cacherefr.c pattern_gen.c tests.c			\
	marchel_template.c		prmarchel_template.c		\
	march/march_marchc-.c		march/march_marchb.c		\
	march/march_scan.c		march/march_mats++.c		\
	march/march_marcha.c		march/march_pmovi.c		\
	march/march_marchg.c		march/march_marchu.c		\
	march/march_marchud.c		march/march_marchlr.c		\
	march/march_marchla.c		march/march_marchy.c		\
	march/march_marchc-r.c		march/march_pmovi-r.c		\
	march/march_marchu-r.c		march/march_mats+.c		\
	prmarch/prmarch_prmarchc-.c	prmarch/prmarch_prpmovi.c	\
	prmarch/prmarch_prscan.c

#
# Path for the floppy disk device
#
FDISK=/dev/fd0

# Use the gcc compiler; with options
CC=gcc
CFLAGS=-Wall -m486 -O2

# The assembler (gcc will know which one to call); with options
AS=gcc -c
ASFLAGS=

# Getting raw code and data from an executable
OBJCOPY=objcopy -O binary -R .note -R .comment -R .stab -R .stabstr

COBJS = $(CSRCS:.c=.o) $(CSSRCS:.c=.o)
#					All .o's that come from .c's

SSRCS = $(CSSRCS:.c=_ml.S)
#					The _ml.S files

SASSS = head.s $(SSRCS:.S=.s)
#					All 32-bit .s's that come from .S's

SOBJS = $(SASSS:.s=.o)
#					All .o's that come from .s's (32-bit)

OBJS = $(SOBJS) $(COBJS)
#					All 32-bit .o's
#
# NOTE: head.o MUST BE FIRST in OBJS, setup.S has hardcoded jump to 0x1000.
# ====

all: image

image: setup bootsect head.out build checksizes Makefile
	./checksizes.sh $(TESTADR) $(DATAADR)
	./build bootsect setup head.out >image

head: $(OBJS) Makefile
	ld -m elf_i386 -o $@ -e do_test -Ttext $(TESTADR) -Tdata $(DATAADR) \
		-Map mapfile $(OBJS)

head.out: head
	$(OBJCOPY) head head.out

setup.s: setup.S defines.h
	$(CC) -E -traditional $< -o $@

setup.o: setup.s
	as86 -a -0 -o $@ $<

setup: setup.o
	ld86 -0 -s -o $@ $<

bootsect.s: bootsect.S defines.h
	$(CC) -E -traditional $< -o $@

bootsect.o: bootsect.s
	as86 -a -0 -o $@ $<

bootsect: bootsect.o
	ld86 -0 -s -o $@ $<

build.o: build.c defines.h

checksizes.o: checksizes.c defines.h Makefile

clean:
	rm -f *.o */*.o *.s */*.s *.?~ */*.?~				\
	      build image bootsect setup head head.out			\
	      mapfile relo relo.out mapfile.relo checksizes Backup.tgz	\
	      update_adr_test

install: all
	dd <image >$(FDISK) bs=512

bak: all
	tar czf Backup.tgz *.[chS] */*.[chS] disasm Makefile
	cat image Backup.tgz > $(FDISK)

indent:
	indent *.c */*.c mtest.h tests.h

# Rules for .c and .S dependencies
# This also makes sure the .s's are indeed generated with -traditional
# preprocessing (see below)
$(OBJS) $(SASSS): defines.h
$(COBJS): mtest.h tests.h

# Not everything depends on this, but why bother.
$(SASSS): marchel_ml_template.S

# We must use our own implicit rule, because we need -traditional here,
# but not with normal .c sources (and both use CPPFLAGS)
%.s: %.S
	gcc -E -Wall -traditional -o $@ $<

# Testing the address update
update_adr_test: update_adr_test.o update_adr.o update_adr_ml.o
	gcc -o $@ $^
