How to use Linux Makefile

Source: Internet
Author: User

1. Rules of Makefile

The framework of makefile is composed of rules. When the make command executes, it looks for various rules in the makefile file and then runs the rules after parsing the various rules. The basic format of the rule is:

TARGET ...:D epends ...

COMMAND

......

  • Target: The goal defined by the rule. Usually the rule is the file name of the last executable file or the target file that is dependent on the executable file, or it can be an action called "pseudo-target";
  • DEPENDS: The dependency conditions that are necessary to execute this rule, such as the target file for the executable file, DEPENDS can also be a target, thus forming a nesting between target;
  • Command: The commands that the rule executes, that is, the action of the rule. Command commands must start with the TAB key and cannot be replaced with the spacebar.
2. Makefile variable

1. User-defined variables

When you use makefile for rule definitions, users can define their own variables, called user-defined variables. For example:

CC = gcc

CFLAGS =–isub–iadd

TARGET = Cacu

RM = Rm–f

Automatic variables in 2.Makefile

$^: On behalf of all dependent files

[email protected]: represents the target

$<: Represents the first dependent file

3. Other

Use "#" comment in Makefile

In makefile, you can add "@" to the command code before canceling the command echo.

How to use Linux Makefile

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.