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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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 :
This entry was posted in Software and tagged , . Bookmark the permalink.