
MKDIR  = mkdir -p
DEFMOD ?= ../defmod/ports/solaris/defmod
override DEFMOD += -q
ARMLIB = armlib
ARMASM = armasm
TOUCH = @touch

VPATH = defs tmp

SWIDEFS := ${wildcard defs/*.swi}
SWIOBJS = ${patsubst defs/%.swi,%.o,${SWIDEFS}}
SWIHDRS = ${patsubst defs/%.swi,%.h,${SWIDEFS}}
ASMSRCS = ${patsubst defs/%.swi,%.s,${SWIDEFS}}
ASMHDRS = ${patsubst defs/%.swi,%.hdr,${SWIDEFS}}
CDOCS   = ${patsubst defs/%.swi,%.ch,${SWIDEFS}}
ASMDOCS = ${patsubst defs/%.swi,%.ah,${SWIDEFS}}
STRDOCS = ${patsubst defs/%.swi,%.cs,${SWIDEFS}}
SWILIB  = OSlib.a

.PHONY: all headers library docs sources
all: headers library

.SUFFIXES:
.SUFFIXES: .ah .ch .cs .h .hdr .o .s .swi

.swi.h:
	$(DEFMOD) > $@ < $< -h
.swi.hdr:
	$(DEFMOD) > $@ < $< -hdr
.swi.s:
	$(DEFMOD) > $@ < $< -s
.swi.ah:
	$(DEFMOD) > $@ < $< -asmhelp
.swi.ch:
	$(DEFMOD) > $@ < $< -chelp
.swi.cs:
	$(DEFMOD) > $@ < $< -cstrong
.swi.o:
	@${MKDIR} tmp/l.$*
	$(DEFMOD) -byte_wide ByteWide -l -o tmp/l.$* < $< 
	${TOUCH} $@

${SWILIB}: ${SWIOBJS}
	${ARMLIB} -c -o $@ tmp/l.*/*.o

clean:
	rm -rf *.o *.s *.cs *.ch *.ah *.h *.hdr tmp ${SWILIB}

headers: ${SWIHDRS} ${ASMHDRS}
library: ${SWILIB}
docs   : ${CDOCS} ${ASMDOCS} ${STRDOCS}
sources: ${ASMSRCS}
