System Compilation: How to pass parameters to the Make command

Source: Internet
Author: User
Article Title: System Compilation: How to pass parameters to the Make command. 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.

During system compilation, we generally only need to simply input make for execution. But sometimes, we still need to let the make command bring some parameters to the makefile script.

For example, you need to define a macro DEBUG in the code to enable the debugging switch. The Code is as follows:

        
         int main()      {          int i=9;      #ifdef DEBUG          i=1;      #else          i=0;      #endif          printf("i=%d\n", i);          return 0;      }
        

Generally, this macro definition can be implemented by directly modifying the source code, but this is obviously not a good solution. Another method is to modify it through makefile, for example:

        
         CFLAGS=-g -Wall -DDEBUG object=myprogall:$objectmyprog:a.c gcc ${CFLAGS} a.c -o ${object}
        

If you do not want to modify the makefile, you can pass the parameters to the make command. Therefore, modify the makefile as follows:

        
         CFLAGS=CFLAGCFLAGS+=-g -Wall -DDEBUG object=myprogall:$objectmyprog:a.c gcc ${CFLAGS} a.c -o ${object}
        

To open the DEBUG macro, enter the make command as follows:

        
         [ychq@ICM3-2 net]$ make CFLAG=-DDEBUG gcc -g -Wall -DDEBUG a.c a.c: In function `main': a.c:9: warning: implicit declaration of function `printf' [ychq@ICM3-2 net]$
        

We can find that the DEBUG macro has been passed in correctly.

Furthermore, we can pass different parameters to make so that make can compile different modules.

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.