Skip to content
makefiles.txt 36.9 KiB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
	Example:
		#arch/ppc/Makefile
		biarch := $(call cc-option-yn, -m32)
		aflags-$(biarch) += -a32
		cflags-$(biarch) += -m32
	
	In the above example $(biarch) is set to y if $(CC) supports the -m32
	option. When $(biarch) equals to y the expanded variables $(aflags-y)
	and $(cflags-y) will be assigned the values -a32 and -m32.

    cc-option-align
	gcc version >= 3.0 shifted type of options used to speify
	alignment of functions, loops etc. $(cc-option-align) whrn used
	as prefix to the align options will select the right prefix:
	gcc < 3.00
		cc-option-align = -malign
	gcc >= 3.00
		cc-option-align = -falign
	
	Example:
		CFLAGS += $(cc-option-align)-functions=4

	In the above example the option -falign-functions=4 is used for
	gcc >= 3.00. For gcc < 3.00 -malign-functions=4 is used.
	
    cc-version
	cc-version return a numerical version of the $(CC) compiler version.
	The format is <major><minor> where both are two digits. So for example
	gcc 3.41 would return 0341.
	cc-version is useful when a specific $(CC) version is faulty in one
	area, for example the -mregparm=3 were broken in some gcc version
	even though the option was accepted by gcc.

	Example:
		#arch/i386/Makefile
		GCC_VERSION := $(call cc-version)
		cflags-y += $(shell \
		if [ $(GCC_VERSION) -ge 0300 ] ; then echo "-mregparm=3"; fi ;)

	In the above example -mregparm=3 is only used for gcc version greater
	than or equal to gcc 3.0.
	

=== 7 Kbuild Variables

The top Makefile exports the following variables:

    VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION

	These variables define the current kernel version.  A few arch
	Makefiles actually use these values directly; they should use
	$(KERNELRELEASE) instead.

	$(VERSION), $(PATCHLEVEL), and $(SUBLEVEL) define the basic
	three-part version number, such as "2", "4", and "0".  These three
	values are always numeric.

	$(EXTRAVERSION) defines an even tinier sublevel for pre-patches
	or additional patches.	It is usually some non-numeric string
	such as "-pre4", and is often blank.

    KERNELRELEASE

	$(KERNELRELEASE) is a single string such as "2.4.0-pre4", suitable
	for constructing installation directory names or showing in
	version strings.  Some arch Makefiles use it for this purpose.

    ARCH

	This variable defines the target architecture, such as "i386",
	"arm", or "sparc". Some kbuild Makefiles test $(ARCH) to
	determine which files to compile.

	By default, the top Makefile sets $(ARCH) to be the same as the
	host system architecture.  For a cross build, a user may
	override the value of $(ARCH) on the command line:

	    make ARCH=m68k ...


    INSTALL_PATH

	This variable defines a place for the arch Makefiles to install
	the resident kernel image and System.map file.
	Use this for architecture specific install targets.

    INSTALL_MOD_PATH, MODLIB

	$(INSTALL_MOD_PATH) specifies a prefix to $(MODLIB) for module
	installation.  This variable is not defined in the Makefile but
	may be passed in by the user if desired.

	$(MODLIB) specifies the directory for module installation.
	The top Makefile defines $(MODLIB) to
	$(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE).  The user may
	override this value on the command line if desired.

=== 8 Makefile language

The kernel Makefiles are designed to run with GNU Make.  The Makefiles
use only the documented features of GNU Make, but they do use many
GNU extensions.

GNU Make supports elementary list-processing functions.  The kernel
Makefiles use a novel style of list building and manipulation with few
"if" statements.

GNU Make has two assignment operators, ":=" and "=".  ":=" performs
immediate evaluation of the right-hand side and stores an actual string
into the left-hand side.  "=" is like a formula definition; it stores the
right-hand side in an unevaluated form and then evaluates this form each
time the left-hand side is used.

There are some cases where "=" is appropriate.  Usually, though, ":="
is the right choice.

=== 9 Credits

Original version made by Michael Elizabeth Chastain, <mailto:mec@shout.net>
Updates by Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
Updates by Sam Ravnborg <sam@ravnborg.org>

=== 10 TODO

- Describe how kbuild support shipped files with _shipped.
- Generating offset header files.
- Add more variables to section 7?