{"id":357,"date":"2014-01-16T22:32:10","date_gmt":"2014-01-16T14:32:10","guid":{"rendered":"http:\/\/www.freezhongzi.info\/?p=357"},"modified":"2014-01-16T22:32:10","modified_gmt":"2014-01-16T14:32:10","slug":"gnu-make%e6%9c%89%e5%85%b3%e5%bb%ba%e7%ab%8b%e7%9b%ae%e5%bd%95","status":"publish","type":"post","link":"https:\/\/bl4kraven.com\/index.php\/2014\/01\/16\/gnu-make%e6%9c%89%e5%85%b3%e5%bb%ba%e7%ab%8b%e7%9b%ae%e5%bd%95\/","title":{"rendered":"gnu make\u6709\u5173\u5efa\u7acb\u76ee\u5f55"},"content":{"rendered":"<p>\u6700\u8fd1\u5199\u4ee3\u7801\u60f3Makefile\u540c\u65f6\u652f\u6301\u4ea4\u53c9\u7f16\u8bd1\u5668\u548c\u4e3b\u673a\u7f16\u8bd1\u5668\uff0c\u6240\u4ee5\u8981\u628a\u4e0d\u540c\u7f16\u8bd1\u5668\u751f\u6210\u7684\u76ee\u6807\u6587\u4ef6\u653e\u5230\u4e0d\u540c\u7684\u76ee\u5f55\u4e2d\u3002\u9996\u5148\u60f3\u5230\u7684\u662f\u76ee\u5f55\u91cc\u8981\u4fdd\u7559\u539f\u6765\u7684\u6e90\u6587\u4ef6\u76ee\u5f55\u7ed3\u6784\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u7528\u9690\u5f0f\u89c4\u5219\u6216\u9759\u6001\u89c4\u5219\u63a8\u5bfc\u51fa\u6e90\u6587\u4ef6\uff0c\u5426\u5219\u6839\u672c\u65e0\u6cd5\u5f97\u5230\u4f9d\u8d56\u5173\u7cfb\u3002\u6700\u540e\u7528\u4e86<br \/>\n\u9690\u5f0f\u89c4\u5219\u6263\u51fa\u6e90\u6587\u4ef6\u8def\u5f84\u624d\u52c9\u5f3a\u53ef\u7528\uff0c\u7167\u8fd9\u4e2a\u601d\u8def\u82b1\u4e86\u70b9\u65f6\u95f4\u5199\u4e86\u4e2a\u6d4b\u8bd5\u4f8b\u5b50\uff0c\u51c6\u5907\u628a\u73b0\u6709\u9700\u8981\u4ea4\u53c9\u7f16\u8bd1\u7684\u7a0b\u5e8f\u90fd\u8f6c\u5230\u8fd9\u79cd\u6a21\u5f0f\uff1a<\/p>\n<pre><code>ifdef HOST\n    objdir:=obj_$(word 1, $(subst -, ,$(HOST)))\nelse\n    objdir:=obj\nendif\n\nSRC_DIR:=. src\nCFILES:=$(shell find $(SRC_DIR) -maxdepth 1 -name \"*.c\")\nOBJS:=$(addprefix $(objdir)\/,$(CFILES:%.c=%.o))\nOBJDIRS:=$(addprefix $(objdir)\/, $(SRC_DIR))\nTARGET=main\n\nall:$(OBJDIRS) $(TARGET)\n\n$(TARGET):$(OBJS)\n    gcc -o $@ $(OBJS)\n\n$(objdir)\/%.o:%.c\n    gcc -c $&lt; -o $@\n\n$(OBJDIRS):\n    @mkdir -p $@\n\nclean:\n    -rm -r -f $(objdir) $(TARGET)\n\n.PHONY: clean all\n<\/code><\/pre>\n<p>\u8fd8\u6709\u5c31\u662f\u67e5\u8d44\u6599\u65f6\u53d1\u73b0\u4e86\u8fd9\u4e2a\u4e1c\u4e1c(order-only prerequisites)\uff0c\u53ef\u60dc\u6ca1\u6cd5\u7528\u5728\u6211\u8fd9\u91cc\uff0c\u56e0\u4e3a\u7528\u9690\u5f0f\u89c4\u5219\u6211\u6ca1\u6cd5\u5f04\u51fa\u76ee\u5f55\u4f9d\u8d56-_-!!!\uff0c\u4e0b\u4e00\u6b65\u662f\u628a\u6240\u6709*.d\u6587\u4ef6\u4e5f\u641e\u8fdb\u76ee\u5f55\u4e2d\u53bb\u3002<\/p>\n<hr \/>\n<h2>gnu make\u7684\u4e24\u79cd\u4f9d\u8d56\u5173\u7cfb(Prerequisites)\uff1a<\/h2>\n<ol>\n<li>\n<p>\u6b63\u5e38\u4f9d\u8d56(normal prerequisites)<\/p>\n<p>1)\u68c0\u67e5\u548c\u91cd\u5efa\u4f9d\u8d56<\/p>\n<p>2)\u5982\u679c\u4f9d\u8d56\u66f4\u65b0\uff0c\u5219\u8981\u91cd\u5efa\u76ee\u6807<\/p>\n<\/li>\n<li>\n<p>\u987a\u5e8f\u4f9d\u8d56(order-only prerequisites)<\/p>\n<p>1)\u68c0\u67e5\u548c\u91cd\u5efa\u4f9d\u8d56<\/p>\n<\/li>\n<\/ol>\n<p>\u987a\u5e8f\u4f9d\u8d56\u4e0d\u4f1a\u5f71\u54cd\u6700\u7ec8\u7684\u76ee\u6807\u7684\u91cd\u5efa\uff0c\u8fd9\u4e2a\u9002\u5408\u4e0e\u5728makefile\u91cc\u5efa\u76ee\u5f55\uff0c\u56e0\u4e3a\u76ee\u5f55\u4f5c\u4e3a\u76ee\u6807\u6709\u4e00\u4e2a\u7279\u6027\u662f\u76ee\u5f55\u91cc\u7684\u6587\u4ef6\u6539\u4e86\uff0c\u76ee\u5f55\u5c31\u66f4\u65b0\u4e86\uff0c\u5bfc\u81f4\u4e00\u7cfb\u5217\u4e0d\u5fc5\u8981\u7684\u91cd\u5efa\uff0c\u7528\u987a\u5e8f\u4f9d\u8d56\u65b9\u5f0f\u7684\u8bdd\uff0c\u5c31\u4e0d\u56de\u5f71\u54cd\u6700\u7ec8\u7684\u76ee\u6807\u4e86<\/p>\n<p>Gnu make\u624b\u518c\u4e0a\u7ed9\u4e86\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre><code> OBJDIR := objdir\n OBJS := $(addprefix $(OBJDIR)\/,foo.o bar.o baz.o)\n\n $(OBJDIR)\/%.o : %.c\n         $(COMPILE.c) $(OUTPUT_OPTION) $&lt;\n\n all: $(OBJS)\n\n $(OBJS): | $(OBJDIR)\n\n $(OBJDIR):\n         mkdir $(OBJDIR)\n<\/code><\/pre>\n<p><a href=\"http:\/\/www.gnu.org\/software\/make\/manual\/html_node\/Prerequisite-Types.html\">http:\/\/www.gnu.org\/software\/make\/manual\/html_node\/Prerequisite-Types.html<\/a> <a href=\"http:\/\/cm.techwell.com\/articles\/weekly\/making-directories-gnu-make\">http:\/\/cm.techwell.com\/articles\/weekly\/making-directories-gnu-make<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5199\u4ee3\u7801\u60f3Makefile\u540c\u65f6\u652f\u6301\u4ea4\u53c9\u7f16\u8bd1\u5668\u548c\u4e3b\u673a\u7f16\u8bd1\u5668\uff0c\u6240\u4ee5\u8981\u628a\u4e0d\u540c\u7f16\u8bd1\u5668\u751f &hellip; <a href=\"https:\/\/bl4kraven.com\/index.php\/2014\/01\/16\/gnu-make%e6%9c%89%e5%85%b3%e5%bb%ba%e7%ab%8b%e7%9b%ae%e5%bd%95\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a> <a href=\"https:\/\/bl4kraven.com\/index.php\/2014\/01\/16\/gnu-make%e6%9c%89%e5%85%b3%e5%bb%ba%e7%ab%8b%e7%9b%ae%e5%bd%95\/\">\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-357","post","type-post","status-publish","format-standard","hentry","category-program"],"_links":{"self":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/357","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=357"}],"version-history":[{"count":0,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"wp:attachment":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}