linux--the simple application and implementation of the makefile of the Study (iii) Simple progress bar

Source: Internet
Author: User

First, makefile

Make is a command, and makefile is a file. when the make command executes, a Makefile file is required to tell the make command what to do to compile and link the program. the source files in a project are not counted, and they are placed in several directories by type, function and module, makefile defines a series of rules to specify which files need to be compiled first, which files need to be compiled, which files need to be recompiled, and even more complex function operations. Because makefile is like a shell script, it can also execute commands from the operating system. Makefile brings the advantage is-"automated compilation", once written, only need a make command, the entire project is automatically compiled, greatly improving the efficiency of software development.

Example: first create a test1.c file

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/82/13/wKioL1dK3UWRLdXIAAA3F480PVo356.png-wh_500x0-wm_3 -wmp_4-s_874673490.png "title=" Capture 1. PNG "alt=" Wkiol1dk3uwrldxiaaa3f480pvo356.png-wh_50 "/>

Create a Makfile file to write the Makfile file

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/82/13/wKioL1dK4C2A8N0GAACD8Ng5kMQ136.png-wh_500x0-wm_3 -wmp_4-s_393623635.png "title=" Capture 2. PNG "alt=" Wkiol1dk4c2a8n0gaacd8ng5kmq136.png-wh_50 "/>

Note: In the dependency method, be sure to start with the TAB key.

Enter make on the command line

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/82/13/wKioL1dK4QPTxv2TAADclsHHQss306.png-wh_500x0-wm_3 -wmp_4-s_886124098.png "title=" Capture 3. PNG "alt=" Wkiol1dk4qptxv2taadclshhqss306.png-wh_50 "/>

make work?
in the default way, we only enter the Make command. Then,
1, make will find the file named "Makefile" or "Makefile" in the current directory.
2, if found, it will find the first target file in the file (target), in the above example, he will find "edit" This file, and put this file as the final target file.
3, if the edit file does not exist, or edit depends on the file modification time of the. o file is newer than the edit this file, then he will execute the command defined later to generate edit this file.
4, if edit depends on the. o file does not exist, then make will find in the current file the target is the. o file dependency, and if found, then generate the. o file according to that rule. (This is a bit like a stack of process)
5, of course, your C files and h files are there, so make generates. o files and then uses. o File the ultimate task of life make, which is to execute the file edit.
This is the dependency of the entire make, which makes a layer-by-layer look at the dependencies of the file until the first target file is finally compiled. In the search process, if there is an error, such as the last dependent file can not be found, then make will directly exit, and error, and for the definition of the command errors, or the compilation is unsuccessful, make does not ignore. Make just file dependencies, that is, if after I find a dependency, the file after the colon is not, then I am sorry, I do not work.
through the above analysis, we know that, like clean, is not directly or indirectly associated with the first target file, then the command defined later will not be automatically executed, however, we can display to make execution. That is, the command-"make clean", which clears all the target files for re-compilation.
So in our programming, if this project has been compiled, when we modify one of the source files, For example FILE.C, according to our dependence, our target FILE.O will be recompiled (that is, in this dependent relationship defined by the command), so FILE.O file is also the latest, so FILE.O file modification time is newer than edit, so edit will be re-linked (see edit The command defined after the file is marked). ()

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/82/14/wKiom1dK6lyS6j97AABXlmuIK74633.png-wh_500x0-wm_3 -wmp_4-s_715218091.png "title=" Capture 2. PNG "alt=" Wkiom1dk6lys6j97aabxlmuik74633.png-wh_50 "/>

The contents of the above file, ". Phony "means that clean is a pseudo-target file.

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/82/13/wKioL1dK5w_RSbCwAACZy3an4CA142.png-wh_500x0-wm_3 -wmp_4-s_3146874115.png "title=" Capture 4. PNG "alt=" Wkiol1dk5w_rsbcwaaczy3an4ca142.png-wh_50 "/>

Add @ before dependency to block details

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/82/13/wKioL1dK7g3QPGHzAABaIC2BjvM614.png-wh_500x0-wm_3 -wmp_4-s_434365362.png "title=" Capture 2. PNG "alt=" Wkiol1dk7g3qpghzaabaic2bjvm614.png-wh_50 "/>

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/82/14/wKiom1dK7kyRPRiUAACmrBovyjY390.png-wh_500x0-wm_3 -wmp_4-s_4225516502.png "title=" Capture 1. PNG "alt=" Wkiom1dk7kyrpriuaacmrbovyjy390.png-wh_50 "/>

Second, the simple implementation of the progress bar

Create a ProBar.h file

#pragma once#include<stdio.h> #define SIZE 103#include<unistd.h> #include <string.h>void probar () {    int i=1;    Char Ch[size];    memset (ch, ' n ', sizeof (CH));    ch[size-1]= ' + ';    Ch[size-2]= '];    Ch[0]= ' [';    Char circle[]= "-\\|/\\0";        while (i<=100) {ch[i]= ' # ';        printf ("%100s[%d%%]%c\r", ch,i,circle[i%4]);        i++;        Fflush (stdout);    Sleep (1); } printf ("\ n");}

Create a TESTPRO.C file

#include <stdio.h> #include "ProBar.h" int main () {Probar (); return 0;}

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/82/13/wKioL1dLC0-QCUBKAAES0ZqjCJE433.png-wh_500x0-wm_3 -wmp_4-s_1615154017.png "title=" Capture 2. PNG "alt=" Wkiol1dlc0-qcubkaaes0zqjcje433.png-wh_50 "/>

Compile, execute, run the result:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/82/13/wKioL1dLDpuCj2JXAAA_9Z1J5vE263.png-wh_500x0-wm_3 -wmp_4-s_3613219104.png "title=" Capture 4. PNG "alt=" Wkiol1dldpucj2jxaaa_9z1j5ve263.png-wh_50 "/>


This article is from the "Shuoyuexinmao Cloud" blog, please be sure to keep this source http://19940325.blog.51cto.com/10789287/1784329

linux--the simple application and implementation of the makefile of the Study (iii) Simple progress bar

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.