Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
programming:makefiles [2007/12/16 23:44]
127.0.0.1 external edit
programming:makefiles [2010/03/26 14:15]
cyril
Line 2: Line 2:
  
 Makefiles are very useful to automate compilation of multi-file projects in c/c++ with Linux. Makefiles are very useful to automate compilation of multi-file projects in c/c++ with Linux.
 +
 +===== Syntax =====
 +  * variables: 
 +<code>
 +<VARIABLE>=<string> # init
 +$(<VARIABLE>      # get content
 +</code>
 +
 +  * targets:
 +<code>
 +<target>: <prerequisite-targets>
 + <code-to-execute>
 +</code>
 +
 +  * template targets:
 +<code>
 +%.o:%.cpp
 + <code-to-execute>
 +</code>
 +
 +  * automatic variables ([[http://www.gnu.org/software/make/manual/make.html#Automatic-Variables|complete list]])::
 +    * ''$@'' : target
 +    * ''$^'' : list of requirements
 +    * ''$<'' : first requirement
 +    * ''$(MAKECMDGOALS)'' : make argument
 +
 +  * functions ([[http://www.gnu.org/software/make/manual/make.html#Functions|complete list]]):
 +    * ''$(subst from,to,text)''
 +    * ''$(filter-out <list>, <list>)''
 +
 +  * **Mini Example**
 +<code>
 +COMPILO=g++
 +SRCSCPP = $(wildcard src/*.cpp)
 +OBJS = $(patsubst %.cpp,build/%.o,$(notdir $(SRCSCPP)))
 +prog: $(OBJS)
 + $(COMPILO) -o build/$@ $(OBJS)
 +build/%.o:%.cpp
 + $(COMPILO) -c -o $@ $^
 +</code>
 +
  
 ===== Example ===== ===== Example =====
Line 56: Line 97:
  $(COMPILO) $(FLAGS) $(INCLUDE) -o file2.o file2.cpp  $(COMPILO) $(FLAGS) $(INCLUDE) -o file2.o file2.cpp
 </code> </code>
 +
  
 ===== pkg-config ===== ===== pkg-config =====
programming/makefiles.txt ยท Last modified: 2013/09/19 16:41 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0