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.