Differences

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

Link to this comparison view

programming:makefiles [2010/03/26 13:47]
cyril
programming:makefiles [2013/09/19 16:41]
Line 1: Line 1:
-====== Makefiles ====== 
- 
-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 <elt> <elt> <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 ===== 
- 
-<code makefile> 
-INCLUDE= \ 
- -I/usr/include \ 
- -I/usr/local/include \ 
- -I. \ 
- `pkg-config --cflags libglade-2.0`  
- 
-BIN_PATH=./ 
- 
-LIBS= \ 
- `pkg-config --libs libglade-2.0` \ 
- `pkg-config --libs gtk+-2.0` \ 
- -export-dynamic 
- 
-LIBS_PATH= \ 
- -L/lib \ 
- -L/usr/lib \ 
- -L/usr/local/lib \ 
- -L. 
- 
-COMPILO=g++ 
- 
-FLAGS= -c -g -Wall -ansi -pedantic 
-#FLAGS= -c -ansi -pedantic 
- 
-OBJ= \ 
- file1.o \ 
- file2.o 
- 
- 
- 
-  
-# cibles : 
- 
-monprog: $(OBJ) 
- $(COMPILO) -o $(BIN_PATH)monprog $(OBJ) $(LIBS_PATH) $(LIBS) 
- 
-clean :  
- rm -f *.o 
- 
-clear :  
- rm -f *.o monprog 
- 
-# compilation des sources : 
- 
-file1.o : file1.cpp file1.h 
- $(COMPILO) $(FLAGS) $(INCLUDE) -o file1.o file1.cpp 
- 
-file2.o : file2.cpp file2.h 
- $(COMPILO) $(FLAGS) $(INCLUDE) -o file2.o file2.cpp 
-</code> 
- 
- 
-===== pkg-config ===== 
- 
- 
-When using libraries, pkg-config is very useful : 
-<code> 
-pkg-config --cflags libxml++-2.6 
-pkg-config --libs libxml++-2.6 
-</code> 
- 
- 
-===== auto-tools ===== 
  
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