Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of makefile in Linux system

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly analyzes the relevant knowledge of what is the principle of makefile in Linux system, the content is detailed and easy to understand, the operation details are reasonable, and has a certain reference value. If you are interested, you might as well follow the editor to have a look, and follow the editor to learn more about "what is the principle of makefile in the Linux system".

A Linux system programmer who does not use GNU make to build and manage his own project is an unqualified programmer. So how should Makefile learn?

Introduction to makefile: Makefile can be simply thought of as the compilation rules of a project file, describing the compilation and linking rules of the whole project.

It contains files that need to be compiled, files that don't need to be compiled, files that need to be compiled first, files that need to be compiled later, files that need to be rebuilt, and so on.

What needs to be involved in compiling the whole project can be described in Makefile. In other words, Makefile can automate the compilation of our project projects without having to manually enter a bunch of source files and parameters every time.

Naming of 1.makefile (two kinds) makefile

Makefile

2. Three elements of makefile's rules: goal, dependency and command

3. Multi-file makefile writing (a source file only recompiles changed files) makefile can have multiple rules. When the command of the first rule is executed without corresponding dependencies, look for it in the following rules. The goal of the top rule is that the ultimate goal must be written at the top, that is, the final file to be generated.

Update principle of multi-file Makefile (based on time)

4. Variables in makefile use $(obj) directly when customizing the variable obj=main.o add.o sub.o reference

Automatic variable () first dependency in the rule @: target in the rule $^: all dependencies in the rule

Pattern automatic matching% sub-rule:

:

Variables maintained by makefile (usually uppercase, can be modified by yourself) CC:cc (that is, gcc) APPFLAGS: options used by preprocessing CFLAGS: options used when compiling LDFLAGS: options used by linked libraries

5. Functions in makefile (all have return values) wildcard looks for all .c files in the current directory and returns values to srcsrc=$ (wildcard. / * .c)

Patsubst replaces all .c files with .o files obj= (src))

6. Make clean adds the goal of clean at the end of makefile. In order to recompile all files, the original generated files have to be deleted.

7. The final simple makefile

This is the end of the introduction on "what is the principle of makefile in Linux system". More related content can be searched for previous articles, hoping to help you answer questions and questions, please support the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report