/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.1
 
5
#                                                                    version 3.2
 
6
#
6
7
# Copyright (c) 2008 Tim Marston <edam@waxworlds.org>.
7
8
#
8
9
# Permission is hereby granted, free of charge, to any person obtaining a copy
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
 
32
# can also find more information/documentation on it's use. The following text
31
33
# 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.
83
85
# SUBDIRS      A list of subdirectories to build before attempting to build the
84
86
#              target. These subdirectories are also included in a clean_all.
85
87
#
 
88
# SUBPROJS     A list of the names of other makefiles to run before attempting
 
89
#              to build the target. This allows you to build multiple targets.
 
90
#              Note that ".mk" is appended to the subproject names. These
 
91
#              subprojects are also included in a clean_all.
 
92
#
86
93
# CPPFLAGS     Flags to give to the C and C++ compilers
87
94
# CFLAGS       Flags to give to the C compiler
88
95
# CXXFLAGS     Flags to give to the C++ compiler
95
102
# command line when you run make:
96
103
#
97
104
# 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.
 
105
#              and subprojects first and then the target.
 
106
#
 
107
# subdirs      Goes through the list of specified subdirectories, changing to
 
108
#              them, and runs make there.
 
109
#
 
110
# subproj      Goes through the list of specified subprojects, running the
 
111
#              makefiles for each of them.
102
112
#
103
113
# target       Builds the target of your Makefile.
104
114
#
113
123
# <subdir>     Builds the specified subdirectory from those that are listed for
114
124
#              the project.
115
125
#
 
126
# <subproj>    Builds the specified subproject from those listed for the
 
127
#              project.
 
128
#
116
129
# <file>       Builds the specified file, either an object file or the target,
117
130
#              from those that that would be built for the project.
118
131
#
120
133
#
121
134
# Known shortcommings:
122
135
# - 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!
 
136
#   should be using ld and specifying the crt libs as required by the sources.
126
137
#
127
138
#_______________________________________________________________________________
128
139
#
208
219
#_______________________________________________________________________________
209
220
#                                                                          RULES
210
221
 
211
 
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
 
222
.PHONY: all subdirs subprojs target clean clean_all run depend dep $(SUBDIRS) $(SUBPROJS)
212
223
 
213
 
all: subdirs target
 
224
all: subdirs subprojs target
214
225
 
215
226
subdirs: $(SUBDIRS)
216
227
 
 
228
subprojs: $(SUBPROJS)
 
229
 
217
230
target: $(TARGET)
218
231
 
219
232
clean:
220
 
ifdef SUBDIRS
 
233
ifneq ($(or $(SUBDIRS),$(SUBPROJS)),)
221
234
ifneq "$(MAKECMDGOALS)" "clean_all"
222
 
        @echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
 
235
        @echo "NOT RECURSING - use 'make clean_all' to clean subdirs and " \
 
236
                "subprojs as well"
223
237
endif
224
238
endif
225
239
        rm -f $(OBJECTS) $(TARGET) $(DEPFILES) core
226
240
 
227
 
clean_all: subdirs clean
 
241
clean_all: subdirs subprojs clean
228
242
 
229
243
ifndef MKSTATICLIB
230
244
ifndef MKSHAREDLIB
233
247
endif
234
248
endif
235
249
 
236
 
$(SUBDIRS):
237
 
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
238
 
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
 
250
$(SUBDIRS) $(SUBPROJS):
 
251
        @if [ "$@" = "$(firstword $(SUBDIRS) $(SUBPROJS))" ]; then echo; fi
 
252
        @$(MAKE) $(if $(filter $@,$(SUBDIRS)),-C $@,-f $@.mk) \
 
253
                $(filter-out $(SUBDIRS) $(SUBPROJS) subdirs subprojs,$(MAKECMDGOALS))
239
254
        @echo
240
255
 
241
256
$(TARGET): $(OBJECTS)
242
257
ifdef MKSTATICLIB
243
258
        $(AR) rcs $(TARGET) $(OBJECTS)
244
259
else
245
 
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS) 
 
260
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS)
246
261
endif
247
262
 
248
263
%.o %_d.o %_p.o: %.c