/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: 2009-03-05 14:26:08 UTC
  • Revision ID: edam@waxworlds.org-20090305142608-63gav9dxralm0mm8
Tags: 3.2
- added subprojects via SUBPROJS variable
- tweaked some comments

Show diffs side-by-side

added added

removed removed

2
2
#
3
3
#                       edam's general-purpose makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                    version 3.5
 
5
#                                                                    version 3.2
6
6
#
7
 
# Copyright (c) 2009 Tim Marston <edam@waxworlds.org>.
 
7
# Copyright (c) 2008 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 and documentation on it's use. The following
33
 
# text can only really be considered a reference to it's use.
 
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.
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".
78
76
#
79
77
# TARGET       The name of the target file.
80
78
#
86
84
#
87
85
# SUBDIRS      A list of subdirectories to build before attempting to build the
88
86
#              target. These subdirectories are also included in a clean_all.
89
 
#              Note that if the file 'emake.mk' exists in a subdirectory, it
90
 
#              will be used explicitly, rather than any default makefile.
91
87
#
92
88
# SUBPROJS     A list of the names of other makefiles to run before attempting
93
89
#              to build the target. This allows you to build multiple targets.
111
107
# subdirs      Goes through the list of specified subdirectories, changing to
112
108
#              them, and runs make there.
113
109
#
114
 
# subprojs     Goes through the list of specified subprojects, running the
 
110
# subproj      Goes through the list of specified subprojects, running the
115
111
#              makefiles for each of them.
116
112
#
117
113
# target       Builds the target of your Makefile.
119
115
# run          Builds the target of your Makefile and, if successful, runs it.
120
116
#              This is not available if you're building a library of some kind.
121
117
#
122
 
# debug        The same as the run goal, except instead of running the target,
123
 
#              it is debugged with gdb.
124
 
#
125
118
# clean        Deletes temporary files.
126
119
#
127
120
# clean_all    Deletes temporary files and then goes through then project's
160
153
MAKE            := make
161
154
 
162
155
# debug/profile build flags
163
 
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(if $(DEBUGMODE),\
164
 
        -g3 -D DEBUG -Wall -Wextra,-D NDEBUG -O2) $(CPPFLAGS)
165
 
CXXFLAGS        := $(if $(DEBUGMODE),-Woverloaded-virtual -Wreorder \
166
 
        -Wctor-dtor-privacy) $(CXXFLAGS)
 
156
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
 
157
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-D NDEBUG -O2) $(CPPFLAGS)
167
158
DFLAGS          := $(if $(DEBUGMODE),,-frelease)
168
159
ASFLAGS         := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-dNDEBUG -O2) $(ASFLAGS)
169
 
LDFLAGS         := $(if $(PROFILEMODE),-pg) \
170
 
        $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
 
160
LDFLAGS         := $(if $(PROFILEMODE),-pg) $(LDFLAGS)
 
161
LDFLAGS         := $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
171
162
 
172
163
# setup options for shared/static libs
173
 
CPPFLAGS        := $(if $(or $(MKSHAREDLIB),$(MKSTATICLIB)),-fPIC) $(CPPFLAGS)
 
164
CPPFLAGS        := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
174
165
LDFLAGS         := $(if $(LINKSTATIC),-static) $(LDFLAGS)
175
166
 
176
167
# add libraries for d
177
 
LIBRARIES       := $(LIBRARIES) $(if $(filter %.d, $(SOURCES)), gphobos2 rt)
 
168
LIBRARIES       := $(LIBRARIES) $(if $(filter %.d, $(SOURCES)), gphobos pthread m)
178
169
 
179
170
# build flags for libraries
180
171
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
181
172
 
 
173
#_______________________________________________________________________________
 
174
#
 
175
 
182
176
# object debug/profile suffix
183
177
BUILDSUFFIX     := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
184
178
 
192
186
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
193
187
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
194
188
TARGET          := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
195
 
ifndef NOLIBPREFIX
196
189
TARGET          := lib$(patsubst lib%,%,$(TARGET))
197
190
endif
198
191
endif
199
 
endif
200
192
 
201
193
# Set up dependency generation build flags and, for those languages where the
202
194
# the compiler/assembler doesn't support dependency generation, commands to be
227
219
#_______________________________________________________________________________
228
220
#                                                                          RULES
229
221
 
230
 
.PHONY: all subdirs subprojs target clean clean_all run debug depend dep \
231
 
        $(SUBDIRS) $(SUBPROJS)
 
222
.PHONY: all subdirs subprojs target clean clean_all run depend dep $(SUBDIRS) $(SUBPROJS)
232
223
 
233
224
all: subdirs subprojs target
234
225
 
245
236
                "subprojs as well"
246
237
endif
247
238
endif
248
 
        rm -f $(OBJECTS) $(TARGET) $(DEPFILES) core *~
 
239
        rm -f $(OBJECTS) $(TARGET) $(DEPFILES) core
249
240
 
250
241
clean_all: subdirs subprojs clean
251
242
 
253
244
ifndef MKSHAREDLIB
254
245
run: target
255
246
        ./$(TARGET)
256
 
 
257
 
debug: target
258
 
        gdb ./$(TARGET)
259
247
endif
260
248
endif
261
249
 
262
250
$(SUBDIRS) $(SUBPROJS):
263
251
        @if [ "$@" = "$(firstword $(SUBDIRS) $(SUBPROJS))" ]; then echo; fi
264
 
        @$(MAKE) $(if $(filter $@,$(SUBPROJS)), -f $@.mk, \
265
 
                -C $@ $(if $(wildcard $@/emake.mk),-f emake.mk,)) \
 
252
        @$(MAKE) $(if $(filter $@,$(SUBDIRS)),-C $@,-f $@.mk) \
266
253
                $(filter-out $(SUBDIRS) $(SUBPROJS) subdirs subprojs,$(MAKECMDGOALS))
267
254
        @echo
268
255