-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
70 lines (55 loc) · 1.21 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
61
62
63
64
65
66
67
68
69
70
CC = clang
CFLAGS = -Wall
OBJDIR = out
LIBDIR = lib
LIBNAME = libowl
LIBTYPE = static
SRCS = $(wildcard *.c */*.c)
OB = $(notdir $(patsubst %.c,%.o,$(SRCS)))
OBJS = $(addprefix $(OBJDIR)/,$(OB))
ifdef SHARED
LIBTYPE = shared
endif
ifeq ($(LIBTYPE),shared)
LIBFILE = $(LIBDIR)/$(LIBNAME).so
CFLAGS += -fPIC
LDFLAGS = -shared
else
LIBFILE = $(LIBDIR)/$(LIBNAME).a
endif
all: main $(LIBFILE)
debug:
@echo 'SRCS: "$(SRCS)"'
@echo 'OB: "$(OB)"'
@echo 'OBJS: "$(OBJS)"'
@echo 'LIBFILE: "$(LIBFILE)"'
@echo 'CFLAGS: "$(CFLAGS)"'
@echo 'LDFLAGS: "$(LDFLAGS)"'
main: $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
# Compile with linked lib
# main: main.o libowl.a
# $(CC) $(CFLAGS) -o $@ $^ -L. -lowl
$(OBJDIR)/%.o: %.c | $(OBJDIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJDIR)/%.o: */%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(LIBDIR):
mkdir $(LIBDIR)
$(OBJDIR):
mkdir $(OBJDIR)
ifeq ($(LIBTYPE),shared)
$(LIBFILE): $(OBJS) | $(LIBDIR)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
else
$(LIBFILE): $(OBJS) | $(LIBDIR)
ar -rcs $@ $^
endif
.PHONY: clean all
clean:
rm -rf *.o */*.o main $(LIBDIR)/*.a $(LIBDIR)/*.so $(OBJDIR) $(LIBDIR)
ifeq ($(filter $(MAKECMDGOALS),lib),lib)
ifndef libtype
$(error libtype is undefined)
endif
endif