/make/edam-mk

To get this branch, use:
bzr branch http://bzr.ed.am/make/edam-mk
9 by edam
- combines sources in to one variable, SOURCES
1
#                                          Edam's general-purpose makefile v1.10
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
13
TARGET		:= tim.a
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
44
.PHONY:	all subdirs target clean clean_all run depend dep $(SUBDIRS)
45
46
all: subdirs target
47
48
subdirs: $(SUBDIRS)
49
50
target: $(TARGET)
1 by edam
initial makefile
51
52
clean:
9 by edam
- combines sources in to one variable, SOURCES
53
ifeq "$(MAKECMDGOALS)" "clean"
8 by edam
- added SUBDIRS for recursing
54
ifdef SUBDIRS
9 by edam
- combines sources in to one variable, SOURCES
55
	@echo NOT RECURSING: Use \"make clean_all\" to clean subdirectoried as well...
56
endif
57
endif
58
	rm -f core $(DEPFILE) $(OBJECTS) $(TARGET)
1 by edam
initial makefile
59
	rm -f *~
60
9 by edam
- combines sources in to one variable, SOURCES
61
clean_all: subdirs clean
8 by edam
- added SUBDIRS for recursing
62
9 by edam
- combines sources in to one variable, SOURCES
63
ifndef BUILDALIB
64
ifndef BUILDSOLIB
65
run: target
66
	./$(TARGET)
67
endif
68
endif
4 by edam
- replaced debug option with debug switch
69
8 by edam
- added SUBDIRS for recursing
70
#depend dep:
9 by edam
- combines sources in to one variable, SOURCES
71
#	makedepend -f- -- $(CPPFLAGS) -- $(SOURCES) > $(DEPFILE)
1 by edam
initial makefile
72
8 by edam
- added SUBDIRS for recursing
73
$(SUBDIRS):
74
	@$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)
75
9 by edam
- combines sources in to one variable, SOURCES
76
$(TARGET): $(OBJECTS)
77
ifdef BUILDALIB
78
	$(AR) rcs $(TARGET) $(OBJECTS)
8 by edam
- added SUBDIRS for recursing
79
else
9 by edam
- combines sources in to one variable, SOURCES
80
	$(CXX) $(if $(BUILDSOLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDLIBS) 
8 by edam
- added SUBDIRS for recursing
81
endif
82
83
#%.o:	%.c
84
#	$(CC) -c $(CPPFLAGS) $(CFLAGS)
85
#%.o:	%.cc
86
#	$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
87
#%.o:	%.s
88
#	$(AS) $(ASFLAGS)
89
90
-include $(DEPFILE)
91
9 by edam
- combines sources in to one variable, SOURCES
92
#_______________________________________________________________________________