-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
114 lines (85 loc) · 3.26 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
109
110
111
112
113
114
SRCDIR := $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
USE_EXTERNAL_LIBDEFLATE ?= 0
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man
CC ?= gcc
CXX ?= g++
CFLAGS ?= -O2
CXXFLAGS ?= $(CFLAGS)
PKG_CONFIG ?= pkg-config
CFLAGS_UV = $(shell $(PKG_CONFIG) --cflags libuv)
LIBS_UV = $(shell $(PKG_CONFIG) --libs libuv)
CFLAGS_LZ4 = $(shell $(PKG_CONFIG) --cflags liblz4)
LIBS_LZ4 = $(shell $(PKG_CONFIG) --libs liblz4)
CFLAGS_ZLIB = $(shell $(PKG_CONFIG) --cflags zlib)
LIBS_ZLIB = $(shell $(PKG_CONFIG) --libs zlib)
DEP_FLAGS := $(CFLAGS_UV) $(CFLAGS_LZ4) $(CFLAGS_ZLIB)
LIBS := $(LIBS_UV) $(LIBS_LZ4) $(LIBS_ZLIB)
OBJDIR := obj
MKDIRS := $(OBJDIR)/src $(OBJDIR)/cli $(OBJDIR)/zopfli/src/zopfli
SRC_CFLAGS += -W -Wall -Wextra -Wno-implicit-function-declaration -DNDEBUG=1
SRC_CXXFLAGS += -W -Wall -Wextra -std=c++11 -I$(SRCDIR)/zopfli/src -I$(SRCDIR)/7zip \
-DNDEBUG=1 -I$(SRCDIR)/libdeflate -Wno-unused-parameter -Wno-unused-variable \
-pthread $(DEP_FLAGS)
SRC_CXX_SRC := $(wildcard $(SRCDIR)/src/*.cpp)
SRC_CXX_TMP := $(SRC_CXX_SRC:.cpp=.o)
SRC_CXX_OBJ := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(SRC_CXX_TMP))
CLI_CXX_SRC := $(wildcard $(SRCDIR)/cli/*.cpp)
CLI_CXX_TMP := $(CLI_CXX_SRC:.cpp=.o)
CLI_CXX_OBJ := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(CLI_CXX_TMP))
ZOPFLI_C_DIR := $(SRCDIR)/zopfli/src/zopfli
ZOPFLI_C_SRC := $(ZOPFLI_C_DIR)/blocksplitter.c $(ZOPFLI_C_DIR)/cache.c \
$(ZOPFLI_C_DIR)/deflate.c $(ZOPFLI_C_DIR)/gzip_container.c \
$(ZOPFLI_C_DIR)/hash.c $(ZOPFLI_C_DIR)/katajainen.c \
$(ZOPFLI_C_DIR)/lz77.c $(ZOPFLI_C_DIR)/squeeze.c \
$(ZOPFLI_C_DIR)/tree.c $(ZOPFLI_C_DIR)/util.c \
$(ZOPFLI_C_DIR)/zlib_container.c $(ZOPFLI_C_DIR)/zopfli_lib.c
ZOPFLI_C_TMP := $(ZOPFLI_C_SRC:.c=.o)
ZOPFLI_C_OBJ := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(ZOPFLI_C_TMP))
ifeq ($(OS),Windows_NT)
LIBDEFLATE := libdeflatestatic.lib
LIBS += -luuid
else
LIBDEFLATE := libdeflate.a
endif
SRC_7ZIP := $(OBJDIR)/7zip/7zip.a
SRC_LIBDEFLATE := $(SRCDIR)/libdeflate/$(LIBDEFLATE)
OBJS := $(SRC_CXX_OBJ) $(CLI_CXX_OBJ) $(ZOPFLI_C_OBJ) $(SRC_7ZIP)
ifeq ($(USE_EXTERNAL_LIBDEFLATE), 0)
OBJS += $(SRC_LIBDEFLATE)
else
CFLAGS_LIBDEFLATE = $(shell $(PKG_CONFIG) --cflags libdeflate)
LIBS_LIBDEFLATE = $(shell $(PKG_CONFIG) --libs libdeflate)
SRC_CXXFLAGS += $(CFLAGS_LIBDEFLATE)
LIBS += $(LIBS_LIBDEFLATE)
endif
.PHONY: all clean install uninstall
all: maxcso
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp $(OBJDIR)/.done
$(CXX) -c $(SRC_CXXFLAGS) $(CXXFLAGS) -o $@ $<
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(OBJDIR)/.done
$(CC) -c $(SRC_CFLAGS) $(CFLAGS) -o $@ $<
maxcso: $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $(SRC_CXXFLAGS) $(CXXFLAGS) $^ $(LIBS)
$(SRC_7ZIP):
$(MAKE) -f $(SRCDIR)/7zip/Makefile 7zip.a
$(SRC_LIBDEFLATE):
$(MAKE) -C $(SRCDIR)/libdeflate $(LIBDEFLATE)
$(OBJDIR)/.done:
@mkdir -p $(MKDIRS)
@touch $@
install: all
mkdir -p $(DESTDIR)$(BINDIR)
mkdir -p $(DESTDIR)$(MANDIR)/man1
cp maxcso $(DESTDIR)$(BINDIR)
cp $(SRCDIR)/maxcso.1 $(DESTDIR)$(MANDIR)/man1
chmod 0755 $(DESTDIR)$(BINDIR)/maxcso
chmod 0644 $(DESTDIR)$(MANDIR)/man1/maxcso.1
uninstall:
rm -f $(DESTDIR)$(BINDIR)/maxcso
rm -f $(DESTDIR)$(MANDIR)/man1/maxcso.1
clean:
rm -rf -- $(OBJDIR)
rm -f maxcso
$(MAKE) -C $(SRCDIR)/libdeflate clean