Advertisement
Guest User

Untitled

a guest
May 27th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.19 KB | None | 0 0
  1. # Simplified form of a rule
  2. target1 target2 target3: prerequisite1 prerequisite2
  3. command1
  4. command2
  5. command3
  6.  
  7. # Additional dependencies appended to target
  8. vpath.o: vpath.c make.h config.h getopt.h gettext.h dep.h
  9. vpath.o: filedef.h hash.h job.h commands.h variable.h vpath.h
  10.  
  11. # Make ’s wildcards are identical to the Bourne
  12. # shell’s: ~ , * , ? , [...] , and [^...]
  13. prog: *.c
  14. $(CC) -o $@ $^
  15.  
  16. # .PHONY tells make that a target is not a real file
  17. # In addition to marking a target as always out of date
  18. .PHONY: clean
  19. clean:
  20. rm -f *.o lexer.c
  21.  
  22. # Standard phony targets
  23. #
  24. # all - Perform all tasks to build the application
  25. # install - Create an installation of the application from the compiled binaries
  26. # clean - Delete the binary files generated from sources
  27. # distclean - Delete all the generated files that were not in the original source distribution
  28. # TAGS - Create a tags table for use by editors
  29. # info - Create GNU info files from their Texinfo sources
  30. # check - Run any tests associated with this application
  31.  
  32. # Automatic Variables
  33. #
  34. # $@ - The filename representing the target
  35. #
  36. # $% - The filename element of an archive member specification
  37. #
  38. # $< - The filename of the first prerequisite
  39. #
  40. # $? - The names of all prerequisites that are newer than the target,
  41. # separated by spaces
  42. #
  43. # $^ - The filenames of all the prerequisites, separated by spaces.
  44. # This list has duplicate filenames removed since for most uses,
  45. # such as compiling, copying, etc., duplicates are not wanted
  46. #
  47. # $+ - Similar to $^ , this is the names of all the prerequisites
  48. # separated by spaces, except that $+ includes duplicates. This variable
  49. # was created for specific situations such as arguments to linkers
  50. # where duplicate values have meaning
  51. #
  52. # $* - The stem of the target filename. A stem is typically a filename
  53. # without its suffix
  54. #
  55. # One variant returns only the directory portion of the value.
  56. # This is indicated by appending a “D” to the symbol, $(@D) , $(<D) , etc.
  57. # The other variant returns only the file portion of the value.
  58. # This is indicated by appending an F to the symbol, $(@F) , $(<F) , etc.
  59.  
  60. # VPATH variable consists of a list of directories to search
  61. VPATH = src
  62. # The vpath directive is a more precise
  63. # vpath pattern directory-list
  64. vpath %.c src
  65. vpath %.h include
  66.  
  67. # Pattern rules
  68. %.o: %.c
  69. $(COMPILE.c) $(OUTPUT_OPTION) $<
  70. # %,v
  71. # s%.o
  72. # wrapper_%
  73.  
  74. # Static pattern rules - objs: pattern: prereq
  75. $(OBJECTS): %.o: %.c
  76. $(CC) -c $(CFLAGS) $< -o $@
  77.  
  78. # The Implicit Rules Database
  79. # make --print-data-base / make -p
  80.  
  81. # Special Targets
  82. # The .PHONY target is the most common special target
  83. #
  84. # .INTERMEDIATE
  85. # Prerequisites of this special target are treated as intermediate files.
  86. # If make creates the file while updating another target, the file will
  87. # be deleted automatically when make exits. If the file already exists when
  88. # make considers updating the file, the file will not be deleted
  89. #
  90. # .SECONDARY
  91. # Prerequisites of this special target are treated as intermediate files
  92. # but are never automatically deleted. The most common use of .SECONDARY
  93. # is to mark object files stored in libraries
  94. #
  95. # .PRECIOUS
  96. # When make is interrupted during execution, it may delete the target
  97. # file it is updating if the file was modified since make started. If you
  98. # mark the file as precious, make will never delete the file if interrupted
  99. #
  100. # .DELETE_ON_ERROR
  101. # This is sort of the opposite of .PRECIOUS
  102.  
  103.  
  104. # When libraries appear as prerequisites, they can be referenced using
  105. # either a standard filename or with the -l syntax
  106. xpong: $(OBJECTS) -lX11 -lXaw
  107. $(LINK) $^ -o $@
  108. # The pattern for recognizing libraries from the -l format is stored in
  109. # .LIBPATTERNS and can be customized for other library filename formats
  110.  
  111.  
  112. # Double-Colon Rules
  113. #
  114. # Same target to be updated with different commands depending on which set
  115. # of prerequisites are newer than the target
  116. file-list:: generate-list-script
  117. chmod +x $<
  118. generate-list-script $(files) > file-list
  119. file-list:: $(files)
  120. generate-list-script $(files) > file-list
  121.  
  122.  
  123. # To get the value of a variable:
  124. # $(var), $letter, ${var}
  125.  
  126. # Macro
  127. define create-jar
  128. @echo Creating $@...
  129. $(RM) $(TMP_JAR_DIR)
  130. endef
  131.  
  132. # Call macro
  133. $(UI_JAR): $(UI_CLASSES)
  134. $(create-jar)
  135.  
  136. # Expansion of b
  137. # a = b - Deferred
  138. # a ?= b - Deferred
  139. # a := b - Immediate
  140. # a += b - Deferred or immediate
  141.  
  142. # Target-Specific Variables
  143. gui.o: CPPFLAGS += -DUSE_NEW_MALLOC=1
  144. gui.o: gui.h
  145. $(COMPILE.c) $(OUTPUT_OPTION) $<
  146. # The general syntax for target-specific variables is:
  147. # target...: variable = value
  148. # target...: variable := value
  149. # target...: variable += value
  150. # target...: variable ?= value
  151.  
  152. # Conditional and include Processing
  153. #
  154. # COMSPEC is defined only on Windows
  155. ifdef COMSPEC
  156. PATH_SEP := ;
  157. EXE_EXT := .exe
  158. else
  159. PATH_SEP := :
  160. EXE_EXT :=
  161. endif
  162.  
  163. # The basic syntax of the conditional directive is:
  164. #
  165. # if-condition
  166. # text if the condition is true
  167. # endif
  168. #
  169. # or:
  170. #
  171. # if-condition
  172. # text if the condition is true
  173. # else
  174. # text if the condition is false
  175. # endif
  176. #
  177. # The if-condition can be one of:
  178. #
  179. # ifdef variable-name
  180. # ifndef variable-name
  181. # ifeq test
  182. # ifneq test
  183. #
  184. # The variable-name should not be surrounded by $( )
  185. # for the ifdef / ifndef test.
  186. # Finally, the test can be expressed as either of:
  187. # "a" "b"
  188. # (a,b)
  189. #
  190. # Whitespace in conditional processing can be tricky to handle.
  191. # For instance, when using the parenthesis form of the test,
  192. # whitespace after the comma is ignored, but all other
  193. # whitespace is significant:
  194. ifeq (a, a)
  195. # These are equal
  196. endif
  197.  
  198. ifeq ( b, b )
  199. # These are not equal - ' b' != 'b '
  200. endif
  201.  
  202. # Personally, I stick with the quoted forms of equality:
  203. ifeq "a" "a"
  204. # These are equal
  205. endif
  206.  
  207. ifeq 'b' 'b'
  208. # So are these
  209. endif
  210.  
  211. libGui.a: $(gui_objects)
  212. $(AR) $(ARFLAGS) $@ $<
  213. ifdef RANLIB
  214. $(RANLIB) $@
  215. endif
  216.  
  217. # Include directive
  218. include definitions.mk
  219.  
  220. # Standard make Variables
  221.  
  222. # MAKE_VERSION
  223. # This is the version number of GNU make
  224. #
  225. # CURDIR
  226. # This variable contains the current working directory (cwd)
  227. # of the executing make process
  228. #
  229. # MAKEFILE_LIST
  230. # This variable contains a list of each file make has read including the default
  231. # makefile and makefiles specified on the command line or through
  232. # include directives
  233. #
  234. # MAKECMDGOALS
  235. # The MAKECMDGOALS variable contains a list of all the targets specified
  236. # on the command line for the current execution of make . It does not include
  237. # command-line options or variable assignments
  238. #
  239. # .VARIABLES
  240. # This contains a list of the names of all the variables defined in makefiles
  241. # read so far, with the exception of target-specific variables. The variable
  242. # is read-only and any assignment to it is ignored
  243.  
  244.  
  245. # Functions
  246. define parent
  247. echo "parent has two parameters: $1, $2"
  248. $(call child,$1)
  249. endef
  250.  
  251. define child
  252. echo "child has one parameter: $1"
  253. echo "but child can also see parent's second parameter: $2!"
  254. endef
  255.  
  256. scoping_issue:
  257. @$(call parent,one,two)
  258.  
  259. # Field references in awk are written as $1 , $2 , etc. These would be
  260. # treated as make variables if we did not quote them in some way.
  261. # We can tell make to pass the $n reference to awk instead of expanding
  262. # it itself by escaping the dollar sign in $n with an additional dollar
  263. # sign, $$n . make will see the double dollar sign, collapse it to a
  264. # single dollar sign and pass it to the subshell
  265.  
  266. # Built-in Functions
  267.  
  268. $(filter pattern...,text)
  269. # The filter function treats text as a sequence of space separated words and
  270. # returns a list of those words matching pattern
  271. $(ui_library): $(filter ui/%.o,$(objects))
  272. $(AR) $(ARFLAGS) $@ $^
  273.  
  274. $(filter-out pattern...,text)
  275. # The filter-out function does the opposite of filter, selecting every
  276. # word that does not match the pattern. Here we select all files
  277. # that are not C headers
  278. all_source := count_words.c counter.c lexer.l counter.h lexer.h
  279. to_compile := $(filter-out %.h, $(all_source))
  280.  
  281. $(findstring string,text)
  282. # This function looks for string in text. If the string is found,
  283. # the function returns string; otherwise, it returns nothing
  284.  
  285. $(subst search-string,replace-string,text)
  286. # This is a simple, nonwildcard, search and replace. One of its most common uses
  287. # is to replace one suffix with another in a list of filenames:
  288. sources := count_words.c counter.c lexer.c
  289. objects := $(subst .c,.o,$(sources))
  290.  
  291. $(patsubst search-pattern , replace-pattern , text)
  292. # This is the wildcard version of search and replace
  293. strip-trailing-slash = $(patsubst %/,%,$(directory-path))
  294.  
  295. $(words text)
  296. # This returns the number of words in text
  297.  
  298. $(word n,text)
  299. # This returns the n th word in text
  300.  
  301. $(firstword text)
  302. # This returns the first word in text
  303.  
  304. $(wordlist start,end,text)
  305. # This returns the words in text from start to end, inclusive. As with the word
  306. # function, the first word is numbered 1
  307.  
  308. $(sort list)
  309. # The sort function sorts its list argument and removes duplicates
  310.  
  311. $(shell command)
  312. # The shell function accepts a single argument that is expanded
  313. # (like all arguments) and passed to a subshell for execution
  314.  
  315. $(wildcard pattern...)
  316. # The wildcard function accepts a list of patterns and performs
  317. # expansion on each one
  318. sources := $(wildcard *.c *.h)
  319.  
  320. $(dir list...)
  321. # The dir function returns the directory portion of each word in list
  322.  
  323. $(notdir name...)
  324. # The notdir function returns the filename portion of a file path
  325.  
  326. $(suffix name...)
  327. # The suffix function returns the suffix of each word in its argument
  328.  
  329. $(basename name...)
  330. # The basename function is the complement of suffix
  331.  
  332. $(addsuffix suffix,name...)
  333. # The addsuffix function appends the given suffix text to each word in name
  334.  
  335. $(addprefix prefix,name...)
  336. # The addprefix function is the complement of addsuffix
  337.  
  338. $(join prefix-list,suffix-list)
  339. # The join function is the complement of dir and notdir
  340.  
  341. $(if condition,then-part,else-part)
  342.  
  343. $(error text)
  344. #The error function is used for printing fatal error messages
  345.  
  346. $(foreach variable,list,body)
  347. # The foreach function provides a way to expand text repeatedly while
  348. # substituting different values into each expansion
  349. letters := $(foreach letter,a b c d,$(letter))
  350. show-words:
  351. # letters has $(words $(letters)) words: '$(letters)'
  352.  
  353. $(strip text)
  354. # The strip function removes all leading and trailing whitespace from text and
  355. # replaces all internal whitespace with a single space
  356.  
  357.  
  358. $(origin variable)
  359. # The origin function returns a string describing the origin of a variable
  360. # The possible return values of origin are:
  361. undefined
  362. # The variable has never been defined
  363. default
  364. # The variable’s definition came from make ’s built-in database.
  365. # If you alter the value of a built-in variable, origin returns the
  366. # origin of the most recent definition
  367. environment
  368. # The variable’s definition came from the environment (and the
  369. # --environment-overrides option is not turned on)
  370. environment override
  371. # The variable’s definition came from the environment (and the
  372. # --environment-overrides option is turned on)
  373. file
  374. # The variable’s definition came from the makefile
  375. command line
  376. # The variable’s definition came from the command line
  377. override
  378. # The variable’s definition came from an override directive
  379. automatic
  380. # The variable is an automatic variable defined by make
  381.  
  382.  
  383. $(warning text)
  384. # The warning function is similar to the error function except that it does not
  385. # cause make to exit
  386.  
  387. $(eval sources := foo.c bar.c)
  388. # The eval function is completely different from the rest of the built-in
  389. # functions. Its purpose is to feed text directly to the make parser
  390.  
  391.  
  392. # Escapes:
  393. .INTERMEDIATE: file_list
  394. file_list:
  395. for d in logic ui; \
  396. do \
  397. echo $$d/*.java; \
  398. done > $@
  399.  
  400. $(config): $(config_template)
  401. if [ ! -d $(dir $@) ]; \
  402. then \
  403. $(MKDIR) $(dir $@); \
  404. else \
  405. true; \
  406. fi
  407. $(M4) $^ > $@
  408. # Command modifiers
  409. @
  410. # Do not echo the command. For historical compatibility, you can make your
  411. # target a prerequisite of the special target .SILENT
  412. QUIET = @
  413. hairy_script:
  414. $(QUIET) complex script
  415.  
  416. -
  417. # The dash prefix indicates that errors in the command should be ignored by make
  418.  
  419. +
  420. # The plus modifier tells make to execute the command even if the --just-print
  421. # (or -n ) command-line option is given to make
  422.  
  423.  
  424. # Shell
  425. #
  426. # When make needs to pass a command line to a subshell, it uses /bin/sh.
  427. # You can change the shell by setting the make variable SHELL
  428. # One such sacrifice is to explicitly set the SHELL variable to /usr/bin/bash
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement