SlideShare a Scribd company logo
1 of 17
MakefileMakefile 의 구조 및 기능의 구조 및 기능
(Linux-2.6.10 version)(Linux-2.6.10 version)
MakefileMakefile 의 구조의 구조
 OverviewOverview
 Who does whatWho does what
 Important check kbuild filesImportant check kbuild files
 Observe Makefiles sourceObserve Makefiles source
overviewoverview
 Top makefileTop makefile
 .config.config
 Arch/$(ARCH)/MakefileArch/$(ARCH)/Makefile
 Script/MakefileScript/Makefile
 Kbuild makefilesKbuild makefiles
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)
.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
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
Who does whatWho does what
 Users : people(build kernels)Users : people(build kernels)
 Normal developersNormal developers
 Make features(device drivers, file systems,Make features(device drivers, file systems,
network protocols)network 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
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 modulesLibrary to built-in object files for modules
and combineand combine
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)
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,-+= $(call add-align,CONFIG_CC_ALIGN_FUNCTIONS,-
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
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-clean-dirs := $(addprefix _clean_,$(vmlinux-
alldirs))alldirs))
 .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)
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
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
Makefile structure and functions in Linux kernel
Makefile structure and functions in Linux kernel
Makefile structure and functions in Linux kernel
Makefile structure and functions in Linux kernel

More Related Content

What's hot

Logrotate sh
Logrotate shLogrotate sh
Logrotate shBen Pope
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & ToolsIan Barber
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0bcoca
 
GHCソースコード読みのススメ
GHCソースコード読みのススメGHCソースコード読みのススメ
GHCソースコード読みのススメKiwamu Okabe
 
eZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedeZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedBertrand Dunogier
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLitecharsbar
 
Apache Hive Hook
Apache Hive HookApache Hive Hook
Apache Hive HookMinwoo Kim
 
mapserver_install_linux
mapserver_install_linuxmapserver_install_linux
mapserver_install_linuxtutorialsruby
 
Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Rupak Roy
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 
WordPress 運用を支える Perl
WordPress 運用を支える PerlWordPress 運用を支える Perl
WordPress 運用を支える Perl鉄次 尾形
 
Function Call Optimization
Function Call OptimizationFunction Call Optimization
Function Call Optimizationppd1961
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 

What's hot (18)

High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0
 
DevOps with Fabric
DevOps with FabricDevOps with Fabric
DevOps with Fabric
 
GHCソースコード読みのススメ
GHCソースコード読みのススメGHCソースコード読みのススメ
GHCソースコード読みのススメ
 
eZ Publish Cluster Unleashed
eZ Publish Cluster UnleashedeZ Publish Cluster Unleashed
eZ Publish Cluster Unleashed
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
 
Apache Hive Hook
Apache Hive HookApache Hive Hook
Apache Hive Hook
 
mapserver_install_linux
mapserver_install_linuxmapserver_install_linux
mapserver_install_linux
 
Dtalk shell
Dtalk shellDtalk shell
Dtalk shell
 
Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export
 
はじめてのSymfony2
はじめてのSymfony2はじめてのSymfony2
はじめてのSymfony2
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
WordPress 運用を支える Perl
WordPress 運用を支える PerlWordPress 運用を支える Perl
WordPress 運用を支える Perl
 
Function Call Optimization
Function Call OptimizationFunction Call Optimization
Function Call Optimization
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 

Viewers also liked

Viewers also liked (6)

technical report
technical reporttechnical report
technical report
 
KCC2007_VoIP
KCC2007_VoIPKCC2007_VoIP
KCC2007_VoIP
 
ce_grad
ce_gradce_grad
ce_grad
 
programming with GDB
programming with GDBprogramming with GDB
programming with GDB
 
ice_grad
ice_gradice_grad
ice_grad
 
2004_P2P chatting program
2004_P2P chatting program2004_P2P chatting program
2004_P2P chatting program
 

Similar to Makefile structure and functions in Linux kernel

Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in RustInfluxData
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
OpenWRT guide and memo
OpenWRT guide and memoOpenWRT guide and memo
OpenWRT guide and memo家榮 吳
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...Puppet
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configurationlutter
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake TutorialFu Haiping
 
SANS @Night There's Gold in Them Thar Package Management Databases
SANS @Night There's Gold in Them Thar Package Management DatabasesSANS @Night There's Gold in Them Thar Package Management Databases
SANS @Night There's Gold in Them Thar Package Management DatabasesPhil Hagen
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
Composer for busy developers - DPC13
Composer for busy developers - DPC13Composer for busy developers - DPC13
Composer for busy developers - DPC13Rafael Dohms
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkBen Scofield
 
Frontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeFrontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeDamien Seguin
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014biicode
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ublnewrforce
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppSmartLogic
 
Crafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyCrafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyNikhil Mungel
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 

Similar to Makefile structure and functions in Linux kernel (20)

Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in Rust
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
OpenWRT guide and memo
OpenWRT guide and memoOpenWRT guide and memo
OpenWRT guide and memo
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake Tutorial
 
SANS @Night There's Gold in Them Thar Package Management Databases
SANS @Night There's Gold in Them Thar Package Management DatabasesSANS @Night There's Gold in Them Thar Package Management Databases
SANS @Night There's Gold in Them Thar Package Management Databases
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
Composer for busy developers - DPC13
Composer for busy developers - DPC13Composer for busy developers - DPC13
Composer for busy developers - DPC13
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
Frontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeFrontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the like
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ubl
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Crafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyCrafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in Ruby
 
Composer
ComposerComposer
Composer
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Linux
Linux Linux
Linux
 
Ant
AntAnt
Ant
 

Makefile structure and functions in Linux kernel

  • 1. MakefileMakefile 의 구조 및 기능의 구조 및 기능 (Linux-2.6.10 version)(Linux-2.6.10 version)
  • 2. MakefileMakefile 의 구조의 구조  OverviewOverview  Who does whatWho does what  Important check kbuild filesImportant check kbuild files  Observe Makefiles sourceObserve Makefiles source
  • 3. overviewoverview  Top makefileTop makefile  .config.config  Arch/$(ARCH)/MakefileArch/$(ARCH)/Makefile  Script/MakefileScript/Makefile  Kbuild makefilesKbuild makefiles
  • 4. 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)
  • 5. .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
  • 6. 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
  • 7. Who does whatWho does what  Users : people(build kernels)Users : people(build kernels)  Normal developersNormal developers  Make features(device drivers, file systems,Make features(device drivers, file systems, network protocols)network 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
  • 8. 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 modulesLibrary to built-in object files for modules and combineand combine
  • 9. 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)
  • 10. 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,-+= $(call add-align,CONFIG_CC_ALIGN_FUNCTIONS,- 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
  • 11. 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-clean-dirs := $(addprefix _clean_,$(vmlinux- alldirs))alldirs))  .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)
  • 12. 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
  • 13. 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