Makefile 6.75 KB
Newer Older
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
1
2
3
4
5
6
7
# NOTE: This Makefile requires GNU make
# Location to put the targets.
TARGETBINDIR = .
TESTBINDIR = tests
TARGETLIBDIR = .
# Name of the targets
LIBOPUSFILE_TARGET = libopusfile.a
8
LIBOPUSURL_TARGET = libopusurl.a
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
9
10
11
12
13
14
15
16
OPUSFILE_EXAMPLE_TARGET = opusfile_example
SEEKING_EXAMPLE_TARGET = seeking_example
# Test targets
#TODO: tests
FOO_TARGET = foo
# The command to use to generate dependency information
MAKEDEPEND = ${CC} -MM
#MAKEDEPEND = makedepend -f- -Y --
17
18
19
# Optional features to enable
#CFLAGS := $(CFLAGS) -DOP_HAVE_LRINTF
CFLAGS := $(CFLAGS) -DOP_ENABLE_HTTP
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
20
21
22
23
24
25
# Extra compilation flags.
# You may get speed increases by including flags such as -O2 or -O3 or
#  -ffast-math, or additional flags, depending on your system and compiler.
# The -g flag will generally include debugging information.
CFLAGS := -g $(CFLAGS)
CFLAGS := -DOP_ENABLE_ASSERTIONS $(CFLAGS)
26
# These are gcc-only, but not actually critical.
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
27
28
29
30
31
CFLAGS := -fPIC $(CFLAGS)
CFLAGS := -std=c89 -pedantic $(CFLAGS)
CFLAGS := -fvisibility=hidden $(CFLAGS)
CFLAGS := -Wextra -Wno-parentheses -Wno-long-long $(CFLAGS)
CFLAGS := -Wall $(CFLAGS)
32
33
34
35
36
37
# The list of pkg-config packages we depend on.
PACKAGES := ogg opus
ifeq ($(findstring -DOP_ENABLE_HTTP,${CFLAGS}),-DOP_ENABLE_HTTP)
PACKAGES += openssl
endif
# The location of include files.
38
# Modify these to point to your Ogg and Opus include directories if they are
39
40
#  not installed in a standard location.
CINCLUDE := `pkg-config --cflags ${PACKAGES}`
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
41
42

# Libraries to link with, and the location of library files.
43
44
45
46
LIBS := `pkg-config --libs ${PACKAGES}`
ifeq ($(findstring -DOP_HAVE_LRINTF,${CFLAGS}),-DOP_HAVE_LRINTF)
LIBS := -lm $(LIBS)
endif
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
47

48
49
50
# Extras for the MS target
ifneq ($(findstring mingw,${CC}),)
LIBS += -lwsock32 -lws2_32 -lgdi32 -lcrypt32
51
EXEEXT := .exe
52
53
endif

54
55
RANLIB ?= ranlib

Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
56
#TODO: tests
57
FOO_LIBS =
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
58
59
60
61
62
63
64
65
66
67

# ANYTHING BELOW THIS LINE PROBABLY DOES NOT NEED EDITING
CINCLUDE := -I../include ${CINCLUDE}
LIBSRCDIR = ../src
BINSRCDIR = ../examples
TESTSRCDIR = ${LIBSRCDIR}
WORKDIR = objs

# C source file lists
LIBOPUSFILE_CSOURCES = \
68
http.c \
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
69
70
71
72
73
info.c \
internal.c \
opusfile.c \
stream.c \

74
75
76
77
LIBOPUSFILE_CHEADERS = \
internal.h \

LIBOPUSURL_CSOURCES = \
78
internal.c \
79
80
http.c \

81
ifneq ($(findstring mingw,${CC}),)
82
LIBOPUSURL_CSOURCES += wincerts.c
83
84
endif

85
LIBOPUSURL_CHEADERS = \
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
86
87
88
89
90
91
internal.h \

OPUSFILE_EXAMPLE_CSOURCES = opusfile_example.c

SEEKING_EXAMPLE_CSOURCES = seeking_example.c

92
93
94
95
96
ifneq ($(findstring mingw,${CC}),)
OPUSFILE_EXAMPLE_CSOURCES += win32utf8.c
SEEKING_EXAMPLE_CSOURCES += win32utf8.c
endif

Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
97
98
99
100
101
102
FOO_CSOURCES = tests/foo.c

# Create object file list.
LIBOPUSFILE_OBJS:= ${LIBOPUSFILE_CSOURCES:%.c=${WORKDIR}/%.o}
LIBOPUSFILE_ASMS:= ${LIBOPUSFILE_OBJS:%.o=%.s}
LIBOPUSFILE_DEPS:= ${LIBOPUSFILE_OBJS:%.o=%.d}
103
104
105
LIBOPUSURL_OBJS:= ${LIBOPUSURL_CSOURCES:%.c=${WORKDIR}/%.o}
LIBOPUSURL_ASMS:= ${LIBOPUSURL_OBJS:%.o=%.s}
LIBOPUSURL_DEPS:= ${LIBOPUSURL_OBJS:%.o=%.d}
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
106
107
108
109
110
111
OPUSFILE_EXAMPLE_OBJS:= ${OPUSFILE_EXAMPLE_CSOURCES:%.c=${WORKDIR}/%.o}
SEEKING_EXAMPLE_OBJS:= ${SEEKING_EXAMPLE_CSOURCES:%.c=${WORKDIR}/%.o}
#TODO: tests
FOO_OBJS:= ${FOO_CSOURCES:%.c=${WORKDIR}/%.o}
ALL_OBJS:= \
 ${LIBOPUSFILE_OBJS} \
112
 ${LIBOPUSURL_OBJS} \
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
113
114
115
116
117
118
119
120
121
122
123
 ${OPUSFILE_EXAMPLE_OBJS} \
 ${SEEKING_EXAMPLE_OBJS} \

#TODO: tests
# ${FOO_OBJS}

# Create the dependency file list
ALL_DEPS:= ${ALL_OBJS:%.o=%.d}
# Prepend source path to file names.
LIBOPUSFILE_CSOURCES:= ${LIBOPUSFILE_CSOURCES:%=${LIBSRCDIR}/%}
LIBOPUSFILE_CHEADERS:= ${LIBOPUSFILE_CHEADERS:%=${LIBSRCDIR}/%}
124
125
LIBOPUSURL_CSOURCES:= ${LIBOPUSURL_CSOURCES:%=${LIBSRCDIR}/%}
LIBOPUSURL_CHEADERS:= ${LIBOPUSURL_CHEADERS:%=${LIBSRCDIR}/%}
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
126
127
128
129
130
131
OPUSFILE_EXAMPLE_CSOURCES:= ${OPUSFILE_EXAMPLE_CSOURCES:%=${BINSRCDIR}/%}
SEEKING_EXAMPLE_CSOURCES:= ${SEEKING_EXAMPLE_CSOURCES:%=${BINSRCDIR}/%}
#TODO: tests
FOO_CSOURCES:= ${FOO_CSOURCES:%=${TESTSRCDIR}/%}
ALL_CSOURCES:= \
 ${LIBOPUSFILE_CSOURCES} \
132
 ${LIBOPUSURL_CSOURCES} \
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
133
134
135
136
137
138
139
 ${OPUSFILE_EXAMPLE_CSOURCES} \
 ${SEEKING_EXAMPLE_CSOURCES} \

#TODO: tests
# ${FOO_CSOURCES} \
# Prepand target path to file names.
LIBOPUSFILE_TARGET:= ${TARGETLIBDIR}/${LIBOPUSFILE_TARGET}
140
LIBOPUSURL_TARGET:= ${TARGETLIBDIR}/${LIBOPUSURL_TARGET}
141
142
OPUSFILE_EXAMPLE_TARGET:= ${TARGETBINDIR}/${OPUSFILE_EXAMPLE_TARGET}${EXEEXT}
SEEKING_EXAMPLE_TARGET:= ${TARGETBINDIR}/${SEEKING_EXAMPLE_TARGET}${EXEEXT}
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
143
144
145
146
147
148
# Prepend test path to file names.
#TODO: tests
FOO_TARGET:= ${TESTBINDIR}/${FOO_TARGET}
# Complete set of targets
ALL_TARGETS:= \
 ${LIBOPUSFILE_TARGET} \
149
 ${LIBOPUSURL_TARGET} \
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
150
151
152
153
154
155
156
157
158
159
160
161
162
 ${OPUSFILE_EXAMPLE_TARGET} \
 ${SEEKING_EXAMPLE_TARGET} \

#TODO: tests
# ${FOO_TARGET} \

# Targets:
# Everything (default)
all: ${ALL_TARGETS}

# libopusfile
${LIBOPUSFILE_TARGET}: ${LIBOPUSFILE_OBJS}
	mkdir -p ${TARGETLIBDIR}
163
	$(AR) cqs $@ ${LIBOPUSFILE_OBJS}
164
	-$(RANLIB) $@
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
165

166
167
168
169
170
171
# libopusurl
${LIBOPUSURL_TARGET}: ${LIBOPUSURL_OBJS}
	mkdir -p ${TARGETLIBDIR}
	$(AR) cqs $@ ${LIBOPUSURL_OBJS}
	-$(RANLIB) $@

Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
172
# opusfile_example
173
174
${OPUSFILE_EXAMPLE_TARGET}: ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
 ${LIBOPUSURL_TARGET}
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
175
	mkdir -p ${TARGETBINDIR}
176
177
	${CC} ${CFLAGS} ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
         ${LIBOPUSURL_TARGET} ${LIBS} -o $@
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
178
179

# seeking_example
180
181
${SEEKING_EXAMPLE_TARGET}: ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
 ${LIBOPUSURL_TARGET}
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
182
	mkdir -p ${TARGETBINDIR}
183
184
	${CC} ${CFLAGS} ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
         ${LIBOPUSURL_TARGET} ${LIBS} -o $@
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
185

186
187
188
#TODO:
#tests: foo
#
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
189
190
191
#${FOO_TARGET}: ${FOO_OBJS}
#	mkdir -p ${TESTBINDIR}
#	${CC} ${CFLAGS} ${FOO_OBJS} ${FOO_LIBS} -o $@
192
193
194
#
#tests-clean:
#	-rmdir ${TESTBINDIR}
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
195
196
197
198
199
200
201
202
203
204
205
206

# Assembly listing
ALL_ASM := ${ALL_OBJS:%.o=%.s}
asm: ${ALL_ASM}

# Check that build is complete.
check: all

# Remove all targets.
clean:
	${RM} ${ALL_ASM} ${ALL_OBJS} ${ALL_DEPS}
	${RM} ${ALL_TARGETS}
207
	-rmdir ${WORKDIR}
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
208
209

# Make everything depend on changes in the Makefile
210
211
# This vpath directive needs to be before any include statements
vpath Makefile $(dir $(lastword $(MAKEFILE_LIST)))
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
${ALL_ASM} ${ALL_OBJS} ${ALL_DEPS} ${ALL_TARGETS} : Makefile

# Specify which targets are phony for GNU make
.PHONY : all clean check

# Rules
${WORKDIR}/%.d: ${LIBSRCDIR}/%.c
	mkdir -p ${dir $@}
	${MAKEDEPEND} ${CINCLUDE} ${CFLAGS} $< -MT ${@:%.d=%.o} > $@
	${MAKEDEPEND} ${CINCLUDE} ${CFLAGS} $< -MT ${@:%.d=%.s} >> $@
	${MAKEDEPEND} ${CINCLUDE} ${CFLAGS} $< -MT $@ >> $@
${WORKDIR}/%.s: ${LIBSRCDIR}/%.c
	mkdir -p ${dir $@}
	${CC} ${CINCLUDE} ${CFLAGS} -S -o $@ $<
${WORKDIR}/%.o: ${LIBSRCDIR}/%.c
	mkdir -p ${dir $@}
	${CC} ${CINCLUDE} ${CFLAGS} -c -o $@ $<

${WORKDIR}/%.d : ${BINSRCDIR}/%.c
	mkdir -p ${dir $@}
	${MAKEDEPEND} ${CINCLUDE} ${CFLAGS} $< -MT ${@:%.d=%.o} > $@
${WORKDIR}/%.s : ${BINSRCDIR}/%.c ${WORKDIR}/%.o
	mkdir -p ${dir $@}
	${CC} ${CINCLUDE} ${CFLAGS} -S -o $@ $<
${WORKDIR}/%.o : ${BINSRCDIR}/%.c
	mkdir -p ${dir $@}
	${CC} ${CINCLUDE} ${CFLAGS} -c -o $@ $<

240
241
# Include header file dependencies, except when cleaning
ifneq ($(MAKECMDGOALS),clean)
Timothy B. Terriberry's avatar
Timothy B. Terriberry committed
242
include ${ALL_DEPS}
243
endif