{"id":200,"date":"2013-01-15T23:19:04","date_gmt":"2013-01-15T15:19:04","guid":{"rendered":"http:\/\/www.freezhongzi.info\/?p=200"},"modified":"2013-01-15T23:19:04","modified_gmt":"2013-01-15T15:19:04","slug":"makefile%e8%87%aa%e5%8a%a8%e4%ba%a7%e7%94%9f%e4%be%9d%e8%b5%96%e6%96%87%e4%bb%b6%e4%b8%80","status":"publish","type":"post","link":"https:\/\/bl4kraven.com\/index.php\/2013\/01\/15\/makefile%e8%87%aa%e5%8a%a8%e4%ba%a7%e7%94%9f%e4%be%9d%e8%b5%96%e6%96%87%e4%bb%b6%e4%b8%80\/","title":{"rendered":"Makefile\u81ea\u52a8\u4ea7\u751f\u4f9d\u8d56\u6587\u4ef6(\u4e00)"},"content":{"rendered":"<p>\u4e00\u76f4\u4ee5\u6765\u7528Makefile\u81ea\u52a8\u4ea7\u751f\u6e90\u6587\u4ef6(C\/C++)\u7684\u5173\u8054\u6587\u4ef6(.d)\u662f\u4e00\u5927\u95ee\u9898\u3002\u8fd9\u91cc\u4e3b\u8981\u6d89\u53ca\u5230\u7684\u662fgcc\u7684-MM\u9009\u9879(-M\u4f1a\u5305\u542b\u7cfb\u7edf\u5934\u6587\u4ef6\uff09\u3002\u4f46gcc\u7684-MM\u4e0d\u662f\u5f88\u5b8c\u7f8e\uff0c\u4e3b\u8981\u6d89\u53ca\u5230\u4e24\u65b9\u9762\uff1a<\/p>\n<ol>\n<li>\n<h2>\u6ca1\u6709\u76ee\u6807\u6587\u4ef6\u8def\u5f84<\/h2>\n<pre><code>g++ -MM src\/string_parse.cpp\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code>string_parse.o: src\/string_parse.cpp src\/string_parse.h\n<\/code><\/pre>\n<p>\u800c\u6211\u4eec\u9700\u8981\u7684\u662f\uff1a<\/p>\n<pre><code>src\/string_parse.o: src\/string_parse.cpp src\/string_parse.h\n<\/code><\/pre>\n<\/li>\n<li>\n<h2>\u5934\u6587\u4ef6\u91cd\u547d\u540d\u65f6\u51fa\u73b0\u9519\u8bef<\/h2>\n<p>\u4e07\u4e00\u6211\u4eec\u91cd\u547d\u540d\u4e86string&#95;parse.h\u4e3astring&#95;other_parse.h\u5219<\/p>\n<pre><code>string_parse.o: src\/string_parse.cpp src\/string_other_parse.h\n<\/code><\/pre>\n<p>make\u4f1a\u627e\u4e0d\u5230\u4f9d\u8d56\u6587\u4ef6str\/string&#95;other&#95;parse.h\u62a5\u9519\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u53c2\u8003\u7f51\u4e0a\u7684\u65b9\u6848\uff0c\u6211\u7684\u89e3\u51b3\u65b9\u6cd5\u662f\u5199\u4e2amakedepend\u811a\u672c\u5904\u7406\uff1a<\/p>\n<pre><code>#!\/usr\/bin\/env bash\n# Generate C\/C++ file make depend file: Makefile.depends.\n# Usage:\n#   makedepend -f files -c (gcc|g++) -p flags\n\nhelp() \n{\n    echo \"${0#*\/} -f files -c (gcc|g++) -p flags\"\n}\n\nwhile getopts \"hf:c:p:\" opt; do\n    case $opt in\n        h)\n            help\n            exit 0\n            ;;\n        f)\n            files=$OPTARG\n            ;;\n\n        c)\n            compiler=$OPTARG\n            ;;\n\n        p)\n            flags=$OPTARG\n            ;;\n        *)\n            exit 1\n            ;;\n    esac\ndone\n\n\nif [ -z \"$files\" ] || [ -z \"$compiler\" ] || [ -z \"$flags\" ] ; then\n    exit 1\nfi\n\nfor file in $files\ndo\n    obj=\"${file%.*}.o\"\n    result=`$compiler -MM $flags $file`\n    if [ $? != 0 ] ; then\n        exit 1\n    fi\n\n    result=${result\/*:\/$obj:}\n    echo $result | sed -e 's\/\\\/\/g'\n    # add all file as target, so rename file will not error.\n    echo $result | sed -e 's\/.*:\/\/' -e 's\/\\\/\/g' | fmt -1 | sed -e 's\/^ *\/\/' -e 's\/$\/:\/'\ndone\n<\/code><\/pre>\n<p>\u5728Makefile\u662f\u8fd9\u4e48\u7528\u7684\uff1a<\/p>\n<pre><code>Makefile.deps: $(FILES) $(HEADERS)\n    makedepend -f \"$(FILES)\" -c \"$(CXX)\" -p \"$(CPPFLAGS)\" &gt;$@\n<\/code><\/pre>\n<p>\u6700\u540e\u751f\u6210\u7684Makefile.deps\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code>src\/string_parse.o: src\/string_parse.cpp src\/string_parse.h\nsrc\/string_parse.cpp:\nsrc\/string_parse.h:\n<\/code><\/pre>\n<p>\u4e3a\u4e86\u9632\u6b62\u4fee\u6539\u6587\u4ef6\u540d\u540e\u627e\u4e0d\u5230\uff0cmakedepend\u4e3a\u6bcf\u4e2a\u4f9d\u8d56\u6587\u4ef6\u90fd\u5efa\u4e86\u4e00\u4e2a\u7a7a\u89c4\u5219\uff0cmake\u5982\u679c\u627e\u4e0d\u5230\u6587\u4ef6\uff0c\u53ef\u4ee5\u5728\u8fd9\u91cc\u627e\u5230\u3002<strong>\u7531\u4e8e\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u6210\u4e3a\u4e86\u4f2a\u76ee\u6807\uff0c\u800c\u4f2a\u76ee\u6807\u6c38\u8fdc\u662f\u6700\u65b0\u7684\uff0c\u4ece\u800c\u89e6\u53d1\u7f16\u8bd1\u547d\u4ee4<\/strong>\u3002<\/p>\n<h2>\u53c2\u8003\uff1a<\/h2>\n<p>\u9648\u7693\u7684\u300a\u8ddf\u6211\u4e00\u8d77\u5199Makefile\u300b<\/p>\n<p><a href=\"http:\/\/scottmcpeak.com\/autodepend\/autodepend.html\">Autodependencies with GNU make<\/a><\/p>\n<p><a href=\"http:\/\/blog.vjeux.com\/category\/makefile\">http:\/\/blog.vjeux.com\/category\/makefile<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u76f4\u4ee5\u6765\u7528Makefile\u81ea\u52a8\u4ea7\u751f\u6e90\u6587\u4ef6(C\/C++)\u7684\u5173\u8054\u6587\u4ef6(.d)\u662f\u4e00\u5927\u95ee &hellip; <a href=\"https:\/\/bl4kraven.com\/index.php\/2013\/01\/15\/makefile%e8%87%aa%e5%8a%a8%e4%ba%a7%e7%94%9f%e4%be%9d%e8%b5%96%e6%96%87%e4%bb%b6%e4%b8%80\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a> <a href=\"https:\/\/bl4kraven.com\/index.php\/2013\/01\/15\/makefile%e8%87%aa%e5%8a%a8%e4%ba%a7%e7%94%9f%e4%be%9d%e8%b5%96%e6%96%87%e4%bb%b6%e4%b8%80\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-200","post","type-post","status-publish","format-standard","hentry","category-program"],"_links":{"self":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/comments?post=200"}],"version-history":[{"count":0,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/200\/revisions"}],"wp:attachment":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/media?parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/categories?post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/tags?post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}