I feel that it is easy to write. I will keep it for a moment and copy it for use next time.
First, generate an executable file for each CPP file in the directory. The file name is the same as the CPP file name, without the suffix.
# <Br/> # testcase makefile lxslove moodlxs@163.com <br/> # <br/> base: = .. /.. <br/> inc_dirs: =-I $ (base)/include/a-I $ (base) /include/B-I $ (base)/include/B <br/> common_dirs: = $ (base)/common/A $ (base) /common/B $ (base)/common/C <br/> common_cpps: = $ (foreach N, $ (common_dirs), $ (wildcard $ {n }/*. CPP) <br/> common_objs: =$ (patsubst %. CPP, %. o, $ (common_cpps) </P> <p> %. o: %. CPP <br/> G ++-C-g-o $ (inc_dirs) </P> <p> SRCS :=$ (wildcard *. CPP) <br/> build =$ (patsubst %. CPP, %, $ (SRCS) <br/> %: %. CPP <br/> G ++-g-o $ (inc_dirs) $ (common_objs)-lpthread </P> <p> All: clean $ (common_objs) $ (build) </P> <p> clean: <br/> RM-F $ (build) <br/>
second, there are public libraries common and several modules X, Y, and Z. Each module depends on the common library.
# <Br/>################## server makefile for Linux ########### <br /># </P> <p> inc_dirs: =-I. /include-I. /include/thread-I. /include/net-I. /include/util </P> <p> bin_dir: = .. /bin <br/> lib_dir: = .. /lib </P> <p> cpp_flags =-dlinux-wall-g-L $ (lib_dir) $ (inc_dirs) </P> <p> %. o: %. CPP <br/> G ++ $ (cpp_flags)-c-o $ @ {1} lt; </P> <p> proxyserver :=$ (bin_dir) /proxyserver <br/> module_bins: = $ (proxyserver) </P> <p>. phony: All </P> <p> All: $ (module_bins) </P> <p> # package common <br/> common_dirs: =. /common/thread. /common/net. /common/util <br/> common_cpps: =$ (foreach N, $ (common_dirs), $ (wildcard $ {n }/*. CPP) <br/> common_objs: =$ (patsubst %. CPP, %. o, $ (common_cpps) </P> <p> # generate the module proxyserver <br/> proxyserver_cpps :=$ (wildcard. /proxyserver /*. CPP) <br/> proxyserver_objs: =$ (patsubst %. CPP, %. o, $ (proxyserver_cpps) <br/> $ (proxyserver): $ (common_objs) $ (proxyserver_objs) <br/> G ++ $ (cpp_flags) -o $ @ $ ^-lpthread </P> <p>. phony: Clean </P> <p> clean: <br/> Find. /-name *. o-exec Rm-RF {}\;