GNU-makefle (1) Basic Introduction

Source: Internet
Author: User

Reference: http://blog.csdn.net/haoel/article/details/2886

Android ndk compilation and source code compiling require writing an mk file, which is actually a makefile file.

On linux (unix) platforms, makefile (or Makefile) is a building rule that describes which files need to be compiled first, which are then compiled, and how to link... make is a command tool used to explain the rules in makefile, execute and generate the definitions in the rules.


Take c/c ++ code as an example.


Compilation and link of the program:

Compile and generate the target file (that is, the intermediate code file object file), and then link these target files to our application to generate executable files.

Target file, win platform:. obj unix platform:. o

A group of target files can be packaged to generate a library file, which is divided into static and dynamic link libraries.

Static library, indicating the library used during program compilation. Win:. lib unix:.

Dynamic library, indicating the library used when the program is running. Win:. dll unix:. so

The dynamic library is loaded only when the program is running. If there is no dynamic library in the program or system, it is loaded. If there is an existing dynamic library, it is directly used.

It facilitates sharing. In line with the principle of transferring in only when needed, the system resources are greatly reduced.


Name of the makefile: maikefile or Makefile

In one example, all. c and. h are in the same level Directory:

Edit: main. o kbd. o command. o display. o insert. o search. o files. o utils. occ-o edit main. o kbd. o command. o display. o insert. o search. o files. o utils. o main. o: main. c defs. hc-c main. c kbd. o: kbd. c defs. h command. hc-c kbd. c command. o: command. c defs. h command. hc-c command. c display. o: display. c defs. h buffer. hc-c display. c insert. o: insert. c defs. h buffer. hc-c insert. c search. o: search. c defs. h buffer. hc-c search. c utils. o: utils. c defs. hc-c utils. c files. o: files. c defs. h buffer. h command. hc-c files. c clean: rm edit main. o kbd. o command. o display. o insert. o search. o files. o utils. o

The left side of the colon is the target definition, and the right side is what it depends on. Target: Dependency

The backslash \ is a line break of a command.

Indicates that the TAB key is used for the indentation on the left when the command is executed. In this example, the left side of the cc command is tab indent. In other cases, spaces are used for the interval.

The preceding example is from top to bottom:

File edit depends on some. o target files

Create the edit execution file, and cc-o continuously links some. o files.

(After executing the make command, find the makefile or Makefile file and read its rules.

When you read the first target file (in this example, edit), it will be treated as the final execution file to be generated.

If A. o does not exist or the file on which the. o target file is modified, generate or regenerate the. o file. make will automatically judge.

Globally Speaking: If the dependent person changes (such as the header file or source file), the dependent person will also change, and the dependent person of each layer will change.

)

Main. o depends on main. c and defs. h, that is, include "defs. h" in main. c"

Compile the command for generating the. o target file cc-c main. c

...

Finally, clean is not directly or indirectly dependent on the first target edit, so it will not be automatically executed. You can use make clean to execute the commands defined by it.

 

Finally, shell enters the directory where the project is located and runs the make command.

Generate an executable file: edit



GNU-makefle (1) Basic Introduction

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.