1############################################################################
2#
3#              Another Programmer's Editor Makefile Template
4#
5# This is a template Makefile for a simple C or C++ program.
6# It is meant to serve as a starting point for creating a portable
7# Makefile, suitable for use under ports systems like *BSD ports,
8# MacPorts, Gentoo Portage, etc.  It contains examples of most common
9# Makefile components you will need.
10#
11# For most small projects, you should be able to create a usable
12# Makefile from this template by assigning the appropriate values
13# to variables like BIN1, LIB1, etc., and removing everything you
14# don't need.
15#
16# For more complex projects, start with the advanced Makefile.
17#
18# Variables that are conditionally assigned (with ?=) can be overridden
19# on the command line as follows:
20#
21#       make VAR=value
22#
23# They can also inheret values from parent Makefiles (as in *BSD ports).
24# This allows different systems to use the Makefile without modifications.
25# For example, MacPorts installs to /opt/local instead of /usr/local,
26# and hence might use the following:
27#
28#       make PREFIX=/opt/local
29#
30# Lastly, they can be overridden by the environment.  I like to add -Wall
31# to my CFLAGS for development, without having to put it in the Makefile,
32# since it's a gcc specific flag.  Hence, I have the following in my
33# .cshrc on gcc-based systems (BSD, Linux, Mac OS X):
34#
35#       setenv CFLAGS "-O -Wall -pipe"
36#
37# Different systems may also use different compilers and keep libraries in
38# different locations:
39#
40#       make CC=gcc CFLAGS=-O2 LDFLAGS1="-L/usr/X11R6 -lX11"
41#
42# Variables can also be appended in the Makefile (with +=), so that
43# flags specified on the command line can be combined with those in
44# the Makefile.
45############################################################################
46
47############################################################################
48# Executable
49
50BIN     = mst-bench
51MAN     = mst-bench.1
52
53############################################################################
54# List object files that comprise BIN.
55
56OBJS    = mst-bench.o
57
58############################################################################
59# Compile, link, and install options
60
61# Install in /usr/local, unless defined by the parent Makefile, the
62# environment, or a command line option such as PREFIX=/opt/local.
63PREFIX      ?= ../local
64MANPREFIX   ?= ${PREFIX}
65MANDIR      ?= ${MANPREFIX}/man
66
67# Where to find local libraries and headers.  For MacPorts, override
68# with "make LOCALBASE=/opt/local"
69LOCALBASE   ?= ${PREFIX}
70
71############################################################################
72# Build flags
73# Override with "make CC=gcc", "make CC=icc", etc.
74# Do not add non-portable options (such as -Wall) using +=
75
76# Portable defaults.  Can be overridden by mk.conf or command line.
77CC          ?= cc
78LD          = ${CC}
79
80# Use optimizer to reflect the way people really use a compiler
81CFLAGS      = -O
82
83############################################################################
84# Assume first command in PATH.  Override with full pathnames if necessary.
85# E.g. "make INSTALL=/usr/local/bin/ginstall"
86# Do not place flags here (e.g. RM = rm -f).  Just provide the command
87# and let each usage dictate the flags.
88
89MKDIR   ?= mkdir
90INSTALL ?= install
91LN      ?= ln
92RM      ?= rm
93AR      ?= ar
94PRINTF  ?= printf
95
96############################################################################
97# Standard targets required by ports
98
99all:    ${BIN}
100
101# Link rules
102${BIN}: ${OBJS}
103	${LD} -o ${BIN} ${OBJS} ${LDFLAGS}
104
105############################################################################
106# Include dependencies generated by "make depend", if they exist.
107# These rules explicitly list dependencies for each object file.
108# See "depend" target below.  If Makefile.depend does not exist, use
109# generic source compile rules.  These have some limitations, so you
110# may prefer to create explicit rules for each target file.  This can
111# be done automatically using "cpp -M" or "cpp -MM".  Run "man cpp"
112# for more information, or see the "depend" target below.
113
114mst-bench.o: mst-bench.c protos.h Makefile
115	${CC} -c ${CFLAGS} -DCOMPILER="\"${CC}\"" mst-bench.c
116
117############################################################################
118# Remove generated files (objs and nroff output from man pages)
119
120clean:
121	rm -f ${OBJS} ${BIN} *.nr *.tempfile
122
123# Keep backup files during normal clean, but provide an option to remove them
124realclean: clean
125	rm -f .*.bak *.bak *.BAK *.gmon core *.core
126
127proto:
128	cproto ${INCLUDES} *.c > protos.h
129
130############################################################################
131# Install all target files (binaries, libraries, docs, etc.)
132
133install: all
134	${MKDIR} -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANDIR}/man1
135	${INSTALL} -s -m 0555 ${BIN} ${DESTDIR}${PREFIX}/bin
136	${INSTALL} -m 0444 ${MAN} ${DESTDIR}${MANDIR}/man1
137