# $Id: makefile,v 1.29 1997/02/07 15:25:44 digulla Exp $
TOP=../..

include $(TOP)/config/make.cfg

OBJDIR=$(GENDIR)/aros

FILES = calcchecksum kprintf nastyfreemem \
	purify removeslist debugmem \
	_kprintf hexdump \
	freestruct \
	readbyte \
	readdouble \
	readfloat \
	readlong \
	readstring \
	readstruct \
	readword \
	writebyte \
	writedouble \
	writefloat \
	writelong \
	writestring \
	writestruct \
	writeword

INCLUDE_FILES = $(wildcard include/*.h)
DEST_INCLUDE_FILES = $(subst include,$(INCDIR)/aros,$(INCLUDE_FILES))

all: setup $(LIBDIR)/libaros.a

setup : make-dirs os-include

os-include: $(DEST_INCLUDE_FILES)

$(INCDIR)/aros/%.h: include/%.h
	$(CP) $< $@

make-dirs :
	@if [ ! -d $(OBJDIR) ]; then $(MKDIR) $(OBJDIR) ; else true ; fi
	@if [ ! -d $(INCDIR) ]; then $(MKDIR) $(INCDIR) ; else true ; fi

clean:
	-$(RM) $(OBJDIR) *.err $(LIBDIR)/libaros.a

$(OBJDIR)/%.o: %.c
	$(SYS_CC) $(CFLAGS) $< -c -o $@ 2>&1|tee $*.err
	@if test ! -s $*.err; then rm $*.err; else true ; fi

$(OBJDIR)/rt_stubs.o: rt_stubs.s
	$(SYS_AS) $(AFLAGS) $< -c -o $@ 2>&1|tee $*.err
	@if test ! -s $*.err; then rm $*.err; else true ; fi

$(LIBDIR)/libaros.a: $(foreach f,$(FILES),$(OBJDIR)/$(f).o)
	$(AR) $@ $?
	$(RANLIB) $@

$(OBJDIR)/%.d: %.c
	@if [ ! -d $(@D) ]; then $(MKDIR) $(@D) ; else true ; fi
	$(MKDEPEND) -f- -p$(@D)/ -- $(APPCFLAGS) -- $^ > $@

ifeq ($(TARGET),clean)
NODEPS:=yes
endif
ifeq ($(TARGET),setup)
NODEPS:=yes
endif

ifndef NODEPS
include $(foreach f,$(FILES),$(OBJDIR)/$(f).d)
endif
