Go to the previous, next section.
Things are much easier if you are writing a brand new program. It would be nice if the `autoconf' distribution or the GNU coding standards were shipped with a template for `Makefile.in', so you could just fill in the blanks. (Note that there is no need for `configure.in' or `config.h.in' templates, since `autoscan' and `autoheader' make those.)
I will provide the beginnings of a `Makefile.in' template here. I have marked with my usual ??? code the parts you will want to modify, or where you will need to add your own files.
# Main Makefile for Mark Galassi's stupid "marklib" library
# Copyright (C) 1996 Mark Galassi.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
SHELL = /bin/sh
top_srcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
.SUFFIXES:
.SUFFIXES: .c .o
OPT=-g -O
AR = ar
AR_FLAGS = rc
RANLIB = @RANLIB@
CC = @CC@
CFLAGS = -I. @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
INSTALL = @INSTALL@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = $(exec_prefix)/bin
libdir = $(prefix)/lib
infodir = $(prefix)/info
# ??? replace these with your own list of files
SOURCES=file1.c file2.c ...
DOCS=PROG.texi PROG.info
MISC=configure mkinstalldirs install-sh aclocal.m4
OBJS=file1.o file2.o ...
LIB_OBJS=libf1.o libf2.o ...
# ??? replace with your targets
all: libMYPROG.a PROG PROG.info
# ??? here I make the bindir, libdir and infodir directories; you
# might not need all of these. also, I assumed the names PROG and
# libMYPROG.a for the program and library.
install: all
$(top_srcdir)/mkinstalldirs $(bindir)
$(top_srcdir)/mkinstalldirs $(libdir)
$(top_srcdir)/mkinstalldirs $(infodir)
$(INSTALL) PROG $(bindir)/PROG
$(INSTALL) libMYPROG.a $(libdir)/libMYPROG.a
$(INSTALL) PROG.info $(infodir)/PROG.info
uninstall:
/bin/rm -f $(bindir)/PROG
/bin/rm -f $(libdir)/libMYPROG.a
/bin/rm -f $(infodir)/PROG.info
libMYPROG.a: $(OBJS)
/bin/rm -f libMYPROG.a
$(AR) $(AR_FLAGS) libMYPROG.a $(LIB_OBJS)
$(RANLIB) libMYPROG.a
PROG: $(OBJS) libMYPROG.a
$(CC) $(CFLAGS) -o PROG $(OBJS) $(LIBS)
clean:
/bin/rm -f core *.o $(OBJS) $(LIB_OBJS) libMYPROG.a
distclean: clean
/bin/rm -f Makefile config.h config.status config.cache config.log \
marklib.dvi
mostlyclean: clean
maintainer-clean: clean
PROG.info: PROG.texi
makeinfo PROG.texi
# automatic re-running of configure if the ocnfigure.in file has changed
${srcdir}/configure: configure.in aclocal.m4
cd ${srcdir} && autoconf
# autoheader might not change config.h.in, so touch a stamp file
${srcdir}/config.h.in: stamp-h.in
${srcdir}/stamp-h.in: configure.in aclocal.m4
cd ${srcdir} && autoheader
echo timestamp > ${srcdir}/stamp-h.in
config.h: stamp-h
stamp-h: config.h.in config.status
./config.status
Makefile: Makefile.in config.status
./config.status
config.status: configure
./config.status --recheck
I must build up a hello world style program here so that I can give a few more concrete examples. The program should ideally have a library, a texinfo file, an executable and a `.h' file.
Go to the previous, next section.