#-------------------------------------------------------
#
#	Generic Crossplatform Makefile
#
#	Author:	stephen beaulieu <hippo@be.com>
#
#	Questions, comments & concerns to <devsupport@be.com>
#
#	Copyright 1998 Be, Inc.  All Rights Reserved
#
#--------------------------------------------------------

#--------------------------------------------------------
#	(Mostly) Project Independent Information
#
#	Include this file at the front of your project
#	makefile to set up platform-specific variables.
#
#	Input:
#		IMG_NAME: The name of the project
#		IMG_TYPE: APP, SHARED, or STATIC
#		CPU: (optional) Target platform; x86 or ppc.
#		FULL_DIR: (optional) Full path to project root directory.
#		OPTIMIZER: (optional) Optimization level flags.
#
#	Output:
#		TARGET_NAME: The name of the final project target,
#			based on IMG_NAME and IMG_TYPE.
#		TARGET: Final project target and path to it.
#		LDFLAGS: Linker flags needed to create IMG_TYPE.
#		CPPLIB: The standard C++ library.
#		CPU: Target platform.
#		COPY: Command to copy a file, including attributes.
#		FULL_DIR: Full path to project root directory.
#		OBJ_DIR: Directory to place objects; obj.$(CPU).
#		DEFAULT_LIBS: Standard objects to always link against.
#		MIMESET: Tool to set MIME info.
#		BEHEADERS: Full path to Be standard header files.
#		LIB_EXTENTION: Extension of shared library files.
#		OPTIMIZER: Optimization level flags.
#		BELIBRARIES: Full path to Be standard libraries.
#		MWLIBRARIES: Full path to Metrowerks libraries.
#		CC: C language compiler.
#		CPLATFLAGS: Standard C compiler flags.
#		LD: Linker.
#		LDPLATFLAGS: Basic linker flags.
#		ADDRES: Tool to add resources.
#		AR: Archiver tool
#		ARGLAGS: Archiver flags
#--------------------------------------------------------

#	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 id not specified
ifeq ($(FULL_DIR),)
	FULL_DIR	:= $(shell pwd)
endif

#	define the target for distrubution files
ifndef DIST_TARGET
	DIST_TARGET	:= $(shell pwd)/dist.$(CPU)/$(IMG_NAME)_$(VERSION)_$(CPU)
	CLEANDIST := yes
else
	CLEANDIST := no
endif

	DEFINE_VERSION :=
	
#	set up version information
ifndef VERSION
	ifdef SUBREV_CODE
		VERSION := $(VERSION_CODE).$(REVISION_CODE).$(SUBREV_CODE)
		DEFINE_VERSION += -DPROGRAM_VERSION_CODE=$(VERSION_CODE)
		DEFINE_VERSION += -DPROGRAM_REVISION_CODE=$(REVISION_CODE)
		DEFINE_VERSION += -DPROGRAM_SUBREV_CODE=$(SUBREV_CODE)
	else
		ifdef REVISION_CODE
			VERSION := $(VERSION_CODE).$(REVISION_CODE)
			DEFINE_VERSION += -DPROGRAM_VERSION_CODE=$(VERSION_CODE)
			DEFINE_VERSION += -DPROGRAM_REVISION_CODE=$(REVISION_CODE)
		else
			ifdef VERSION_CODE
				VERSION := $(VERSION_CODE)
				DEFINE_VERSION += -DPROGRAM_VERSION_CODE=$(VERSION_CODE)
			endif
		endif
	endif
endif

	DEFINE_VERSION += -DPROGRAM_VERSION=\"$(VERSION)\"
	
#	set the object directory
	OBJ				:= obj.$(CPU)
	OBJ_DIR			:= obj.$(CPU)

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

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

#	specify the MIMESET tool
	MIMESET			= mimeset

#	specify the command to copy a file and attributes
ifeq ($(shell [ -e /bin/copyattr ] && echo "YES"), YES)
	COPY			= copyattr --data
else
	COPY			= cp
endif

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

#		specify the compiler
		CC				= mwcc$(CPU)
		
#		set the initial compiler flags
		CPLATFLAGS		+= -g
		
#		specify the linker
		LD				= mwld$(CPU)

#		specify the basic linker flags
		LDPLATFLAGS		= \
							-nodefaults \
							$(BELIBRARIES)/glue-noinit.a \
							$(BELIBRARIES)/init_term_dyn.o \
							$(BELIBRARIES)/start_dyn.o 
							
							# -imagebase 0x80000000 \
							
#		specify the tool to add resources
		ADDRES			= copyres

#		set the Archiver tool and flags
		AR		= $(LD)
		ARFLAGS	+= -xml -o

#	platform specific settings
ifeq ($(CPU), x86)

#		specify the library extention
		LIB_EXTENTION	= .LIB

#		specify the optimizer setting
		ifndef OPTIMIZER
			OPTIMIZER 	= -O3
		endif

#		specify additional compiler flags
		CPLATFLAGS		+= -inline off
		
#		specify additional linker flags
		LDLATFLAGS		+=
		
else

ifeq ($(CPU), ppc)

#		specify the library extention
		LIB_EXTENTION	=

#		specify the optimizer setting
		ifndef OPTIMIZER
			OPTIMIZER 	= -O7
		endif

#		specify additional compiler flags
		CPLATFLAGS		+= 
		
#		specify additional linker flags
		LDPLATFLAGS		+= \
							-export pragma \
							-init _init_routine_ \
							-term _term_routine_

endif
endif

#	specify the Standard C++ link library
	CPPLIB			= $(shell cd $(MWLIBRARIES); ls libmslcpp*.a )

	TARGET_NAME		= $(IMG_NAME)
	
ifeq ($(IMG_TYPE), SHARED)
	TARGET_NAME = lib$(IMG_NAME).so
endif

ifeq ($(IMG_TYPE), STATIC)
	TARGET_NAME = lib$(IMG_NAME).a
endif

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