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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
hello_world example for the ACR
===============================
Introduction:
-------------
As you knows after read the ../README file. ACR is an autotools replacement.
This tool allows developers to create portable and lightweight 'configure'
scripts in a lightweight way.
Configure script allows end-users and developers to check what libs are
installed on the system, allowing the user to choose between different
options and prepare all scripts and Makefiles to build the target package
with the chosen options.
The Hello World:
----------------
The most faster way to understand how acr works is creating a simple program
like this hello.c:
----8<------
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello World!\n");
return 0;
}
---->8------
Ok, now we have our powerful hello world program created.
The first thing you must think about is what kind of requirements will your
program need...
- C compiler
- stdio.h
- printf function
In a second term we can add new flags to the configure script to allow
end-users to modify some functionality of our program like:
- disable message output
- build it statically
- etc..
Creating the configuration file
-------------------------------
It's recommended to read the doc/syntax and doc/keywords files to understand
all ACR commands, possibilities and syntax.
Now we create this file called 'configure.acr':
-----8<------------
PKGNAME helloworld
VERSION 1.0
LANG_C! // we need a C compiler \\
// check for includes and libraries \\
CHKINC! stdio.h
CHKLIB! c printf
// Makefiles \\
CHECK_PROG INSTALL install
SUBDIRS . ;
----->8------------
Ok, Now that looks fine.
Generating the ./configure script
---------------------------------
That's the most easy tip of the tutorial =)
Just type "acr" and ./configure script will be generated.
$ acr
acr: ./configure script created successfully.
$ ls
configure configure.acr hello.c
$
Creating the Makefile
---------------------
All above work must be joined into the Makefiles that will build and install
our program.
Now we have to create a Makefile prototype. A file used by 'configure' to
create the final Makefile.
ACR can filter Makefiles and simple plain text files, by now, we only need
to filter a Makefile. Then we will use "SUBDIRS" command to tell ACR what
directories must find for Makefile.acr files.
For this reason out 'configure.acr' file has the 'SUBDIRS . ;' line.
Our Makefile will use the @VAR@ syntax like autotools does.
Let's see how Makefile.acr looks like:
---------8<---------------
all:
@CC@ hello.c -o hello
install:
mkdir -p @PREFIX@/bin
@INSTALL@ hello @PREFIX@/bin/hello
clean:
rm -f hello Makefile
-------->8----------------
Testing
-------
Everything is done now. We can test that.
$ ls
Makefile.acr configure configure.acr hello.c
$ ./configure --prefix=/tmp/hello/
checking build system type... i686-unknown-linux
checking host system type... i686-unknown-linux
checking target system type... i686-unknown-linux
checking for c compiler... gcc
checking for cpp... cpp
checking library c : printf()... yes
checking for stdio.h... yes
checking for install... /usr/bin/install
configure: (tags) filtering ./Makefile.acr
cleaning temporally files... done
$ make
gcc hello.c -o hello
$ make install
mkdir -p /tmp/hello/bin
/usr/bin/install hello /tmp/hello/bin/hello
That's all... easy no? :)
|