-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathMakefile
108 lines (91 loc) · 3.15 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
.PHONY: all clean
PLATFORM ?= $(shell uname -s)
BUILD_PATH ?= build
OBJ_PATH ?= obj
# installation prefix
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
BINDIR ?= $(PREFIX)/bin
# platform specific settings:
ifeq ($(PLATFORM), Linux)
LDFLAGS = -lm -ldl
RANLIB = ar -crs
LIBEXT = so
DYNAMIC_CFLAGS_EXTRA = -shared -fvisibility=hidden
else ifeq ($(PLATFORM), Darwin)
LDFLAGS =
RANLIB = libtool -static -o
LIBEXT = dylib
DYNAMIC_CFLAGS_EXTRA = -dynamiclib -fvisibility=hidden
else ifneq ($(findstring MINGW64_NT,$(PLATFORM)),)
LDFLAGS = -lm
RANLIB = ar -crs
LIBEXT = so
DYNAMIC_CFLAGS_EXTRA = -shared -fvisibility=hidden
endif
# identical for all platforms:
UMKA_LIB_STATIC = $(BUILD_PATH)/libumka.a
UMKA_LIB_DYNAMIC = $(BUILD_PATH)/libumka.$(LIBEXT)
UMKA_EXE = $(BUILD_PATH)/umka
CFLAGS = -s -fPIC -O3 -Wall -Wno-format-security -malign-double -fno-strict-aliasing -DUMKA_EXT_LIBS
STATIC_CFLAGS = $(CFLAGS) -DUMKA_STATIC
DYNAMIC_CFLAGS = $(CFLAGS) -DUMKA_BUILD $(DYNAMIC_CFLAGS_EXTRA)
SRCS = $(filter-out src/umka.c,$(wildcard src/*.c))
OBJS_STATIC = $(sort $(SRCS:src/%.c=$(OBJ_PATH)/%_static.o))
OBJS_DYNAMIC = $(sort $(SRCS:src/%.c=$(OBJ_PATH)/%_dynamic.o))
APIS = src/umka_api.h
OBJS_EXE = $(OBJ_PATH)/umka_static.o
all: $(UMKA_EXE) $(UMKA_LIB_STATIC) $(UMKA_LIB_DYNAMIC)
static: $(UMKA_LIB_STATIC)
dynamic: $(UMKA_LIB_DYNAMIC)
exe: $(UMKA_EXE)
clean:
$(RM) $(BUILD_PATH) $(OBJ_PATH) -r
install: all
@echo "Installing to the following directories:"
@echo " Libraries: $(DESTDIR)$(LIBDIR)"
@echo " Includes: $(DESTDIR)$(INCLUDEDIR)"
@echo " Binaries: $(DESTDIR)$(BINDIR)"
@mkdir -p -- $(DESTDIR)$(LIBDIR)
@mkdir -p -- $(DESTDIR)$(BINDIR)
@mkdir -p -- $(DESTDIR)$(INCLUDEDIR)
@echo "Copying files..."
@cp $(UMKA_LIB_STATIC) $(DESTDIR)$(LIBDIR)/
@cp $(UMKA_LIB_DYNAMIC) $(DESTDIR)$(LIBDIR)/
@cp $(UMKA_EXE) $(DESTDIR)$(BINDIR)/
@cp $(APIS) $(DESTDIR)$(INCLUDEDIR)/
@echo "Installation complete!"
uninstall:
@echo "Uninstalling following files:"
@echo " $(DESTDIR)$(LIBDIR)/libumka.a"
@echo " $(DESTDIR)$(LIBDIR)/libumka.so"
@echo " $(DESTDIR)$(BINDIR)/umka"
@echo " $(DESTDIR)$(INCLUDEDIR)/umka_api.h"
@rm -f -- $(DESTDIR)$(LIBDIR)/libumka.a
@rm -f -- $(DESTDIR)$(LIBDIR)/libumka.so
@rm -f -- $(DESTDIR)$(BINDIR)/umka
@rm -f -- $(DESTDIR)$(INCLUDEDIR)/umka_api.h
@echo "Uninstallation complete!"
$(UMKA_LIB_STATIC): $(OBJS_STATIC)
@echo AR $@
@mkdir -p -- $(BUILD_PATH)/include/
@$(RANLIB) $(UMKA_LIB_STATIC) $^
@cp $(APIS) $(BUILD_PATH)/include/
$(UMKA_LIB_DYNAMIC): $(OBJS_DYNAMIC)
@echo LD $@
@mkdir -p -- $(BUILD_PATH)/include/
@$(CC) $(DYNAMIC_CFLAGS) -o $(UMKA_LIB_DYNAMIC) $^ $(LDFLAGS)
@cp $(APIS) $(BUILD_PATH)/include/
$(UMKA_EXE): $(OBJS_EXE) $(UMKA_LIB_STATIC)
@echo LD $@
@mkdir -p -- $(dir $@)
@$(CC) $(STATIC_CFLAGS) -o $(UMKA_EXE) $^ $(LDFLAGS)
$(OBJ_PATH)/%_static.o: src/%.c
@echo CC $@
@mkdir -p -- $(dir $@)
@$(CC) $(STATIC_CFLAGS) -o $@ -c $^
$(OBJ_PATH)/%_dynamic.o: src/%.c
@echo CC $@
@mkdir -p -- $(dir $@)
@$(CC) $(DYNAMIC_CFLAGS) -o $@ -c $^