2005_Structures and functions of Makefile

17
Makefile Makefile 의 의의 의 의의 의 의의 의 의의 (Linux-2.6.10 version) (Linux-2.6.10 version)

Transcript of 2005_Structures and functions of Makefile

Page 1: 2005_Structures and functions of Makefile

MakefileMakefile 의 구조 및 기능의 구조 및 기능

(Linux-2.6.10 version)(Linux-2.6.10 version)

Page 2: 2005_Structures and functions of Makefile

MakefileMakefile 의 구조의 구조

OverviewOverview Who does whatWho does what Important check kbuild filesImportant check kbuild files Observe Makefiles sourceObserve Makefiles source

Page 3: 2005_Structures and functions of Makefile

overviewoverview

Top makefileTop makefile .config.config Arch/$(ARCH)/MakefileArch/$(ARCH)/Makefile Script/MakefileScript/Makefile Kbuild makefilesKbuild makefiles

Page 4: 2005_Structures and functions of Makefile

Top makefileTop makefile

The top makefile reads the .config fileThe top makefile reads the .config file

Two major product :Two major product : Vmlinux(the resident kernel image)Vmlinux(the resident kernel image)

Modules(any module files)Modules(any module files)

Page 5: 2005_Structures and functions of Makefile

.config & arch makefile.config & arch makefile

.config file.config file From kernel configuration processFrom kernel configuration process Get list of subderectoriesGet list of subderectories

Arch makefileArch makefile Supplies architecture specific informationSupplies architecture specific information

Page 6: 2005_Structures and functions of Makefile

Script & kbuild makefileScript & kbuild makefile

Script makefileScript makefile Contains all the definitions/rules etcContains all the definitions/rules etc

Kbuild makefileKbuild makefile Build any built-in or modular targetsBuild any built-in or modular targets Uses from the .config fileUses from the .config file

Page 7: 2005_Structures and functions of Makefile

Who does whatWho does what Users : people(build kernels)Users : people(build kernels) Normal developersNormal developers

Make features(device drivers, file systems, netMake features(device drivers, file systems, network protocols)work protocols)

Arch developersArch developers Make entire architecture(sparc or ia64..etc)Make entire architecture(sparc or ia64..etc)

Kbuild developersKbuild developers Make kernel build system itselfMake kernel build system itself

Page 8: 2005_Structures and functions of Makefile

Check important kbuild filesCheck important kbuild files

Goal definitionsGoal definitions Contain files to built, compilation options, Contain files to built, compilation options, and any subdirectories..etcand any subdirectories..etc

Built-in object goals(obj-y)Built-in object goals(obj-y) Object file to compileObject file to compile

Loadable module goals(obj-m)Loadable module goals(obj-m) Library file goals(lib-y)Library file goals(lib-y)

Library to built-in object files for modules Library to built-in object files for modules and combineand combine

Page 9: 2005_Structures and functions of Makefile

Makefiles source 1Makefiles source 1 MRPROPER_DIRS += include/config include2MRPROPER_DIRS += include/config include2 MRPROPER_FILES += .config .config.old include/asm .version \MRPROPER_FILES += .config .config.old include/asm .version \ include/linux/autoconf.h include/linux/version.h \include/linux/autoconf.h include/linux/version.h \ Module.symvers tags TAGS cscope*Module.symvers tags TAGS cscope* mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS)) mrproper: rm-files := $(wildcard $(MRPROPER_FILES))mrproper: rm-files := $(wildcard $(MRPROPER_FILES)) mrproper-dirs := $(addprefix_mrproper_,Documentation/DocBook scripts)mrproper-dirs := $(addprefix_mrproper_,Documentation/DocBook scripts)

.PHONY: $(mrproper-dirs) mrproper archmrproper.PHONY: $(mrproper-dirs) mrproper archmrproper $(mrproper-dirs):$(mrproper-dirs): $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)

mrproper: clean archmrproper $(mrproper-dirs)mrproper: clean archmrproper $(mrproper-dirs) $(call cmd,rmdirs)$(call cmd,rmdirs) $(call cmd,rmfiles)$(call cmd,rmfiles)

Page 10: 2005_Structures and functions of Makefile

Makefile source 2Makefile source 2 include/config/MARKER: include/linux/autoconf.hinclude/config/MARKER: include/linux/autoconf.h include $(srctree)/arch/$(ARCH)/Makefile export KBUILD_DEFCONFIGinclude $(srctree)/arch/$(ARCH)/Makefile export KBUILD_DEFCONFIG init-yinit-y := init/:= init/ drivers-ydrivers-y := drivers/ sound/:= drivers/ sound/ net-ynet-y := net/:= net/ libs-ylibs-y := lib/:= lib/ core-ycore-y := usr/:= usr/ CFLAGSCFLAGS += $(call add-align,CONFIG_CC_ALIGN_FUNCTIONS,-functions)+= $(call add-align,CONFIG_CC_ALIGN_FUNCTIONS,-functions) CFLAGSCFLAGS += $(call add-align,CONFIG_CC_ALIGN_LABELS,-labels)+= $(call add-align,CONFIG_CC_ALIGN_LABELS,-labels) CFLAGSCFLAGS += $(call add-align,CONFIG_CC_ALIGN_LOOPS,-loops)+= $(call add-align,CONFIG_CC_ALIGN_LOOPS,-loops) CFLAGSCFLAGS += $(call add-align,CONFIG_CC_ALIGN_JUMPS,-jumps)+= $(call add-align,CONFIG_CC_ALIGN_JUMPS,-jumps)

CFLAGSCFLAGS += -fno-omit-frame-pointer+= -fno-omit-frame-pointer elseelse CFLAGSCFLAGS += -fomit-frame-pointer+= -fomit-frame-pointer CFLAGSCFLAGS += -g+= -g

Page 11: 2005_Structures and functions of Makefile

Makefiles source 3Makefiles source 3

clean: rm-dirs := $(CLEAN_DIRS)clean: rm-dirs := $(CLEAN_DIRS) clean: rm-files := $(CLEAN_FILES)clean: rm-files := $(CLEAN_FILES) clean-dirs := $(addprefix _clean_,$(vmlinux-allclean-dirs := $(addprefix _clean_,$(vmlinux-all

dirs))dirs)) .PHONY: $(clean-dirs) clean archclean.PHONY: $(clean-dirs) clean archclean $(clean-dirs):$(clean-dirs): $(Q)$(MAKE) $(clean)=$(patsubst _clean$(Q)$(MAKE) $(clean)=$(patsubst _clean

_%,%,$@)_%,%,$@)

clean: archclean $(clean-dirs)clean: archclean $(clean-dirs)

Page 12: 2005_Structures and functions of Makefile

Makefile source 4Makefile source 4 core-ycore-y += kernel/ mm/ fs/ ipc/ security/ crypto/+= kernel/ mm/ fs/ ipc/ security/ crypto/ vmlinux-dirsvmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \:= $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \$(core-y) $(core-m) $(drivers-y) $(drivers-m) \ $(net-y) $(net-m) $(libs-y) $(libs-m)))$(net-y) $(net-m) $(libs-y) $(libs-m)))

vmlinux-alldirsvmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \:= $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \ $(init-n) $(init-) \$(init-n) $(init-) \ $(core-n) $(core-) $(drivers-n) $(drivers-) \$(core-n) $(core-) $(drivers-n) $(drivers-) \ $(net-n) $(net-) $(libs-n) $(libs-))))$(net-n) $(net-) $(libs-n) $(libs-)))) init-yinit-y := $(patsubst %/, %/built-in.o, $(init-y)):= $(patsubst %/, %/built-in.o, $(init-y)) core-ycore-y := $(patsubst %/, %/built-in.o, $(core-y)):= $(patsubst %/, %/built-in.o, $(core-y)) drivers-ydrivers-y := $(patsubst %/, %/built-in.o, $(drivers-y)):= $(patsubst %/, %/built-in.o, $(drivers-y)) net-ynet-y := $(patsubst %/, %/built-in.o, $(net-y)):= $(patsubst %/, %/built-in.o, $(net-y)) libs-y1libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)):= $(patsubst %/, %/lib.a, $(libs-y)) libs-y2libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y)):= $(patsubst %/, %/built-in.o, $(libs-y)) libs-ylibs-y := $(libs-y1) $(libs-y2):= $(libs-y1) $(libs-y2) vmlinux-init := $(head-y) $(init-y)vmlinux-init := $(head-y) $(init-y) vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y) vmlinux-all := $(vmlinux-init) $(vmlinux-main)vmlinux-all := $(vmlinux-init) $(vmlinux-main) vmlinux-lds := arch/$(ARCH)/kernel/vmlinux.ldsvmlinux-lds := arch/$(ARCH)/kernel/vmlinux.lds kallsyms.o := .tmp_kallsyms$(last_kallsyms).okallsyms.o := .tmp_kallsyms$(last_kallsyms).o

Page 13: 2005_Structures and functions of Makefile

Makefile source 5Makefile source 5 vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCEvmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCE $(call if_changed_rule,vmlinux__)$(call if_changed_rule,vmlinux__) $(vmlinux-dirs): prepare-all scripts$(vmlinux-dirs): prepare-all scripts $(Q)$(MAKE) $(build)=$@$(Q)$(MAKE) $(build)=$@ modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) @echo ' Building modules, stage 2.';@echo ' Building modules, stage 2.'; $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost @rm -rf $(MODLIB)/kernel@rm -rf $(MODLIB)/kernel @rm -f $(MODLIB)/source@rm -f $(MODLIB)/source @mkdir -p $(MODLIB)/kernel@mkdir -p $(MODLIB)/kernel @ln -s $(srctree) $(MODLIB)/source@ln -s $(srctree) $(MODLIB)/source @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \@if [ ! $(objtree) -ef $(MODLIB)/build ]; then \ rm -f $(MODLIB)/build ; \rm -f $(MODLIB)/build ; \ ln -s $(objtree) $(MODLIB)/build ; \ln -s $(objtree) $(MODLIB)/build ; \ fifi $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst

Page 14: 2005_Structures and functions of Makefile
Page 15: 2005_Structures and functions of Makefile
Page 16: 2005_Structures and functions of Makefile
Page 17: 2005_Structures and functions of Makefile