#############################################################################
#	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		#
#	This software is released under the GNU General Public License, version	#
#	3, with the exemptions that 1) the header files installed by this 	 	#
#	package can be included in closed-source code and 2) the libraries		#
#	built by this package can be statically linked into a closed-source 	#
#	binary. See the file LICENSE for the details.							#
#	This software is provided "AS IS", without any warranty or guarantee.	#
#	By using this software you acknowledge that neither Bendor Research nor	#
#	any of its personnel or affiliates can be held liable for any damages,	#
#	including, but not limited to, loss of business, loss of money, loss of #
#	life, loss of reputation, arising out of this software being faulty or	#
#	not performing as advertised, even if Bendor Research was aware of such	#
#	faults in the software. You use this software at your own risk, any and #
#	all liabilities that arise out of your using this software are strictly	#
#	yours.																	#
#############################################################################

#	Define the target processor variant
#	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#	This library is aimed for the NXP LPC2xxx series, so the default target
#	is arm7tdmi-s. If you want it to use some other ARM variant, you have
#	to specify the relevant GCC processor name here. Note that the library
#	implicitely assumes that the target is a little endian, 32-bit ARM chip
#	that supports both the ARM and THUMB (not THUMB2) modes and has a HW
#	multiplier (i.e. that it is an ARM4t derivative).

CPU		:= arm7tdmi-s

#	The location of the result
#	~~~~~~~~~~~~~~~~~~~~~~~~~~
#	Under the specified location four directories will be created, namely
#	include, bin, lib and doc. That's where all the results go.
#	This library has to be writable by you (or you have have to have root
#	privileges when you install the library). If the library does not exist,
#	then it will be created, including all components in its path. That is,
#	if you set this to /usr/local/foo/bar then first /usr/local/foo is
#	created (and you must be able to write /usr/local) then bar is created
#	within foo and then bar will be populated with include, bin, lib and doc.
#	This variable is used only when you type make install, building the
#	library does not touch that location.

INSTALL	:= /usr/local/armlib

#	The name of the libraries without the suffix
#	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#	Of each library up to 8 versions are built. If you specify 'FOO' here,
#	the libraries will be called libFOO-XXX.a where 'XXX' tells you how
#	the library was compiled:
#		ans		ARM, no interworking, optimised for size
#		anf		ARM, no interworking, optimised for speed
#		ais		ARM, with interworking, optimised for size
#		aif		ARM, with interworking, optimised for speed
#		tns		THUMB, no interworking, optimised for size
#		tnf		THUMB, no interworking, optimised for speed
#		tis		THUMB, with interworking, optimised for size
#		tif		THUMB, with interworking, optimised for speed
#
#	Note that if you compile your code with interworking enabled, then
#	you can link against any lib*-ai?.a or lib*-ti?.a library but if
#	you compile your code with interworking disabled, you *must* link
#	against lib*-an?.a if you compiled for ARM or lib*-tn?.a for THUMB.

LIBC_NAME	:= c					# Name of the C library
LIBM_NAME	:= m					# Name of the math library
CRYP_NAME	:= crypto				# Name of the cryptographic library
EXEC_NAME	:= exec					# Name of the preemptive kernel
COOP_NAME	:= coop					# Name of the cooperative kernel
FIXP_NAME	:= fixpt				# Name of the fixpoint library
GCCS_NAME	:= gccs					# Name of the GCC supplementary library

#	What kind of libraries do you want to build
#	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#	As described above, you can have up to 8 variants for each library.
#	That means that every file is compiled 8 times, with different flags
#	specified to the compiler. If you know that you will never use certain
#	combinations, you can speed up the compilation of the library by not
#	building them. The following definition is a list of the library
#	types you want to build.
#	The default is to only build an ARM and a THUMB version, supporting
#	interwoking and optimised for size. The commented out line can be
#	used instead if you want all 8 versions.

# VERSIONS	:= ans anf ais aif tns tnf tis tif
VERSIONS	:= ais tis

#	Do you want the libraries to have private sections
#	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#	Normally the libraries will have .text, .rodata (and, in case of the
#	kernel, a .bss) sections. If you define this macro to YES, then each
#	library will have a .libname prefix for its segments, except the debug
#	segments. That is, if you defined some ????_NAME to 'foo' and this macro
#	to YES, then the generated libfoo??.a libraries will have .foo.text,
#	.foo.rodata and possibly .foo.bss segments. If you leave the macro empty,
#	then the segments will be called .text, .rodata and .bss. If you define
#	it to anything other than YES or being left empty, then that definition
#	will be used as a prefix in every library.
#	For example, defining this macro to 'bar' will cause every library to have
#	bar.text and bar.rodata sections. Note that while defining the macro
#	to YES will generate segment names starting with a period, defining it to
#	any other string generates names starting with the first character of the
#	string, be it a period or otherwise.

SECTPFX	:=

#	Tool prefix
#	~~~~~~~~~~~
#	It is usually arm-elf- or arm-eabi-, depending on your gcc and binutils
#	build. The basic differences between -elf and -eabi are the following:
#
#	-	structures in ELF are always aligned on 4-byte boundaries, in EABI
#		they are aligned to the boundary dictated by their members, i.e.
#		if you have a struct of containing only chars, the aligment will
#		be to byte. Accordinly, structure sizes are rounded up to the
#		nearest multiple of 4 in ELF, rounded up to the nearest multiple
#		of 1, 2, 4 or 8 in EABI, depending on the type of the members.
#
#	-	ELF aligns long longs and doubles to 4 byte, EABI aligns them to
#		8 bytes.  It is true in structs as well as in any memory allocation
#		for such variables, let it be a variable on the stack or a static
#		one.
#
#	-	ELF passes parameters in r0,r1,r2,r3 and the stack, as they come,
#		everything extended to 4 bytes if they are smaller. EABI always
#		passes long longs and doubles in an even numbered and the next
#		register and the stack is aligned to 8 bytes for them. That is,
#		if you have a function f(int a, double b, double c, int d, double e)
#		then in ELF you will have a in r0, b in r1:r2, c in r3:sp[0], d in
#		sp[4] and e in sp[8]:sp[12]. With EABI it will be a in r0, b in
#		r2:r3, c in sp[0]:sp[4], d in sp[8] and e in sp[16]:sp[20] while r1
#		and sp[12] will be left unused. This, of course, leads to higher
#		stack consumption, variables being passed on the stack instead of
#		registers (even though memory access is expensive) and of course
#		extra code to get those stack parameters into registers when you
#		use them. You don't want to know about varargs...
#
#	-	ELF stores doubles in big-endian word order while EABI stores them
#		in the processor's native endianness. This is true for both memory
#		representation and for register allocation as well.
#
#	If you use doubles or long longs often and you do not want the
#	alignment penalty, use ELF. Otherwise use EABI. If you choose ELF,
#	note that the gcc people do not really support ELF on ARM any more.
#	According to them, if you develop software where those alignment issues
#	matter then you are working with, quote, "badly written code on antique
#	hardware" and they couldn't care less about fixing issues related to the
#	ELF format for ARM. The standard response is "you should use EABI".
#
#	If you write code where the difference matters and you want it to
#	(correctly) compile for both ABIs (such as this library), gcc kindly
#	defines the preprocessor symbol __ARM_EABI__ when it compiles for EABI,
#	so you can use #if -s to compile the ABI specific code segments.
#
#	WARNING:	You *must* use the same ABI for the library and your
#				application. As you could see from the above, the ELF
#				and EABI formats are incompatible if you use structs or
#				any 64-bit datum. If you mix them, you will get very hard
#				to debug crashes.

TOOLPFX	:= arm-elf-

#	The name of the crosscompilation tools
#	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#	These *must* be the GNU gcc and binutils but you might have named
#	them differently. We always use gcc as assembler and linker as well,
#	so they are just aliases to gcc.
#
#	Note that there are other tools used by the build process and they are
#	assumed to have the usual name and behaviour: sh, cc, cp, rm, mv, mkdir,
#	awk, install, echo, sort, grep, make. Of these make *must* be the GNU
#	make (at least version 3.81) and the rest should behave as their GNU
#	equivalents for simple cases (the fancy GNU extensions are not used).

CC		:= $(TOOLPFX)gcc
AS		:= $(CC)
LD		:= $(CC)
AR		:= $(TOOLPFX)ar
OC		:= $(TOOLPFX)objcopy
OD		:= $(TOOLPFX)objdump

#	The gcc version you want to use
#	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#	If you leave it unspecified, the default gcc version  will be used.
#	Otherwise, GCC_VER will be set to  whatever you specify here.
#	That is, if you have both 4.0.1 and 4.3.2 installed, then if you leave
#	it empty, the default (4.3.2) will be used. If you define it as 4.0.1
#	then the old compiler will be used.
#
#	WARNING:	The 4.4.x GCC versions have a bug in the wrapper code that,
#				if you specify a compiler version, will make the compiler to
#				return a 0 exit code even if there was an error. If you have
#				a 4.4.x compiler do not use this feature! If you absolutely
#				must use this with a 4.4.x, then install an older compiler as
#				well (e.g. 4.0.1) and set gcc to *that* compiler then set this
#				macro. That is, you will specify
#
#				CC      = $(TOOLPFX)gcc-4.0.1
#				USE_GCC = 4.4.3
#
#				and thus the wrapper code will be that of the 4.0.1 compiler
#				(which works) but the compiler proper will be the 4.4.3 one.

USE_GCC	:=

#	The location of the build directory
#	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#	If you leave it empty, then a directory called 'objs' will be created
#	within the current directory. All temporary files, objects, dependencies
#	and so on will be created within that directory. Of course, it assumes
#	that the current directory is writeable by you. If it is not the case,
#	you can specify any location here. If the nominated directory does not
#	exist, it will then be created but at least its parent directory must
#	already exist. There's no trailing / at the end of this definition,
#	if you want the build to be done in /tmp, then you define it as /tmp
#	and not /tmp/.
#
#	WARNING:	If you issue a make clean, then the entire content of this
#				directory will be deleted. Now if you choose the humble / and
#				you are root... You get the picture.

OBJDIR	:=

