Linux Makefile Learning

Source: Internet
Author: User

Compiling the environment GNU make 4.1

# variables are declared in a way that expands when they are needed # looks like a variable preceded by a space is not related to objects= MAIN.O test1.o TEST3.O # Regardless of whether you perform make or do clean, the printed testval value is the value of the variable re-assignment may have some unexpected problems testval=1.phony:out# first target named default final target name #out:main.o test1.o test3.o# equivalent statement out1:$ (OBJECTS) #gcc-O out MAIN.O TEST1.O test3.o# equivalent statement #gcc-o out $ (OBJECTS) # equivalent statement # [email protected] stands for all output Gcc-o [email protected] $ (OBJECTS) # The equivalent statement # $^ represents all input #gcc-o [email protected] $^@# each sentence is displayed during execution, plus @ @echo $ (testval) main.o:main.c test1.h test3.h If you do not want to display Gcc-c main.ctest1.o:test1.c test1.h test2.hgcc-c test1.c# if test1.c compile error, even if TOUCH,TEST1.O and test3.o do not appear, in gcc-c TEST1.C Front Plus "-" number can be implemented to continue Make#touch test1.o test3.o:test3.c test3.h test4.hgcc-c test3.c#%.O represents all of the matching. o Output file #%. C for. o the corresponding name. C # If there are other. o files that need to be matched in addition to MAIN.O, TEST1.O, TEST2.O, then use this rule%.o:%.cgcc-c $^# equivalent statement # $< represents the first input parameter #gcc-c $<# Whether you perform make or do clean, the printed testval value is a * so variable re-assignment can have some unexpected problems testval=2# wildcard on behalf of the wildcard expansion, if "objs=*.o" is wrong # If the variable is annotated as follows, there is a space behind the variable, and in some cases the error # objs=$ (wildcard *.o) # #. Phony: The representative ignores dependencies, executes every time, and is used in CLEAn is to prevent the file name from being called clean. Phony:cleanclean:rm-f MAIN.O test1.o test3.o Out@echo $ (testval) # equivalent statement #rm-f $ (OBJS) out# equivalent statement # here to add the "-" number, otherwise the first step is not executed after the second step is not executed #-rm-f main.o test1.o #-rm-f test3.o out# equivalent statement #rm-f *.O out

There are many advanced techniques to be continued.

References: Write Makefile with me Chenhao

http://blog.csdn.net/haoel/article/details/2886/

http://blog.csdn.net/haoel/article/details/2887/

http://blog.csdn.net/haoel/article/details/2888/

http://blog.csdn.net/haoel/article/details/2889/

http://blog.csdn.net/haoel/article/details/2890/

http://blog.csdn.net/haoel/article/details/2891/

http://blog.csdn.net/haoel/article/details/2892/

http://blog.csdn.net/haoel/article/details/2893/

http://blog.csdn.net/haoel/article/details/2894/

http://blog.csdn.net/haoel/article/details/2895/

http://blog.csdn.net/haoel/article/details/2896/

http://blog.csdn.net/haoel/article/details/2897/

http://blog.csdn.net/haoel/article/details/2898/

http://blog.csdn.net/haoel/article/details/2899/

Linux Makefile Learning

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.