A makefile template


The following is a template for the core of a makefile that uses selected parts of the gnu make conventions which I’ve been using more frequent.

SHELL = /bin/sh
.SUFFIXES:
.SUFFIXES: .c .o

#Package
pkg_name =
pkg_version = 1.0

CFLAGS = -g
ALL_CFLAGS = -I. $(CFLAGS)
CPPFLAGS =

INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = ${INSTALL} -m 644

#Two root variables for the installation
prefix = /usr/local
exec_prefix = $(prefix)

#Executable programs are installed in one
#of the following directories.
bindir = $(exec_prefix)/bin
sbindir = $(exec_prefix)/sbin
libexecdir = $(exec_prefix)/libexec/$(pkg_name)

#Data files are installed in one of
#the following directories.
datarootdir = $(prefix)/share
datadir = $(datarootdir)
sysconfdir = $(prefix)/etc
sharedstatedir = $(prefix)/com
localstatedir = $(prefix)/var

includedir = $(prefix)/include
oldincludedir = /usr/include
docdir = $(datarootdir)/doc/$(pkg_name)
libdir = $(exec_prefix)/lib
$(srcdir) =

#Targets for Users

#All is the default target.
#Purpose : to compile the entire program.
all:

#Install target.
#Purpose : to install the program.
#1) compile the program,
#2) copy the executables, libraries, and so on
#   to the file names where they should reside
#   for actual use and
#3) verify that a program is properly installed.
install: all

#Uninstall target.
#Purpose : to delete all the installed files,
#i.e. the copies that the ‘install’ and
#‘install-*’ targets create.
uninstall:

#Clean target.
#Purpose : to delete all files in the current
#directory (or created by this makefile) that
#are normally created by building the program.
#Don't delete the files that record the configuration.
clean:

#Distclean target.
#Purpose : to delete all files in the current
#directory (or created by this makefile) that
#are normally created by building or configuring
#the program. Only the files that were in the
#distribution should remain.
distclean: clean

#Dist target
#Purpose : to create a distribution tar file
#for this program.
#1) Create a subdirectory appropriately named
#   (e.g. $pkg-name)-$(pkg-version),
#2) install the proper files in it,
#3) tar that subdirectory and
#4) Compress the tar file e.g. with gzip.
dist:

#Check target.
#Purpose : to perform self-tests.
check: all

#Installcheck target.
#Purpose : to perform installation tests.
installcheck : all install

#Installdirs target.
#Purpose : to create the directories where
#files are installed, and their parent directories.
installdirs :