⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makefiles.txt

📁 讲述linux的初始化过程
💻 TXT
📖 第 1 页 / 共 3 页
字号:
Linux Kernel Makefiles2000-September-14Michael Elizabeth Chastain, <mec@shout.net>=== Table of ContentsThis document describes the Linux kernel Makefiles.  1  Overview  2  Who does what  3  Makefile language  4  Variables passed down from the top  5  The structure of an arch Makefile     5.1  Architecture-specific variables     5.2  Vmlinux build variables     5.3  Post-vmlinux goals     5.4  Mandatory arch-specific goals  6  The structure of a subdirectory Makefile     6.1  Comments     6.2  Goal definitions     6.3  Adapter section     6.4  Rules.make section     6.5  Special rules  7  Rules.make variables     7.1  Subdirectories     7.2  Object file goals     7.3  Library file goals     7.4  Loadable module goals     7.5  Multi-part modules     7.6  Compilation flags     7.7  Miscellaneous variables  8  New-style variables     8.1  New variables     8.2  Converting to old-style  9  Compatibility with Linux Kernel 2.2 10  Credits=== 1 OverviewThe Makefiles have five parts:    Makefile: the top Makefile.    .config: the kernel configuration file.    arch/*/Makefile: the arch Makefiles.    Subdirectory Makefiles: there are about 300 of these.    Rules.make: the common rules for all subdirectory Makefiles.The top Makefile reads the .config file, which comes from thekernel configuration process.The top Makefile is responsible for building two major products: vmlinux(the resident kernel image) and modules (any module files).  It buildsthese goals by recursively descending into the subdirectories of thekernel source tree.  The list of subdirectories which are visited dependsupon the kernel configuration.The top Makefile textually includes an arch Makefile with the namearch/$(ARCH)/Makefile.  The arch Makefile supplies architecture-specificinformation to the top Makefile.Each subdirectory has a Makefile which carries out the commands passeddown from above.  The subdirectory Makefile uses information from the.config file to construct various file lists, and then it textuallyincludes the common rules in Rules.make.Rules.make defines rules which are common to all the subdirectoryMakefiles.  It has a public interface in the form of certain variablelists.  It then declares rules based on those lists.=== 2 Who does whatPeople have four different relationships with the kernel Makefiles.*Users* are people who build kernels.  These people type commands such as"make menuconfig" or "make bzImage".  They usually do not read or editany kernel Makefiles (or any other source files).*Normal developers* are people who work on features such as devicedrivers, file systems, and network protocols.  These people need tomaintain the subdirectory Makefiles for the subsystem that they areworking on.  In order to do this effectively, they need some overallknowledge about the kernel Makefiles, plus detailed knowledge about thepublic interface for Rules.make.*Arch developers* are people who work on an entire architecture, suchas sparc or ia64.  Arch developers need to know about the arch Makefilesas well as subdirectory Makefiles.*Kbuild developers* are people who work on the kernel build system itself.These people need to know about all aspects of the kernel Makefiles.This document is aimed towards normal developers and arch developers.=== 3 Makefile languageThe kernel Makefiles are designed to run with Gnu Make.  The Makefilesuse only the documented features of Gnu Make, but they do use manyGnu extensions.Gnu Make supports elementary list-processing functions.  The kernelMakefiles use a novel style of list building and manipulation with few"if" statements.Gnu Make has two assignment operators, ":=" and "=".  ":=" performsimmediate evaluation of the right-hand side and stores an actual stringinto the left-hand side.  "=" is like a formula definition; it stores theright-hand side in an unevaluated form and then evaluates this form eachtime the left-hand side is used.There are some cases where "=" is appropriate.  Usually, though, ":="is the right choice.All of the examples in this document were drawn from actual kernelsources.  The examples have been reformatted (white space changed, linessplit), but are otherwise exactly the same.=== 4 Variables passed down from the topThe 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".   Many subdirectory Makefiles test $(ARCH)	to determine which files to compile.	By default, the top Makefile sets $(ARCH) to be the same as the	host system system architecture.  For a cross build, a user may	override the value of $(ARCH) on the command line:	    make ARCH=m68k ...    TOPDIR, HPATH		$(TOPDIR) is the path to the top of the kernel source tree.	Subdirectory Makefiles need this so that they can include	$(TOPDIR)/Rules.make.	$(HPATH) is equal to $(TOPDIR)/include.  A few arch Makefiles	need to use this to do special things using include files.    SUBDIRS	$(SUBDIRS) is a list of directories which the top Makefile	enters in order to build either vmlinux or modules.  The actual	directories in $(SUBDIRS) depend on the kernel configuration.	The top Makefile defines this variable, and the arch Makefile	extends it.    HEAD, CORE_FILES, NETWORKS, DRIVERS, LIBS    LINKFLAGS	$(HEAD), $(CORE_FILES), $(NETWORKS), $(DRIVERS), and $(LIBS)	specify lists of object files and libraries to be linked into	vmlinux.		The files in $(HEAD) are linked first in vmlinux.	$(LINKFLAGS) specifies the flags to build vmlinux.	The top Makefile and the arch Makefile jointly define these	variables.  The top Makefile defines $(CORE_FILES), $(NETWORKS),	$(DRIVERS), and $(LIBS).  The arch Makefile defines $(HEAD)	and $(LINKFLAGS), and extends $(CORE_FILES) and $(LIBS).	Note: there are more names here than necessary.  $(NETWORKS),	$(DRIVERS), and even $(LIBS) could be subsumed into $(CORE_FILES).    CPP, CC, AS, LD, AR, NM, STRIP, OBJCOPY, OBJDUMP    CPPFLAGS, CFLAGS, CFLAGS_KERNEL, MODFLAGS, AFLAGS, LDFLAGS    PERL    GENKSYMS	These variables specify the commands and flags that Rules.make	uses to build goal files from source files.	$(CFLAGS_KERNEL) contains extra C compiler flags used to compile	resident kernel code.	$(MODFLAGS) contains extra C compiler flags used to compile code	for loadable kernel modules.  In the future, this flag may be	renamed to the more regular name $(CFLAGS_MODULE).	$(AFLAGS) contains assembler flags.	$(GENKSYMS) contains the command used to generate kernel symbol	signatures when CONFIG_MODVERSIONS is enabled.	The genksyms	command comes from the modutils package.    CROSS_COMPILE	This variable is a prefix path for other variables such as $(CC),	$(AS), and $(LD).  The arch Makefiles sometimes use and set this	variable explicitly.  Subdirectory Makefiles don't need to worry	about it.	The user may override $(CROSS_COMPILE) on the command line if	desired.    HOSTCC, HOSTCFLAGS	These variables define the C compiler and C compiler flags to	be used for compiling host side programs.  These are separate	variables because the target architecture can be different from	the host architecture.	If your Makefile compiles and runs a program that is executed	during the course of building the kernel, then it should use	$(HOSTCC) and $(HOSTCFLAGS).	For example, the subdirectory drivers/pci has a helper program	named gen-devlist.c.  This program reads a list of PCI ID's and	generates C code in the output files classlist.h and devlist.h.	Suppose that a user has an i386 computer and wants to build a	kernel for an ia64 machine.  Then the user would use an ia64	cross-compiler for most of the compilation, but would use a	native i386 host compiler to compile drivers/pci/gen-devlist.c.	For another example, kbuild helper programs such as	scripts/mkdep.c and scripts/lxdialog/*.c are compiled with	$(HOSTCC) rather than $(CC).    ROOT_DEV, SVGA_MODE, RAMDISK	End users edit these variables to specify certain information	about the configuration of their kernel.  These variables	are ancient!  They are also specific to the i386 architecture.	They really should be replaced with CONFIG_* options.    MAKEBOOT	This variable is defined and used only inside the main arch	Makefiles.  The top Makefile should not export it.    INSTALL_PATH	This variable defines a place for the arch Makefiles to install	the resident kernel image and System.map file.    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.    CONFIG_SHELL	This variable is private between Makefile and Rules.make.	Arch makefiles and subdirectory Makefiles should never use this.    MODVERFILE	An internal variable.  This doesn't need to be exported, as it	is never used outside of the top Makefile.    MAKE, MAKEFILES	Some variables internal to Gnu Make.	$(MAKEFILES) in particular is used to force the arch Makefiles	and subdirectory Makefiles to read $(TOPDIR)/.config without	including it explicitly.  (This was an implementation hack and	could be fixed).=== 5 The structure of an arch Makefile--- 5.1 Architecture-specific variablesThe top Makefile includes one arch Makefile file, arch/$(ARCH)/Makefile.This section describes the functions of the arch Makefile.An arch Makefile extends some of the top Makefile's variables witharchitecture-specific values.    SUBDIRS	The top Makefile defines $(SUBDIRS).  The arch Makefile extends	$(SUBDIRS) with a list of architecture-specific directories.	Example:		# arch/alpha/Makefile		SUBDIRS := $(SUBDIRS) arch/alpha/kernel arch/alpha/mm \		           arch/alpha/lib arch/alpha/math-emu	This list may depend on the configuration:		# arch/arm/Makefile		ifeq ($(CONFIG_ARCH_ACORN),y)		SUBDIRS         += drivers/acorn		...		endif    CPP, CC, AS, LD, AR, NM, STRIP, OBJCOPY, OBJDUMP    CPPFLAGS, CFLAGS, CFLAGS_KERNEL, MODFLAGS, AFLAGS, LDFLAGS	The top Makefile defines these variables, and the arch Makefile	extends them.	Many arch Makefiles dynamically run the target C compiler to	probe what options it supports:		# arch/i386/Makefile		# prevent gcc from keeping the stack 16 byte aligned		CFLAGS += $(shell if $(CC) -mpreferred-stack-boundary=2 \			  -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \			  then echo "-mpreferred-stack-boundary=2"; fi)	And, of course, $(CFLAGS) can depend on the configuration:		# arch/i386/Makefile		ifdef CONFIG_M386		CFLAGS += -march=i386		endif		ifdef CONFIG_M486		CFLAGS += -march=i486		endif		ifdef CONFIG_M586		CFLAGS += -march=i586		endif	Some arch Makefiles redefine the compilation commands in order	to add architecture-specific flags:		# arch/s390/Makefile		LD=$(CROSS_COMPILE)ld -m elf_s390		OBJCOPY=$(CROSS_COMPILE)objcopy -O binary -R .note -R .comment -S--- 5.2 Vmlinux build variablesAn arch Makefile co-operates with the top Makefile to define variableswhich specify how to build the vmlinux file.  Note that there is nocorresponding arch-specific section for modules; the module-buildingmachinery is all architecture-independent.    HEAD, CORE_FILES, LIBS    LINKFLAGS	The top Makefile defines the architecture-independent core of	thse variables, and the arch Makefile extends them.  Note that the	arch Makefile defines (not just extends) $(HEAD) and $(LINKFLAGS).	Example:		# arch/m68k/Makefile		ifndef CONFIG_SUN3		LINKFLAGS = -T $(TOPDIR)/arch/m68k/vmlinux.lds		else		LINKFLAGS = -T $(TOPDIR)/arch/m68k/vmlinux-sun3.lds -N		endif		...		ifndef CONFIG_SUN3		HEAD := arch/m68k/kernel/head.o		else		HEAD := arch/m68k/kernel/sun3-head.o		endif		SUBDIRS += arch/m68k/kernel arch/m68k/mm arch/m68k/lib		CORE_FILES := arch/m68k/kernel/kernel.o arch/m68k/mm/mm.o $(CORE_FILES)		LIBS += arch/m68k/lib/lib.a--- 5.3 Post-vmlinux goalsAn arch Makefile specifies goals that take the vmlinux file, compressit, wrap it in bootstrapping code, and copy the resulting files somewhere.This includes various kinds of installation commands.These post-vmlinux goals are not standardized across differentarchitectures.  Here is a list of these goals and the architecturesthat support each of them (as of kernel version 2.4.0-test6-pre5):    balo		mips    bootimage		alpha    bootpfile		alpha, ia64    bzImage		i386, m68k    bzdisk		i386    bzlilo		i386

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -