e56291a990bfc9443f94fb1b4a6eaf84e94c738f
[opus.git] / Makefile.unix
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
10 CFLAGS := -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 #      inline: Don't use the 'inline' keyword (for ANSI C compilers)
16 #CFLAGS := -DHAVE_LRINTF $(CFLAGS)
17 #CFLAGS := -Dinline= $(CFLAGS)
18
19 ###################### END OF OPTIONS ######################
20
21 -include package_version
22
23 include silk_sources.mk
24 include celt_sources.mk
25 include opus_sources.mk
26
27 ifdef FIXED_POINT
28 SILK_SOURCES += $(SILK_SOURCES_FIXED)
29 else
30 SILK_SOURCES += $(SILK_SOURCES_FLOAT)
31 OPUS_SOURCES += $(OPUS_SOURCES_FLOAT)
32 endif
33
34 EXESUFFIX =
35 LIBPREFIX = lib
36 LIBSUFFIX = .a
37 OBJSUFFIX = .o
38
39 CC     = $(TOOLCHAIN_PREFIX)cc$(TOOLCHAIN_SUFFIX)
40 AR     = $(TOOLCHAIN_PREFIX)ar
41 RANLIB = $(TOOLCHAIN_PREFIX)ranlib
42 CP     = $(TOOLCHAIN_PREFIX)cp
43
44 cppflags-from-defines   = $(addprefix -D,$(1))
45 cppflags-from-includes  = $(addprefix -I,$(1))
46 ldflags-from-ldlibdirs  = $(addprefix -L,$(1))
47 ldlibs-from-libs        = $(addprefix -l,$(1))
48
49 WARNINGS = -Wall -W -Wstrict-prototypes -Wextra -Wcast-align -Wnested-externs -Wshadow
50 CFLAGS  += -O2 -g $(WARNINGS) -DOPUS_BUILD
51 CINCLUDES = include silk celt
52
53 ifdef FIXED_POINT
54 CFLAGS += -DFIXED_POINT=1 -DDISABLE_FLOAT_API
55 CINCLUDES += silk/fixed
56 else
57 CINCLUDES += silk/float
58 endif
59
60
61 LIBS = m
62
63 LDLIBDIRS = ./
64
65 CFLAGS  += $(call cppflags-from-defines,$(CDEFINES))
66 CFLAGS  += $(call cppflags-from-includes,$(CINCLUDES))
67 LDFLAGS += $(call ldflags-from-ldlibdirs,$(LDLIBDIRS))
68 LDLIBS  += $(call ldlibs-from-libs,$(LIBS))
69
70 COMPILE.c.cmdline   = $(CC) -c $(CFLAGS) -o $@ $<
71 LINK.o              = $(CC) $(LDPREFLAGS) $(LDFLAGS)
72 LINK.o.cmdline      = $(LINK.o) $^ $(LDLIBS) -o $@$(EXESUFFIX)
73
74 ARCHIVE.cmdline     = $(AR) $(ARFLAGS) $@ $^ && $(RANLIB) $@
75
76 %$(OBJSUFFIX):%.c
77         $(COMPILE.c.cmdline)
78
79 %$(OBJSUFFIX):%.cpp
80         $(COMPILE.cpp.cmdline)
81
82 # Directives
83
84
85 # Variable definitions
86 LIB_NAME = opus
87 TARGET = $(LIBPREFIX)$(LIB_NAME)$(LIBSUFFIX)
88
89 SRCS_C = $(SILK_SOURCES) $(CELT_SOURCES) $(OPUS_SOURCES)
90
91 OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SRCS_C))
92
93 OPUSDEMO_SRCS_C = src/opus_demo.c
94 OPUSDEMO_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSDEMO_SRCS_C))
95
96 OPUSCOMPARE_SRCS_C = src/opus_compare.c
97 OPUSCOMPARE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSCOMPARE_SRCS_C))
98
99 # Rules
100 all: lib opus_demo opus_compare
101
102 lib: $(TARGET)
103
104 $(TARGET): $(OBJS)
105         $(ARCHIVE.cmdline)
106
107 opus_demo$(EXESUFFIX): $(OPUSDEMO_OBJS) $(TARGET)
108         $(LINK.o.cmdline)
109
110 opus_compare$(EXESUFFIX): $(OPUSCOMPARE_OBJS)
111         $(LINK.o.cmdline)
112
113 celt/celt.o: CFLAGS += -DPACKAGE_VERSION='$(PACKAGE_VERSION)'
114 celt/celt.o: package_version
115
116 package_version: force
117         @if [ -x ./update_version ]; then \
118                 ./update_version || true; \
119         elif [ ! -e ./package_version ]; then \
120                 echo 'PACKAGE_VERSION="unknown"' > ./package_version; \
121         fi
122
123 force:
124
125 clean:
126         rm -f opus_demo$(EXESUFFIX) opus_compare$(EXESUFFIX) $(TARGET) \
127                 $(OBJS) $(OPUSDEMO_OBJS) $(OPUSCOMPARE_OBJS)
128
129 .PHONY: all lib clean