Two makefiles of brother

Source: Internet
Author: User

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 {}\;

Related Article

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.