Editing Documentation/Maemo 5 Developer Guide/GNU Build System

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.

Warning: This page is 70 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 398: Line 398:
Now the previously used makefile is reused, but some variables are introduced. This also shows the syntax of defining the variables, and how to use them (reference them): [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/Makefile.5 simple-make-files/Makefile.5]
Now the previously used makefile is reused, but some variables are introduced. This also shows the syntax of defining the variables, and how to use them (reference them): [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/Makefile.5 simple-make-files/Makefile.5]
-
<source lang="make">
+
<tt><span>''<span><font color="#9A1900"><nowiki># define the command that we use for compilation</nowiki></font></span>''</span>
-
# define the command that we use for compilation
+
CC <span><font color="#990000"><nowiki>=</nowiki></font></span> gcc -Wall
-
CC = gcc -Wall
+
<span>''<span><font color="#9A1900"><nowiki># which targets do we want to build by default?</nowiki></font></span>''</span>
-
# which targets do we want to build by default?
+
<span>''<span><font color="#9A1900"><nowiki># note that 'targets' is just a variable, its name</nowiki></font></span>''</span>
-
# note that 'targets' is just a variable, its name
+
<span>''<span><font color="#9A1900"><nowiki># does not have any special meaning to make</nowiki></font></span>''</span>
-
# does not have any special meaning to make
+
targets <span><font color="#990000"><nowiki>=</nowiki></font></span> hello
-
targets = hello
+
<span>''<span><font color="#9A1900"><nowiki># first target defined will be the default target</nowiki></font></span>''</span>
-
# first target defined will be the default target
+
<span>''<span><font color="#9A1900"><nowiki># we use the variable to hold the dependencies</nowiki></font></span>''</span>
-
# we use the variable to hold the dependencies
+
<span><font color="#990000">.</font></span>PHONY<span><font color="#990000"><nowiki>:</nowiki></font></span> all
-
.PHONY: all
+
all<span><font color="#990000"><nowiki>:</nowiki></font></span> <span><font color="#009900">$(targets)</font></span>
-
all: $(targets)
+
hello<span><font color="#990000"><nowiki>:</nowiki></font></span> hello<span><font color="#990000">.</font></span>o hello_func<span><font color="#990000">.</font></span>o
-
hello: hello.o hello_func.o
+
        <span><font color="#009900">$(CC)</font></span> hello<span><font color="#990000">.</font></span>o hello_func<span><font color="#990000">.</font></span>o -o hello
-
        $(CC) hello.o hello_func.o -o hello
+
hello<span><font color="#990000">.</font></span>o<span><font color="#990000"><nowiki>:</nowiki></font></span> hello<span><font color="#990000">.</font></span>c hello_api<span><font color="#990000">.</font></span>h
-
hello.o: hello.c hello_api.h
+
        <span><font color="#009900">$(CC)</font></span> -c hello<span><font color="#990000">.</font></span>c -o hello<span><font color="#990000">.</font></span>o
-
        $(CC) -c hello.c -o hello.o
+
hello_func<span><font color="#990000">.</font></span>o<span><font color="#990000"><nowiki>:</nowiki></font></span> hello_func<span><font color="#990000">.</font></span>c hello_api<span><font color="#990000">.</font></span>h
-
hello_func.o: hello_func.c hello_api.h
+
        <span><font color="#009900">$(CC)</font></span> -c hello_func<span><font color="#990000">.</font></span>c -o hello_func<span><font color="#990000">.</font></span>o
-
        $(CC) -c hello_func.c -o hello_func.o
+
<span>''<span><font color="#9A1900"><nowiki># we'll make our cleaning target more powerful</nowiki></font></span>''</span>
-
# we'll make our cleaning target more powerful
+
<span>''<span><font color="#9A1900"><nowiki># we remove the targets that we build by default and also</nowiki></font></span>''</span>
-
# we remove the targets that we build by default and also
+
<span>''<span><font color="#9A1900"><nowiki># remove all object files</nowiki></font></span>''</span>
-
# remove all object files
+
<span><font color="#990000">.</font></span>PHONY<span><font color="#990000"><nowiki>:</nowiki></font></span> clean
-
.PHONY: clean
+
clean<span><font color="#990000"><nowiki>:</nowiki></font></span>
-
clean:
+
        rm -f <span><font color="#009900">$(targets)</font></span> <span><font color="#990000"><nowiki>*.</nowiki></font></span>o
-
        rm -f $(targets) *.o
+
</tt>
-
</source>
+
The CC variable is the standard variable to hold the name of the C compiler executable. GNU make comes preloaded with a list of tools that can be accessed in similar way (as will be shown with $(RM) shortly, but there are others). Most UNIX tools related to building software already have similar pre-defined variables in GNU make. Here one of them is overridden to demonstrate how it is done. Overriding variables like this is not recommended, because the user running make later might want to use some other compiler, and would have to edit the makefile to do so.
The CC variable is the standard variable to hold the name of the C compiler executable. GNU make comes preloaded with a list of tools that can be accessed in similar way (as will be shown with $(RM) shortly, but there are others). Most UNIX tools related to building software already have similar pre-defined variables in GNU make. Here one of them is overridden to demonstrate how it is done. Overriding variables like this is not recommended, because the user running make later might want to use some other compiler, and would have to edit the makefile to do so.

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)

Templates used on this page: