source:forever.h forever.cpp(from qt/examples)
the Makefile:

CC= g++
INCL= -I$(QTDIR)/include
CFLAGS= -Wall -O
LFLAGS= -L$(QTDIR)/lib -L/usr/X11R6/lib
LIBS= -lqt -lX11

all: forever

forever: forever.o forever.moc.o
$(CC) $(LFLAGS) -o $@ $^ $(LIBS)

forever.o: forever.cpp forever.h

forever.moc.cpp: forever.h
$(QTDIR)/bin/moc forever.h -o $@

clean:
rm -f forever
rm -f *.o
rm -f .moc.cpp

.SUFFIXES: .cpp

.cpp.o:
$(CC) $(CFLAGS) $(INCL) -c $< -o $@

Let’s take a look at the contents of the user-provided input files that are relevant to this minimal project. Here is the `Makefile.am’:

bin_PROGRAMS = foonly
foonly_SOURCES = main.c foo.c foo.h nly.c scanner.l parser.y
foonly_LDADD = @LEXLIB@

This `Makefile.am’ specifies that we want a program called `foonly’ to be built and installed in the `bin’ directory when make install is run. The source files that are used to build `foonly’ are the C source files `main.c’, `foo.c’, `nly.c’ and `foo.h’, the lex program in `scanner.l’ and a yacc grammar in `parser.y’. This points out a particularly nice aspect about Automake: because lex and yacc both generate intermediate C programs from their input files, Automake knows how to build such intermediate files and link them into the final executable. Finally, we must remember to link a suitable lex library, if `configure’ concludes that one is needed.

And here is the `configure.in’:

dnl Process this file with autoconf to produce a configure script.
AC_INIT(main.c)
AM_INIT_AUTOMAKE(foonly, 1.0)
AC_PROG_CC
AM_PROG_LEX
AC_PROG_YACC
AC_OUTPUT(Makefile)

This `configure.in’ invokes some mandatory Autoconf and Automake initialization macros, and then calls on some Autoconf macros from the AC_PROG family to find suitable C compiler, lex, and yacc programs. Finally, the AC_OUTPUT macro is used to cause the generated `configure’ script to output a `Makefile’—but from what? It is processed from `Makefile.in’, which Automake produces for you based on your `Makefile.am’ (see section C. Generated File Dependencies).


评论

该日志第一篇评论

发表评论

评论也有版权!