blob: 90a48f0cc0e92e514f270bb2af552fe6f66b3e4f [file] [log] [blame]
Jean-Marc Valin445d5f42011-03-09 14:15:32 -05001#################### COMPILE OPTIONS #######################
2
Ralph Giles6f06d342011-07-25 13:26:57 -07003# Uncomment this for fixed-point build
Jean-Marc Valinaa8c5f62014-06-19 04:11:20 -04004#FIXED_POINT=1
Jean-Marc Valin445d5f42011-03-09 14:15:32 -05005
Ralph Giles6f06d342011-07-25 13:26:57 -07006# 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
Gregory Maxwellfc8b6052011-09-28 17:09:23 -040010CFLAGS := -DUSE_ALLOCA $(CFLAGS)
11#CFLAGS := -DVAR_ARRAYS $(CFLAGS)
Jean-Marc Valin445d5f42011-03-09 14:15:32 -050012
Ralph Giles6f06d342011-07-25 13:26:57 -070013# These options affect performance
14# HAVE_LRINTF: Use C99 intrinsics to speed up float-to-int conversion
Gregory Maxwellfc8b6052011-09-28 17:09:23 -040015#CFLAGS := -DHAVE_LRINTF $(CFLAGS)
Ralph Giles6f06d342011-07-25 13:26:57 -070016
Jean-Marc Valin445d5f42011-03-09 14:15:32 -050017###################### END OF OPTIONS ######################
Jean-Marc Valinedaf7882011-03-09 11:42:15 -050018
Ron2f2f9d62013-05-11 02:05:24 +093019-include package_version
20
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050021include silk_sources.mk
22include celt_sources.mk
23include opus_sources.mk
24
Jean-Marc Valinb2c00d22011-08-02 08:13:42 -040025ifdef FIXED_POINT
26SILK_SOURCES += $(SILK_SOURCES_FIXED)
27else
28SILK_SOURCES += $(SILK_SOURCES_FLOAT)
Jean-Marc Valin5f4b8dd2012-10-09 14:25:06 -040029OPUS_SOURCES += $(OPUS_SOURCES_FLOAT)
Jean-Marc Valinb2c00d22011-08-02 08:13:42 -040030endif
31
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050032EXESUFFIX =
33LIBPREFIX = lib
34LIBSUFFIX = .a
35OBJSUFFIX = .o
36
Jean-Marc Valin72273002012-04-20 10:26:08 -040037CC = $(TOOLCHAIN_PREFIX)cc$(TOOLCHAIN_SUFFIX)
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050038AR = $(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))
Ron8ee899b2013-05-11 02:13:47 +093045ldlibs-from-libs = $(addprefix -l,$(1))
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050046
Gregory Maxwellee931fc2011-09-07 02:25:55 -040047WARNINGS = -Wall -W -Wstrict-prototypes -Wextra -Wcast-align -Wnested-externs -Wshadow
Jean-Marc Valinaa8c5f62014-06-19 04:11:20 -040048CFLAGS += -O2 -g $(WARNINGS) -DOPUS_BUILD
Ron8ee899b2013-05-11 02:13:47 +093049CINCLUDES = include silk celt
50
Jean-Marc Valinedaf7882011-03-09 11:42:15 -050051ifdef FIXED_POINT
Jean-Marc Valin445d5f42011-03-09 14:15:32 -050052CFLAGS += -DFIXED_POINT=1 -DDISABLE_FLOAT_API
Ron8ee899b2013-05-11 02:13:47 +093053CINCLUDES += silk/fixed
54else
55CINCLUDES += silk/float
Jean-Marc Valinedaf7882011-03-09 11:42:15 -050056endif
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050057
Gregory Maxwellfc8b6052011-09-28 17:09:23 -040058
59LIBS = m
60
61LDLIBDIRS = ./
62
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050063CFLAGS += $(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 $@ $<
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050069LINK.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
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050082
83# Variable definitions
Jean-Marc Valinf85bc8a2011-02-03 12:08:38 -050084LIB_NAME = opus
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050085TARGET = $(LIBPREFIX)$(LIB_NAME)$(LIBSUFFIX)
86
87SRCS_C = $(SILK_SOURCES) $(CELT_SOURCES) $(OPUS_SOURCES)
88
89OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SRCS_C))
90
Gregory Maxwella5ff49e2011-10-26 19:56:00 -040091OPUSDEMO_SRCS_C = src/opus_demo.c
92OPUSDEMO_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSDEMO_SRCS_C))
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -050093
Gregory Maxwell5b215d82014-01-08 11:04:29 -080094TESTOPUSAPI_SRCS_C = tests/test_opus_api.c
95TESTOPUSAPI_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSAPI_SRCS_C))
96
97TESTOPUSDECODE_SRCS_C = tests/test_opus_decode.c
98TESTOPUSDECODE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSDECODE_SRCS_C))
99
Jean-Marc Valin880f57a2016-10-29 16:10:57 -0400100TESTOPUSENCODE_SRCS_C = tests/test_opus_encode.c tests/opus_encode_regressions.c
Gregory Maxwell5b215d82014-01-08 11:04:29 -0800101TESTOPUSENCODE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSENCODE_SRCS_C))
102
103TESTOPUSPADDING_SRCS_C = tests/test_opus_padding.c
104TESTOPUSPADDING_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSPADDING_SRCS_C))
105
Jean-Marc Valinc4ca21f2011-09-15 10:10:40 -0700106OPUSCOMPARE_SRCS_C = src/opus_compare.c
107OPUSCOMPARE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSCOMPARE_SRCS_C))
108
Ralph Gilescf902db2015-12-28 23:37:49 -0800109TESTS := test_opus_api test_opus_decode test_opus_encode test_opus_padding
110
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -0500111# Rules
Ralph Gilescf902db2015-12-28 23:37:49 -0800112all: lib opus_demo opus_compare $(TESTS)
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -0500113
114lib: $(TARGET)
115
Ralph Gilescf902db2015-12-28 23:37:49 -0800116check: all
117 for test in $(TESTS); do ./$$test; done
118
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -0500119$(TARGET): $(OBJS)
120 $(ARCHIVE.cmdline)
121
Gregory Maxwella5ff49e2011-10-26 19:56:00 -0400122opus_demo$(EXESUFFIX): $(OPUSDEMO_OBJS) $(TARGET)
Jean-Marc Valin1c09feb2011-02-03 11:34:11 -0500123 $(LINK.o.cmdline)
Ralph Giles5f6e4722012-03-19 17:10:13 -0700124
Gregory Maxwell5b215d82014-01-08 11:04:29 -0800125test_opus_api$(EXESUFFIX): $(TESTOPUSAPI_OBJS) $(TARGET)
126 $(LINK.o.cmdline)
127
128test_opus_decode$(EXESUFFIX): $(TESTOPUSDECODE_OBJS) $(TARGET)
129 $(LINK.o.cmdline)
130
131test_opus_encode$(EXESUFFIX): $(TESTOPUSENCODE_OBJS) $(TARGET)
132 $(LINK.o.cmdline)
133
134test_opus_padding$(EXESUFFIX): $(TESTOPUSPADDING_OBJS) $(TARGET)
135 $(LINK.o.cmdline)
136
Jean-Marc Valinc4ca21f2011-09-15 10:10:40 -0700137opus_compare$(EXESUFFIX): $(OPUSCOMPARE_OBJS)
138 $(LINK.o.cmdline)
Ralph Giles66767ee2011-10-31 10:36:39 -0700139
Ron2f2f9d62013-05-11 02:05:24 +0930140celt/celt.o: CFLAGS += -DPACKAGE_VERSION='$(PACKAGE_VERSION)'
141celt/celt.o: package_version
142
143package_version: force
Ron8d925ec2013-05-11 07:33:03 +0930144 @if [ -x ./update_version ]; then \
145 ./update_version || true; \
146 elif [ ! -e ./package_version ]; then \
147 echo 'PACKAGE_VERSION="unknown"' > ./package_version; \
148 fi
Ron2f2f9d62013-05-11 02:05:24 +0930149
150force:
151
Jean-Marc Valin34e99da2011-02-03 13:46:32 -0500152clean:
Ron8f486e72013-05-12 14:09:28 +0930153 rm -f opus_demo$(EXESUFFIX) opus_compare$(EXESUFFIX) $(TARGET) \
Gregory Maxwell5b215d82014-01-08 11:04:29 -0800154 test_opus_api$(EXESUFFIX) test_opus_decode$(EXESUFFIX) \
155 test_opus_encode$(EXESUFFIX) test_opus_padding$(EXESUFFIX) \
156 $(OBJS) $(OPUSDEMO_OBJS) $(OPUSCOMPARE_OBJS) $(TESTOPUSAPI_OBJS) \
157 $(TESTOPUSDECODE_OBJS) $(TESTOPUSENCODE_OBJS) $(TESTOPUSPADDING_OBJS)
Ron8ee899b2013-05-11 02:13:47 +0930158
Ralph Gilescf902db2015-12-28 23:37:49 -0800159.PHONY: all lib clean force check