#---------------------------------------------------------------------------#
#			CONFIGURATION PARAMETERS
#---------------------------------------------------------------------------#

P = $(shell pwd)
A = $(shell dirname $(P))
T = $(PATH)
H =
PATH += .:$(P):$(A)/inc:/bin/:/usr/bin:/sbin:/usr/sbin
D = $(shell date +%y%m%d)

TMP = /tmp

NASM =
I += -i./ -i$(P)/../../inc/asmutils/ -i$(P)/../../inc/dbg/
#I += -i/usr/local/lib/nasm/other/hp/
#I += -i./ -i/usr/local/lib/nasm/ -i/usr/local/lib/nasm/other/hp/

# additional files
FILES += xectime testop lis2lis
INSTALLDIR = /usr/local/bin/
INSTALLFILES +=

# Operating system (LINUX/FREEBSD)
OS = LINUX

# Optimization method (SIZE / SPEED)
OPTIMIZE = SIZE
OPTIMIZE = SPEED

# Kernel version (LINUX only: 20/22)
KERNEL = 22

# ELF hack for smaller binaries (LINUX only)
ELF_MACROS = y

# the assembler
#AS = ../../util/nasm
#AS = /usr/src/asm/nasm.latest/nasm
AS = /usr/local/bin/nasm
#AS = $(shell type -p "nasm")

# 'listing' output
#L = -l $*.lis

__AU__	= 014

__NI	= x
#
ASFLAGS += -w+orphan-labels $(I) $(L) $(PROGF) -DDATE=\"$(shell date +%y%m%d)\" -DTMP=$(TMP) -D__NI=$(__NI)

#---------------------------------------------------------------------------#

LN = /bin/ln -sf
LDFLAGS = -s
ASFLAGS += -D__$(OS)__ -D__OPTIMIZE__=__O_$(OPTIMIZE)__

FILES +=

${OS} = y

ifdef KERNEL
ASFLAGS += -D__KERNEL__=$(KERNEL) 
endif

#1
ifdef ELF_MACROS

ASFLAGS += -D__ELF_MACROS__ -f bin

%:	%.asm
	test ! -L ./$*.asm||touch ./$*.asm
	rm -f ./*.mkh
	touch ./$*.inc
ifdef ASM2MKH
	$(ASM2MKH) $< "$(ASFLAGS)"
else
	$(AS) $(ASFLAGS) $< 2>&1|tee LOG.$<
endif
	/bin/chmod a+x ./$*
#1
else

ASFLAGS += -f elf

%.o:	%.asm
	$(AS) $(ASFLAGS) $<

%:	%.o
	touch ./$*.inc
	$(LD) $(LDFLAGS) -o $* $<
	strip --remove-section .note --remove-section .comment $*
#1
endif

all:	$(FILES)

clean:
	rm -f *.mkh *.lis *.lst *.o $(FILES) $(LINKS)

new:	clean all
