/make/edam-mk

To get this branch, use:
bzr branch http://bzr.ed.am/make/edam-mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#                                          Edam's general-purpose makefile v1.10
#_______________________________________________________________________________
#                                                                S E T T I N G S

# Overridable options
# (better to specify these in environment/command line)
#export DEBUGMODE	:= 1
#export STATICLIBS	:= 1

# Target binary/library
#BUILDALIB	:= 1
#BUILDSOLIB	:= 1
TARGET		:= tim.a

# All source files
SOURCES		:= tim.cc

# Libraries to link
LIBRARIES	:= 

# Subdirectories to make
SUBDIRS		:= 

# Software
AS		:= nasm
CC		:= gcc
CXX		:= g++

# Flags
CPPFLAGS	:= 
CFLAGS		:= $(if $(DEBUGMODE),-g -D DEBUG,-O2)
CXXFLAGS	:= $(if $(DEBUGMODE),-g -D DEBUG,-O2)
ASFLAGS		:= -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2)
LDFLAGS		:= -Wall $(if $(DEBUGMODE),,-s) $(if $(STATICLIBS), -static)

#_______________________________________________________________________________

DEPFILE		:= depends.mk
OBJECTS		:= $(addsuffix .o,$(basename $(SOURCES)))
LDLIBS		:= $(addprefix -l,$(LIBRARIES))
TARGET		:= $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
TARGET		:= $(TARGET)$(if $(BUILDALIB),.a,)$(if $(BUILDSOLIB),.so,)

.PHONY:	all subdirs target clean clean_all run depend dep $(SUBDIRS)

all: subdirs target

subdirs: $(SUBDIRS)

target: $(TARGET)

clean:
ifeq "$(MAKECMDGOALS)" "clean"
ifdef SUBDIRS
	@echo NOT RECURSING: Use \"make clean_all\" to clean subdirectoried as well...
endif
endif
	rm -f core $(DEPFILE) $(OBJECTS) $(TARGET)
	rm -f *~

clean_all: subdirs clean

ifndef BUILDALIB
ifndef BUILDSOLIB
run: target
	./$(TARGET)
endif
endif

#depend dep:
#	makedepend -f- -- $(CPPFLAGS) -- $(SOURCES) > $(DEPFILE)

$(SUBDIRS):
	@$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)

$(TARGET): $(OBJECTS)
ifdef BUILDALIB
	$(AR) rcs $(TARGET) $(OBJECTS)
else
	$(CXX) $(if $(BUILDSOLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDLIBS) 
endif

#%.o:	%.c
#	$(CC) -c $(CPPFLAGS) $(CFLAGS)
#%.o:	%.cc
#	$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
#%.o:	%.s
#	$(AS) $(ASFLAGS)

-include $(DEPFILE)

#_______________________________________________________________________________