• <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   管理


            午夜精品久久久久成人| 久久久久亚洲Av无码专| 99久久综合狠狠综合久久| 99久久国产热无码精品免费久久久久 | 久久国产V一级毛多内射| 久久精品国产第一区二区| 伊人情人综合成人久久网小说| 久久夜色精品国产噜噜亚洲AV| 韩国三级大全久久网站| 久久久久亚洲精品中文字幕| 一本一本久久aa综合精品| 大香网伊人久久综合网2020| 久久亚洲精品无码VA大香大香| 国产精品免费看久久久| 三级片免费观看久久| 国产精品一区二区久久不卡| 四虎国产精品成人免费久久| 久久AV高清无码| 国产精品久久久香蕉| 精品多毛少妇人妻AV免费久久| 精品国产乱码久久久久久呢| 91精品国产综合久久香蕉 | 国产精品99久久精品爆乳| 久久午夜夜伦鲁鲁片免费无码影视 | 亚洲精品国产综合久久一线| 99久久人妻无码精品系列| 久久久久亚洲国产| 国产亚州精品女人久久久久久| 久久久久亚洲AV成人片| 综合久久国产九一剧情麻豆| 国产成人综合久久精品尤物| 久久99亚洲网美利坚合众国| 亚洲αv久久久噜噜噜噜噜| 免费精品国产日韩热久久| 热久久国产欧美一区二区精品| 久久精品国产清自在天天线| 99久久精品九九亚洲精品| 麻豆精品久久精品色综合| 久久香蕉国产线看观看99| 久久精品免费观看| 国产三级观看久久|