Using The AutoTools(Scripts)

Submitted by maslan on Fri, 15/10/2004 - 14:07.
( categories: Howtos )

Using The AutoTools

If you think one day to start programming on linux, sure you will use C language (not me, i will always use assembly), but when your program sources get biggers as its version increase or you want to publish its source code, how users gonna to use it, are they gonna to compile every source file separetely then link them all together, no it's a bad idea and very handy, you will have to use the autoscripts.

In this article i will describe how to use the autoscripts for your own program sources, so i will write a simple C sourcefile to show you how to use the autoscripts(autoheader,automake,autoconf).

Remark :

when you a compile a program from source you should have done this :

./configure make make install

That's what the autoscripts we gonna make.

I will use emacs in this article, but your free to use any text editor even pico.

Let's start by creating directories which will contain the source files, assume our program name is "ctest" , type the following in a bash prompt :

mkdir ctest cd ctest mkdir src cd src emacs main.c /* this is a sample C source to test autoscript */ #include #include #include "ctest.h" int main(void) { printf("Programming In Assembly Is The Best \n"); return 0; }

Save it like that : press f10 then f then s then f10 then f then e .

emacs ctest.h /* This is a sample header to test autoscripts */ #define _WHO_AM_I "Hacker" #define _WHO_IS_MASLAN "Assembler"

Save it like that : press f10 then f then s then f10 then f then e .

now we have finished writing our program source files, so we gonna to create the compiling and installing script as follows.

emacs Makefile.am bin_PROGRAMS = ctest ctest_SOURCES = main.c ctest.h

Save it like that : press f10 then f then s then f10 then f then e .

we have created a file containing our program name "ctest" and our sources names "main.c , ctest.h", this file is used by automake.

cd.. emacs Makefile.am SUBDIRS = src

Save it like that : press f10 then f then s then f10 then f then e .

we have just created another automake file which points to our src directory, in case if your program have more than source directory or have "po" subdirectory which contains other languages interface for your program.

emacs configure.in AC_INIT(src/main.c) AM_INIT_AUTOMAKE(ctest,0.0.1) AM_CONFIG_HEADER(config.h) AC_OUTPUT([ Makefile src/Makefile ])

Save it like that : press f10 then f then s then f10 then f then e .

We have created a file used by autoconf, which will be used to generate ./configure script, which will create Makefile used by make.

now we have everything done, just type the following :

aclocal autoheader autoconf automake --add-missing

You can test if it works , like that :

./configure make cd src ./ctest Programming In Assembly Is The Best

I prefer to strip it in order to save space.

strip ctest ./ctest Programming In Assembly Is The Best


Reply





*

  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <ul> <pre> <blockquote> <img> <ins> <del> <br> <div> <span> <em> <h1> <h2> <h3> <h4> <h5> <h6> <code> <p> <hr>
  • You can insert tables with comma separated values (CSV) into the text, they will be automatically converted to appropriate HTML-tables.
  • You may link to images on this site using a special syntax
  • You can embed nodes within other nodes using the following syntax:
    [node:node_id,param_1="val1",param_2="val2"]
  • You may write mixed Arabic and English freely, line direction will be computed automaticaly
  • Glossary terms will be automatically marked with links to their descriptions