/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.2
 
5
#                                                                    version 3.4
6
6
#
7
 
# Copyright (c) 2008 Tim Marston <edam@waxworlds.org>.
 
7
# Copyright (c) 2009 Tim Marston <edam@waxworlds.org>.
8
8
#
9
9
# Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
# of this software and associated documentation files (the "Software"), to deal
29
29
#
30
30
# This is a general-purpose makefile for use with GNU make. It can be downloaded
31
31
# from http://www.waxworlds.org/edam/software/general-purpose-makefile where you
32
 
# can also find more information/documentation on it's use. The following text
33
 
# 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.
34
34
#
35
35
# To use this makefile, put a file named "Makefile" in your project directory.
36
36
# Add all your project's settings to your Makefile and then include this file
73
73
# MKSHAREDLIB  Boolean. Target type: Set to build a shared library target. If
74
74
#              neither this nor MKSTATICLIB are set, the target defaults to a
75
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".
76
78
#
77
79
# TARGET       The name of the target file.
78
80
#
84
86
#
85
87
# SUBDIRS      A list of subdirectories to build before attempting to build the
86
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.
87
91
#
88
92
# SUBPROJS     A list of the names of other makefiles to run before attempting
89
93
#              to build the target. This allows you to build multiple targets.
107
111
# subdirs      Goes through the list of specified subdirectories, changing to
108
112
#              them, and runs make there.
109
113
#
110
 
# subproj      Goes through the list of specified subprojects, running the
 
114
# subprojs     Goes through the list of specified subprojects, running the
111
115
#              makefiles for each of them.
112
116
#
113
117
# target       Builds the target of your Makefile.
153
157
MAKE            := make
154
158
 
155
159
# debug/profile build flags
156
 
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
157
 
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)
158
164
DFLAGS          := $(if $(DEBUGMODE),,-frelease)
159
165
ASFLAGS         := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-dNDEBUG -O2) $(ASFLAGS)
160
 
LDFLAGS         := $(if $(PROFILEMODE),-pg) $(LDFLAGS)
161
 
LDFLAGS         := $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
 
166
LDFLAGS         := $(if $(PROFILEMODE),-pg) \
 
167
        $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
162
168
 
163
169
# setup options for shared/static libs
164
 
CPPFLAGS        := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
 
170
CPPFLAGS        := $(if $(or $(MKSHAREDLIB),$(MKSTATICLIB)),-fPIC) $(CPPFLAGS)
165
171
LDFLAGS         := $(if $(LINKSTATIC),-static) $(LDFLAGS)
166
172
 
167
173
# add libraries for d
170
176
# build flags for libraries
171
177
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
172
178
 
173
 
#_______________________________________________________________________________
174
 
#
175
 
 
176
179
# object debug/profile suffix
177
180
BUILDSUFFIX     := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
178
181
 
186
189
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
187
190
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
188
191
TARGET          := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
 
192
ifndef NOLIBPREFIX
189
193
TARGET          := lib$(patsubst lib%,%,$(TARGET))
190
194
endif
191
195
endif
 
196
endif
192
197
 
193
198
# Set up dependency generation build flags and, for those languages where the
194
199
# the compiler/assembler doesn't support dependency generation, commands to be
219
224
#_______________________________________________________________________________
220
225
#                                                                          RULES
221
226
 
222
 
.PHONY: all subdirs subprojs target clean clean_all run depend dep $(SUBDIRS) $(SUBPROJS)
 
227
.PHONY: all subdirs subprojs target clean clean_all run depend dep \
 
228
        $(SUBDIRS) $(SUBPROJS)
223
229
 
224
230
all: subdirs subprojs target
225
231
 
236
242
                "subprojs as well"
237
243
endif
238
244
endif
239
 
        rm -f $(OBJECTS) $(TARGET) $(DEPFILES) core
 
245
        rm -f $(OBJECTS) $(TARGET) $(DEPFILES) core *~
240
246
 
241
247
clean_all: subdirs subprojs clean
242
248
 
249
255
 
250
256
$(SUBDIRS) $(SUBPROJS):
251
257
        @if [ "$@" = "$(firstword $(SUBDIRS) $(SUBPROJS))" ]; then echo; fi
252
 
        @$(MAKE) $(if $(filter $@,$(SUBDIRS)),-C $@,-f $@.mk) \
 
258
        @$(MAKE) $(if $(filter $@,$(SUBPROJS)), -f $@.mk, \
 
259
                -C $@ $(if $(wildcard $@/subdir.mk),-f subdir.mk,)) \
253
260
                $(filter-out $(SUBDIRS) $(SUBPROJS) subdirs subprojs,$(MAKECMDGOALS))
254
261
        @echo
255
262