-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
60 lines (45 loc) · 1.32 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
CXX = gcc
CFLAGS = -Wall -Werror -fpic -pedantic
LIBSDIR = -L.
INCLUDEDIR = -I.
LIBCORENAME = container
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb -DDEBUG
endif
ifeq ($(OS), Windows_NT)
($warning Windows build is not supported yet)
# EXPORT = export.bat
# LIBTARGET :=$(LIBCORENAME:=.dll)
# CLEANCMD = @del /q *.o *.dll *.exe *.so
else
EXPORT = sh export.sh
LIBTARGET := lib$(LIBCORENAME:=.so)
LIBSDIR += -L/usr/lib
INCLUDEDIR += -I/usr/include
CLEANCMD = rm -rf build/
P = -p
endif
SOURCEDIR=.
BUILDDIR=build
SOURCES = $(wildcard $(SOURCEDIR)/*.c)
OBJECTS = $(patsubst $(SOURCEDIR)/%.c,$(BUILDDIR)/%.o,$(SOURCES))
EXECUTABLE = main
LIBCORENAME = container
LIBTARGET:=lib$(LIBCORENAME:=.so)
all: dir $(OBJECTS) $(LIBTARGET) $(EXECUTABLE)
dir:
@mkdir $(BUILDDIR) $(P)
run: all
./$(EXECUTABLE)
$(EXECUTABLE): $(LIBTARGET)
$(CXX) $(CFLAGS) $(INCLUDEDIR) $(LIBSDIR) $(BUILDDIR)/$(EXECUTABLE:=.o) -o $(EXECUTABLE) -l$(LIBCORENAME) -lm
$(LIBTARGET) : $(OBJECTS)
$(CXX) $(CFLAGS) -shared $(filter-out $(BUILDDIR)/main.o,$(OBJECTS)) -o $(LIBTARGET)
$(BUILDDIR)/$(EXECUTABLE): $(OBJECTS)
$(CXX) $(CFLAGS) -c -o $@ $<
$(OBJECTS): $(BUILDDIR)/%.o : $(SOURCEDIR)/%.c
$(CXX) $(CFLAGS) $(INCLUDEDIR) -c -o $@ $<
clean:
rm -rf build/ $(EXECUTABLE) $(LIBTARGET)
@echo CLEAN