/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

Lines of Context:
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
 
62
62
 
63
63
# build flags
64
64
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
65
 
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-O2) $(CPPFLAGS)
66
 
CPPFLAGS        := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
 
65
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG,-O2) $(CPPFLAGS)
67
66
ASFLAGS         := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2) $(ASFLAGS)
68
 
LDFLAGS         := $(if $(PROFILEMODE),-pg) $(LDFLAGS)
69
 
LDFLAGS         := $(if $(or $(PROFILEMODE),$(DEBUGMODE)),,-Wl,-S) $(LDFLAGS)
70
 
LDFLAGS         := $(if $(LINKSTATIC),-static) $(LDFLAGS)
 
67
LDFLAGS         := $(if $(PROFILEMODE),-pg,$(if $(DEBUGMODE),,-s)) $(LDFLAGS)
 
68
LDFLAGS         := -Wall $(if $(LINKSTATIC),-static) $(LDFLAGS)
71
69
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
72
70
 
73
71
#_______________________________________________________________________________
74
 
#
75
72
 
76
73
# object debug/profile suffix
77
74
BUILDSUFFIX     := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
78
75
 
79
76
# files
80
77
OBJECTS         := $(addsuffix $(BUILDSUFFIX).o,$(basename $(SOURCES)))
81
 
DEPFILES        := $(addsuffix .dep,$(basename $(SOURCES)))
 
78
DEPFILES        := $(addsuffix .d,$(basename $(SOURCES)))
82
79
 
83
80
# fixup target
84
81
ifdef TARGET
85
 
TARGET          := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET))
86
 
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
87
 
ifneq ($(strip $(MKSHAREDLIB) $(MKSTATICLIB)),)
88
 
TARGET          := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
89
 
TARGET          := lib$(patsubst lib%,%,$(TARGET))
90
 
endif
 
82
TARGET          := $(basename $(TARGET))$(BUILDSUFFIX)$(suffix $(TARGET))
 
83
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
 
84
TARGET          := $(TARGET)$(if $(MKSHAREDLIB),.so,$(if $(MKSTATICLIB),.a))
91
85
endif
92
86
 
93
87
# Set up dependancy generation build flags and a commands to be executed after
100
94
ifndef PROFILEMODE
101
95
FIXUP_DEPENDANCY_FILES = \
102
96
        sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \
103
 
        $(basename $<).dep > .$$$$~; cat .$$$$~ >> $(basename $<).dep; rm .$$$$~;
104
 
DEPFLAGS        = -MD -MF $(basename $<).dep
 
97
                $(basename $<).d > .$$$$~; cat .$$$$~ >> $(basename $<).d; rm .$$$$~;
 
98
DEPFLAGS        = -MD -MF $(basename $<).d
105
99
endif
106
100
endif
107
101
 
144
138
endif
145
139
 
146
140
$(SUBDIRS):
147
 
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
148
141
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
149
142
        @echo
150
143
 
176
169
%.o %_d.o %_p.o: %.asm
177
170
        $(AS) $(ASFLAGS) -o $@ $<
178
171
 
179
 
%.dep: %.s
180
 
        $(AS) $(ASFLAGS) -M $< > $@
181
 
        $(FIXUP_DEPENDANCY_FILES)
182
 
%.dep: %.S
183
 
        $(AS) $(ASFLAGS) -M $< > $@
184
 
        $(FIXUP_DEPENDANCY_FILES)
185
 
%.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
186
179
        $(AS) $(ASFLAGS) -M $< > $@
187
180
        $(FIXUP_DEPENDANCY_FILES)
188
181