1#################### COMPILE OPTIONS #######################
2
3# Uncomment this for fixed-point build
4#FIXED_POINT=1
5
6# It is strongly recommended to uncomment one of these
7# VAR_ARRAYS: Use C99 variable-length arrays for stack allocation
8# USE_ALLOCA: Use alloca() for stack allocation
9# If none is defined, then the fallback is a non-threadsafe global array
10CFLAGS := -DUSE_ALLOCA $(CFLAGS)
11#CFLAGS := -DVAR_ARRAYS $(CFLAGS)
12
13# These options affect performance
14# HAVE_LRINTF: Use C99 intrinsics to speed up float-to-int conversion
15#CFLAGS := -DHAVE_LRINTF $(CFLAGS)
16
17###################### END OF OPTIONS ######################
18
19-include package_version
20
21include silk_sources.mk
22include celt_sources.mk
23include opus_sources.mk
24
25ifdef FIXED_POINT
26SILK_SOURCES += $(SILK_SOURCES_FIXED)
27else
28SILK_SOURCES += $(SILK_SOURCES_FLOAT)
29OPUS_SOURCES += $(OPUS_SOURCES_FLOAT)
30endif
31
32EXESUFFIX =
33LIBPREFIX = lib
34LIBSUFFIX = .a
35OBJSUFFIX = .o
36
37CC     = $(TOOLCHAIN_PREFIX)cc$(TOOLCHAIN_SUFFIX)
38AR     = $(TOOLCHAIN_PREFIX)ar
39RANLIB = $(TOOLCHAIN_PREFIX)ranlib
40CP     = $(TOOLCHAIN_PREFIX)cp
41
42cppflags-from-defines   = $(addprefix -D,$(1))
43cppflags-from-includes  = $(addprefix -I,$(1))
44ldflags-from-ldlibdirs  = $(addprefix -L,$(1))
45ldlibs-from-libs        = $(addprefix -l,$(1))
46
47WARNINGS = -Wall -W -Wstrict-prototypes -Wextra -Wcast-align -Wnested-externs -Wshadow
48CFLAGS  += -O2 -g $(WARNINGS) -DOPUS_BUILD
49CINCLUDES = include silk celt
50
51ifdef FIXED_POINT
52CFLAGS += -DFIXED_POINT=1 -DDISABLE_FLOAT_API
53CINCLUDES += silk/fixed
54else
55CINCLUDES += silk/float
56endif
57
58
59LIBS = m
60
61LDLIBDIRS = ./
62
63CFLAGS  += $(call cppflags-from-defines,$(CDEFINES))
64CFLAGS  += $(call cppflags-from-includes,$(CINCLUDES))
65LDFLAGS += $(call ldflags-from-ldlibdirs,$(LDLIBDIRS))
66LDLIBS  += $(call ldlibs-from-libs,$(LIBS))
67
68COMPILE.c.cmdline   = $(CC) -c $(CFLAGS) -o $@ $<
69LINK.o              = $(CC) $(LDPREFLAGS) $(LDFLAGS)
70LINK.o.cmdline      = $(LINK.o) $^ $(LDLIBS) -o $@$(EXESUFFIX)
71
72ARCHIVE.cmdline     = $(AR) $(ARFLAGS) $@ $^ && $(RANLIB) $@
73
74%$(OBJSUFFIX):%.c
75	$(COMPILE.c.cmdline)
76
77%$(OBJSUFFIX):%.cpp
78	$(COMPILE.cpp.cmdline)
79
80# Directives
81
82
83# Variable definitions
84LIB_NAME = opus
85TARGET = $(LIBPREFIX)$(LIB_NAME)$(LIBSUFFIX)
86
87SRCS_C = $(SILK_SOURCES) $(CELT_SOURCES) $(OPUS_SOURCES)
88
89OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SRCS_C))
90
91OPUSDEMO_SRCS_C = src/opus_demo.c
92OPUSDEMO_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSDEMO_SRCS_C))
93
94OPUSCOMPARE_SRCS_C = src/opus_compare.c
95OPUSCOMPARE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSCOMPARE_SRCS_C))
96
97# Rules
98all: lib opus_demo opus_compare
99
100lib: $(TARGET)
101
102$(TARGET): $(OBJS)
103	$(ARCHIVE.cmdline)
104
105opus_demo$(EXESUFFIX): $(OPUSDEMO_OBJS) $(TARGET)
106	$(LINK.o.cmdline)
107
108opus_compare$(EXESUFFIX): $(OPUSCOMPARE_OBJS)
109	$(LINK.o.cmdline)
110
111celt/celt.o: CFLAGS += -DPACKAGE_VERSION='$(PACKAGE_VERSION)'
112celt/celt.o: package_version
113
114package_version: force
115	@if [ -x ./update_version ]; then \
116		./update_version || true; \
117	elif [ ! -e ./package_version ]; then \
118		echo 'PACKAGE_VERSION="unknown"' > ./package_version; \
119	fi
120
121force:
122
123clean:
124	rm -f opus_demo$(EXESUFFIX) opus_compare$(EXESUFFIX) $(TARGET) \
125		$(OBJS) $(OPUSDEMO_OBJS) $(OPUSCOMPARE_OBJS)
126
127.PHONY: all lib clean
128