/make/edam-mk

To get this branch, use:
bzr branch http://bzr.ed.am/make/edam-mk
10 by edam
- fixed recursive cleaning
1
#                                          Edam's general-purpose makefile v1.11
9 by edam
- combines sources in to one variable, SOURCES
2
#_______________________________________________________________________________
3
#                                                                S E T T I N G S
3 by edam
- added propper header
4
8 by edam
- added SUBDIRS for recursing
5
# Overridable options
6
# (better to specify these in environment/command line)
7
#export DEBUGMODE	:= 1
8
#export STATICLIBS	:= 1
9
10
# Target binary/library
9 by edam
- combines sources in to one variable, SOURCES
11
#BUILDALIB	:= 1
12
#BUILDSOLIB	:= 1
10 by edam
- fixed recursive cleaning
13
TARGET		:= 
1 by edam
initial makefile
14
15
# All source files
9 by edam
- combines sources in to one variable, SOURCES
16
SOURCES		:= tim.cc
3 by edam
- added propper header
17
8 by edam
- added SUBDIRS for recursing
18
# Libraries to link
7 by edam
- set CC correctly
19
LIBRARIES	:= 
20
8 by edam
- added SUBDIRS for recursing
21
# Subdirectories to make
22
SUBDIRS		:= 
3 by edam
- added propper header
23
24
# Software
9 by edam
- combines sources in to one variable, SOURCES
25
AS		:= nasm
26
CC		:= gcc
27
CXX		:= g++
8 by edam
- added SUBDIRS for recursing
28
29
# Flags
9 by edam
- combines sources in to one variable, SOURCES
30
CPPFLAGS	:= 
8 by edam
- added SUBDIRS for recursing
31
CFLAGS		:= $(if $(DEBUGMODE),-g -D DEBUG,-O2)
32
CXXFLAGS	:= $(if $(DEBUGMODE),-g -D DEBUG,-O2)
33
ASFLAGS		:= -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2)
34
LDFLAGS		:= -Wall $(if $(DEBUGMODE),,-s) $(if $(STATICLIBS), -static)
35
9 by edam
- combines sources in to one variable, SOURCES
36
#_______________________________________________________________________________
8 by edam
- added SUBDIRS for recursing
37
38
DEPFILE		:= depends.mk
9 by edam
- combines sources in to one variable, SOURCES
39
OBJECTS		:= $(addsuffix .o,$(basename $(SOURCES)))
7 by edam
- set CC correctly
40
LDLIBS		:= $(addprefix -l,$(LIBRARIES))
9 by edam
- combines sources in to one variable, SOURCES
41
TARGET		:= $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
42
TARGET		:= $(TARGET)$(if $(BUILDALIB),.a,)$(if $(BUILDSOLIB),.so,)
43
10 by edam
- fixed recursive cleaning
44
# Turn clean_all in to a recursive clean
45
ifeq "$(MAKECMDGOALS)" "clean_all"
46
export RECURSIVE_CLEAN := 1
47
MAKECMDGOALS := clean
48
endif
49
9 by edam
- combines sources in to one variable, SOURCES
50
.PHONY:	all subdirs target clean clean_all run depend dep $(SUBDIRS)
51
52
all: subdirs target
53
54
subdirs: $(SUBDIRS)
55
56
target: $(TARGET)
1 by edam
initial makefile
57
10 by edam
- fixed recursive cleaning
58
ifdef RECURSIVE_CLEAN
59
clean clean_all: subdirs
60
else
61
clean:	
62
@echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
63
endif
64
	rm -f $(OBJECTS) $(TARGET) core $(DEPFILE) *~
8 by edam
- added SUBDIRS for recursing
65
9 by edam
- combines sources in to one variable, SOURCES
66
ifndef BUILDALIB
67
ifndef BUILDSOLIB
68
run: target
69
	./$(TARGET)
70
endif
71
endif
4 by edam
- replaced debug option with debug switch
72
8 by edam
- added SUBDIRS for recursing
73
#depend dep:
9 by edam
- combines sources in to one variable, SOURCES
74
#	makedepend -f- -- $(CPPFLAGS) -- $(SOURCES) > $(DEPFILE)
1 by edam
initial makefile
75
8 by edam
- added SUBDIRS for recursing
76
$(SUBDIRS):
10 by edam
- fixed recursive cleaning
77
	@echo ==== Sub directory: $@
78
	@$(MAKE) --no-print-directory -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
8 by edam
- added SUBDIRS for recursing
79
9 by edam
- combines sources in to one variable, SOURCES
80
$(TARGET): $(OBJECTS)
81
ifdef BUILDALIB
82
	$(AR) rcs $(TARGET) $(OBJECTS)
8 by edam
- added SUBDIRS for recursing
83
else
9 by edam
- combines sources in to one variable, SOURCES
84
	$(CXX) $(if $(BUILDSOLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDLIBS) 
8 by edam
- added SUBDIRS for recursing
85
endif
86
87
#%.o:	%.c
88
#	$(CC) -c $(CPPFLAGS) $(CFLAGS)
89
#%.o:	%.cc
90
#	$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
91
#%.o:	%.s
92
#	$(AS) $(ASFLAGS)
93
94
-include $(DEPFILE)
95
9 by edam
- combines sources in to one variable, SOURCES
96
#_______________________________________________________________________________