• <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文件
            這里$^因為會包含依賴的文件名,如果包含的該文件存在,那么將返回其含路徑的文件名
            所以$(wildcard $^)就是用來過濾$^包含的所有文件并且該文件確實在本地存在.

            自動化變量$?代表依賴文件列表中被改變過的所有文件。
            自動化變量$^代表所有通過目錄搜索得到的依賴文件的完整路徑名(目錄 + 一般文件名)列表。
            自動化變量$@代表規(guī)則的目標(biāo)。
            自動化變量$<代表規(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ī)則存在多個目標(biāo),
            并且不同的目標(biāo)可以根據(jù)目標(biāo)
            文件的名字來自動構(gòu)造出依賴文件。
            靜態(tài)模式規(guī)則比多目標(biāo)規(guī)則更通用,
            它不需要多個
            目標(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”說明了如何為每一個目標(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)模式的其余部分必須精確的匹配??匆粋€例子:目標(biāo)
            “foo.o”符合模式“%.o”
            ,其“莖”為“foo”
            。而目標(biāo)“foo.c”和“foo.out”就不符
            合此目標(biāo)模式。
            每一個目標(biāo)的依賴文件是使用此目標(biāo)的“莖”代替依賴模式
            (PREREQ-PATTERNS)中的模式字符“%”而得到。例如:上邊的例子中依賴模式
            (PREREQ-PATTERNS)為“%.c”
            ,那么使用“莖”
            “foo”替代依賴模式中的“%”
            得到的依賴文件就是“foo.c”
            。需要明確的一點是:在模式規(guī)則的依賴列表中使用不包
            含模式字符“%”也是合法的。代表這個文件是所有目標(biāo)的依賴文件。
            在模式規(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文件,對于目標(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”
            。命令行中“$<”和“$@”是自動化變量,
            “$<”
            表示規(guī)則中的第一個依賴文件,
            “$@”
            表示規(guī)則中的目標(biāo)文件
            (可參考 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ī)則時,指定的目標(biāo)必須和目標(biāo)模式相匹配,否則執(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ī)則描述了這些目標(biāo)
            文件是通過編譯對應(yīng)的.c 源文件來重建的。同樣第二條規(guī)則也是使用這種方式。
            我們通過另外一個例子來看一下自動環(huán)變量“$*”在靜態(tài)模式規(guī)則中的使用方法:
            bigoutput littleoutput : %output : text.g
            generate text.g -$* > $@
            當(dāng)執(zhí)行此規(guī)則的命令時,
            自動環(huán)變量
            “$*”
            被展開為
            “莖” 在這里就是

            “big” “little”

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


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


            亚洲αv久久久噜噜噜噜噜| 国产精品美女久久久m| 久久99热只有频精品8| 国产免费久久精品99re丫y| 国产精品欧美亚洲韩国日本久久| 久久99精品国产自在现线小黄鸭 | 久久99亚洲网美利坚合众国| 久久久久亚洲国产| 亚洲精品NV久久久久久久久久 | 久久亚洲国产精品五月天婷| 国产日韩久久免费影院| 色综合久久中文色婷婷| 久久噜噜电影你懂的| 久久中文字幕一区二区| 久久夜色tv网站| 久久国产精品国语对白| 色婷婷久久综合中文久久一本| 久久无码国产| 久久综合亚洲鲁鲁五月天| 国产成年无码久久久免费| 99久久99久久精品国产片果冻| 亚洲精品午夜国产VA久久成人| 久久人人爽人人爽人人AV东京热 | 日本精品一区二区久久久| 亚洲精品无码久久不卡| 7777久久久国产精品消防器材| 精品久久久久久无码专区不卡| 久久99国产精品久久99果冻传媒| 国产成人精品久久一区二区三区av | 欧美大香线蕉线伊人久久| 狠狠色丁香久久综合五月| 久久精品成人欧美大片| 伊人久久成人成综合网222| 亚洲综合精品香蕉久久网| 97久久精品无码一区二区| a级毛片无码兔费真人久久| 久久亚洲AV无码西西人体| 久久精品国产2020| 色综合久久综精品| 欧美日韩精品久久久久| 久久精品国产福利国产秒|