/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 Makefile

  • Committer: edam
  • Date: 2009-03-05 13:47:12 UTC
  • Revision ID: edam@waxworlds.org-20090305134712-grzh787t06ojomf8
Tags: 2.0
- smartened up comments
- added PROFILEMODE
- renamed STATICLIBS to LINKSTATIC
- renamed lib target switched to MKSHAREDLIB and MKSTATICLIB
- added setting of software variables
- added debug & profile suffixes
- added dependency file generation system
- added rules to build various source types and added dependency generation

Show diffs side-by-side

added added

removed removed

1
1
#_______________________________________________________________________________
2
2
#
3
 
#                       edam's general-purpose makefile                     v2.3
 
3
#                                       edam's general-purpose makefile v2.0
4
4
#_______________________________________________________________________________
5
5
#                                                                COMMON SETTINGS
6
6
 
40
40
CPPFLAGS        := 
41
41
CFLAGS          := 
42
42
CXXFLAGS        := 
43
 
DFLAGS          := 
44
43
ASFLAGS         := 
45
44
LDFLAGS         := 
46
45
LDPOSTFLAGS     := 
54
53
endif
55
54
 
56
55
# software
 
56
AS                      := nasm
57
57
CC                      := gcc
58
58
CXX                     := g++
59
 
GDC                     := gdc
60
 
AS                      := nasm
61
59
LD                      := g++
62
60
AR                      := ar
63
61
MAKE            := make
64
62
 
65
 
# debug/profile build flags
 
63
# build flags
66
64
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
67
 
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-O2) $(CPPFLAGS)
68
 
DFLAGS          := $(if $(DEBUGMODE),,-frelease)
 
65
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG,-O2) $(CPPFLAGS)
69
66
ASFLAGS         := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2) $(ASFLAGS)
70
 
LDFLAGS         := $(if $(PROFILEMODE),-pg) $(LDFLAGS)
71
 
LDFLAGS         := $(if $(or $(PROFILEMODE), $(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
72
 
 
73
 
# setup options for shared/static libs
74
 
CPPFLAGS        := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
75
 
LDFLAGS         := $(if $(LINKSTATIC),-static) $(LDFLAGS)
76
 
 
77
 
# add libraries for d
78
 
LIBRARIES       := $(LIBRARIES) $(if $(filter %.d, $(SOURCES)), gphobos pthread m)
79
 
 
80
 
# build flags for libraries
 
67
LDFLAGS         := $(if $(PROFILEMODE),-pg,$(if $(DEBUGMODE),,-s)) $(LDFLAGS)
 
68
LDFLAGS         := -Wall $(if $(LINKSTATIC),-static) $(LDFLAGS)
81
69
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
82
70
 
83
71
#_______________________________________________________________________________
84
 
#
85
72
 
86
73
# object debug/profile suffix
87
74
BUILDSUFFIX     := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
88
75
 
89
 
# work out object and dependency files
 
76
# files
90
77
OBJECTS         := $(addsuffix $(BUILDSUFFIX).o,$(basename $(SOURCES)))
91
 
DEPFILES        := $(addsuffix .dep,$(basename $(SOURCES)))
 
78
DEPFILES        := $(addsuffix .d,$(basename $(SOURCES)))
92
79
 
93
 
# fixup target name
 
80
# fixup target
94
81
ifdef TARGET
95
82
TARGET          := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET))
96
83
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
97
 
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
98
84
TARGET          := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
99
 
TARGET          := lib$(patsubst lib%,%,$(TARGET))
100
 
endif
101
85
endif
102
86
 
103
 
# Set up dependency generation build flags and, for those languages where the
104
 
# the compiler/assembler doesn't support dependency generation, commands to be
105
 
# executed after generating any dependency file. The commands append the names
106
 
# of all the depended-on files in the dependency file to the end of the file as
 
87
# Set up dependancy generation build flags and a commands to be executed after
 
88
# generating any dependancy file. The commands append the names of all the
 
89
# depended-on files in the dependancy file to the end of the dependancy file as
107
90
# empty rules with no prerequesits or commands. This causes make not to fail if
108
 
# one of these files becomes non-existant, but causes files dependent on these
109
 
# files to be rebuilt (and thus also have their dependencies regenerated).
 
91
# one of these files becomes non-existant, but causes files dependant on these
 
92
# files to be rebuilt (and thus also have their dependancies regenerated).
110
93
ifdef DEBUGMODE
111
94
ifndef PROFILEMODE
112
 
FIXUP_DEPENDENCY_FILES = \
 
95
FIXUP_DEPENDANCY_FILES = \
113
96
        sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \
114
 
        $(basename $<).dep > .$$$$~; cat .$$$$~ >> $(basename $<).dep; rm .$$$$~;
115
 
DEPFLAGS        = -MMD -MP -MF $(basename $<).dep
 
97
                $(basename $<).d > .$$$$~; cat .$$$$~ >> $(basename $<).d; rm .$$$$~;
 
98
DEPFLAGS        = -MD -MF $(basename $<).d
116
99
endif
117
100
endif
118
101
 
119
 
# include dependencies
 
102
# include dependancies
120
103
ifneq "$(MAKECMDGOALS)" "clean"
121
104
ifneq "$(MAKECMDGOALS)" "clean_all"
122
105
-include $(DEPFILES)
143
126
        @echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
144
127
endif
145
128
endif
146
 
        rm -f $(OBJECTS) $(TARGET) *.dep core
 
129
        rm -f $(OBJECTS) $(TARGET) core
147
130
 
148
131
clean_all: subdirs clean
149
132
 
155
138
endif
156
139
 
157
140
$(SUBDIRS):
158
 
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
159
141
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
160
142
        @echo
161
143
 
168
150
 
169
151
%.o %_d.o %_p.o: %.c
170
152
        $(CC) -c $(CPPFLAGS) $(DEPFLAGS) $(CFLAGS) -o $@ $<
 
153
        $(FIXUP_DEPENDANCY_FILES)
171
154
 
172
155
%.o %_d.o %_p.o: %.cc
173
156
        $(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
 
157
        $(FIXUP_DEPENDANCY_FILES)
174
158
%.o %_d.o %_p.o: %.C
175
159
        $(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
 
160
        $(FIXUP_DEPENDANCY_FILES)
176
161
%.o %_d.o %_p.o: %.cpp
177
162
        $(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
178
 
 
179
 
%.o %_d.o %_p.o: %.d
180
 
        $(GDC) -c $(CPPFLAGS) $(DFLAGS) -o $@ $<
 
163
        $(FIXUP_DEPENDANCY_FILES)
181
164
 
182
165
%.o %_d.o %_p.o: %.s
183
166
        $(AS) $(ASFLAGS) -o $@ $<
184
 
ifdef DEBUGMODE
185
 
        $(AS) $(ASFLAGS) -M $< > $(basename $<).dep
186
 
        $(FIXUP_DEPENDENCY_FILES)
187
 
endif
188
167
%.o %_d.o %_p.o: %.S
189
168
        $(AS) $(ASFLAGS) -o $@ $<
190
 
ifdef DEBUGMODE
191
 
        $(AS) $(ASFLAGS) -M $< > $(basename $<).dep
192
 
        $(FIXUP_DEPENDENCY_FILES)
193
 
endif
194
169
%.o %_d.o %_p.o: %.asm
195
170
        $(AS) $(ASFLAGS) -o $@ $<
196
 
ifdef DEBUGMODE
197
 
        $(AS) $(ASFLAGS) -M $< > $(basename $<).dep
198
 
        $(FIXUP_DEPENDENCY_FILES)
199
 
endif
 
171
 
 
172
%.d: %.s
 
173
        $(AS) $(ASFLAGS) -M $< > $@
 
174
        $(FIXUP_DEPENDANCY_FILES)
 
175
%.d: %.S
 
176
        $(AS) $(ASFLAGS) -M $< > $@
 
177
        $(FIXUP_DEPENDANCY_FILES)
 
178
%.d: %.asm
 
179
        $(AS) $(ASFLAGS) -M $< > $@
 
180
        $(FIXUP_DEPENDANCY_FILES)
200
181
 
201
182
#_______________________________________________________________________________