CROSS := ppc-amigaos
CC    := $(CROSS)-gcc
STRIP := $(CROSS)-strip
RM    := rm -f
CP    := cp -p --remove-destination

TARGET  := xfdmaster.library
VERSION := 53

BINDIR := ../release/xfdmaster/bin

CFLAGS     := -mcrt=clib2 -O2 -g -Wall -Werror -Wwrite-strings -Wno-multichar -Wno-deprecated-declarations -Iinclude
LDFLAGS    := -mcrt=clib2 -N -nostartfiles
LIBS       := 
STRIPFLAGS := -R.comment

main_SRCS    := $(wildcard main/*.c)
main_OBJS    := $(main_SRCS:.c=.o)
slaves_SRCS  := m68k/xfd-m68k.c slaves/XPK.c
linkers_SRCS := 
SRCS         := init.c xfdmaster_68k.c xfdmaster.c
OBJS         := $(main_SRCS:.c=.o) $(slaves_SRCS:.c=.o) $(linkers_SRCS:.c=.o) $(SRCS:.c=.o)

.PHONY: all
all: $(TARGET) external_slaves utils

$(TARGET): $(OBJS)
	$(CC) $(LDFLAGS) -o $@.debug $^ $(LIBS)
	$(STRIP) $(STRIPFLAGS) -o $@ $@.debug

init.o: $(TARGET)_rev.h xfdmaster_vectors.c xfdmaster_vectors.h
$(main_OBJS): xfdmaster_vectors.h
$(OBJS): xfdmaster_internal.h

m68k/xfd-m68k.c: m68k/xfd-m68k.s m68k/slaves/*.s
	$(MAKE) -C m68k xfd-m68k.c

.PHONY: external_slaves
external_slaves:
	$(MAKE) -C external_slaves all

.PHONY: utils
utils:
	$(MAKE) -C utils all

.PHONY: clean
clean:
	$(RM) $(TARGET) $(TARGET).debug *.o main/*.o slaves/*.o linkers/*.o m68k/*.o
	$(MAKE) -C m68k clean
	$(MAKE) -C external_slaves clean
	$(MAKE) -C utils clean

.PHONY: revision
revision:
	bumprev $(VERSION) $(TARGET)

.PHONY: autodoc
autodoc:
	autodoc -l100 $(SRCS) $(main_SRCS) >xfdmaster.doc

.PHONY: install
install: $(TARGET)
	copy $(TARGET) SYS:Libs
	$(MAKE) -C external_slaves install
	$(MAKE) -C utils install

.PHONY: dist
dist: $(TARGET)
	$(CP) $(TARGET) $(BINDIR)/libs
	$(MAKE) -C external_slaves dist
	$(MAKE) -C utils dist

