-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile.7
More file actions
58 lines (43 loc) · 1.4 KB
/
Copy pathMakefile.7
File metadata and controls
58 lines (43 loc) · 1.4 KB
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
CXX := g++
# files that are compiled AND linked to create an application
APPS := app1.cc app2.cc app11.cc
# binaries are applications to run from the command line, linked from APPS
BINS := $(APPS:%.cc=%)
# source files are only compiled, typically one file for each class
SRCS := $(filter-out $(APPS), $(wildcard *.cc))
# name of object files generated automatically from source files
OBJS := $(subst .cc,.o, $(SRCS))
# name of our library
OURLIB := CMP
LIBFILE := lib$(OURLIB).a
# our linking options are added to LDFLAGS. If it has no previous value
# it only has what we add
LDFLAGS += -L. -l$(OURLIB)
# Use @ at the beginning of a recipe to prevent the comment from being shown in output
# only the output of the display will be displayed
list:
@echo "source files:\t" $(SRCS)
@echo "objects files:\t" $(OBJS)
@echo "applications:\t" $(APPS)
@echo "executables:\t" $(BINS)
# target to buil all binaries
bin: ${BINS}
## rule to make a BIN from an APPS file and the library
%: %.cc lib
$(CXX) -o $@ $(LDFLAGS) $<
# lib target requires there be a library called $(LIBFILE)
lib: $(LIBFILE)
# the library file needs the object files
$(LIBFILE): $(OBJS)
libtool -static -o $@ $^
# remove the object files that are no longer needed
rm -f $(OBJS)
# Rule to compile cc files
%.o: %.cc
$(CXX) -c $(CPPFLAGS) $<
# Rule to compile C files
%.o: %.C
$(CXX) -c $(CPPFLAGS) $<
clean:
rm -f $(LIBFILE)
rm -f $(BINS)