/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:01:29 UTC
  • Revision ID: edam@waxworlds.org-20090305140129-ykjca5rvvfggzwjt
Tags: 3.0
- renamed to edam.mk; makefile should now be included rather than duplicated and modified
- added documentation comments and a disclaimer
- removed settings that should now be specified in a separaet Makefile before including edam.mk

Show diffs side-by-side

added added

removed removed

2
2
#
3
3
#                       edam's general-purpose makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                    version 3.3
6
 
#
7
 
# Copyright (c) 2009 Tim Marston <edam@waxworlds.org>.
 
5
#                                                                    version 3.0
 
6
# Copyright (c) 2008 Tim Marston <edam@waxworlds.org>.
8
7
#
9
8
# Permission is hereby granted, free of charge, to any person obtaining a copy
10
9
# of this software and associated documentation files (the "Software"), to deal
23
22
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
23
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
24
# THE SOFTWARE.
26
 
#
27
25
#_______________________________________________________________________________
28
26
#
29
27
#
30
28
# This is a general-purpose makefile for use with GNU make. It can be downloaded
31
29
# 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
 
30
# might also find more information/documentation on it's use. The following text
33
31
# can only really be considered a reference to it's use.
34
32
#
35
33
# To use this makefile, put a file named "Makefile" in your project directory.
73
71
# MKSHAREDLIB  Boolean. Target type: Set to build a shared library target. If
74
72
#              neither this nor MKSTATICLIB are set, the target defaults to a
75
73
#              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
74
#
79
75
# TARGET       The name of the target file.
80
76
#
87
83
# SUBDIRS      A list of subdirectories to build before attempting to build the
88
84
#              target. These subdirectories are also included in a clean_all.
89
85
#
90
 
# SUBPROJS     A list of the names of other makefiles to run before attempting
91
 
#              to build the target. This allows you to build multiple targets.
92
 
#              Note that ".mk" is appended to the subproject names. These
93
 
#              subprojects are also included in a clean_all.
94
 
#
95
86
# CPPFLAGS     Flags to give to the C and C++ compilers
96
87
# CFLAGS       Flags to give to the C compiler
97
88
# CXXFLAGS     Flags to give to the C++ compiler
104
95
# command line when you run make:
105
96
#
106
97
# all          This is the default if no goal is specified. It builds subdirs
107
 
#              and subprojects first and then the target.
108
 
#
109
 
# subdirs      Goes through the list of specified subdirectories, changing to
110
 
#              them, and runs make there.
111
 
#
112
 
# subprojs     Goes through the list of specified subprojects, running the
113
 
#              makefiles for each of them.
 
98
#              first and then the target.
 
99
#
 
100
# subdirs      Changes to the subdirectories specified for the project and runs
 
101
#              make in them.
114
102
#
115
103
# target       Builds the target of your Makefile.
116
104
#
125
113
# <subdir>     Builds the specified subdirectory from those that are listed for
126
114
#              the project.
127
115
#
128
 
# <subproj>    Builds the specified subproject from those listed for the
129
 
#              project.
130
 
#
131
116
# <file>       Builds the specified file, either an object file or the target,
132
117
#              from those that that would be built for the project.
133
118
#
135
120
#
136
121
# Known shortcommings:
137
122
# - Using C is probably broken because g++ is currently used for linking. We
138
 
#   should be using ld and specifying the crt libs as required by the sources.
 
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!
139
126
#
140
127
#_______________________________________________________________________________
141
128
#
188
175
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
189
176
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
190
177
TARGET          := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
191
 
ifndef NOLIBPREFIX
192
178
TARGET          := lib$(patsubst lib%,%,$(TARGET))
193
179
endif
194
180
endif
195
 
endif
196
181
 
197
182
# Set up dependency generation build flags and, for those languages where the
198
183
# the compiler/assembler doesn't support dependency generation, commands to be
223
208
#_______________________________________________________________________________
224
209
#                                                                          RULES
225
210
 
226
 
.PHONY: all subdirs subprojs target clean clean_all run depend dep $(SUBDIRS) $(SUBPROJS)
 
211
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
227
212
 
228
 
all: subdirs subprojs target
 
213
all: subdirs target
229
214
 
230
215
subdirs: $(SUBDIRS)
231
216
 
232
 
subprojs: $(SUBPROJS)
233
 
 
234
217
target: $(TARGET)
235
218
 
236
219
clean:
237
 
ifneq ($(or $(SUBDIRS),$(SUBPROJS)),)
 
220
ifdef SUBDIRS
238
221
ifneq "$(MAKECMDGOALS)" "clean_all"
239
 
        @echo "NOT RECURSING - use 'make clean_all' to clean subdirs and " \
240
 
                "subprojs as well"
241
 
endif
242
 
endif
243
 
        rm -f $(OBJECTS) $(TARGET) $(DEPFILES) core
 
222
        @echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
 
223
endif
 
224
endif
 
225
        rm -f $(OBJECTS) $(TARGET) *.dep core
244
226
 
245
 
clean_all: subdirs subprojs clean
 
227
clean_all: subdirs clean
246
228
 
247
229
ifndef MKSTATICLIB
248
230
ifndef MKSHAREDLIB
251
233
endif
252
234
endif
253
235
 
254
 
$(SUBDIRS) $(SUBPROJS):
255
 
        @if [ "$@" = "$(firstword $(SUBDIRS) $(SUBPROJS))" ]; then echo; fi
256
 
        @$(MAKE) $(if $(filter $@,$(SUBDIRS)),-C $@,-f $@.mk) \
257
 
                $(filter-out $(SUBDIRS) $(SUBPROJS) subdirs subprojs,$(MAKECMDGOALS))
 
236
$(SUBDIRS):
 
237
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
 
238
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
258
239
        @echo
259
240
 
260
241
$(TARGET): $(OBJECTS)
261
242
ifdef MKSTATICLIB
262
243
        $(AR) rcs $(TARGET) $(OBJECTS)
263
244
else
264
 
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS)
 
245
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS) 
265
246
endif
266
247
 
267
248
%.o %_d.o %_p.o: %.c