09 2012 档案
摘要:继续翻译Choosing a Shell in DOS and Windows...................................Choosing a shell in MS-DOS and MS-Windows is much more complex than onother systems. On MS-DOS, if `SHELL' is not set, the value of the variable`COMSPEC' (which is always set) is used instead. The processing of lines t
阅读全文
摘要:继续翻译5.3.2 Choosing the Shell------------------------The program used as the shell is taken from the variable `SHELL'. Ifthis variable is not set in your makefile, the program `/bin/sh' isused as the shell. The argument(s) passed to the shell are taken fromthe variable `.SHELLFLAGS'. The
阅读全文
摘要:继续翻译 If `.ONESHELL' is provided, then only the first line of the recipewill be checked for the special prefix characters (`@', `-', and `+').Subsequent lines will include the special characters in the recipe linewhen the `SHELL' is invoked. If you want your recipe to start with o
阅读全文
摘要:继续翻译5.3.1 Using One Shell---------------------Sometimes you would prefer that all the lines in the recipe be passedto a single invocation of the shell. There are generally twosituations where this is useful: first, it can improve performance inmakefiles where recipes consist of many command lines, .
阅读全文
摘要:继续翻译5.3 Recipe Execution====================When it is time to execute recipes to update a target, they areexecuted by invoking a new subshell for each line of the recipe, unlessthe `.ONESHELL' special target is in effect (*note Using One Shell: OneShell.) (In practice, `make' may take short
阅读全文
摘要:继续翻译5.2 Recipe Echoing==================Normally `make' prints each line of the recipe before it is executed.We call this "echoing" because it gives the appearance that you aretyping the lines yourself. When a line starts with `@', the echoing of that line is suppressed.The `@'
阅读全文
摘要:继续翻译5.1.2 Using Variables in Recipes--------------------------------The other way in which `make' processes recipes is by expanding anyvariable references in them (*note Basics of Variable References:Reference.). This occurs after make has finished reading all themakefiles and the target is dete
阅读全文
摘要:继续翻译 Sometimes you want to split a long line inside of single quotes, butyou don't want the backslash-newline to appear in the quoted content.This is often the case when passing scripts to languages such as Perl,where extraneous backslashes inside the script can change its meaningor even be a sy
阅读全文
摘要:继续翻译5.1.1 Splitting Recipe Lines----------------------------One of the few ways in which `make' does interpret recipes is checkingfor a backslash just before the newline. As in normal makefile syntax,a single logical recipe line can be split into multiple physical linesin the makefile by placing
阅读全文
摘要:继续翻译5.1 Recipe Syntax=================Makefiles have the unusual property that there are really two distinctsyntaxes in one file. Most of the makefile uses `make' syntax (*noteWriting Makefiles: Makefiles.). However, recipes are meant to beinterpreted by the shell and so they are written using s
阅读全文
摘要:继续翻译5 Writing Recipes in Rules**************************The recipe of a rule consists of one or more shell command lines to beexecuted, one at a time, in the order they appear. Typically, theresult of executing these commands is that the target of the rule isbrought up to date. Users use many dif...
阅读全文
摘要:继续翻译 Once you've defined the rule to remake the `.d' files, you then usethe `include' directive to read them all in. *Note Include::. Forexample: sources = foo.c bar.c include $(sources:.c=.d)(This example uses a substitution variable reference to translate thelist of source files `foo.c
阅读全文
摘要:继续翻译 Here is the pattern rule to generate a file of prerequisites (i.e.,a makefile) called `NAME.d' from a C source file called `NAME.c': %.d: %.c @set -e; rm -f $@; \ $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;...
阅读全文
摘要:继续翻译 Note that such a prerequisite constitutes mentioning `main.o' in amakefile, so it can never be considered an intermediate file by implicitrule search. This means that `make' won't ever remove the file afterusing it; *note Chains of Implicit Rules: Chained Rules. With old `make'
阅读全文
摘要:继续翻译4.14 Generating Prerequisites Automatically===========================================In the makefile for a program, many of the rules you need to write oftensay only that some object file depends on some header file. Forexample, if `main.c' uses `defs.h' via an `#include', you would
阅读全文
摘要:继续翻译 The double-colon rules for a target are executed in the order theyappear in the makefile. However, the cases where double-colon rulesreally make sense are those where the order of executing the recipeswould not matter. Double-colon rules are somewhat obscure and not often very useful;they ...
阅读全文
摘要:继续翻译4.13 Double-Colon Rules=======================Double-colon rules are explicit rules written with `::' instead of`:' after the target names. They are handled differently from ordinaryrules when the same target appears in more than one rule. Patternrules with double-colons have an entirely
阅读全文
摘要:继续翻译4.12.2 Static Pattern Rules versus Implicit Rules-------------------------------------------------A static pattern rule has much in common with an implicit rule definedas a pattern rule (*note Defining and Redefining Pattern Rules: PatternRules.). Both have a pattern for the target and patterns.
阅读全文
摘要:上例子LIBS=foo.k bar.k.PHONY : allall: $(LIBS) @echo final$(LIBS): %.k : text.g @echo $*text.g: echo text.g运行结果:text.gfoobarfinal结束
阅读全文
摘要:继续翻译 Each target specified must match the target pattern; a warning isissued 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 (*note Functions for StringSubstitution and Analysi
阅读全文
摘要:继续翻译 `%' characters in pattern rules can be quoted with precedingbackslashes (`\'). Backslashes that would otherwise quote `%'characters can be quoted with more backslashes. Backslashes that quote`%' characters or other backslashes are removed from the pattern beforeit is compared to
阅读全文
摘要:继续翻译 The TARGET-PATTERN and PREREQ-PATTERNS say how to compute theprerequisites of each target. Each target is matched against theTARGET-PATTERN to extract a part of the target name, called the "stem".This stem is substituted into each of the PREREQ-PATTERNS to make theprerequisite names (
阅读全文
摘要:继续翻译4.12 Static Pattern Rules=========================Static pattern rules are rules which specify multiple targets andconstruct the prerequisite names for each target based on the targetname. They are more general than ordinary rules with multiple targetsbecause the targets do not have to have ide.
阅读全文
摘要:objects = foo.o bar.oall: $(objects)$(objects): %.o : %.c $(CC) -c $< -o $@$(objects): %.o : %.c 表示, 每个.o 文件依赖于 同名的 .c 文件。
阅读全文
摘要:继续翻译4.11 Multiple Rules for One Target==================================One file can be the target of several rules. All the prerequisitesmentioned in all the rules are merged into one list of prerequisites forthe target. If the target is older than any prerequisite from any rule,the recipe is exe..
阅读全文
摘要:继续翻译4.10 Multiple Targets in a Rule===============================A rule with multiple targets is equivalent to writing many rules, eachwith one target, and all identical aside from that. The same recipeapplies to all the targets, but its effect may vary because you cansubstitute the actual target .
阅读全文
摘要:继续翻译`.ONESHELL' If `.ONESHELL' is mentioned as a target, then when a target is built all lines of the recipe will be given to a single invocation of the shell rather than each line being invoked separately (*note Recipe Execution: Execution.).`.POSIX' If `.POSIX' is mentioned as ...
阅读全文
摘要:需要声明的是 gnu make 的 3.81 中尚未包含 .ONESHELL 功能。3.82 中方有此功能。如下的例子是在安装了 gnu make 3.82 后验证成功的:上例子:#.NOTPARALLEL:#.ONESHELL:.SECONDEXPANSION:.PHONY: allall: a a: t1=abc;export t1 @echo $$t1;此时,make 的结果显示:t1=abc; export t1而把 .ONESHELL 前面的注释去掉后,#.NOTPARALLEL:.ONESHELL:.SECONDEXPANSION:.PHONY: alla...
阅读全文
摘要:运行yum 的时候,如果出现 Another app is currently holding the yum lock...之类,要运行 :rm -f /var/run/yum.pid。
阅读全文
摘要:上例子事先准备好三个脚本:a01.sh b01.sh c01.sh:脚本内容如下, 即每睡眠一秒钟后再输出内容:a01.shfor ((i=0;i<10;i++));do @echo "a01..." $i; sleep 1;done;b01.shfor ((i=0;i<10;i++));do @echo "b01..." $i; sleep 1;done;c01.shfor ((i=0;i<10;i++));do @echo "c01..." $i; sleep 1;done;makefile 的内容如下:.PHO
阅读全文
摘要:继续翻译`.NOTPARALLEL' If `.NOTPARALLEL' is mentioned as a target, then this invocation of `make' will be run serially, even if the `-j' option is given. Any recursively invoked `make' command will still run recipes in parallel (unless its makefile also contains this target). Any pr.
阅读全文
摘要:为了学习 .EXPORT_ALL_VARIABLES ,查阅了如下的文章:http://blog.csdn.net/zplove003/article/details/7066595这个文章写得很棒,演示了makefile 的嵌套调用。这里我把其中的 顶层 Makefile改一下,用 .EXPORT_ALL_VARIABLES 来代替。//顶层目录下的Makeflie文件cc=gcc SUBD...
阅读全文
摘要:继续翻译`.EXPORT_ALL_VARIABLES' Simply by being mentioned as a target, this tells `make' to export all variables to child processes by default. *Note Communicating Variables to a Sub-`make': Variables/Recursion.通过简单地声明 .EXPORT_ALL_VARIABLES ,可以告诉 make 来到出所有的变量给 子进程。*Note Communicating Varia.
阅读全文
摘要:继续翻译`.SILENT' If you specify prerequisites for `.SILENT', then `make' will not print the recipe used to remake those particular files before executing them. The recipe for `.SILENT' is ignored. If mentioned as a target with no prerequisites, `.SILENT' says not to print any recipe
阅读全文
摘要:继续翻译`.LOW_RESOLUTION_TIME' If you specify prerequisites for `.LOW_RESOLUTION_TIME', `make' assumes that these files are created by commands that generate low resolution time stamps. The recipe for the `.LOW_RESOLUTION_TIME' target are ignored. The high resolution file time stamps of
阅读全文
摘要:上例子:.IGNORE: gao.3LIBS =gao.1 gao.2 gao.3all:$(LIBS) @echo finalgao.1: gao.2 @echo gao.1gao.2: gao.3 ./me.o @echo gao.2gao.3: @echo gao.3运行结果:gao.3./me.ohellomake:***[gao.2] Error 2此时由于仅忽略 gao.3 中的错误,所以在 gao.2 中失败退出了。结束
阅读全文
摘要:上例子:.IGNORE:LIBS =gao.1 gao.2 gao.3all:$(LIBS) @echo finalgao.1: gao.2 @echo gao.1gao.2: gao.3 @echo gao.2gao.3: ./me.o @echo gao.3其中,./me.o 是C语言写的程序,会显示 hello, 然后 return 2 退出。执行状况如下:./me.o hellomake: [gao.3] Error 2 (ignored)gao.3gao.2gao.1这是 .IGNORE 忽略所有错误的情况。 结束
阅读全文
摘要:继续翻译`.SECONDARY' The targets which `.SECONDARY' depends on are treated as intermediate files, except that they are never automatically deleted. *Note Chains of Implicit Rules: Chained Rules. `.SECONDARY' with no prerequisites causes all targets to be treated as secondary (i.e., ...
阅读全文
摘要:上例子SHELL=bash.DELETE_ON_ERRORS: LIBS=foo.gaoall: $(LIBS) @echo finalfoo.gao: @echo $@ touch $@ ./me.o其中,me.o 程序是由C语言编译而成。其内容是显示 helloworld ,然后 return 2(即非正常退出)。运行结果要看如何来运行:make --dry-run的运行结果:echo foo.gaotouch foo.gao./me.oecho final此时 ls 命令可以发现,在当前目录下,并没有 foo.gao 文件。而如果是仅仅运行 make,结果则是这样...
阅读全文
摘要:上例子LIBS=foo.gao bar.gao.INTERMEDIATE:$(LIBS).SECONDARY:bar.gaoall: $(LIBS) #passfoo.gao: @echo $@ touch $@bar.gao: @echo $@ touch $@ make --dry-run 的结果:foo.gaotouch foo.gaobar.gaotouch bar.gao#passrm foo.gao可见,SECONDARY 确实起到了保护 中间文件的作用结束
阅读全文
摘要:先看例子一.INTERMEDIATE: foo.gaoall: foo.gao #passfoo.gao: @echo "test" touch foo.gao$make --dry-runtesttouch foo.gao#passrm foo.gao再看例子二all: foo.gao #passfoo.gao: @echo "test" touch foo.gao$make --dry-runtesttouch foo.gao#pass结束
阅读全文
摘要:继续翻译`.PRECIOUS' The targets which `.PRECIOUS' depends on are given the following special treatment: if `make' is killed or interrupted during the execution of their recipes, the target is not deleted. *Note Interrupting or Killing `make': Interrupts. Also, if the target...
阅读全文
摘要:参考 stackoverflow 的例子:http://stackoverflow.com/questions/5426934/why-this-makefile-removes-my-goal下面的 :%.txt: foo.log #pass%.log: #pass 运行时,用 make a.txt --dry-run, 会得到如下的结果:#pass#passrm foo.log也就是说, 中间文件 foo.log 被删除。但是,如果改为:all: foo.log #pass%.log: #pass这时候,再运行 make --dry-run, 会得到如下的结果:#pass#pas...
阅读全文
摘要:当前目录中存在 gao.g 文件(其实际内容是一个简单的C语言程序)先是用如下的例子来看:例子一.SUFFIXES:.SUFFIXES: .g .oLIBS=gao.oall: $(LIBS)%.o:%g @echo "in %.o:%g"运行结果是: no rule to make target gao.o...也就是说 .SUFFIXES 和 %.o:%g 模式规则一起使用没有效果。再看看如下的例子:把.SUFFIXES 去掉看看,例子二LIBS=gao.oall: $(LIBS)%.o:%g @echo "in %.o:%g"运行结果仍然是:no
阅读全文
摘要:上例子:all:gao @echo "final".DEFAULT: @echo "In default" 由于 gao 是一个前提条件,但是 makefile中没有一个名字为 gao的目的。所以符合 .DEFAULT 目的的执行条件。故执行结果为:In defaultfinal完毕
阅读全文
摘要:继续翻译4.9 Special Built-in Target Names=================================Certain names have special meanings if they appear as targets.`.PHONY' The prerequisites of the special target `.PHONY' are considered to be phony targets. When it is time to consider such a target, `make' will run it.
阅读全文
摘要:看例子:LIBS=gao.oall: $(LIBS) @echo "final".c.o: gcc -o $@ $< echo "in .c.o rule"执行 结果:gcc -o gao.o gao.cin .c.o rulefinal注意其中的 .c.o ,其实是 和 %o:%c 等价。是一个旧格式。所以 $@ 对应了 gao.o ,$< 对应了 gao.c ,不要弄反了。
阅读全文
摘要:继续翻译4.8 Empty Target Files to Record Events=======================================The "empty target" is a variant of the phony target; it is used to holdrecipes for an action that you request explicitly from time to time.Unlike a phony target, this target file can really exist; but the fil
阅读全文
摘要:继续翻译4.7 Rules without Recipes or Prerequisites==========================================If a rule has no prerequisites or recipe, and the target of the rule isa nonexistent file, then `make' imagines this target to have beenupdated whenever its rule is run. This implies that all targetsdepending
阅读全文
摘要:继续翻译Now you can say just `make' to remake all three programs, or specify asarguments the ones to remake (as in `make prog1 prog3'). Phoniness isnot inherited: the prerequisites of a phony target are not themselvesphony, unless explicitly declared to be so. When one phony target is a prerequi
阅读全文
摘要:继续翻译 A phony target should not be a prerequisite of a real target file;if it is, its recipe will be run every time `make' goes to update that file. As long as a phony target is never a prerequisite of a real target, the phony target recipe will be executed only when the phony target is a specifi
阅读全文
摘要:继续翻译 By declaring the subdirectories as phony targets (you must do this asthe subdirectory obviously always exists; otherwise it won't be built)you can remove these problems: SUBDIRS = foo bar baz .PHONY: subdirs $(SUBDIRS) subdirs: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@ ...
阅读全文
摘要:上例子主 Makefile内容:SUBDIRS=foo bar bazsubdirs: for dir in $(SUBDIRS); do\ $(MAKE) -C $$dir; \ done当前目录下各个子目录的Makfile内容:./foo/Makefile:foo: @echo "foo..."./bar/Makefile:bar: @echo "bar..."./baz/Makefile:baz: @echo "baz..."执行结果:for dir in foo bar baz;do\ make -C $dir; \donem
阅读全文
摘要:上例子SUBDIRS=foo bar bazsubdir: for dir in $(SUBDIRS); do \ @echo $$dir; \ done执行结果:for dir in foo bar baz ; do @echo $dir;donefoobarbaz
阅读全文
摘要:返回:Linux/Unix 索引页 上例子 for i in f1 f2 f3; do @echo $i; done 执行结果: f1 f2 f3 但是,请注意:如果是在makefile 中写,要写成这个样子: all: for i in f1 f2 f3; do\ @echo $$i; \ don
阅读全文
摘要:继续翻译 Thus, you first write the line that states that `clean' is a phony target, then you write the rule, like this: .PHONY: clean clean: rm *.o temp Another example of the usefulness of phony targets is in conjunction with recursive invocations of `make' (for more information...
阅读全文
摘要:继续翻译 The phony target will cease to work if anything ever does create afile named `clean' in this directory. Since it has no prerequisites,the file `clean' would inevitably be considered up to date, and itsrecipe would not be executed. To avoid this problem, you can explicitlydeclare the tar
阅读全文
摘要:继续翻译4.6 Phony Targets================= A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve...
阅读全文
摘要:继续翻译 Although the default set of files to be searched for is `libNAME.so'and `libNAME.a', this is customizable via the `.LIBPATTERNS' variable.Each word in the value of this variable is a pattern string. When aprerequisite like `-lNAME' is seen, `make' will replace the percent in
阅读全文
摘要:继续翻译4.5.6 Directory Search for Link Libraries ----------------------------------------- Directory search applies in a special way to libraries used with the linker. This special feature comes into play when you write a prerequisi...
阅读全文
摘要:继续翻译4.5.5 Directory Search and Implicit Rules-----------------------------------------The search through the directories specified in `VPATH' or with `vpath' also happens during consideration of implicit rules (*note Using Implicit Rules: Implicit Rules.). For example, when a file `foo.o'
阅读全文
摘要:继续翻译4.5.4 Writing Recipes with Directory Search-------------------------------------------When a prerequisite is found in another directory through directorysearch, this cannot change the recipe of the rule; they will execute aswritten. Therefore, you must write the recipe with care so that itwill .
阅读全文
摘要:继续翻译4.5.3 How Directory Searches are Performed ------------------------------------------ When a prerequisite is found through directory search, regardless of type (general or selective), the pathname located may not be the one th...
阅读全文
摘要:继续翻译 If several `vpath' patterns match the prerequisite file's name, then `make' processes each matching `vpath' directive one by one, searching all the directories mentioned in each directive. `make' handles multiple `vpath' directives in the order in which they appear in th
阅读全文
摘要:继续翻译 `%' characters in a `vpath' directive's pattern 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 patt
阅读全文
摘要:继续翻译`vpath PATTERN' Clear out the search path associated with PATTERN. `vpath' Clear all search paths previously specified with `vpath' directives. ...
阅读全文
摘要:继续翻译4.5.2 The `vpath' Directive --------------------------- Similar to the `VPATH' variable, but more selective, is the `vpath' directive (note lower case), which allows you to specify a search path for a particular class of file ...
阅读全文
摘要:继续翻译4.5.1 `VPATH': Search Path for All Prerequisites ------------------------------------------------ The value of the `make' variable `VPATH' specifies a list of directories that `make' should search. Most often, the directories...
阅读全文
摘要:继续翻译4.5 Searching Directories for Prerequisites =========================================== For large systems, it is often desirable to put sources in a separate directory from the binaries. The "directory search" features of `ma...
阅读全文
摘要:继续翻译4.4.3 The Function `wildcard' ----------------------------- Wildcard expansion happens automatically in rules. But wildcard expansion does not normally take place when a variable is set, or inside the arguments of a function....
阅读全文
摘要:继续翻译4.4.2 Pitfalls of Using Wildcards --------------------------------- Now here is an example of a naive way of using wildcard expansion, thatdoes not do what you would intend. Suppose you would like to say that the executable file `foo' is made from all the object files in...
阅读全文
摘要:见如下例子:LIB=*.oall: $(LIB) @echo $^$(LIB): @echo $@执行结果:*.o*.o所以
阅读全文
摘要:继续翻译4.4.1 Wildcard Examples ----------------------- Wildcards can be used in the recipe of a rule, where they are expanded by the shell. For example, here is a rule to delete all the object files: clean: ...
阅读全文
摘要:继续翻译 Wildcard expansion is performed by `make' automatically in targets and in prerequisites. In recipes, the shell is responsible for wildcard expansion. In other contexts, wildcard expansion happens only if you request it explicitly with the `wildcard' function. ...
阅读全文
摘要:继续翻译4.4 Using Wildcard Characters in File Names =========================================== A single file name can specify many files using "wildcard characters". The wildcard characters in `make' are `*', `?' and `[...]', the sam...
阅读全文
摘要:Consider an example where your targets are to be placed in a separate directory, and that directory might not exist before `make' is run. Inthis situation, you want the directory to be created before any targets are placed into it but, because the timestamps on directories change whenever a file
阅读全文
摘要:“order-only”依赖的使用举例: LIBS = libtest.afoo : foo.c | $(LIBS) $(CC) $(CFLAGS) $< -o $@ $(LIBS)make在执行这个规则时,如果目标文件“foo”已经存在。当“foo.c”被修改以后,目标“foo”将会被重建,但是当“libtest.a”被修改以后。将不执行规则的命令来重建目标“foo”。还是自己做一个小例子会比较爽:LIBS=lib.afoo: foo.c | $(LIBS) touch foo @echo "gao"在 foo.c 文件 和 lib.a 文件都存在的情况下。执行 m
阅读全文
摘要:继续翻译 The normal prerequisites section may of course be empty. Also, you may still declare multiple lines of prerequisites for the same target: they are appended appropriately (normal prerequisites are appended to the list of normal prerequisites; order-only prerequisites are appended to the list ...
阅读全文
摘要:继续翻译 Occasionally, however, you have a situation where you want to impose a specific ordering on the rules to be invoked _without_ forcing the target to be updated if one of those rules is executed. In that case, you want to define "order-only" prerequisites. Order-only prerequisites can b
阅读全文
摘要:继续翻译4.3 Types of Prerequisites ========================== There are actually two different types of prerequisites understood by GNU `make': normal prerequisites such as described in the previous section, and "order-only" prerequis...
阅读全文
摘要:继续翻译 You may split a long line by inserting a backslash followed by a newline, but this is not required, as `make' places no limit on the length of a line in a makefile. A rule tells `make' two things: when the targets are out of date, and how to updat...
阅读全文
摘要:继续翻译 The RECIPE lines start with a tab character (or the first character in the value of the `.RECIPEPREFIX' variable; *note Special Variables::). The first recipe line may appear on the line after the prerequisites, with a tab character, or may appear on the same line,with a semicolon. Either w
阅读全文
摘要:学习makefile的写法的时候,遇到了 ar 命令。进行了学习。下面的网址写得非常好:http://www.thegeekstuff.com/2010/08/ar-command-examples/还是通过例子来学习,来得比较快。此文很完美,暂时记录以作备忘。再回头来 看 makefile 的说法:Archive Members as TargetsAn individual member of an archive file can be used as a target or dependency in make. You specify the member named member
阅读全文
摘要:继续翻译4.2 Rule Syntax =============== In general, a rule looks like this: TARGETS : PREREQUISITES RECIPE ......
阅读全文
摘要:继续翻译4.1 Rule Example ================ Here is an example of a rule: foo.o : foo.c defs.h # module for twiddling the frobs cc -c -g foo.c ...
阅读全文
摘要:看stackoverflow 中的例子:http://stackoverflow.com/questions/7891097/what-are-double-colon-rules-in-a-makefile-forL :: L1 cat $< >> $@ && rm $<L :: L2 cat $< >> $@ && rm $<log 文件的来源不止一个,所以 L1 或者 L2 更新,都会导致 L 被生成。
阅读全文
摘要:上例子:all: foo.o echo finalfoo.o: bar.c echo $*bar.c 文件存在,执行后的结果:foofinal
阅读全文
摘要:$?所有比目标新的依赖目标的集合。以空格分隔。例子:在目录下,touch footouch bar然后建立Makefile:all: foo bar echo $?此时 由于目录下没有 all 文件,所以 make 的执行结果是:foo bar然后准备再次运行,touch all此时,all 比其他文件(foo bar)都新,运行 make 的执行结果是:all is up to date第三次运行:touch bar此时 新旧顺序是: bar > all > foo,运行 make 的结果是:bar
阅读全文
摘要:继续翻译4 Writing Rules *************** A "rule" appears in the makefile and says when and how to remake certain files, called the rule's "targets" (most often only one per rule). It lists the other files that are the "prerequisites"...
阅读全文
摘要:继续翻译 Note that the directory prefix (D), as described in *note Implicit Rule Search Algorithm: Implicit Rule Search, is appended (after expansion) to all the patterns in the prerequisites list. As an example: .SECONDEXPANSION: ...
阅读全文
摘要:继续翻译Secondary Expansion of Implicit Rules ------------------------------------- As `make' searches for an implicit rule, it substitutes the stem and then performs secondary expansion for every rule with a matching target pattern. ...
阅读全文
摘要:学习 makefile遇到了静态模式规则部分,研究一下:http://www.gnu.org/software/make/manual/html_node/Static-Usage.html用的是大家经常用的例子: objects = foo.o bar.o all: $(objects) $(objects): %.o: %.c $(CC) -c $(CFLAGS) $< -o $@我想,是否可以把它类比于通配符。 $(objects)里的内容都要是.o 格式。而每个 .o 都依赖于 .c。
阅读全文
摘要:继续翻译Secondary Expansion of Static Pattern Rules ------------------------------------------- Rules for secondary expansion of static pattern rules are identical to those for explicit rules, above, with one exception: for static pat...
阅读全文
摘要:啥也别说了,上例子: 输出为: foo1 foo2 foo1.bar foo2.bar 改变为: 输出为: foo1 foo2 foo1.bar foo2.bar foo2.bar foo1.bar foo2.bar 也就是说, 对 $+而言,就是将 前提条件中的内容原样输出 对 $^ 而言,前提条
阅读全文
摘要:Rules undergo secondary expansion in makefile order, except that the rule with the recipe is always evaluated last. The variables `$$?' and `$$*' are not available and expand to the empty string. 二次扩展遵循 makefile中的自然顺序,除了 片段中...
阅读全文
摘要:继续翻译Secondary Expansion of Explicit Rules ------------------------------------- During the secondary expansion of explicit rules, `$$@' and `$$%' evaluate, respectively, to the file name of the target and, when the target is an ar...
阅读全文
摘要:继续翻译 You can also mix in functions here, as long as they are properly escaped: main_SRCS := main.c try.c test.c lib_SRCS := lib.c api.c .SECONDEXPANSION: main lib:...
阅读全文
摘要:继续翻译 .SECONDEXPANSION: main_OBJS := main.o try.o test.o lib_OBJS := lib.o api.o main lib: $$($$@_OBJS) Here, after the initial expansion the p...
阅读全文
摘要:继续翻译 This is marginally more exciting, but the true power of this feature only becomes apparent when you discover that secondary expansions always take place within the scope of the automatic variables for that target. This means that you can use variables such as `$@', `$*', etc. during the
阅读全文
摘要:继续翻译 Obviously, this is not a very interesting case since the same result could more easily have been achieved simply by having both variables appear, unescaped, in the prerequisites list. One difference becomes apparent if the variables are reset; consider this example: .SECONDEXPANSION: ...
阅读全文
摘要:看例子:.SECONDEXPANSION:ONE=onefileTWO=twofilemyfile: $(ONE) $$(TWO) echo "myfile"onefile: echo "onefile"twofile: echo "twofile"执行结果:onefiletwofilemyfile如果把 .SECONDEXPANSION: 一行去掉:#.SECONDEXPANSION:ONE=onefileTWO=twofilemyfile: $(ONE) $$(TWO) echo "myfile"onefile
阅读全文
摘要:继续翻译 After the first expansion phase the prerequisites list of the 'myfile' target will be `onefile' and `$(TWOVAR)'; the first (unescaped) variable reference to ONEVAR is expanded, while the second (escaped) variable reference is simply unescaped, without being recognized as a varia
阅读全文
摘要:继续翻译 If that special target is defined then in between the two phases mentioned above, right at the end of the read-in phase, all the prerequisites of the targets defined after the special target are expanded a _second time_. In most circumstances this secondary expansion will have no effect, ...
阅读全文
摘要:继续翻译3.8 Secondary Expansion ======================= In the previous section we learned that GNU `make' works in two distinct phases: a read-in phase and a target-update phase (*note How `make' Reads a Makefile: Reading Makefiles....
阅读全文
摘要:继续翻译Rule Definition --------------- A rule is always expanded the same way, regardless of the form: IMMEDIATE : IMMEDIATE ; DEFERRED DEFERRED ...
阅读全文
摘要:继续翻译Conditional Directives ---------------------- Conditional directives are parsed immediately. This means, for example, that automatic variables cannot be used in conditional directives, as automatic variables are not set until...
阅读全文
摘要:继续翻译Variable Assignment ------------------- Variable definitions are parsed as follows: IMMEDIATE = DEFERRED IMMEDIATE ?= DEFERRED ...
阅读全文
摘要:继续翻译 It's important to understand this two-phase approach because it has a direct impact on how variable and function expansion happens; this is often a source of some confusion when writing makefiles. Here we will present a summary of the phases in which expansion happens for different construc
阅读全文
摘要:继续翻译3.7 How `make' Reads a Makefile =============================== GNU `make' does its work in two distinct phases. During the first phase it reads all the makefiles, included makefiles, etc. and internalizes all the variables a...
阅读全文
摘要:继续翻译 The way this works is that the pattern rule has a pattern of just `%', so it matches any target whatever. The rule specifies a prerequisite `force', to guarantee that the recipe will be run even if the target file already exists. We give the `force' target an empty recipe to prevent
阅读全文
摘要:继续翻译 For example, if you have a makefile called `Makefile' that says howto make the target `foo' (and other targets), you can write a makefile called `GNUmakefile' that contains: foo: frobnicate > foo ...
阅读全文
摘要:在对makefile进行了部分学习后,感觉到还是多看看简短的例子比较好。发现下面这个网站讲得很好:http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/hellomake.c:#include int main() { // call a function in another file myPrintHelloMake(); return(0);}hellofunc.c:#include #include void myPrintHelloMake(void) { printf("Hello makefiles!\n
阅读全文
摘要:继续翻译3.6 Overriding Part of Another Makefile ======================================= Sometimes it is useful to have a makefile that is mostly just like another makefile. You can often use the `include' directive to include one in ...
阅读全文
摘要:继续翻译 However, on occasion you might actually wish to prevent updating of even the makefiles. You can do this by specifying the makefiles asgoals in the command line as well as specifying them as makefiles. When the makefile name is specified explicitly as a goal, the options `-t' and so on do ap
阅读全文
摘要:继续翻译 When you use the `-t' or `--touch' option (*note Instead of Executing Recipes: Instead of Execution.), you would not want to use anout-of-date makefile to decide which targets to touch. So the `-t' option has no effect on updating makefiles; they are really updated even if `-t'
阅读全文
摘要:继续翻译 If you do not specify any makefiles to be read with `-f' or `--file'options, `make' will try the default makefile names; *note What Name to Give Your Makefile: Makefile Names. Unlike makefiles explicitly requested with `-f' or `--file' options, `make' is not certain that
阅读全文
摘要:继续翻译 If you know that one or more of your makefiles cannot be remade and you want to keep `make' from performing an implicit rule search onthem, perhaps for efficiency reasons, you can use any normal method of preventing implicit rule lookup to do so. For example, you can write an explicit rule
阅读全文
摘要:继续翻译3.5 How Makefiles Are Remade ============================ Sometimes makefiles can be remade from other files, such as RCS or SCCS files. If a makefile can be remade from other files, you probably want `make' to get an up-to-d...
阅读全文
摘要:继续翻译3.4 The Variable `MAKEFILES' ============================ If the environment variable `MAKEFILES' is defined, `make' considers its value as a list of names (separated by whitespace) of additionalmakefiles to be rea...
阅读全文
摘要:继续翻译 For compatibility with some other `make' implementations, `sinclude'is another name for `-include'. ---------- Footnotes ---------- (1) GNU Make compiled for MS-DOS and MS-Windo...
阅读全文
摘要:继续翻译 If you want `make' to simply ignore a makefile which does not exist or cannot be remade, with no error message, use the `-include' directive instead of `include', like this: -include FILENAMES... ...
阅读全文
摘要:继续翻译 If the specified name does not start with a slash, and the file is not found in the current directory, several other directories are searched. First, any directories you have specified with the `-I' or`--include-dir' option are searched (*note Summary of Options: Options Summary.). Then
阅读全文
摘要:继续翻译 Another such occasion is when you want to generate prerequisites from source files automatically; the prerequisites can be put in a file that is included by the main makefile. This practice is generally cleaner than that of somehow appending the prerequisites to the end of the main makefile...
阅读全文
摘要:继续翻译 When `make' processes an `include' directive, it suspends reading of the containing makefile and reads from each listed file in turn. When that is finished, `make' resumes reading the makefile in which the directive appears. One occasion for...
阅读全文
摘要:继续翻译 For example, if you have three `.mk' files, `a.mk', `b.mk', and `c.mk', and `$(bar)' expands to `bish bash', then the following expression include foo *.mk $(bar) is equivalent to include foo a.mk b.mk c.mk bish bash 例如,如果你有三个 .mk文件,a....
阅读全文
摘要:继续翻译 Extra spaces are allowed and ignored at the beginning of the line,but the first character must not be a tab (or the value of `.RECIPEPREFIX')--if the line begins with a tab, it will be considered a recipe line. Whitespace is required between `include' and the file name...
阅读全文
摘要:继续翻译3.3 Including Other Makefiles ============================= The `include' directive tells `make' to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the m...
阅读全文
摘要:继续翻译 If `make' finds none of these names, it does not use any makefile.Then you must specify a goal with a command argument, and `make' willattempt to figure out how to remake it using only its built-in implicitrules. *Note Using Implicit Rules: Implicit Rules. If you want to us...
阅读全文
摘要:继续翻译3.2 What Name to Give Your Makefile =================================== By default, when `make' looks for the makefile, it tries the following names, in order: `GNUmakefile', `makefile' and `Makefile'. ...
阅读全文
摘要:继续翻译 You cannot use comments within variable references or function calls: any instance of `#' will be treated literally (rather than as the start of a comment) inside a variable reference or function call. Comments within a reci...
阅读全文
摘要:继续翻译 * `#' in a line of a makefile starts a "comment". It and the rest of the line are ignored, except that a trailing backslash not escaped by another backslash will continue the comment across multiple lines. A line containing just a comment (with perhaps spaces before it) ...
阅读全文
摘要:继续翻译 * A "directive" is an instruction for `make' to do something special while reading the makefile. These include: * Reading another makefile (*note Including Other Makefiles: Include.). ...
阅读全文
摘要:继续翻译 * A "variable definition" is a line that specifies a text string value for a variable that can be substituted into the text later. The simple makefile example shows a variable definition for `objects' as a list of all object files (*note Variables Make Makefiles Simpler: V...
阅读全文
摘要:继续翻译 * An "explicit rule" says when and how to remake one or more files, called the rule's "targets". It lists the other files that the targets depend on, called the "prerequisites" of the target, and may also give a recipe to use to create or update the targets. *N
阅读全文
摘要:继续翻译3 Writing Makefiles ******************* The information that tells `make' how to recompile a system comes from reading a data base called the "makefile". 3....
阅读全文
摘要:继续翻译A rule such as this should not be placed at the beginning of the makefile, because we do not want it to run by default! Thus, in theexample makefile, we want the rule for `edit', which recompiles the editor, to remain the default goal. Since `c...
阅读全文
摘要:继续翻译 In practice, we might want to write the rule in a somewhat more complicated manner to handle unanticipated situations. We would dothis: .PHONY : clean clean : -rm edit $(object...
阅读全文
摘要:继续翻译2.7 Rules for Cleaning the Directory ==================================== Compiling a program is not the only thing you might want to write rules for. Makefiles commonly tell how to do a few other things besidescompiling a pr...
阅读全文
摘要:继续翻译Here `defs.h' is given as a prerequisite of all the object files;`command.h' and `buffer.h' are prerequisites of the specific objectfiles listed for them. Whether this is better is a matter of taste: it is more compact, but some people dislike it...
阅读全文
摘要:继续翻译2.6 Another Style of Makefile ============================= When the objects of a makefile are created only by implicit rules, an alternative style of makefile is possible. In this style of makefile,you group entries by their...
阅读全文
摘要:继续翻译This is how we would write the makefile in actual practice. (The complications associated with `clean' are described elsewhere. See *note Phony Targets::, and *note Errors in Recipes: Errors.) Because implicit rules are so convenient, they are ...
阅读全文
摘要:继续翻译 When a `.c' file is used automatically in this way, it is also automatically added to the list of prerequisites. We can therefore omit the `.c' files from the prerequisites, provided we omit the recipe. Here is the entire example, with both of these ...
阅读全文
摘要:继续翻译2.5 Letting `make' Deduce the Recipes ===================================== It is not necessary to spell out the recipes for compiling the individual C source files, because `make' can figure them out: it has an implicit rule ...
阅读全文
摘要:继续翻译Then, each place we want to put a list of the object file names, we can substitute the variable's value by writing `$(objects)' (*note How toUse Variables: Using Variables.). Here is how the complete simple makefile looks when you use a variable ...
阅读全文
摘要:继续翻译 It is standard practice for every makefile to have a variable named `objects', `OBJECTS', `objs', `OBJS', `obj', or `OBJ' which is a listof all object file names. We would define such a variable `objects'with a line like this in the makefile: ...
阅读全文
摘要:继续翻译2.4 Variables Make Makefiles Simpler ==================================== In our example, we had to list all the object files twice in the rule for `edit' (repeated here): ...
阅读全文
摘要:继续翻译 After recompiling whichever object files need it, `make' decides whether to relink `edit'. This must be done if the file `edit' doesnot exist, or if any of the object files are newer than it. If an object file was just recompiled, it is now newer than `edit', so `edit' is re
阅读全文
摘要:继续翻译 The other rules are processed because their targets appear as prerequisites of the goal. If some other rule is not depended on by thegoal (or anything it depends on, etc.), that rule is not processed, unless you tell `make' to do so (with a command such as `make clean'). ...
阅读全文
摘要:继续翻译 Thus, when you give the command: make `make' reads the makefile in the current directory and begins by processing the first rule. In the example, this rule is for relinking `edit'; but before `make' can fully process this rule, it must process the rules for the fi...
阅读全文
摘要:继续翻译2.3 How `make' Processes a Makefile =================================== By default, `make' starts with the first target (not targets whose names start with `.'). This is called the "default goal". ("Goals" are the targets that `make' strives ultimately to upda
阅读全文
摘要:继续翻译 The target `clean' is not a file, but merely the name of an action. Since you normally do not want to carry out the actions in this rule, `clean' is not a prerequisite of any other rule. Consequently, `make' never does anything with it unless you tell it specifically. Note that ...
阅读全文
摘要:继续翻译 A recipe may follow each line that contains a target and prerequisites. These recipes say how to update the target file. A tab character (or whatever character is specified by the `.RECIPEPREFIX' variable; *note Special Variables::) must come at the beginning of every line in th...
阅读全文
摘要:继续翻译 In the example makefile, the targets include the executable file `edit', and the object files `main.o' and `kbd.o'. The prerequisites are files such as `main.c' and `defs.h'. In fact, each `.o' file is both a target and a prerequisite. Recipes include `cc -c main.c'
阅读全文
摘要:继续翻译We split each long line into two lines using backslash-newline; this is like using one long line, but is easier to read. To use this makefile to create the executable file called `edit', type: make To use this makefile to delete the executable file and all the o...
阅读全文
摘要:继续翻译2.2 A Simple Makefile ===================== Here is a straightforward makefile that describes the way an executable file called `edit' depends on eight object files which, in turn, depend on eight C source and three header files. In this example, all the C files include...
阅读全文
摘要:继续翻译 A "rule", then, explains how and when to remake certain files which are the targets of the particular rule. `make' carries out the recipe on the prerequisites to create or update the target. A rule can also explain how and when to carry out an action. *Note Writing Rules: Rules...
阅读全文
摘要:继续翻译 A "recipe" is an action that `make' carries out. A recipe may have more than one command, either on the same line or each on its own line. *Please note:* you need to put a tab character at the beginning of every recipe line! This is an obscurity that catches the unwary. If you ...
阅读全文
摘要:继续翻译2.1 What a Rule Looks Like ========================== A simple makefile consists of "rules" with the following shape: TARGET ... : PREREQUISITES ... RECIPE ... ... A "target" is usually the name of a file that is gen...
阅读全文
摘要:继续翻译2 An Introduction to Makefiles ****************************** You need a file called a "makefile" to tell `make' what to do. Most often, the makefile tells `make' how to compile and link a program. In this chapter, we will discuss a simple makefile that describes how...
阅读全文
摘要:继续翻译In addition to the information above, please be careful to include the version number of `make' you are using. You can get this information with the command `make --version'. Be sure also to include the type of machine and operating system you are using. One way to obtain this inf...
阅读全文
摘要:继续翻译 Before reporting a bug or trying to fix it yourself, try to isolate it to the smallest possible makefile that reproduces the problem. Then send us the makefile and the exact results `make' gave you, including any error or warning messages. Please don't paraphrase these messages: ...
阅读全文
摘要:继续翻译1.2 Problems and Bugs ===================== If you have problems with GNU `make' or think you've found a bug, please report it to the developers; we cannot promise to do anything but we might well want to fix it. Before reporting a bug, make sure you've actually found a...
阅读全文
摘要:继续翻译1.1 How to Read This Manual =========================== If you are new to `make', or are looking for a general introduction, read the first few sections of each chapter, skipping the later sections. In each chapter, the first few sections contain introductory or general infor...
阅读全文
摘要:继续翻译Preparing and Running Make ========================== To prepare to use `make', you must write a file called the makefile that describes the relationships among files in your program and provides commands for updating each file. In a program, typically, the executable file...
阅读全文
摘要:当分析PostgreSQL 的源代码的时候,经常遇到 Makefile,读不懂其中的语句,很是令人烦恼。最近准备静下心来,好好地阅读。为了达到这一目的,进行一次翻译。1 Overview of `make' ******************** The `make' utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. This manual describes...
阅读全文
摘要:在gram.c 中,有一行:#define yyparse base_yyparse看gram.y 中,与此对应的是: %name-prefix="base_yy"而看 bison 的 manual:http://www.gnu.org/software/bison/manual/html_node/Parser-Function.html4.1 The Parser FunctionyyparseYou call the functionyyparseto cause parsing to occur. This function reads tokens, execut
阅读全文
摘要:修改gram.y 的select 部分,看能否找出 target_list中的 各个字段名称:simple_select: SELECT opt_distinct target_list into_clause from_clause where_clause group_clause having_clause window_clause { SelectStmt *n = makeNode(SelectStmt); n-...
阅读全文
摘要:进一步分析 ColumnRef:查了一下, 原来 makeColumnRef 就在 gram.y 里面:static Node * makeColumnRef(char *colname, List *indirection, int location, core_yyscan_t yyscanner){ /*...
阅读全文
摘要:上文说到 ColumnRef由于 a_expr 回溯到 c_expr。其对应的 makeColumnRef 需要构建 ColumnRef 型Node, 看看 parsenodes.h:00203 typedef struct ColumnRef00204 {00205 NodeTag type;00206 List *fields; /* field names (Value strings) or A_Star */00207 int location; /* token location, or -1 ...
阅读全文
摘要:根据 <PostgreSQL 数据库内核分析>200和201页的说法,ResTarget 应该指向 ColumnRef 。这是如何实现的呢?target_list: target_el { $$ = list_make1($1); } | target_list ',' target_el { $$ = lappend($1, $3); } ; ...
阅读全文
摘要:struct ListCellstruct ListCell{ union { void *ptr_value; int int_value; Oid oid_value; } data; ListCell *next;}由于在 target_list 相关部分,其 ptr_value 指向 ResTargettypedef struct ResTarget{ NodeTag type; char *name; List *indi...
阅读全文
摘要:simple_select: SELECT ... target_list... { ... n->targetList =$3; ... }修改为:simple_select: SELECT ... target_list... { ... n->targetList =$3; ... if ( n->targetList->head->data.ptr_value == NULL) fprintf(stderr,"ptr_value is NU...
阅读全文
摘要:从网上查到资料,以作为备忘。当结构体是一个指针时要引用结构体的成员就用-> 而如果不是指针就用. 如:struct msg_st { int a;};struct msg_st msg;struct msg_st *ms;msg.a = 10;ms->a = 20;
阅读全文
摘要:在gram.y 中, 有如下一段:target_el: a_expr AS ColLabel{ $$=makeNode(Restarget); $$->name =$3; $$->indirection=NIL; ...}...那么,makeNode到底是什么呢?nodes.h 里有这样的宏:#define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
阅读全文
摘要:前面我们说过了 listmake1其实是特殊的 lcons,而lcons 函数位于 list.c 中。00259 lcons(void *datum, List *list)00260 {00261 Assert(IsPointerList(list));00262 00263 if (list == NIL)00264 list = new_list(T_List);00265 else00266 new_head_cell(list);00267 00268 lfirst(list->head) = datum;00269 ...
阅读全文
摘要:看 gram.y 中的 target_list 的定义:target_list: target_el { $$ = list_make1($1); } | target_list ',' target_el { $$ = lappend($1, $3); } ; 而list_make1 到底是什么呢?#define lis...
阅读全文
摘要:首先看 lappend00128 lappend(List *list, void *datum)00129 {00130 Assert(IsPointerList(list));00131 00132 if (list == NIL)00133 list = new_list(T_List);00134 else00135 new_tail_cell(list);00136 00137 lfirst(list->tail) = datum;00138 check_list_invariants(list);00139 ...
阅读全文
摘要:最近在学习 PostgreSQL 的语法分析。看到 lappend函数,其中有一句:lappend(List *list, void *datum) { …… lfirst(list->tail) = datum; ……} lfirst 到底是什么,好神秘,函数的返回值被赋值?看到 pg_list.h,才明白:#define lfirst(lc) ((lc)->data.ptr_value)原来如此。 但是令我不解的是, 这么做的目的是什么? 是一种优雅的表达?会不会引起误解?
阅读全文
摘要:#include <stdlib.h> exec sql include sqlca; main() { exec sql connect to 'enterprisedb@localhost:9999' user 'enterprisedb' identified by 'enterprisedb'; exec sql BEGIN TRANSACTION; exec sql UPDATE a5 SET id=100 WHERE id=88; exec sql COMMIT; exec s...
阅读全文
摘要:例子从网络上摘抄回来。作为备忘。#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ typedef struct { char name[21]; char city[21]; char state[3]; } Rec; typedef Rec *RecPointer; RecPointer rpr; rpr=(RecPointer)malloc(sizeof(Rec)); strcpy( (*rpr).name, "gaojian"); ...
阅读全文
摘要:在对指针的学习中,看到如下的网页,是日语的。但是例子和图形都非常好。特此备忘。http://www9.plala.or.jp/sgwr-t/c/sec10-4.html
阅读全文
摘要:返回:Linux/Unix 索引页 #include <stdio.h> int main() { char *pst[3]={"Jan","Feb","Mar"}; int i; for (i=0; i<3;i++) printf("Array :%s\n", pst[i]); for (i=0;
阅读全文
摘要:在 gram.y 中:simple_select: SELECT opt_distinct target_list into_clause from_clause where_clause group_clause having_clause window_clause { ...
阅读全文
摘要:根据我的分析,其List 的定义,来自于:./src/include/pg_list.htypedef struct List{ NodeTag type; /*T_List, T_IntList or T_OidList*/ int length; ListCell *head; ListCell *tail;} List;是一个链表结构。*tail 指向下一个节点。
阅读全文
摘要:PostgreSQL 的gram.y 中所说的 window_clause, 与 window 函数不同。是一定要出现在 语句最后的:create table a8(id integer, name varchar(10), salary integer); insert into a8 values(1, 'aa', 1000); insert into a8 values(2, 'bb', 3000); insert into a8 values(3, 'cc', 2000); insert into a8 values(4, 'dd
阅读全文
摘要:create table test(id integer);insert into test values(1);insert into test values(3);insert into test values(6);insert into test values(10);insert into test values(15);insert into test values(24);------------------------------------------select id, lag(id, 1,0) from test;id lag1 03 16 310 6...
阅读全文
摘要:用PostgreSQL给的例子,可以看得比较清楚:SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary DESC) FROM empsalary; depname | empno | salary | rank -----------+-------+--------+------ develop | 8 | 6000 | 1 develop | 10 | 5200 | 2 develop | 11 | 5200 | 2 ...
阅读全文
摘要:create table a7(id integer, value integer);insert into a7 values(1,100);insert into a7 values(2,200);insert into a7 values(3,300);insert into a7 values(4,400);insert into a7 values(5,500);select id, value, cume_dist() over (order by id) as percent from a7;1 100 0.22 200 0.43 300 0.64 400 0.8...
阅读全文
摘要:以例子来说明问题:create table salaries(id integer,sal integer,site varchar(4));insert into salaries values(1,100,'A');insert into salaries values(1,200,'A');insert into salaries values(2,300,'B');insert into salaries values(2,400,'B');insert into salaries values(3,500,'C&
阅读全文
摘要:把target_list 中的这一段改变一下:| a_expr IDENT { $$ = makeNode(ResTarget); $$->name = $2; $$->indirection = NIL; $$->val = (Node *)$1; $$->location = @1; } 变...
阅读全文
摘要:对于 gram.y 中, target_list 进一步理解:其中有如下一段:| a_expr IDENT { $$ = makeNode(ResTarget); $$->name = $2; $$->indirection = NIL; $$->val = (Node *)$1; $$->location = @1; } ...
阅读全文
摘要:接上文,从 simple_select 中的 target_list ,再看target_list部分的内容:/***************************************************************************** * * target list for SELECT * ...
阅读全文
摘要:simple_select: SELECT opt_distinct target_list into_clause from_clause where_clause group_clause having_clause window_clause { ...
阅读全文
摘要:./src/backend/parser/gram.y 中有如下的一段:opt_distinct: DISTINCT { $$ = list_make1(NIL); } | DISTINCT ON '(' expr_list ')' { $$ = $4; } | ALL { $$ = NIL; } | /*EMPTY*/ { $$ = NIL; } ; opt_sort_clause: sort_clause { $$ = $1;} | /*EMPTY*/ { $$ = NIL; ...
阅读全文
摘要:对于PostgreSQL的语法分析,修改其 gram.y后,opt_distinct: DISTINCT { $$ = list_make1(NIL); } | DISTINCT ON '(' expr_list ')' { $$ = $4; } | ALL { $$ = NIL; } | /*EMPTY*/ { $$ = NIL; }simpl...
阅读全文
摘要:对于 select distinct on , 可以利用下面的例子来理解:create table a6(id integer, name varchar(10));insert into a6 values(1, ' 001');insert into a6 values(1, '002');insert into a6 values(2, '003');insert into a6 values(2, '004');select distinct on (id) id, name from a6;id | name---+--
阅读全文
摘要:目前,可以知道,PostgreSQL的词法分析和句法分析,用的也是flex 和bison。gram.y 就是用来生成 gram.c 的。为了验证一下,先分析 distinct 一段:/* We use (NIL) as a placeholder to indicate that all target expressions * should be placed in the DISTINCT list during parsetree analysis. */ opt_distinct: DISTINCT { $$ = list_mak...
阅读全文
摘要:pgpool-II中凡是涉及到SQL文解析的部分,都是拷贝了 PostgreSQL的 raw_parser来完成的。而这时来自于 gram.y。psql 使用 了 psqlscan.l 和 gram.y
阅读全文