How to use make

Source: Internet
Author: User
Article Title: how to use make. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
If you type "make" under the shell prompt symbol, it will search for the Makefile file in the current directory. Then, follow the steps recorded in the Makefile to perform the operation step by step. When we write a program, if we first write the steps required by the compiler program in Makefile, we only need to input the make command when we want the compiler program. If the program is correct, you can get the expected results! Makefile format:
(1) Annotation:
In Makefile, any text starting with "#" is Annotated. make ignores the Makefile when interpreting it.
(2) continued downlink:
In Makefile, if one line is insufficient for the command. You can add a backslash () at the bottom of the row to indicate the continuation of the next row. the two rows should be treated as one row.
(3) macro)
The format of a huge set is string = value.
For example:
CFLAGS =-O-policype bsd43
In fact, make already has many default macro. if you want to view these macro, you can run the make-p command.
(4) Rules)
The format is as follows:
   : Depend
  
  
....
   : Depend
  
  
....
(5) a very simple Makefile
Suppose we have a program, which is divided into the following parts:
Main program code section of menu. c
Include file of menu. h menu. c
Utils. c provides some functions of the menu. c call.
Include file of utils. h utils. c
In addition, this program uses ncurses function CILS.
Menu. c and utils. c are both placed under/usr/src/menu.
However, menu. h and utils. h are stored in/usr/src/menu/include.
After the program is completed, the execution file named menu should be placed under/usr/bin.
# This is the Makefile of menu
CC = gcc
CFLAGS =-DDEBUG-c
LIBS =-lncurses
INCLUDE =-I/usr/src/menu/include
All: clean install
Install: menu
Chmod 750 menu
Cp menu/usr/bin
Menu: menu. o utils. o
$ (CC)-o $? $ (LIBS)
Menu. o:
$ (CC) $ (CFLAGS)-o $ @ menu. c $ (INCLUDE)
Utils. o:
$ (CC) $ (CFLAGS)-o $ @ utils. c $ (INCLUDE)
Clean:
-Rm *. o
-Rm *~
In the Makefile above, use a macro available $ (macro_name) format. Make is automatically expanded.
$ @ Is the Target of the rule, and $? The depend of the rule. If a "-" is added before the command, it indicates that if an error occurs in this command, it is ignored and the command continues to be executed. The Makefile relationship can be expressed as follows:
All
/
Clean install
Menu
/Menu. o utils. o
If you only want to clear files other than source, you can make clean.
If you only want to make menu. o, you can make menu. o.
If you want to finish all the tasks at a time, make all or make.
Note that before command, you must have a TAB (that is, the TAB key ).
  
  

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.