• <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)
            表示列舉當(dāng)前目錄下的所有.c文件
            這里$^因?yàn)闀?huì)包含依賴的文件名,如果包含的該文件存在,那么將返回其含路徑的文件名
            所以$(wildcard $^)就是用來過濾$^包含的所有文件并且該文件確實(shí)在本地存在.

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

            替它之前會(huì)從模式中被刪除。反斜杠不會(huì)因?yàn)橐?#8220;%”而混亂。如,模式
            “the\%weird\\%pattern\\”是“the%weird\”+“%”+“pattern\\”構(gòu)成。最后的兩個(gè)
            反斜杠由于沒有任何轉(zhuǎn)義引用“%”所以保持不變。
            我們來看一個(gè)例子,它根據(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文件,對于目標(biāo)“foo.o”
            ,取
            其莖“foo”替代對應(yīng)的依賴模式“%.c”中的模式字符“%”之后可得到目標(biāo)的依賴文
            件“foo.c”
            。這就是目標(biāo)“foo.o”的依賴關(guān)系“foo.o: foo.c”
            ,規(guī)則的命令行描述了如
            何完成由“foo.c”編譯生成目標(biāo)“foo.o”
            。命令行中“$<”和“$@”是自動(dòng)化變量,
            “$<”
            表示規(guī)則中的第一個(gè)依賴文件,
            “$@”
            表示規(guī)則中的目標(biāo)文件
            (可參考 10.5.3 自
            動(dòng)化變量 一小節(jié))
            。上邊的這個(gè)規(guī)則描述了以下兩個(gè)具體的規(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ī)則時(shí),指定的目標(biāo)必須和目標(biāo)模式相匹配,否則執(zhí)行make時(shí)將
            會(huì)得到一個(gè)錯(cuò)誤提示。
            如果存在一個(gè)文件列表,
            其中一部分符合某一種模式而另外一部
            分符合另外一種模式,這種情況下我們可以使用“filter”函數(shù)(可參考 第八章 make
            的內(nèi)嵌函數(shù))來對這個(gè)文件列表進(jìn)行分類,在分類之后對確定的某一類使用模式規(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ī)則描述了這些目標(biāo)
            文件是通過編譯對應(yīng)的.c 源文件來重建的。同樣第二條規(guī)則也是使用這種方式。
            我們通過另外一個(gè)例子來看一下自動(dòng)環(huán)變量“$*”在靜態(tài)模式規(guī)則中的使用方法:
            bigoutput littleoutput : %output : text.g
            generate text.g -$* > $@
            當(dāng)執(zhí)行此規(guī)則的命令時(shí),
            自動(dòng)環(huán)變量
            “$*”
            被展開為
            “莖” 在這里就是

            “big” “little”


            靜態(tài)模式規(guī)則對一個(gè)較大工程的管理非常有用。
            它可以對整個(gè)工程的同一類文件的
            重建規(guī)則進(jìn)行一次定義,而實(shí)現(xiàn)對整個(gè)工程中此類文件指定相同的重建規(guī)則。比如,可
            以用來描述整個(gè)工程中所有的.o 文件的依賴規(guī)則和編譯命令。通常的做法是將生成同
            一類目標(biāo)的模式定義在一個(gè) make.rules 的文件中。在工程各個(gè)模塊的 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 閱讀(699) 評論(0)  編輯 收藏 引用

            四虎国产精品免费久久5151 | 国产精品久久久久久久app| 国产精品久久久久久搜索| 国产成人精品久久亚洲高清不卡 | 国产精品VIDEOSSEX久久发布| 亚洲午夜无码AV毛片久久| 无码国内精品久久人妻| 国产精品gz久久久| 久久天天躁狠狠躁夜夜96流白浆 | 香蕉久久一区二区不卡无毒影院 | 久久经典免费视频| 久久国产亚洲精品无码| 四虎影视久久久免费观看| 久久精品日日躁夜夜躁欧美| 国产精自产拍久久久久久蜜| 日韩久久久久久中文人妻 | 国产精品免费看久久久| 中文成人无码精品久久久不卡| 99久久精品国产免看国产一区| 久久一区二区三区99| 国产精品视频久久久| 久久天天躁狠狠躁夜夜2020一| 国产福利电影一区二区三区久久久久成人精品综合| 久久久99精品一区二区| 99精品久久精品| 一本一道久久综合狠狠老| 亚洲国产成人久久综合野外| 日本精品久久久久中文字幕8| 精品久久8x国产免费观看| 国产精品久久久久久久app| 久久久久久极精品久久久 | 亚洲乱码精品久久久久.. | 久久久免费观成人影院| 狠狠干狠狠久久| 国产欧美久久一区二区| 99国产欧美久久久精品蜜芽| 91久久精一区二区三区大全| 精品久久久久久久| 色噜噜狠狠先锋影音久久| 国产精品美女久久久久av爽| 久久97久久97精品免视看秋霞|