configure.info: Getting Started Example 1
Go forward to Getting Started Example 2
Go up to Getting Started Example
Go to the top op configure
First Try
Here is our first try at `poke.c'. Note that we've written it
without ANSI/ISO C prototypes, since we want it to be highly portable.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <utime.h>
int
main (argc, argv)
int argc;
char **argv;
{
if (argc != 2)
{
fprintf (stderr, "Usage: poke file\n");
exit (1);
}
if (utime (argv[1], NULL) < 0)
{
perror ("utime");
exit (1);
}
exit (0);
}
We also write a simple `Makefile'.
CC = gcc
CFLAGS = -g -O2
all: poke
poke: poke.o
$(CC) -o poke $(CFLAGS) $(LDFLAGS) poke.o
So far, so good.
Unfortunately, there are a few problems.
On older Unix systems derived from BSD 4.3, the `utime' system call
does not accept a second argument of `NULL'. On those systems, we need
to pass a pointer to `struct utimbuf' structure. Unfortunately, even
older systems don't define that structure; on those systems, we need to
pass an array of two `long' values.
The header file `stdlib.h' was invented by ANSI C, and older systems
don't have a copy. We included it above to get a declaration of `exit'.
We can find some of these portability problems by running
`autoscan', which will create a `configure.scan' file which we can use
as a prototype for our `configure.in' file. I won't show the output,
but it will notice the potential problems with `utime' and `stdlib.h'.
In our `Makefile', we don't provide any way to install the program.
This doesn't matter much for such a simple example, but a real program
will need an `install' target. For that matter, we will also want a
`clean' target.
Created Wed Sep 1 16:41:59 2004 on bee with info_to_html version 0.9.6.