/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.2
 
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
87
# Set up dependancy generation build flags and a commands to be executed after
110
94
ifndef PROFILEMODE
111
95
FIXUP_DEPENDANCY_FILES = \
112
96
        sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \
113
 
        $(basename $<).dep > .$$$$~; cat .$$$$~ >> $(basename $<).dep; rm .$$$$~;
114
 
DEPFLAGS        = -MD -MF $(basename $<).dep
 
97
                $(basename $<).d > .$$$$~; cat .$$$$~ >> $(basename $<).d; rm .$$$$~;
 
98
DEPFLAGS        = -MD -MF $(basename $<).d
115
99
endif
116
100
endif
117
101
 
142
126
        @echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
143
127
endif
144
128
endif
145
 
        rm -f $(OBJECTS) $(TARGET) *.dep core
 
129
        rm -f $(OBJECTS) $(TARGET) core
146
130
 
147
131
clean_all: subdirs clean
148
132
 
154
138
endif
155
139
 
156
140
$(SUBDIRS):
157
 
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
158
141
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
159
142
        @echo
160
143
 
179
162
        $(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
180
163
        $(FIXUP_DEPENDANCY_FILES)
181
164
 
182
 
%.o %_d.o %_p.o: %.d
183
 
        $(GDC) -c $(CPPFLAGS) $(DFLAGS) -o $@ $<
184
 
 
185
165
%.o %_d.o %_p.o: %.s
186
166
        $(AS) $(ASFLAGS) -o $@ $<
187
167
%.o %_d.o %_p.o: %.S
189
169
%.o %_d.o %_p.o: %.asm
190
170
        $(AS) $(ASFLAGS) -o $@ $<
191
171
 
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
 
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
199
179
        $(AS) $(ASFLAGS) -M $< > $@
200
180
        $(FIXUP_DEPENDANCY_FILES)
201
181