#!/bin/sh
#
# Makefile for Amachi add-ons
#
# 


SHELL=/bin/sh 
#MAKE=make -j 2 

#	determine the CPU if not specified on the command line
ifndef CPU
	MACHINE =$(shell uname -m)
ifeq ($(MACHINE), BePC)
	CPU = x86
else
	CPU = ppc
endif
endif

#.SILENT:

	SOURCES		=	3d2 3ds Aoff Cob Dxf Iob Lwob Nff NffWtk	\
					Obj Ply
# Mgf

# generate add-ons directory
# 'a' is appended
#----------------------------------------------------------
define SOURCES_LIST_TO_ADDONS
	$(addprefix a, $(foreach file, $(SOURCES), $(basename $(notdir $(file)))))
endef

# generate "Clean" add-ons (add-ons to be cleared)
# 'c' is appended
#----------------------------------------------------------
define SOURCES_LIST_TO_CADDONS
	$(addprefix c, $(foreach file, $(SOURCES), $(basename $(notdir $(file)))))
endef

# generate "Clean Both" add-ons (add-ons to be cleared for both $CPU)
# 'cb' is appended
#----------------------------------------------------------
define SOURCES_LIST_TO_CBADDONS
	$(addprefix cb, $(foreach file, $(SOURCES), $(basename $(notdir $(file)))))
endef

# generate "Zip" add-ons (add-ons to be zipped)
# 'z' is appended
#----------------------------------------------------------
define SOURCES_LIST_TO_ZADDONS
	$(addprefix z, $(foreach file, $(SOURCES), $(basename $(notdir $(file)))))
endef


	ADD_ONS		:= $(SOURCES_LIST_TO_ADDONS)
	CADD_ONS	:= $(SOURCES_LIST_TO_CADDONS)
	CBADD_ONS	:= $(SOURCES_LIST_TO_CBADDONS)
	ZADD_ONS	:= $(SOURCES_LIST_TO_ZADDONS)


#########################################################
# Building the projects...
#########################################################

# make all the projects for $CPU
all: $(ADD_ONS)

# make all ppc & x86 projects
all-both: all-ppc all-x86

# make all ppc projects
all-ppc:
	make CPU=ppc

# make all x86 projects
all-x86:
	make CPU=x86

# make one project for $CPU
$(ADD_ONS)::
	make -C $@
	cp $@/obj.$(CPU)/$@	../Amachi/add-ons/


#########################################################
# Cleaning up the projects...
#########################################################

# clean the projects for $CPU
clean:
	for file in $(ADD_ONS) ; do		\
		make -C $$file clean ;		\
	done 

# clean both the ppc & x86 projects
clean-both: clean-ppc clean-x86

# clean the ppc projects
clean-ppc:
	make clean CPU=ppc

# clean the x86 projects
clean-x86:
	make clean CPU=x86

# clean one project for $CPU
$(CADD_ONS)::
	make clean -C a`echo $@ | cut -b2-`

# clean one project for both ppc & x86
$(CBADD_ONS)::
	make clean CPU=ppc -C a`echo $@ | cut -b3-`
	make clean CPU=x86 -C a`echo $@ | cut -b3-`
