summaryrefslogtreecommitdiff
path: root/080_blog/00030_The-Hell-of-Autotools/index.md
blob: 746bd8265bc4229149fe7234c39323c362b54c62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
The Hell of Autotools
=====================
    March 19, 2018
In this trivial example we compile a custom **webkit2gtk+ extension** with 
**autotools**. For a start we need to  provide two files, `Makefile.am` 
and `configure.ac`, beside our actual `ext.c` source file, which contains 
the extension code itself.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.c .numberLines}
// File: ext.c //

#include <webkit2/webkit-web-extension.h>
 
G_MODULE_EXPORT void
webkit_web_extension_initialize_with_user_data (WebKitWebExtension *extension,
                                                GVariant           *user_data)
{
    g_print("Hello Extension!\n");
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.makefile .numberLines}
# File: Makefile.am #

webextension_LTLIBRARIES = libmyappwebextension.la
webextensiondir = /home/miguel/temp
 
WEB_EXTENSION_CFLAGS = `pkg-config --cflags webkit2gtk-web-extension-4.0`
WEB_EXTENSION_LIBS2 = `pkg-config --libs webkit2gtk-web-extension-4.0`
 
libmyappwebextension_la_SOURCES = ext.c
libmyappwebextension_la_CFLAGS = $(WEB_EXTENSION_CFLAGS)
libmyappwebextension_la_LIBADD = $(WEB_EXTENSION_LIBS)
libmyappwebextension_la_LDFLAGS = -module -avoid-version -no-undefined $(WEB_EXTENSION_LIBS2)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.makefile .numberLines}
# File: configure.ac #

AC_PREREQ([2.69])
AC_INIT(ext,0.1,test@example.com)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([ext.c])
AC_PROG_CC
LT_INIT
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Put the above files in a new fresh directory and you are ready to see the 
powers of autotools in action. 

Run the following commands on your pash prompt: 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash}
touch NEWS README AUTHORS ChangeLog
aclocal
autoconf
automake --add-missing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After this steps, we end up with 18 files in our directory. Finally we 
can _configure_, _build_ and _install_ our extension. The following 
commands will probably look familiar. Note that the _configure_ step 
generates 6 additional files, totaling in **24 files** before the actual 
_make_ command is run.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash}
./configure 
make
make install
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

... just to compile one **single C file**.