-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
44 lines (36 loc) · 910 Bytes
/
Makefile
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
PROJECT=cfc
SOURCES=object.cpp string.cpp
LIBRARY=shared
INCPATHS=
LIBPATHS=
LDFLAGS=
CFLAGS=-c -Wall
CC=gcc
# ------------ MAGIC BEGINS HERE -------------
# Automatic generation of some important lists
OBJECTS=$(SOURCES:.cpp=.o)
INCFLAGS=$(foreach TMP,$(INCPATHS),-I$(TMP))
LIBFLAGS=$(foreach TMP,$(LIBPATHS),-L$(TMP))
# Set up the output file names for the different output types
ifeq "$(LIBRARY)" "shared"
BINARY=lib$(PROJECT).so
LDFLAGS += -shared -fPIC
else ifeq "$(LIBRARY)" "static"
BINARY=lib$(PROJECT).a
else
BINARY=$(PROJECT)
endif
all: $(SOURCES) $(BINARY)
$(BINARY): $(OBJECTS)
# Link the object files, or archive into a static library
ifeq "$(LIBRARY)" "static"
ar rcs $(BINARY) $(OBJECTS)
else
$(CC) $(LIBFLAGS) $(OBJECTS) $(LDFLAGS) -o $@
endif
.cpp.o:
$(CC) $(INCFLAGS) $(CFLAGS) -O3 -fPIC $< -o $@
distclean: clean
rm -f $(BINARY)
clean:
rm -f $(OBJECTS)