Makefile for Linux development tools (below) and makefile for development tools

Source: Internet
Author: User

Makefile for Linux development tools (below) and makefile for development tools
Ii. Makefile (lower) 01. make common embedded function calls $ (function arguments) $ (wildcard PATTERN) files in the current directory that match the PATTERN, such as: src = $ (wildcard *. c) $ (patsubst PATTERN, REPLACEMENT, TEXT) mode REPLACEMENT function example: $ (patsubst %. c, %. o, $ src) is equivalent to $ (src :. c =. o) the shell function executes the color wolf command, for example: $ (shell ls-d */) # lsMakefile02. multi-level directory Makefile # touch main. c # mkdir bll (application logic layer) # mkdir ui (interface layer) # mkdir dal (Data logic layer) # cd ui # touch ui. h ui. c # cd .. # cd dll # touch dal. h dal. c # cd .. # cd bll # touch bll. h bll. C # lsbll dll Makefile ui # vi Makefile (with a level-2 Directory) CC = gccCFLAGS =-Wall-gBIN = mainSUBDIR = $ (shell ls-d */) (all folders in the current directory) ROOTSRC = $ (wildcard *. c) (ALL *. file c) ROOTOBJ = $ (ROOTSRC: %. c = %. o) SUBSRC = $ (shell find $ (SUBDIR)-name '*. c ') SUBOBJ = $ (SUBSRC: %. c = %. o) $ (BIN): $ (ROOTOBJ) $ (SUBOBJ) $ (CC) $ (CFLAGS)-o $ (BIN) $ (ROOTOBJ) $ (SUBOBJ ). c. o: $ (CC) $ (CFLAGS)-o $ <-o $ @ clean: rm-f $ (BIN) $ (ROOTOBJ) $ (SUBOBJ) # ls-d */( List all the folders in the directory) # find bll dll ui-name '*. c' bll/bll. cdll/dll. cui/ui. c # make # makeclean # ls03.Makefile may generate multiple executable files. How to generate only one executable file # vi MakefileSUBDIRS = test1 test2.PHONYL: default all clean $ (SUBDIRS) default: allall clean: $ (MAKE) $ (SUBDIRS) TARGET =$ $ (SUBDIRS): $ (MAKE)-C $ @ $ (TARGET) # cd .. /test1 # vi MakefileCC = gccBIN = test1OBJS = test1.o. PHONY: all clean printall: print $ (BIN) print @ echo "---- make all in $ (PW D) ---- "$ (BIN): $ (OBJS) $ (CC) $ (OBJS)-o $ @ %. o: %. c $ (CC) $ (OBJS)-o $ @ %. o: %. c $ (CC)-c $ <clean: @ echo "---- make clean in $ (PWD) ----" rm-f $ (BIN) $ (OBJS) # cd .. /test2 # ls # vi MakefileCXX = g ++ (implement C ++ compilation) BIN = test2OBJS = test2.oCPPFLAGS =-Wall-g. PHONY: all clean printall: print $ (BIN) @ echo "---- make all in $ (PWD) ----" $ (BIN): $ (OBJS) $ (CXX) $ (OBJS)-o $ @. o: %. cpp $ (CXX)-c $ <clean: @ echo "---- make clean in $ (PWD) ---- "Rm-f $ (BIN) $ (OBJS) If a folder exists in the subdirectory, you can also use the Makefile method similar to the top-level directory to implement multi-level directories and scalable methods.

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.