Advance understanding of software development (makefile) writing and application of document

Source: Internet
Author: User
Tags command line header lowercase linux

Makefile is used for compiling the entire project under Linux, which is very important for the compiler of C/s + + language under Linux.

This paper takes the practical C source program as an example, introduces how to use makefile to compile the C language project under Linux, which provides a reference for the development of related work.

One, what is makefile?

What is makefile? If you're writing a program that's just running under windows, then you probably don't know about this stuff. And if you're going to compile and run the program on Linux, you'll almost inevitably have to deal with makefile.

Makefile is a file that defines a set of rules that specify which files in a project need to be compiled first, which files need to be compiled, which files need to be recompiled, and even more complex functions to operate. To put it simply, Makefile is a compile scheduler under Linux.

Second, the grammar rules of Makefile

Since it's a compile scheduler, it has its own set of rules. The makefile rules are as follows:

Target ...: Prerequisites
    
... Command
    
...
    
......

Description

(1) target is a target file, which is the file name (which can include the suffix) that we want to output in this step.

(2) Prerequisites is the file needed to generate that target, which is equivalent to the source code files needed for the EXE file under Windows Engineering.

(3) command is the order that make needs to be executed, that is, how to use prerequisites to generate target. Notice that the command line starts with the TAB key.

Three, c program source code

This paper takes a real Linux C program Engineering as an example to introduce the writing method and usage of makefile.

The program in this article implements the ability to convert lowercase letters in a string to uppercase letters. There are two header files: TestMakeFileMore1.h and TestMakeFileMore2.h, placed in the "head" directory, two source files: testmakefilemore1.c and testmakefilemore2.c, respectively "Exec1" and "EXEC2" directories.

The Testmakefilemore of the project is organized as shown in Figure 1 (the "release" directory is used to hold the generated files).

Fig. 1 The organization of the project

1. "TestMakeFileMore1.h" File code content

/**********************************************************************
    
* All rights reserved (C) 2014, Zhou Zhaoxiong.
    
*
    
* file name: TestMakeFileMore1.h
    
* file ID: no
    
* Content summary: Turn uppercase letters in the input string to lowercase letters
    
* Other notes: No
    
* Current version: V1.0
    
*    Person: Zhou zhaoxiong
    
* Completion Date: 20140430
    
* *
    
Modify record 1://modify history, including modified date, version number, modified person and modified content
    
* Date Modified: 20140430< c14/>* version Number: V1.0
    
* Modified by: Zhou zhaoxiong
    
* Modify content: Create
    
**************************************************** /
    
#ifndef _testmakefilemore1_h_       //Prevent header files from being repeatedly referenced
    
#define _testmakefilemore1_h_
    
     
    
#include <stdio.h>
    
#include <stdlib.h>
    
#include <string.h>
    
     
    
//Redefining data types
    
typedef unsigned CHAR  UINT8;
    
typedef          INT   INT32;
    
typedef unsigned int   UINT32;
    
#endif

Related Article

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.