• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            tqsheng

            go.....
            隨筆 - 366, 文章 - 18, 評論 - 101, 引用 - 0
            數(shù)據(jù)加載中……

            makefile下$(wildcard $^),$^,$@,$?,$<,$(@D),$(@F)

            makefile下$(wildcard $^),$^,$@,$?,$<,$(@D),$(@F)代表的不同含義


            $(filter-out $(PHONY) $(wildcard $^),$^)
            常用用法為$(wildcard *.c)
            表示列舉當前目錄下的所有.c文件
            這里$^因為會包含依賴的文件名,如果包含的該文件存在,那么將返回其含路徑的文件名
            所以$(wildcard $^)就是用來過濾$^包含的所有文件并且該文件確實在本地存在.

            自動化變量$?代表依賴文件列表中被改變過的所有文件。
            自動化變量$^代表所有通過目錄搜索得到的依賴文件的完整路徑名(目錄 + 一般文件名)列表。
            自動化變量$@代表規(guī)則的目標。
            自動化變量$<代表規(guī)則中通過目錄搜索得到的依賴文件列表的第一個依賴文件。
            自動化變量$(@D) 
            The directory part of the file name of the target, 
            with the trailing slash removed. If the value of ‘$@’ is dir/foo.o 
            then ‘$(@D)’ is dir. This value is . if ‘$@’ does not contain a slash.
            http://www.gnu.org/software/make/manual/make.html
            自動化變量$(@F)
            The file-within-directory part of the file name of 
            the target. If the value of ‘$@’ is dir/foo.o then ‘$(@F)’ is foo.o. 
            ‘$(@F)’ is equivalent to ‘$(notdir $@)’. 

            4.12 靜態(tài)模式
            靜態(tài)模式規(guī)則是這樣一個規(guī)則:
            規(guī)則存在多個目標,
            并且不同的目標可以根據(jù)目標
            文件的名字來自動構(gòu)造出依賴文件。
            靜態(tài)模式規(guī)則比多目標規(guī)則更通用,
            它不需要多個
            目標具有相同的依賴。
            但是靜態(tài)模式規(guī)則中的依賴文件必須是相類似的而不是完全相同
            的。
            4.12.1
            靜態(tài)模式規(guī)則的語法
            首先,我們來看一下靜態(tài)模式規(guī)則的基本語法:
            TARGETS ...: TARGET-PATTERN: PREREQ-PATTERNS ...
            COMMANDS
            ...
            “TAGETS”
            列出了此規(guī)則的一系列目標文件。
            像普通規(guī)則的目標一樣可以包含通
            配符。關(guān)于通配符的使用可參考 4.4 文件名使用通配符 一節(jié)
            “TAGET-PATTERN”和“PREREQ-PATTERNS”說明了如何為每一個目標文件
            生成依賴文件。從目標模式(TAGET-PATTERN)的目標名字中抽取一部分字符串(稱
            為“莖”。使用“莖”替代依賴模式(PREREQ-PATTERNS)中的相應(yīng)部分來產(chǎn)生對
            )
            應(yīng)目標的依賴文件。下邊詳細介紹這一替代的過程。
            首 先 在目標模式和依賴模式中 ,一般需要包含模式字符“% ”
            。在目標模式
            (TAGET-PATTERN)中“%”可以匹配目標文件的任何部分,模式字符“%”匹配的
            部分就是“莖”
            。目標文件和目標模式的其余部分必須精確的匹配。看一個例子:目標
            “foo.o”符合模式“%.o”
            ,其“莖”為“foo”
            。而目標“foo.c”和“foo.out”就不符
            合此目標模式。
            每一個目標的依賴文件是使用此目標的“莖”代替依賴模式
            (PREREQ-PATTERNS)中的模式字符“%”而得到。例如:上邊的例子中依賴模式
            (PREREQ-PATTERNS)為“%.c”
            ,那么使用“莖”
            “foo”替代依賴模式中的“%”
            得到的依賴文件就是“foo.c”
            。需要明確的一點是:在模式規(guī)則的依賴列表中使用不包
            含模式字符“%”也是合法的。代表這個文件是所有目標的依賴文件。
            在模式規(guī)則中字符‘%’可以用前面加反斜杠“\”方法引用。引用“%”的反斜杠
            也可以由更多的反斜杠引用。引用“%”“\”的反斜杠在和文件名比較或由“莖”代

            替它之前會從模式中被刪除。反斜杠不會因為引用“%”而混亂。如,模式
            “the\%weird\\%pattern\\”是“the%weird\”+“%”+“pattern\\”構(gòu)成。最后的兩個
            反斜杠由于沒有任何轉(zhuǎn)義引用“%”所以保持不變。
            我們來看一個例子,它根據(jù)相應(yīng)的.c 文件來編譯生成“foo.o”和“bar.o”文件:
            objects = foo.o bar.o
            all: $(objects)
            $(objects): %.o: %.c
            $(CC) -c $(CFLAGS) $< -o $@
            例子中,規(guī)則描述了所有的.o文件的依賴文件為對應(yīng)的.c文件,對于目標“foo.o”
            ,取
            其莖“foo”替代對應(yīng)的依賴模式“%.c”中的模式字符“%”之后可得到目標的依賴文
            件“foo.c”
            。這就是目標“foo.o”的依賴關(guān)系“foo.o: foo.c”
            ,規(guī)則的命令行描述了如
            何完成由“foo.c”編譯生成目標“foo.o”
            。命令行中“$<”和“$@”是自動化變量,
            “$<”
            表示規(guī)則中的第一個依賴文件,
            “$@”
            表示規(guī)則中的目標文件
            (可參考 10.5.3 自
            動化變量 一小節(jié))
            。上邊的這個規(guī)則描述了以下兩個具體的規(guī)則:
            foo.o : foo.c
            $(CC) -c $(CFLAGS) foo.c -o foo.o
            bar.o : bar.c
            $(CC) -c $(CFLAGS) bar.c -o bar.o
            在使用靜態(tài)模式規(guī)則時,指定的目標必須和目標模式相匹配,否則執(zhí)行make時將
            會得到一個錯誤提示。
            如果存在一個文件列表,
            其中一部分符合某一種模式而另外一部
            分符合另外一種模式,這種情況下我們可以使用“filter”函數(shù)(可參考 第八章 make
            的內(nèi)嵌函數(shù))來對這個文件列表進行分類,在分類之后對確定的某一類使用模式規(guī)則。
            例如:
            files = foo.elc bar.o lose.o
            $(filter %.o,$(files)): %.o: %.c
            $(CC) -c $(CFLAGS) $< -o $@
            $(filter %.elc,$(files)): %.elc: %.el
            emacs -f batch-byte-compile $<
            其中;$(filter %.o,$(files))的結(jié)果為“bar.o lose.o”“filter”函數(shù)過濾不符合“%.o”

            模式的文件名而返回所有符合此模式的文件列表。
            第一條靜態(tài)模式規(guī)則描述了這些目標
            文件是通過編譯對應(yīng)的.c 源文件來重建的。同樣第二條規(guī)則也是使用這種方式。
            我們通過另外一個例子來看一下自動環(huán)變量“$*”在靜態(tài)模式規(guī)則中的使用方法:
            bigoutput littleoutput : %output : text.g
            generate text.g -$* > $@
            當執(zhí)行此規(guī)則的命令時,
            自動環(huán)變量
            “$*”
            被展開為
            “莖” 在這里就是

            “big” “little”


            靜態(tài)模式規(guī)則對一個較大工程的管理非常有用。
            它可以對整個工程的同一類文件的
            重建規(guī)則進行一次定義,而實現(xiàn)對整個工程中此類文件指定相同的重建規(guī)則。比如,可
            以用來描述整個工程中所有的.o 文件的依賴規(guī)則和編譯命令。通常的做法是將生成同
            一類目標的模式定義在一個 make.rules 的文件中。在工程各個模塊的 Makefile 中包含
            此文件。

            1. 靜態(tài)模式makefile中$(cobjs): $(obj)/%.o: $(src)/%.c

            2. http://www.gnu.org/software/make/manual/make.html
            3. 4.12.1 Syntax of Static Pattern Rules

            4. Here is the syntax of a static pattern rule:

            5.      targets ...: target-pattern: prereq-patterns ...
            6.              recipe
            7.              ...

            8. The targets list specifies the targets that the rule applies to. The targets can contain wildcard characters, just like the targets of ordinary rules (see Using Wildcard Characters in File Names).

            9. The target-pattern and prereq-patterns say how to compute the prerequisites of each target. Each target is matched against the target-pattern to extract a part of the target name, called the stem. This stem is substituted into each of the prereq-patterns to make the prerequisite names (one from each prereq-pattern).

            10. Each pattern normally contains the character ‘%’ just once. When the target-pattern matches a target, the ‘%’ can match any part of the target name; this part is called the stem. The rest of the pattern must match exactly. For example, the target foo.o matches the pattern ‘%.o’, with ‘foo’ as the stem. The targets foo.and foo.out do not match that pattern.

            11. The prerequisite names for each target are made by substituting the stem for the ‘%’ in eachprerequisite pattern. For example, if one prerequisite pattern is %.c, then substitution of the stem ‘foo’ gives the prerequisite name foo.c. It is legitimate to write a prerequisite pattern that does not contain ‘%; then this prerequisite is the same for all targets.

            12. %’ characters in pattern rules can be quoted with preceding backslashes (\). Backslashes that would otherwise quote ‘%’ characters can be quoted with more backslashes. Backslashes that quote ‘%’ characters or other backslashes are removed from the pattern before it is compared to file names or has a stem substituted into it. Backslashes that are not in danger of quoting ‘%’ characters go unmolested. For example, the pattern the\%weird\\%pattern\\ has ‘the%weird\’ preceding the operative ‘%’ character, and ‘pattern\\’ following it. The final two backslashes are left alone because they cannot affect any ‘%’ character.

            13. Here is an example, which compiles each of foo.and bar.o from the corresponding .c file:

            14.      objects = foo.o bar.o
            15.      
            16.      all: $(objects)
            17.      
            18.      $(objects): %.o: %.c
            19.              $(CC) -c $(CFLAGS) $< -o $@

            20. Here ‘$<’ is the automatic variable that holds the name of the prerequisite and ‘$@’ is the automatic variable that holds the name of the target; see Automatic Variables.

            21. Each target specified must match the target pattern; a warning is issued for each target that does not. If you have a list of files, only some of which will match the pattern, you can use the filter function to remove nonmatching file names (see Functions for String Substitution and Analysis):

            22.      files = foo.elc bar.o lose.o
            23.      
            24.      $(filter %.o,$(files)): %.o: %.c
            25.              $(CC) -c $(CFLAGS) $< -o $@
            26.      $(filter %.elc,$(files)): %.elc: %.el
            27.              emacs -f batch-byte-compile $<

            28. In this example the result of ‘$(filter %.o,$(files))’ is bar.o lose.o, and the first static pattern rule causes each of these object files to be updated by compiling the corresponding C source file. The result of ‘$(filter %.elc,$(files))’ is foo.elc, so that file is made from foo.el.

            29. Another example shows how to use $* in static pattern rules:

            30.      bigoutput littleoutput : %output : text.g
            31.              generate text.-$* > $@

            32. When the generate command is run, $* will expand to the stem, either ‘big’ or ‘little’.

            posted on 2012-07-13 10:30 tqsheng 閱讀(697) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            欧美日韩成人精品久久久免费看| 久久综合给合久久狠狠狠97色69| av午夜福利一片免费看久久| 久久久久99这里有精品10| 一本色道久久综合狠狠躁篇| 久久99久久99小草精品免视看| 国产精品视频久久久| 久久久精品久久久久久 | 久久综合九色欧美综合狠狠| 久久久久亚洲AV无码麻豆| 日韩美女18网站久久精品| 无遮挡粉嫩小泬久久久久久久| 久久精品免费观看| 色婷婷狠狠久久综合五月| 99久久无码一区人妻a黑| 亚洲欧洲久久av| 色偷偷偷久久伊人大杳蕉| 大蕉久久伊人中文字幕| 久久国产高潮流白浆免费观看| 欧美日韩中文字幕久久久不卡| 国产美女久久精品香蕉69| 久久无码AV中文出轨人妻| 久久九九青青国产精品| 久久精品国产半推半就| 波多野结衣AV无码久久一区| 日本五月天婷久久网站| 99久久99久久精品国产片果冻| 国产精品成人99久久久久| 久久久久女人精品毛片| 亚洲精品白浆高清久久久久久| 久久夜色精品国产| 国产精品久久久久久久久久免费| 日韩精品久久久肉伦网站| 亚洲乱码日产精品a级毛片久久| 91精品国产综合久久四虎久久无码一级 | 国产高潮国产高潮久久久91 | 精品久久久久久国产| 久久精品国产清自在天天线| 日产精品99久久久久久| 亚洲中文字幕无码久久2017| 久久久噜噜噜www成人网|