/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:55:34 UTC
  • Revision ID: edam@waxworlds.org-20090305135534-omg3htccymsu5ki4
Tags: 2.2
- added support for D!
- also cleanup dependency files

Show diffs side-by-side

added added

removed removed

1
1
#_______________________________________________________________________________
2
2
#
3
 
#                                       edam's general-purpose makefile v2.0
 
3
#                     edam's general-purpose makefile v2.2
4
4
#_______________________________________________________________________________
5
5
#                                                                COMMON SETTINGS
6
6
 
40
40
CPPFLAGS        := 
41
41
CFLAGS          := 
42
42
CXXFLAGS        := 
 
43
DFLAGS          := 
43
44
ASFLAGS         := 
44
45
LDFLAGS         := 
45
46
LDPOSTFLAGS     := 
53
54
endif
54
55
 
55
56
# software
56
 
AS                      := nasm
57
57
CC                      := gcc
58
58
CXX                     := g++
 
59
GDC                     := gdc
 
60
AS                      := nasm
59
61
LD                      := g++
60
62
AR                      := ar
61
63
MAKE            := make
62
64
 
63
 
# build flags
 
65
# debug/profile build flags
64
66
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
65
 
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG,-O2) $(CPPFLAGS)
 
67
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-O2) $(CPPFLAGS)
 
68
DFLAGS          := $(if $(DEBUGMODE),,-frelease)
66
69
ASFLAGS         := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2) $(ASFLAGS)
67
 
LDFLAGS         := $(if $(PROFILEMODE),-pg,$(if $(DEBUGMODE),,-s)) $(LDFLAGS)
68
 
LDFLAGS         := -Wall $(if $(LINKSTATIC),-static) $(LDFLAGS)
 
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
69
81
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
70
82
 
71
83
#_______________________________________________________________________________
 
84
#
72
85
 
73
86
# object debug/profile suffix
74
87
BUILDSUFFIX     := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
75
88
 
76
 
# files
 
89
# work out object and dependency files
77
90
OBJECTS         := $(addsuffix $(BUILDSUFFIX).o,$(basename $(SOURCES)))
78
 
DEPFILES        := $(addsuffix .d,$(basename $(SOURCES)))
 
91
DEPFILES        := $(addsuffix .dep,$(basename $(SOURCES)))
79
92
 
80
 
# fixup target
 
93
# fixup target name
81
94
ifdef TARGET
82
95
TARGET          := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET))
83
96
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
 
97
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
84
98
TARGET          := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
 
99
TARGET          := lib$(patsubst lib%,%,$(TARGET))
 
100
endif
85
101
endif
86
102
 
87
103
# Set up dependancy generation build flags and a commands to be executed after
94
110
ifndef PROFILEMODE
95
111
FIXUP_DEPENDANCY_FILES = \
96
112
        sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \
97
 
                $(basename $<).d > .$$$$~; cat .$$$$~ >> $(basename $<).d; rm .$$$$~;
98
 
DEPFLAGS        = -MD -MF $(basename $<).d
 
113
        $(basename $<).dep > .$$$$~; cat .$$$$~ >> $(basename $<).dep; rm .$$$$~;
 
114
DEPFLAGS        = -MD -MF $(basename $<).dep
99
115
endif
100
116
endif
101
117
 
126
142
        @echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
127
143
endif
128
144
endif
129
 
        rm -f $(OBJECTS) $(TARGET) core
 
145
        rm -f $(OBJECTS) $(TARGET) *.dep core
130
146
 
131
147
clean_all: subdirs clean
132
148
 
138
154
endif
139
155
 
140
156
$(SUBDIRS):
 
157
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
141
158
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
142
159
        @echo
143
160
 
162
179
        $(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
163
180
        $(FIXUP_DEPENDANCY_FILES)
164
181
 
 
182
%.o %_d.o %_p.o: %.d
 
183
        $(GDC) -c $(CPPFLAGS) $(DFLAGS) -o $@ $<
 
184
 
165
185
%.o %_d.o %_p.o: %.s
166
186
        $(AS) $(ASFLAGS) -o $@ $<
167
187
%.o %_d.o %_p.o: %.S
169
189
%.o %_d.o %_p.o: %.asm
170
190
        $(AS) $(ASFLAGS) -o $@ $<
171
191
 
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
 
192
%.dep: %.s
 
193
        $(AS) $(ASFLAGS) -M $< > $@
 
194
        $(FIXUP_DEPENDANCY_FILES)
 
195
%.dep: %.S
 
196
        $(AS) $(ASFLAGS) -M $< > $@
 
197
        $(FIXUP_DEPENDANCY_FILES)
 
198
%.dep: %.asm
179
199
        $(AS) $(ASFLAGS) -M $< > $@
180
200
        $(FIXUP_DEPENDANCY_FILES)
181
201