-
Notifications
You must be signed in to change notification settings - Fork 40
/
Makefile
190 lines (151 loc) · 4.63 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
VERSION = 0.2.0
API_MAJOR = 0
API_MINOR = 1
API_PATCH = 0
CFLAGS := -std=gnu99 -D_FILE_OFFSET_BITS=64 -Wall -Wextra -O3 -ffast-math -g -MMD $(CFLAGS)
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
SRC_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
vpath %.c $(SRC_DIR)
vpath %.h $(SRC_DIR)
vpath %.pc.in $(SRC_DIR)
-include .config
ifdef CONFIG_DEBUG
CFLAGS += -D_DEBUG
else
CFLAGS += -DNDEBUG
endif
ifdef CONFIG_WINDOWS
EXESUF ?= .exe
DLLSUF ?= .dll
LIBSUF ?= .a
else
DLLSUF ?= .so
LIBSUF ?= .a
LIBS ?= -lm
ifdef CONFIG_SHARED
SONAMESUF ?= .$(API_MAJOR).$(API_MINOR).$(API_PATCH)
SONAMESUF_MAJOR ?= .$(API_MAJOR)
SONAME ?= libdcadec$(DLLSUF)$(SONAMESUF_MAJOR)
endif
endif
ifdef CONFIG_SHARED
OUT_LIB ?= libdcadec/libdcadec$(DLLSUF)$(SONAMESUF)
else
OUT_LIB ?= libdcadec/libdcadec$(LIBSUF)
endif
OUT_DEC ?= dcadec$(EXESUF)
OUT_CUT ?= dcacut$(EXESUF)
OUT_DEV ?= test/stddev$(EXESUF)
SRC_DEV ?= test/stddev.c
CFLAGS_DEV ?= -O2 -Wall -Wextra
SRC_LIB = \
libdcadec/bitstream.c \
libdcadec/core_decoder.c \
libdcadec/dca_context.c \
libdcadec/dmix_tables.c \
libdcadec/exss_parser.c \
libdcadec/idct_fixed.c \
libdcadec/idct_float.c \
libdcadec/interpolator.c \
libdcadec/interpolator_fixed.c \
libdcadec/interpolator_float.c \
libdcadec/lbr_decoder.c \
libdcadec/ta.c \
libdcadec/xll_decoder.c
INC_LIB = \
libdcadec/dca_context.h
ifndef CONFIG_SMALL
SRC_LIB += libdcadec/dca_frame.c
SRC_LIB += libdcadec/dca_stream.c
SRC_LIB += libdcadec/dca_waveout.c
INC_LIB += libdcadec/dca_frame.h
INC_LIB += libdcadec/dca_stream.h
INC_LIB += libdcadec/dca_waveout.h
endif
OBJ_LIB = $(SRC_LIB:.c=.o)
DEP_LIB = $(SRC_LIB:.c=.d)
SRC_DEC = dcadec.c
OBJ_DEC = $(SRC_DEC:.c=.o)
DEP_DEC = $(SRC_DEC:.c=.d)
SRC_CUT = dcacut.c
OBJ_CUT = $(SRC_CUT:.c=.o)
DEP_CUT = $(SRC_CUT:.c=.d)
default: $(OUT_LIB) $(OUT_DEC)
lib: $(OUT_LIB)
all: $(OUT_LIB) $(OUT_DEC) $(OUT_CUT)
-include $(DEP_LIB) $(DEP_DEC) $(DEP_CUT)
$(OBJ_LIB): | objdir
$(OBJ_DEC): | objdir
$(OBJ_CUT): | objdir
objdir:
mkdir -p libdcadec
ifdef CONFIG_SHARED
CFLAGS_DLL = $(CFLAGS) -DDCADEC_SHARED -DDCADEC_INTERNAL
LDFLAGS_DLL = $(LDFLAGS) -shared
ifdef CONFIG_WINDOWS
IMP_LIB = libdcadec/libdcadec$(DLLSUF)$(LIBSUF)
IMP_DEF = libdcadec/libdcadec.def
EXTRA_LIB = $(IMP_LIB) $(IMP_DEF)
LDFLAGS_DLL += -static-libgcc
LDFLAGS_DLL += -Wl,--nxcompat,--dynamicbase
LDFLAGS_DLL += -Wl,--output-def,$(IMP_DEF)
LDFLAGS_DLL += -Wl,--out-implib,$(IMP_LIB)
else
CFLAGS_DLL += -fPIC -fvisibility=hidden
ifdef SONAME
LDFLAGS_DLL += -Wl,-soname,$(SONAME)
EXTRA_LIB += libdcadec/libdcadec$(DLLSUF)
EXTRA_LIB += libdcadec/libdcadec$(DLLSUF)$(SONAMESUF_MAJOR)
endif
IMP_LIB = -Llibdcadec -ldcadec
endif
libdcadec/%.o: libdcadec/%.c
$(CC) -c $(CFLAGS_DLL) -o $@ $<
$(OUT_LIB): $(OBJ_LIB)
$(CC) $(LDFLAGS_DLL) -o $@ $(OBJ_LIB) $(LIBS)
ifdef SONAME
ln -sf $(@F) libdcadec/libdcadec$(DLLSUF)
ln -sf $(@F) libdcadec/libdcadec$(DLLSUF)$(SONAMESUF_MAJOR)
endif
$(OUT_DEC): $(OBJ_DEC) $(OUT_LIB)
$(CC) $(LDFLAGS) -o $@ $(OBJ_DEC) $(IMP_LIB) $(LIBS)
$(OUT_CUT): $(OBJ_CUT) $(OUT_LIB)
$(CC) $(LDFLAGS) -o $@ $(OBJ_CUT) $(IMP_LIB) $(LIBS)
else
$(OUT_LIB): $(OBJ_LIB)
$(AR) crsu $@ $(OBJ_LIB)
$(OUT_DEC): $(OBJ_DEC) $(OUT_LIB)
$(CC) $(LDFLAGS) -o $@ $(OBJ_DEC) $(OUT_LIB) $(LIBS)
$(OUT_CUT): $(OBJ_CUT) $(OUT_LIB)
$(CC) $(LDFLAGS) -o $@ $(OBJ_CUT) $(OUT_LIB) $(LIBS)
endif
$(OUT_DEV): $(SRC_DEV)
$(CC) $(LDFLAGS) -o $@ $(CFLAGS_DEV) $< $(LIBS)
check: $(OUT_DEC) $(OUT_DEV)
cd test && ./test.sh
clean:
$(RM) $(OUT_LIB) $(OBJ_LIB) $(DEP_LIB) $(EXTRA_LIB)
$(RM) $(OUT_DEC) $(OBJ_DEC) $(DEP_DEC)
$(RM) $(OUT_CUT) $(OBJ_CUT) $(DEP_CUT)
$(RM) dcadec.pc
$(RM) $(OUT_DEV)
$(RM) -r test/decoded
.PHONY: dcadec.pc
dcadec.pc: dcadec.pc.in
sed 's,%PREFIX%,$(PREFIX),;s,%LIBDIR%,$(LIBDIR),;s,%INCLUDEDIR%,$(INCLUDEDIR),;s,%VERSION%,$(VERSION),' $< > $@
install-lib: $(OUT_LIB) dcadec.pc
install -d -m 755 $(DESTDIR)$(LIBDIR) $(DESTDIR)$(LIBDIR)/pkgconfig $(DESTDIR)$(INCLUDEDIR)/libdcadec
install -m 644 $(OUT_LIB) $(DESTDIR)$(LIBDIR)
install -m 644 $(addprefix $(SRC_DIR)/, $(INC_LIB)) $(DESTDIR)$(INCLUDEDIR)/libdcadec
install -m 644 dcadec.pc $(DESTDIR)$(LIBDIR)/pkgconfig
ifdef SONAME
ln -sf libdcadec$(DLLSUF)$(SONAMESUF) $(DESTDIR)$(LIBDIR)/libdcadec$(DLLSUF)
ln -sf libdcadec$(DLLSUF)$(SONAMESUF) $(DESTDIR)$(LIBDIR)/libdcadec$(DLLSUF)$(SONAMESUF_MAJOR)
endif
install-dec: $(OUT_DEC)
install -d -m 755 $(DESTDIR)$(BINDIR)
install -m 755 $(OUT_DEC) $(DESTDIR)$(BINDIR)
install: install-lib install-dec