
#	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

OBJ_DIR = obj.$(CPU)

CC			= 	mwcc$(CPU)
LD			= 	mwld$(CPU)
SRCS  		= 	kernel_interface.c \
				iso.c 

OBJS		=	$(OBJ_DIR)/kernel_interface.o \
			$(OBJ_DIR)/iso.o 

INCLUDES	= 	-i- -I.

TARGET		=  $(OBJ_DIR)/iso9660

ifeq ($(CPU), x86)
		LIB_EXTENTION	= .LIB
else
ifeq ($(CPU), ppc)
		LIB_EXTENTION	= 
endif
endif

#	specify the directory for libraries
	BELIBRARIES		=	/boot/develop/lib/$(CPU)


LDFLAGS		= 	-G -nodefaults -map $(TARGET).xMAP\
				$(BELIBRARIES)/glue-noinit.a \
				$(BELIBRARIES)/_KERNEL_$(LIB_EXTENTION)

CFLAGS 		= -O5 $(INCLUDES)

$(TARGET):	$(OBJ_DIR) $(OBJS)
		$(LD) -o $@ $(OBJS) $(LDFLAGS)
		-mkdir -p /boot/home/config/add-ons/kernel/file_systems > /dev/null 2>&1
		cp $(TARGET) /boot/home/config/add-ons/kernel/file_systems/
		cp $(TARGET).xMAP /boot/home/config/add-ons/kernel/file_systems/

#--------------------------------------------------------
#	Rules for the whole system
#--------------------------------------------------------

#	rule to create the object file directory if needed
$(OBJ_DIR)::
	@[ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1

#	default rule for take xxx.c files on compile into $(OBJ_DIR)/xxx.o
$(OBJ_DIR)/%.o : %.c
	$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@

#	default rule for take xxx.cpp files on compile into $(OBJ_DIR)/xxx.o
$(OBJ_DIR)/%.o : %.cpp
	$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@

#	empty rule. Things that depend on this rule will always get triggered
FORCE:

#	The generic clean command. Delete everything in the object folder.
clean :: FORCE
	-rm -rf $(OBJ_DIR)

#	remove just the application from the object folder
rmapp ::
	-rm -f $(TARGET)
