/make/edam-mk

To get this branch, use:
bzr branch http://bzr.ed.am/make/edam-mk

« back to all changes in this revision

Viewing changes to edam.mk

  • Committer: edam
  • Date: 2010-02-02 15:50:53 UTC
  • Revision ID: edam@waxworlds.org-20100202155053-pzlmflt7vq1q9ya9
- a file names 'subdir.mk' in subdirectories mentioned in the SUBDIRS variable is now explicitly used during the making the subdirectory, if it is present
- used line breaks for long lines, rather than multiple variable definitions
- added extra warnings for C++ compilation
- create position independant code in static libs as well as shared
- also clean *~ files

Show diffs side-by-side

added added

removed removed

2
2
#
3
3
#                       edam's general-purpose makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                    version 3.0
6
 
# Copyright (c) 2008 Tim Marston <edam@waxworlds.org>.
 
5
#                                                                    version 3.4
 
6
#
 
7
# Copyright (c) 2009 Tim Marston <edam@waxworlds.org>.
7
8
#
8
9
# Permission is hereby granted, free of charge, to any person obtaining a copy
9
10
# of this software and associated documentation files (the "Software"), to deal
22
23
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
24
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
25
# THE SOFTWARE.
 
26
#
25
27
#_______________________________________________________________________________
26
28
#
27
29
#
28
30
# This is a general-purpose makefile for use with GNU make. It can be downloaded
29
31
# from http://www.waxworlds.org/edam/software/general-purpose-makefile where you
30
 
# might also find more information/documentation on it's use. The following text
31
 
# can only really be considered a reference to it's use.
 
32
# can also find more information and documentation on it's use. The following
 
33
# text can only really be considered a reference to it's use.
32
34
#
33
35
# To use this makefile, put a file named "Makefile" in your project directory.
34
36
# Add all your project's settings to your Makefile and then include this file
71
73
# MKSHAREDLIB  Boolean. Target type: Set to build a shared library target. If
72
74
#              neither this nor MKSTATICLIB are set, the target defaults to a
73
75
#              binary executable.
 
76
# NOLIBPREFIX  Boolean. When building a static or shared library, do not ensure
 
77
#              that the target's name is prefixed with "lib".
74
78
#
75
79
# TARGET       The name of the target file.
76
80
#
82
86
#
83
87
# SUBDIRS      A list of subdirectories to build before attempting to build the
84
88
#              target. These subdirectories are also included in a clean_all.
 
89
#              Note that if the file 'subdir.mk' exists in a subdirectory, it
 
90
#              will be used explicitly, rather than any default makefile.
 
91
#
 
92
# SUBPROJS     A list of the names of other makefiles to run before attempting
 
93
#              to build the target. This allows you to build multiple targets.
 
94
#              Note that ".mk" is appended to the subproject names. These
 
95
#              subprojects are also included in a clean_all.
85
96
#
86
97
# CPPFLAGS     Flags to give to the C and C++ compilers
87
98
# CFLAGS       Flags to give to the C compiler
95
106
# command line when you run make:
96
107
#
97
108
# all          This is the default if no goal is specified. It builds subdirs
98
 
#              first and then the target.
99
 
#
100
 
# subdirs      Changes to the subdirectories specified for the project and runs
101
 
#              make in them.
 
109
#              and subprojects first and then the target.
 
110
#
 
111
# subdirs      Goes through the list of specified subdirectories, changing to
 
112
#              them, and runs make there.
 
113
#
 
114
# subprojs     Goes through the list of specified subprojects, running the
 
115
#              makefiles for each of them.
102
116
#
103
117
# target       Builds the target of your Makefile.
104
118
#
113
127
# <subdir>     Builds the specified subdirectory from those that are listed for
114
128
#              the project.
115
129
#
 
130
# <subproj>    Builds the specified subproject from those listed for the
 
131
#              project.
 
132
#
116
133
# <file>       Builds the specified file, either an object file or the target,
117
134
#              from those that that would be built for the project.
118
135
#
120
137
#
121
138
# Known shortcommings:
122
139
# - Using C is probably broken because g++ is currently used for linking. We
123
 
#   should switch to ld and specify the correct crt as required by source files.
124
 
# - Currently can only specify one target. If we could specify several targets
125
 
#   though, we'd need separate sources, libraries and build params for each!
 
140
#   should be using ld and specifying the crt libs as required by the sources.
126
141
#
127
142
#_______________________________________________________________________________
128
143
#
142
157
MAKE            := make
143
158
 
144
159
# debug/profile build flags
145
 
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
146
 
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-D NDEBUG -O2) $(CPPFLAGS)
 
160
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(if $(DEBUGMODE),\
 
161
        -g -D DEBUG -Wall -Wextra,-D NDEBUG -O2) $(CPPFLAGS)
 
162
CXXFLAGS        := $(if $(DEBUGMODE),-Woverloaded-virtual -Wreorder \
 
163
        -Wctor-dtor-privacy) $(CXXFLAGS)
147
164
DFLAGS          := $(if $(DEBUGMODE),,-frelease)
148
165
ASFLAGS         := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-dNDEBUG -O2) $(ASFLAGS)
149
 
LDFLAGS         := $(if $(PROFILEMODE),-pg) $(LDFLAGS)
150
 
LDFLAGS         := $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
 
166
LDFLAGS         := $(if $(PROFILEMODE),-pg) \
 
167
        $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
151
168
 
152
169
# setup options for shared/static libs
153
 
CPPFLAGS        := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
 
170
CPPFLAGS        := $(if $(or $(MKSHAREDLIB),$(MKSTATICLIB)),-fPIC) $(CPPFLAGS)
154
171
LDFLAGS         := $(if $(LINKSTATIC),-static) $(LDFLAGS)
155
172
 
156
173
# add libraries for d
159
176
# build flags for libraries
160
177
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
161
178
 
162
 
#_______________________________________________________________________________
163
 
#
164
 
 
165
179
# object debug/profile suffix
166
180
BUILDSUFFIX     := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
167
181
 
175
189
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
176
190
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
177
191
TARGET          := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
 
192
ifndef NOLIBPREFIX
178
193
TARGET          := lib$(patsubst lib%,%,$(TARGET))
179
194
endif
180
195
endif
 
196
endif
181
197
 
182
198
# Set up dependency generation build flags and, for those languages where the
183
199
# the compiler/assembler doesn't support dependency generation, commands to be
208
224
#_______________________________________________________________________________
209
225
#                                                                          RULES
210
226
 
211
 
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
 
227
.PHONY: all subdirs subprojs target clean clean_all run depend dep \
 
228
        $(SUBDIRS) $(SUBPROJS)
212
229
 
213
 
all: subdirs target
 
230
all: subdirs subprojs target
214
231
 
215
232
subdirs: $(SUBDIRS)
216
233
 
 
234
subprojs: $(SUBPROJS)
 
235
 
217
236
target: $(TARGET)
218
237
 
219
238
clean:
220
 
ifdef SUBDIRS
 
239
ifneq ($(or $(SUBDIRS),$(SUBPROJS)),)
221
240
ifneq "$(MAKECMDGOALS)" "clean_all"
222
 
        @echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
223
 
endif
224
 
endif
225
 
        rm -f $(OBJECTS) $(TARGET) *.dep core
 
241
        @echo "NOT RECURSING - use 'make clean_all' to clean subdirs and " \
 
242
                "subprojs as well"
 
243
endif
 
244
endif
 
245
        rm -f $(OBJECTS) $(TARGET) $(DEPFILES) core *~
226
246
 
227
 
clean_all: subdirs clean
 
247
clean_all: subdirs subprojs clean
228
248
 
229
249
ifndef MKSTATICLIB
230
250
ifndef MKSHAREDLIB
233
253
endif
234
254
endif
235
255
 
236
 
$(SUBDIRS):
237
 
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
238
 
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
 
256
$(SUBDIRS) $(SUBPROJS):
 
257
        @if [ "$@" = "$(firstword $(SUBDIRS) $(SUBPROJS))" ]; then echo; fi
 
258
        @$(MAKE) $(if $(filter $@,$(SUBPROJS)), -f $@.mk, \
 
259
                -C $@ $(if $(wildcard $@/subdir.mk),-f subdir.mk,)) \
 
260
                $(filter-out $(SUBDIRS) $(SUBPROJS) subdirs subprojs,$(MAKECMDGOALS))
239
261
        @echo
240
262
 
241
263
$(TARGET): $(OBJECTS)
242
264
ifdef MKSTATICLIB
243
265
        $(AR) rcs $(TARGET) $(OBJECTS)
244
266
else
245
 
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS) 
 
267
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS)
246
268
endif
247
269
 
248
270
%.o %_d.o %_p.o: %.c