#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# $Id: makefile,v 1.7 2009/08/08 22:10:38 swift Exp $
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# RCS Log:
#
# $Log: makefile,v $
# Revision 1.7  2009/08/08 22:10:38  swift
# Implemented a new XA development environment that depends on linux/DosEmu.
#
# Revision 1.6  2006/01/06 23:12:06  swift
# Delete files to be built as a workaround for samba configuration problem.
#
# Revision 1.5  2004/12/29 23:06:50  swift
# Modified LogEntry() to use strings stored in the CODE segment.  This saves
# lots of space in the DATA segment and significantly speeds code start-up.
#
# Revision 1.4  2004/07/14 22:52:30  swift
# Modifications needed to transition to the new stdio library.
#
# Revision 1.3  2004/04/30 00:21:56  swift
# Modifications to account for changes in the installation directores for
# HiTech and PsdExpress.
#
# Revision 1.2  2003/11/13 19:45:51  swift
# Modifications to account for refactored directory structure.
#
# Revision 1.1  2003/11/12 18:15:44  swift
# Initial revision
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.DEFAULT:
.SUFFIXES:
.PRECIOUS: %.obj %.hex %.h
.PHONY: headers include force lib apex
SHELL=/bin/tcsh

# definitions needed to compile using XAC under DOSEMU
TERM    = vt100#                       XTERM def required to prevent slang errors
HiTech  = c:\HiTech\bin#               DOS path for HiTech bin directory
Root    = c:\apf9#                     Base directory for embedded projects
Project = $(shell echo `pwd`|perl -ne 's|.*/([^/]+)/lib|\1|;print')
DOSPATH = $(Root)\$(Project)\lib#      DOS path where compilation will happen
export DOSPATH#                        export the DOSPATH to sub-process environments

# definitions needed for actions under linux (ie., not under DOS)
binDir = ../bin#
srcDir = ../lib#
incDir = ../include#

# construct a list of all source files in source directory
srcFiles  = $(filter-out regengin.c, $(wildcard *.c)) 

objFiles := $(subst .c,.obj, $(srcFiles))

hFiles :=  $(addprefix $(incDir)/, \
           $(filter-out vfprintf.h regexec.h regfree.h stdlib.h, \
           $(subst .c,.h, $(srcFiles)))) $(incDir)/regex.h \
           $(incDir)/regex2.h $(incDir)/regutils.h 

all: include apex
	@echo Done making all ...

clean: force
	-rm -f $(objFiles) $(hFiles) apex.lib apex.cmd
 
test:
	@echo incDir = $(incDir)
	@echo Project = $(Project)
	@echo Apf9 = $(Apf9)
	@echo HiTech = $(HiTech)
	@echo srcDir = $(srcDir)
	@echo srcFiles = $(srcFiles)
	@echo objFiles = $(objFiles)
	@echo hFiles = $(hFiles)

$(incDir)/%.h: %.c 
	$(binDir)/swh D=$(shell echo $*.h|tr a-z.- A-Z__) if=$< of=$@

%.obj: %.c
	@rm -f $@
	$(binDir)/asdos "$(HiTech)\xac -q -E -Bl -LF -Zg -I$(incDir) -C $<" 

headers include: $(hFiles)
	@echo Done making $* ... 

$(incDir)/regex.h: 
	cp {$(srcDir),$(incDir)}/regex.h

$(incDir)/regex2.h: 
	cp {$(srcDir),$(incDir)}/regex2.h

$(incDir)/regutils.h: 
	cp {$(srcDir),$(incDir)}/regutils.h

powerup.obj: powerup.as
	$(binDir)/asdos -e"DOSPATH=$(DOSPATH)" "$(HiTech)\asxa -x powerup.as"

rtxa--l.obj: rtxa--l.as
	$(binDir)/asdos -e"DOSPATH=$(DOSPATH)" "$(HiTech)\asxa -x rtxa--l.as"

apex lib: $(objFiles)
	@rm -f apex.lib
	@echo r apex.lib $^ | (perl -ne 's/([^ ]+[ ]+)/\1\\\n/g;print' > apex.cmd)
	$(binDir)/asdos -e"DOSPATH=$(DOSPATH)" "$(HiTech)\libr < apex.cmd"
	@echo Done making $* ...
