forked from Thealexbarney/LibAtrac9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
60 lines (44 loc) · 1.47 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
NAME = libatrac9
CC = gcc
AR = ar
SFLAGS = -O2
CFLAGS = $(EXTRA_CFLAGS) -Wall -Wextra -std=c99
SHARED_SFLAGS = $(SFLAGS) -flto
SHARED_CFLAGS = $(CFLAGS) -fPIC
LDFLAGS = -shared -s -Wl,--version-script=libatrac9.version
SRCDIR = src
OBJDIR = obj
BINDIR = bin
STATIC_OBJDIR = $(OBJDIR)_static
SHARED_OBJDIR = $(OBJDIR)_shared
SRCS = $(wildcard $(SRCDIR)/*.c)
STATIC_OBJS = $(SRCS:$(SRCDIR)/%.c=$(STATIC_OBJDIR)/%.o)
SHARED_OBJS = $(SRCS:$(SRCDIR)/%.c=$(SHARED_OBJDIR)/%.o)
STATIC_FILENAME = $(NAME).a
SHARED_FILENAME = $(NAME).so
STATIC_NAME = $(BINDIR)/$(STATIC_FILENAME)
SHARED_NAME = $(BINDIR)/$(SHARED_FILENAME)
MKDIR = mkdir -p
RM = rm -f
RMDIR = rm -df
all: static shared
static: create_static_dir create_bin_dir $(STATIC_NAME)
shared: create_shared_dir create_bin_dir $(SHARED_NAME)
create_static_dir:
@$(MKDIR) $(STATIC_OBJDIR)
create_shared_dir:
@$(MKDIR) $(SHARED_OBJDIR)
create_bin_dir:
@$(MKDIR) $(BINDIR)
$(SHARED_NAME): $(SHARED_OBJS)
$(CC) $(SHARED_OBJS) $(SHARED_SFLAGS) $(LDFLAGS) -o $@
$(SHARED_OBJS): $(SHARED_OBJDIR)/%.o : $(SRCDIR)/%.c
$(CC) $(SHARED_SFLAGS) $(SHARED_CFLAGS) -c $< -o $@
$(STATIC_NAME): $(STATIC_OBJS)
$(AR) rcs $@ $^
$(STATIC_OBJS): $(STATIC_OBJDIR)/%.o : $(SRCDIR)/%.c
$(CC) $(SFLAGS) $(CFLAGS) -c $< -o $@
clean:
$(RM) $(SHARED_OBJS) $(SHARED_NAME) $(STATIC_OBJS) $(STATIC_NAME)
-@$(RMDIR) $(STATIC_OBJDIR) $(SHARED_OBJDIR) $(BINDIR) 2>/dev/null || true
.PHONY: all static shared create_static_dir create_shared_dir create_bin_dir clean