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 74 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 47: Line 47:
This example deals with that as simply as possible. There is a project that consists of two source files and one header file. The contents of these files are listed below: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/hello.c simple-make-files/hello.c]
This example deals with that as simply as possible. There is a project that consists of two source files and one header file. The contents of these files are listed below: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/hello.c simple-make-files/hello.c]
-
<source lang="c">
+
<tt><span>''<span><font color="#9A1900">/**</font></span>''</span>
-
/**
+
  <span>''<span><font color="#9A1900"> * The old faithful hello world.</font></span>''</span>
-
  * The old faithful hello world.
+
  <span>''<span><font color="#9A1900"> *</font></span>''</span>
-
  *
+
  <span>''<span><font color="#9A1900"> * This maemo code example is licensed under a MIT-style license,</font></span>''</span>
-
  * This maemo code example is licensed under a MIT-style license,
+
  <span>''<span><font color="#9A1900"> * that can be found in the file called "License" in the same</font></span>''</span>
-
  * that can be found in the file called "License" in the same
+
  <span>''<span><font color="#9A1900"> * directory as this file.</font></span>''</span>
-
  * directory as this file.
+
  <span>''<span><font color="#9A1900"> * Copyright (c) 2007-2008 Nokia Corporation. All rights reserved.</font></span>''</span>
-
  * Copyright (c) 2007-2008 Nokia Corporation. All rights reserved.
+
  <span>''<span><font color="#9A1900"> */</font></span>''</span>
-
  */
+
<span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;stdlib.h&gt;</font></span>    <span>''<span><font color="#9A1900">/* EXIT_* */</font></span>''</span>
-
#include <stdlib.h>    /* EXIT_* */
+
<span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">"hello_api.h"</font></span> <span>''<span><font color="#9A1900">/* sayhello */</font></span>''</span>
-
#include "hello_api.h" /* sayhello */
+
<span><font color="#009900">int</font></span> <span>'''<span><font color="#000000">main</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#009900">int</font></span> argc<span><font color="#990000">,</font></span> <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span>argv<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
int main(int argc, char **argv) {
+
  <span>'''<span><font color="#000000">sayhello</font></span>'''</span><span><font color="#990000">();</font></span>
-
  sayhello();
+
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> EXIT_SUCCESS<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  return EXIT_SUCCESS;
+
<span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
[https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/hello_func.c simple-make-files/hello_func.c]
[https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/hello_func.c simple-make-files/hello_func.c]
-
<source lang="c">
+
<tt><span>''<span><font color="#9A1900">/**</font></span>''</span>
-
/**
+
  <span>''<span><font color="#9A1900"> * Implementation of sayhello.</font></span>''</span>
-
  * Implementation of sayhello.
+
  <span>''<span><font color="#9A1900"> *</font></span>''</span>
-
  *
+
  <span>''<span><font color="#9A1900"> * This maemo code example is licensed under a MIT-style license,</font></span>''</span>
-
  * This maemo code example is licensed under a MIT-style license,
+
  <span>''<span><font color="#9A1900"> * that can be found in the file called "License" in the same</font></span>''</span>
-
  * that can be found in the file called "License" in the same
+
  <span>''<span><font color="#9A1900"> * directory as this file.</font></span>''</span>
-
  * directory as this file.
+
  <span>''<span><font color="#9A1900"> * Copyright (c) 2007-2008 Nokia Corporation. All rights reserved.</font></span>''</span>
-
  * Copyright (c) 2007-2008 Nokia Corporation. All rights reserved.
+
  <span>''<span><font color="#9A1900"> */</font></span>''</span>
-
  */
+
-
 
+
<span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;stdio.h&gt;</font></span>    <span>''<span><font color="#9A1900">/* printf */</font></span>''</span>
-
#include <stdio.h>    /* printf */
+
<span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">"hello_api.h"</font></span> <span>''<span><font color="#9A1900">/* sayhello declaration */</font></span>''</span>
-
#include "hello_api.h" /* sayhello declaration */
+
-
 
+
<span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">sayhello</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
void sayhello(void) {
+
  <span>'''<span><font color="#000000">printf</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#FF0000">"Hello world!</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">"</font></span><span><font color="#990000">);</font></span>
-
  printf("Hello world!\n");
+
<span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
[https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/hello_api.h simple-make-files/hello_api.h]
[https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/hello_api.h simple-make-files/hello_api.h]
-
<source lang="c">
+
<tt><span>''<span><font color="#9A1900">/**</font></span>''</span>
-
/**
+
  <span>''<span><font color="#9A1900"> * Interface description for the hello_func module.</font></span>''</span>
-
  * Interface description for the hello_func module.
+
  <span>''<span><font color="#9A1900"> *</font></span>''</span>
-
  *
+
  <span>''<span><font color="#9A1900"> * This maemo code example is licensed under a MIT-style license,</font></span>''</span>
-
  * This maemo code example is licensed under a MIT-style license,
+
  <span>''<span><font color="#9A1900"> * that can be found in the file called "License" in the same</font></span>''</span>
-
  * that can be found in the file called "License" in the same
+
  <span>''<span><font color="#9A1900"> * directory as this file.</font></span>''</span>
-
  * directory as this file.
+
  <span>''<span><font color="#9A1900"> * Copyright (c) 2007-2008 Nokia Corporation. All rights reserved.</font></span>''</span>
-
  * Copyright (c) 2007-2008 Nokia Corporation. All rights reserved.
+
  <span>''<span><font color="#9A1900"> */</font></span>''</span>
-
  */
+
-
 
+
<span>'''<span><font color="#000080"><nowiki>#ifndef</nowiki></font></span>'''</span> INCLUDE_HELLO_API_H
-
#ifndef INCLUDE_HELLO_API_H
+
<span>'''<span><font color="#000080"><nowiki>#define</nowiki></font></span>'''</span> INCLUDE_HELLO_API_H
-
#define INCLUDE_HELLO_API_H
+
<span>''<span><font color="#9A1900">/* The above is protection against circular header inclusion. */</font></span>''</span>
-
/* The above is protection against circular header inclusion. */
+
-
 
+
<span>''<span><font color="#9A1900">/* Function to print out "Hello world!\n". */</font></span>''</span>
-
/* Function to print out "Hello world!\n". */
+
<span>'''<span><font color="#0000FF">extern</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">sayhello</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
-
extern void sayhello(void);
+
-
 
+
<span>'''<span><font color="#000080"><nowiki>#endif</nowiki></font></span>'''</span>
-
#endif
+
<span>''<span><font color="#9A1900">/* ifndef INCLUDE_HELLO_API_H */</font></span>''</span>
-
/* ifndef INCLUDE_HELLO_API_H */
+
</tt>
-
</source>
+
So, in effect, there is the main application in '''hello.c''', which uses a function that is implemented in '''hello_func.c''' and declared in '''hello_api.h'''. Building an application out of these files can be performed manually like this:
So, in effect, there is the main application in '''hello.c''', which uses a function that is implemented in '''hello_func.c''' and declared in '''hello_api.h'''. Building an application out of these files can be performed manually like this:
Line 127: Line 124:
The file describing this situation to make is as follows: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/Makefile simple-make-files/Makefile]
The file describing this situation to make is as follows: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/simple-make-files/Makefile simple-make-files/Makefile]
-
<source lang="make">
+
<tt><span>''<span><font color="#9A1900"><nowiki># define default target (first target = default)</nowiki></font></span>''</span>
-
# define default target (first target = default)
+
<span>''<span><font color="#9A1900"><nowiki># it depends on 'hello.o' (which will be created if necessary)</nowiki></font></span>''</span>
-
# it depends on 'hello.o' (which will be created if necessary)
+
<span>''<span><font color="#9A1900"><nowiki># and hello_func.o (same as hello.o)</nowiki></font></span>''</span>
-
# and hello_func.o (same as hello.o)
+
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
+
        gcc -Wall hello<span><font color="#990000">.</font></span>o hello_func<span><font color="#990000">.</font></span>o -o hello
-
        gcc -Wall hello.o hello_func.o -o hello
+
<span>''<span><font color="#9A1900"><nowiki># define hello.o target</nowiki></font></span>''</span>
-
# define hello.o target
+
<span>''<span><font color="#9A1900"><nowiki># it depends on hello.c (and is created from it)</nowiki></font></span>''</span>
-
# it depends on hello.c (and is created from it)
+
<span>''<span><font color="#9A1900"><nowiki># also depends on hello_api.h which would mean that</nowiki></font></span>''</span>
-
# also depends on hello_api.h which would mean that
+
<span>''<span><font color="#9A1900"><nowiki># changing the hello.h api would force make to rebuild</nowiki></font></span>''</span>
-
# changing the hello.h api would force make to rebuild
+
<span>''<span><font color="#9A1900"><nowiki># this target (hello.o).</nowiki></font></span>''</span>
-
# this target (hello.o).
+
<span>''<span><font color="#9A1900"><nowiki># gcc -c: compile only, do not link</nowiki></font></span>''</span>
-
# gcc -c: compile only, do not link
+
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
+
        gcc -Wall -c hello<span><font color="#990000">.</font></span>c -o hello<span><font color="#990000">.</font></span>o
-
        gcc -Wall -c hello.c -o hello.o
+
<span>''<span><font color="#9A1900"><nowiki># define hello_func.o target</nowiki></font></span>''</span>
-
# define hello_func.o target
+
<span>''<span><font color="#9A1900"><nowiki># it depends on hello_func.c (and is created from)</nowiki></font></span>''</span>
-
# it depends on hello_func.c (and is created from)
+
<span>''<span><font color="#9A1900"><nowiki># and hello_api.h (since that's its declaration)</nowiki></font></span>''</span>
-
# and hello_api.h (since that's its declaration)
+
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
+
        gcc -Wall -c hello_func<span><font color="#990000">.</font></span>c -o hello_func<span><font color="#990000">.</font></span>o
-
        gcc -Wall -c hello_func.c -o hello_func.o
+
<span>''<span><font color="#9A1900"><nowiki># </nowiki></font></span>''</span></tt>
-
#  
+
-
</source>
+
This file is in the simplest form without using any variables or relying on built-in magic in GNU make. Later it will be shown that the same rules can be written in a much shorter way.
This file is in the simplest form without using any variables or relying on built-in magic in GNU make. Later it will be shown that the same rules can be written in a much shorter way.

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: