Linux kernel series -12.E. Makefile of operating system development

Source: Internet
Author: User

First look at a simple makefile, we put it in the directory/boot, can be used to compile boot.bin and loader.bin.

# Makefile for boot# Programs, flags, etc. asm= nasmasmflags=-I include/# this programtarget= boot.bin loader.bin# all phony Targets.PHONY:everything clean all# D Efault starting positioneverything: $ (target) Clean:rm-f $ (target) All:clean everythingboot.bin:boot.asm include/load . Inc include/fat12hdr.inc$ (ASM) $ (asmflags)-o [email protected] $<loader.bin:loader.asm Include/load.inc include/ Fat12hdr.inc include/pm.inc$ (ASM) $ (asmflags)-o [email protected] $<

Lines that begin with a character # are comments. = used to define variables, where ASM and asmflags are two variables, it is important to note that they are used with $ (ASM) and $ (asmflags) instead of their prototypes.

. Phony for the time being, take a look at Makefile's most important syntax:

Target:prerequisites            Command

The above form represents two layers of meaning:

1. To get target, you need to execute command.

2.target relies on prerequisites, command is executed when at least one file in prerequisites is newer than the target file.

The last two lines of this makefile, for example, are translated:

1. To get loader.bin, you need to execute "$ (ASM) $ (asmflags)-o [email protected] $<".

2.loader.bin relies on the following files:

A.loader.asm

B.include/load.inc

C.include/pm.inc

D.include/fat12hdr.inc

command is executed when at least one of them is newer than loader.bin.

[email protected] represents the first name of target;$< on behalf of prerequisites. In relation to the $ (ASM) and $ (asmflags) We said earlier, this command line is equivalent to:

Nasm-o Loader.bin Loader.asm

In makefile it is easy to notice that not only the Boot.bin and loader.bin two files have colons behind them, everything, clean, and all have colons, but they are 3 not 3 files, just the action name. If you run make clean, the rm-f $ (TARGET) will be executed, which means "rm-f boot.bin loader.bin".

All followed by clean and everything, which indicates that the actions represented by clean and everything will be executed separately if "make all" is executed. Here is the result of make all execution:

>make All

Rm-f Boot.bin Loader.bin

Nasm-i include/-o boot.bin boot.asm

Nasm-i include/-o loader.bin loader.asm

The key word just now. Phony, in fact, means that the name behind it is not a file, but merely a label for the behavior.

Not finished ...

Compile method:

Make

Make image

Operation Result:

" Source "

Linux kernel series -12.E. Makefile of operating system development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.