/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:24:59 UTC
  • Revision ID: edam@waxworlds.org-20090305142459-qwm14g5rsttq2f9b
Tags: 3.1
properly cleanup dependencies

Show diffs side-by-side

added added

removed removed

2
2
#
3
3
#                       edam's general-purpose makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                    version 3.2
6
 
#
 
5
#                                                                    version 3.1
7
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
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.
85
83
# SUBDIRS      A list of subdirectories to build before attempting to build the
86
84
#              target. These subdirectories are also included in a clean_all.
87
85
#
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
 
#
93
86
# CPPFLAGS     Flags to give to the C and C++ compilers
94
87
# CFLAGS       Flags to give to the C compiler
95
88
# CXXFLAGS     Flags to give to the C++ compiler
102
95
# command line when you run make:
103
96
#
104
97
# all          This is the default if no goal is specified. It builds subdirs
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.
 
98
#              first and then the target.
 
99
#
 
100
# subdirs      Changes to the subdirectories specified for the project and runs
 
101
#              make in them.
112
102
#
113
103
# target       Builds the target of your Makefile.
114
104
#
123
113
# <subdir>     Builds the specified subdirectory from those that are listed for
124
114
#              the project.
125
115
#
126
 
# <subproj>    Builds the specified subproject from those listed for the
127
 
#              project.
128
 
#
129
116
# <file>       Builds the specified file, either an object file or the target,
130
117
#              from those that that would be built for the project.
131
118
#
133
120
#
134
121
# Known shortcommings:
135
122
# - Using C is probably broken because g++ is currently used for linking. We
136
 
#   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!
137
126
#
138
127
#_______________________________________________________________________________
139
128
#
219
208
#_______________________________________________________________________________
220
209
#                                                                          RULES
221
210
 
222
 
.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)
223
212
 
224
 
all: subdirs subprojs target
 
213
all: subdirs target
225
214
 
226
215
subdirs: $(SUBDIRS)
227
216
 
228
 
subprojs: $(SUBPROJS)
229
 
 
230
217
target: $(TARGET)
231
218
 
232
219
clean:
233
 
ifneq ($(or $(SUBDIRS),$(SUBPROJS)),)
 
220
ifdef SUBDIRS
234
221
ifneq "$(MAKECMDGOALS)" "clean_all"
235
 
        @echo "NOT RECURSING - use 'make clean_all' to clean subdirs and " \
236
 
                "subprojs as well"
 
222
        @echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
237
223
endif
238
224
endif
239
225
        rm -f $(OBJECTS) $(TARGET) $(DEPFILES) core
240
226
 
241
 
clean_all: subdirs subprojs clean
 
227
clean_all: subdirs clean
242
228
 
243
229
ifndef MKSTATICLIB
244
230
ifndef MKSHAREDLIB
247
233
endif
248
234
endif
249
235
 
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))
 
236
$(SUBDIRS):
 
237
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
 
238
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
254
239
        @echo
255
240
 
256
241
$(TARGET): $(OBJECTS)
257
242
ifdef MKSTATICLIB
258
243
        $(AR) rcs $(TARGET) $(OBJECTS)
259
244
else
260
 
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS)
 
245
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS) 
261
246
endif
262
247
 
263
248
%.o %_d.o %_p.o: %.c