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
93
94
95
96
|
# Edam's general-purpose makefile v1.11
#_______________________________________________________________________________
# 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 :=
# 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,)
# Turn clean_all in to a recursive clean
ifeq "$(MAKECMDGOALS)" "clean_all"
export RECURSIVE_CLEAN := 1
MAKECMDGOALS := clean
endif
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
all: subdirs target
subdirs: $(SUBDIRS)
target: $(TARGET)
ifdef RECURSIVE_CLEAN
clean clean_all: subdirs
else
clean:
@echo "NOT RECURSING: use 'make clean_all' to clean subdirectories as well."
endif
rm -f $(OBJECTS) $(TARGET) core $(DEPFILE) *~
ifndef BUILDALIB
ifndef BUILDSOLIB
run: target
./$(TARGET)
endif
endif
#depend dep:
# makedepend -f- -- $(CPPFLAGS) -- $(SOURCES) > $(DEPFILE)
$(SUBDIRS):
@echo ==== Sub directory: $@
@$(MAKE) --no-print-directory -C $@ $(filter-out $(SUBDIRS),$(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)
#_______________________________________________________________________________
|