/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:26:41 UTC
  • Revision ID: edam@waxworlds.org-20090305132641-42u18q8sg2lx966x
Tags: 1.6
- added cpp build switch
- added static linking switch

Show diffs side-by-side

added added

removed removed

1
 
#_______________________________________________________________________________
2
 
#
3
 
#                     edam's general-purpose makefile v2.2
4
 
#_______________________________________________________________________________
5
 
#                                                                COMMON SETTINGS
6
 
 
7
 
#
8
 
# overridable options
9
 
# (better to specify in environment/command line)
10
 
#
11
 
#export DEBUGMODE       := 1
12
 
#export PROFILEMODE := 1
13
 
#export LINKSTATIC      := 1
14
 
 
15
 
#
16
 
# target binary/library
17
 
#
18
 
#MKSTATICLIB    := 1
19
 
#MKSHAREDLIB    := 1
20
 
TARGET          := tim
21
 
 
22
 
#
23
 
# all source files
24
 
#
25
 
SOURCES         := tim.cc
26
 
 
27
 
#
28
 
# libraries to link against
29
 
#
30
 
LIBRARIES       := 
31
 
 
32
 
#
33
 
# subdirectories to make first
34
 
#
35
 
SUBDIRS         := 
36
 
 
37
 
#
38
 
# additional build flags
39
 
#
40
 
CPPFLAGS        := 
41
 
CFLAGS          := 
42
 
CXXFLAGS        := 
43
 
ASFLAGS         := 
44
 
LDFLAGS         := 
45
 
LDPOSTFLAGS     := 
46
 
 
47
 
#_______________________________________________________________________________
48
 
#                                                                 OTHER SETTINGS
49
 
 
50
 
# set debug mode if profiling
51
 
ifdef PROFILEMODE
52
 
export DEBUGMODE := 1
53
 
endif
54
 
 
55
 
# software
56
 
AS                      := nasm
57
 
CC                      := gcc
58
 
CXX                     := g++
59
 
LD                      := g++
60
 
AR                      := ar
61
 
MAKE            := make
62
 
 
63
 
# build flags
64
 
CPPFLAGS        := $(if $(PROFILEMODE),-pg -D PROFILE) $(CPPFLAGS)
65
 
CPPFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG -Wall,-O2) $(CPPFLAGS)
66
 
CPPFLAGS        := $(if $(MKSHAREDLIB),-fPIC) $(CPPFLAGS)
67
 
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)
71
 
LDPOSTFLAGS := $(addprefix -l,$(LIBRARIES)) $(LDPOSTFLAGS)
72
 
 
73
 
#_______________________________________________________________________________
74
 
#
75
 
 
76
 
# object debug/profile suffix
77
 
BUILDSUFFIX     := $(if $(PROFILEMODE),_p,$(if $(DEBUGMODE),_d))
78
 
 
79
 
# files
80
 
OBJECTS         := $(addsuffix $(BUILDSUFFIX).o,$(basename $(SOURCES)))
81
 
DEPFILES        := $(addsuffix .dep,$(basename $(SOURCES)))
82
 
 
83
 
# fixup target
84
 
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
91
 
endif
92
 
 
93
 
# Set up dependancy generation build flags and a commands to be executed after
94
 
# generating any dependancy file. The commands append the names of all the
95
 
# depended-on files in the dependancy file to the end of the dependancy file as
96
 
# empty rules with no prerequesits or commands. This causes make not to fail if
97
 
# one of these files becomes non-existant, but causes files dependant on these
98
 
# files to be rebuilt (and thus also have their dependancies regenerated).
99
 
ifdef DEBUGMODE
100
 
ifndef PROFILEMODE
101
 
FIXUP_DEPENDANCY_FILES = \
102
 
        sed 's/\#.*//;s/^[^:]*://;s/^[ \t]*//;s/ *\\$$//;/^$$/d;s/$$/:/' < \
103
 
        $(basename $<).dep > .$$$$~; cat .$$$$~ >> $(basename $<).dep; rm .$$$$~;
104
 
DEPFLAGS        = -MD -MF $(basename $<).dep
105
 
endif
106
 
endif
107
 
 
108
 
# include dependancies
109
 
ifneq "$(MAKECMDGOALS)" "clean"
110
 
ifneq "$(MAKECMDGOALS)" "clean_all"
111
 
-include $(DEPFILES)
112
 
endif
113
 
endif
114
 
 
115
 
# default rule
116
 
.DEFAULT_GOAL := all
117
 
 
118
 
#_______________________________________________________________________________
119
 
#                                                                          RULES
120
 
 
121
 
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
122
 
 
123
 
all: subdirs target
124
 
 
125
 
subdirs: $(SUBDIRS)
126
 
 
127
 
target: $(TARGET)
 
1
#                                                       Edam's Makefile v1.6
 
2
#___________________________________________________________________________
 
3
#                                                            S E T T I N G S
 
4
 
 
5
# Target binary
 
6
TARGET          = groups
 
7
 
 
8
# All source files
 
9
CC_SRCS         =
 
10
C_SRCS          = groups.c xmalloc.c
 
11
S_SRCS          = 
 
12
 
 
13
# Libraries
 
14
LIBRARIES       = 
 
15
 
 
16
# Options (comment-out to disable)
 
17
DEBUG           = 1
 
18
#CPPBUILD       = 1
 
19
#STATICLIBS     = 1
 
20
 
 
21
#___________________________________________________________________________
 
22
#                                                                    M E A T
 
23
 
 
24
# Software
 
25
AS=nasm
 
26
 
 
27
ifdef DEBUG
 
28
 
 
29
# Debug build flags
 
30
CPPFLAGS        = -g -D DEBUG
 
31
ASFLAGS         = -f elf -g -dDEBUG
 
32
LDFLAGS         = -Wall $(if $(STATICLIBS), -static)
 
33
 
 
34
else
 
35
 
 
36
# Release build flags
 
37
CPPFLAGS        = -O2
 
38
ASFLAGS         = -f elf -O2
 
39
LDFLAGS         = -Wall -s $(if $(STATICLIBS), -static)
 
40
 
 
41
endif
 
42
 
 
43
# More variables...
 
44
DEPFILE         = Depends
 
45
_SRCS           = $(CC_SRCS) $(C_SRCS) $(S_SRCS)
 
46
_OBJS           = $(addsuffix .o,$(basename $(_SRCS)))
 
47
LDLIBS          = $(addprefix -l,$(LIBRARIES))
 
48
 
 
49
# Main rule...
 
50
$(TARGET): $(_OBJS)
 
51
        $(if $(CPPBUILD), g++, gcc) -o $(TARGET) $(LDFLAGS) $(_OBJS) $(LDLIBS)
 
52
 
 
53
#___________________________________________________________________________
 
54
#                                                                  R U L E S
 
55
 
 
56
.PHONY: all clean run depend dep
 
57
 
 
58
all:    clean depend $(TARGET)
128
59
 
129
60
clean:
130
 
ifdef SUBDIRS
131
 
ifneq "$(MAKECMDGOALS)" "clean_all"
132
 
        @echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
133
 
endif
134
 
endif
135
 
        rm -f $(OBJECTS) $(TARGET) core
136
 
 
137
 
clean_all: subdirs clean
138
 
 
139
 
ifndef MKSTATICLIB
140
 
ifndef MKSHAREDLIB
141
 
run: target
 
61
        rm -f core $(DEPFILE) $(_OBJS)
 
62
        rm -f *~
 
63
 
 
64
run:    $(TARGET)
142
65
        ./$(TARGET)
143
 
endif
144
 
endif
145
 
 
146
 
$(SUBDIRS):
147
 
        @if [ "$@" = "$(firstword $(SUBDIRS))" ]; then echo; fi
148
 
        @$(MAKE) -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
149
 
        @echo
150
 
 
151
 
$(TARGET): $(OBJECTS)
152
 
ifdef MKSTATICLIB
153
 
        $(AR) rcs $(TARGET) $(OBJECTS)
154
 
else
155
 
        $(LD) $(if $(MKSHAREDLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDPOSTFLAGS) 
156
 
endif
157
 
 
158
 
%.o %_d.o %_p.o: %.c
159
 
        $(CC) -c $(CPPFLAGS) $(DEPFLAGS) $(CFLAGS) -o $@ $<
160
 
        $(FIXUP_DEPENDANCY_FILES)
161
 
 
162
 
%.o %_d.o %_p.o: %.cc
163
 
        $(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
164
 
        $(FIXUP_DEPENDANCY_FILES)
165
 
%.o %_d.o %_p.o: %.C
166
 
        $(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
167
 
        $(FIXUP_DEPENDANCY_FILES)
168
 
%.o %_d.o %_p.o: %.cpp
169
 
        $(CXX) -c $(CPPFLAGS) $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
170
 
        $(FIXUP_DEPENDANCY_FILES)
171
 
 
172
 
%.o %_d.o %_p.o: %.s
173
 
        $(AS) $(ASFLAGS) -o $@ $<
174
 
%.o %_d.o %_p.o: %.S
175
 
        $(AS) $(ASFLAGS) -o $@ $<
176
 
%.o %_d.o %_p.o: %.asm
177
 
        $(AS) $(ASFLAGS) -o $@ $<
178
 
 
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
186
 
        $(AS) $(ASFLAGS) -M $< > $@
187
 
        $(FIXUP_DEPENDANCY_FILES)
188
 
 
189
 
#_______________________________________________________________________________
 
66
 
 
67
depend dep:
 
68
#       makedepend -f- -- $(CPPFLAGS) -- $(_SRCS) > $(DEPFILE)
 
69
 
 
70
#___________________________________________________________________________
 
71
#include $(DEPFILE)