# --------------------------------------------
#	Generic Sample Code Makefile
#
#	Copyright 1998 Be Inc.
# --------------------------------------------

# -----------------------------------------------
#	Application Specific information
# -----------------------------------------------

#	set the application name
	APP_NAME = Indexer

#	specify the list of source files
	SRCS		=	\
					indexer.cpp \
					vInfoView.cpp \
					dInfoView.cpp \
					fInfoView.cpp \
					lInfoView.cpp \
					Defs.cpp

#	specify any additional beos libraries needed to link against
#	these libraries should be specified by their actual name
#	the makefile determines the appropriate path and adds the .LIB
#	extention if necessary
#	libbe.so and libroot.so are automatically included
	ADD_BELIBS	=	

#	specify additional non-beos libraries to link against
#	these libraries are assumed to be below the current directory
#	the makefile will determine platform independant extentions
	ADD_LIBS	=


#	specify any additional system include paths
	SYSTEM_INCLUDES =	
	
#	specify any additional local include patsh
	LOCAL_INCLUDES =

	
#	All other settings are determined automatically
#	based on the platform	




# --------------------------------------------
#	Application Independant Information
# --------------------------------------------

# 	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

#	set the full directory variable if not specified
ifeq ($(FULL_DIR),)
	FULL_DIR	:= $(shell pwd)
endif

#	set the object directory
	OBJ				:= obj.$(CPU)
	OBJ_DIR			:= obj.$(CPU)

#	set the varible path
	VPATH			:= $(CPU)

#	specify the default libraries
	DEFAULT_LIBS	=	\
						libbe.so	\
						libroot.so

#	specify the the MIMESET tool
	MIMESET			:=	mimeset

#	set a series of variables depending on the CPU
ifeq ($(CPU), x86)

#	specify the resource fork
	RESOURCE_FORK 	:=$(APP_NAME)x86.rsrc
	
#	specify the Library extention
	LIB_EXTENTION	= .LIB

#	set the optimizer setting
	ifndef OPTIMIZER
		OPTIMIZER = -O3
	endif
#	set the directory for libraries
	BELIBRARIES		:=	/boot/develop/lib/x86
	

#	set the basic linker flags
	LDFLAGS			+=  \
						-nodefaults \
						$(BELIBRARIES)/glue-noinit.a \
						$(BELIBRARIES)/init_term_dyn.o \
						$(BELIBRARIES)/start_dyn.o 
							
#	set the compiler and flags
	CC		= mwccx86
	CFLAGS	+= -g -inline off -pragma "def_inherited on"

#	set the linker and flags
	LD		= mwldx86
	LDFLAGS	+= -imagebase 0x80000000
	LDLIBS	=

#	set tool to add resources
	ADDRES	= copyres
#	set the AS tools and flags
	AS		= gas
	ASFLAGS	+= 
#	set the AR tool and flags
   	AR		= $(LD)
   	ARFLAGS	+= -xml -o

else # end of x86 variables

ifeq ($(CPU), ppc)

#	specify the resource fork
	RESOURCE_FORK 	:=$(APP_NAME)PPC.rsrc

#	specify the Library extention
	LIB_EXTENTION	=
	
#	set the optimizer setting
	ifndef OPTIMIZER
		OPTIMIZER = -O7
	endif

#	set the directory for libraries
	BELIBRARIES		:=	/boot/beos/system/lib/
	
#	set the basic linker flags
	LDFLAGS			+=  \
						-nodefaults \
						/boot/develop/lib/libdll.a 
							

#	set the compiler and flags
	CC		= mwcc
	CFLAGS	+= -pragma "def_inherited on"

#	set the linker and flags
	LD		= mwld
	LDFLAGS	+= -export pragma
	LDFLAGS	+= \
				-init _init_routine_ \
				-term _term_routine_
	LDLIBS	=

#	set tool to add resources
	ADDRES  = copyres

#	set the AS tool and flags
	AS		= echo NO ASSEMBLER!
	ASFLAGS	= 

#	set the AR tool and flags
	AR		= mwld
	ARFLAGS	+= -xml -o

endif
endif

#	create the final list of BeOS libraries

LIBRARIES_TO_USE := $(addsuffix $(LIB_EXTENTION),$(addprefix $(BELIBRARIES)/, $(DEFAULT_LIBS) $(ADD_BELIBS)) $(ADD_LIBS))


#	additional common linker flags
	LDFLAGS		+=	-L$(BELIBRARIES) $(LIBRARIES_TO_USE)


#	specify the path to the be headers
	BEHEADERS	=	/boot/develop/headers/be

#	include paths
	INCLUDES = -i . $(addprefix -i ,$(LOCAL_INCLUDES)) -i- $(addprefix -i $(BEHEADERS)/,$(SYSTEM_INCLUDES)) 

# psuedo-function for converting a list of source files in SRCS variable
# to a corresponding list of object files in $(OBJ_DIR)/xxx.o
# The "function" strips off the src file suffix (.ccp or .c or whatever)
# and then strips of the directory name, leaving just the root file name.
# It then appends the .o suffix and prepends the $(OBJ_DIR)/ path
define SRCS_LIST_TO_OBJS
	$(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(foreach file, $(SRCS), $(basename $(notdir $(file))))))
endef

#	specify where to create the application binary
	TARGET		:=$(OBJ_DIR)/$(APP_NAME)

#	specify the list of objects
	OBJS		:= $(SRCS_LIST_TO_OBJS)

#	define the actual work to be done	
default: $(TARGET)

$(TARGET):	$(OBJ_DIR) $(OBJS) $(RESOURCE_FORK)
	echo $(OBJS)
		$(LD) -o $@ $(OBJS) $(LDFLAGS)
		$(ADDRES) $(RESOURCE_FORK) $@
		$(MIMESET) -f $@
		
delapp:
	-rm $(APP_NAME)

tar: delapp	$(APP_NAME)
	tar c $(APP_NAME)
	

###
### Generate mapfiles for metrowerks.  Cannot be done in make.pre, as
### the TARGET name is not yet known.
###

SYMBOL_FILE	:= 
SYMBOL_FILE	:= $(TARGET).xMAP
LDFLAGS		+= -map $(SYMBOL_FILE) $(LDSYM)


###
### Rules generic to the entire 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 $@

### Default rule for take xxx.s files on compile into $(OBJ_DIR)/xxx.o
ifeq ($(CPU), ppc)
$(OBJ_DIR)/%.o : %.s
	$(AS) $(INCLUDES) $(ASFLAGS) -c $< -o $@
endif

### Default rule for take xxx.S files on compile into $(OBJ_DIR)/xxx.o
ifeq ($(CPU), x86)
$(OBJ_DIR)/%.o : %.S
	$(CC) $(INCLUDES) $(CFLAGS) $(ASFLAGS) -e $< > $(OBJ_DIR)/$*.s
	$(AS) $(OBJ_DIR)/$*.s -o $@
endif


# 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 $(FULL_DIR)/$(OBJ_DIR)

rmapp ::
	-rm -f $(TARGET)



