Chris@69: # NOTE: This Makefile requires GNU make Chris@69: # Location to put the targets. Chris@69: TARGETBINDIR = . Chris@69: TESTBINDIR = tests Chris@69: TARGETLIBDIR = . Chris@69: # Name of the targets Chris@69: LIBOPUSFILE_TARGET = libopusfile.a Chris@69: LIBOPUSURL_TARGET = libopusurl.a Chris@69: OPUSFILE_EXAMPLE_TARGET = opusfile_example Chris@69: SEEKING_EXAMPLE_TARGET = seeking_example Chris@69: # Test targets Chris@69: #TODO: tests Chris@69: FOO_TARGET = foo Chris@69: # The command to use to generate dependency information Chris@69: MAKEDEPEND = ${CC} -MM Chris@69: #MAKEDEPEND = makedepend -f- -Y -- Chris@69: # Optional features to enable Chris@69: #CFLAGS := $(CFLAGS) -DOP_HAVE_LRINTF Chris@69: CFLAGS := $(CFLAGS) -DOP_ENABLE_HTTP Chris@69: # Extra compilation flags. Chris@69: # You may get speed increases by including flags such as -O2 or -O3 or Chris@69: # -ffast-math, or additional flags, depending on your system and compiler. Chris@69: # The -g flag will generally include debugging information. Chris@69: CFLAGS := -g $(CFLAGS) Chris@69: CFLAGS := -DOP_ENABLE_ASSERTIONS $(CFLAGS) Chris@69: # These are gcc-only, but not actually critical. Chris@69: CFLAGS := -fPIC $(CFLAGS) Chris@69: CFLAGS := -std=c89 -pedantic $(CFLAGS) Chris@69: CFLAGS := -fvisibility=hidden $(CFLAGS) Chris@69: CFLAGS := -Wextra -Wno-parentheses -Wno-long-long $(CFLAGS) Chris@69: CFLAGS := -Wall $(CFLAGS) Chris@69: # The list of pkg-config packages we depend on. Chris@69: PACKAGES := ogg opus Chris@69: ifeq ($(findstring -DOP_ENABLE_HTTP,${CFLAGS}),-DOP_ENABLE_HTTP) Chris@69: PACKAGES += openssl Chris@69: endif Chris@69: # The location of include files. Chris@69: # Modify these to point to your Ogg and Opus include directories if they are Chris@69: # not installed in a standard location. Chris@69: CINCLUDE := `pkg-config --cflags ${PACKAGES}` Chris@69: Chris@69: # Libraries to link with, and the location of library files. Chris@69: LIBS := `pkg-config --libs ${PACKAGES}` Chris@69: ifeq ($(findstring -DOP_HAVE_LRINTF,${CFLAGS}),-DOP_HAVE_LRINTF) Chris@69: LIBS := -lm $(LIBS) Chris@69: endif Chris@69: Chris@69: # Extras for the MS target Chris@69: ifneq ($(findstring mingw,${CC}),) Chris@69: LIBS += -lwsock32 -lws2_32 -lgdi32 -lcrypt32 Chris@69: EXEEXT := .exe Chris@69: endif Chris@69: Chris@69: RANLIB ?= ranlib Chris@69: Chris@69: #TODO: tests Chris@69: FOO_LIBS = Chris@69: Chris@69: # ANYTHING BELOW THIS LINE PROBABLY DOES NOT NEED EDITING Chris@69: CINCLUDE := -I../include ${CINCLUDE} Chris@69: LIBSRCDIR = ../src Chris@69: BINSRCDIR = ../examples Chris@69: TESTSRCDIR = ${LIBSRCDIR} Chris@69: WORKDIR = objs Chris@69: Chris@69: # C source file lists Chris@69: LIBOPUSFILE_CSOURCES = \ Chris@69: http.c \ Chris@69: info.c \ Chris@69: internal.c \ Chris@69: opusfile.c \ Chris@69: stream.c \ Chris@69: Chris@69: LIBOPUSFILE_CHEADERS = \ Chris@69: internal.h \ Chris@69: Chris@69: LIBOPUSURL_CSOURCES = \ Chris@69: internal.c \ Chris@69: http.c \ Chris@69: Chris@69: ifneq ($(findstring mingw,${CC}),) Chris@69: LIBOPUSURL_CSOURCES += wincerts.c Chris@69: endif Chris@69: Chris@69: LIBOPUSURL_CHEADERS = \ Chris@69: internal.h \ Chris@69: Chris@69: OPUSFILE_EXAMPLE_CSOURCES = opusfile_example.c Chris@69: Chris@69: SEEKING_EXAMPLE_CSOURCES = seeking_example.c Chris@69: Chris@69: ifneq ($(findstring mingw,${CC}),) Chris@69: OPUSFILE_EXAMPLE_CSOURCES += win32utf8.c Chris@69: SEEKING_EXAMPLE_CSOURCES += win32utf8.c Chris@69: endif Chris@69: Chris@69: FOO_CSOURCES = tests/foo.c Chris@69: Chris@69: # Create object file list. Chris@69: LIBOPUSFILE_OBJS:= ${LIBOPUSFILE_CSOURCES:%.c=${WORKDIR}/%.o} Chris@69: LIBOPUSFILE_ASMS:= ${LIBOPUSFILE_OBJS:%.o=%.s} Chris@69: LIBOPUSFILE_DEPS:= ${LIBOPUSFILE_OBJS:%.o=%.d} Chris@69: LIBOPUSURL_OBJS:= ${LIBOPUSURL_CSOURCES:%.c=${WORKDIR}/%.o} Chris@69: LIBOPUSURL_ASMS:= ${LIBOPUSURL_OBJS:%.o=%.s} Chris@69: LIBOPUSURL_DEPS:= ${LIBOPUSURL_OBJS:%.o=%.d} Chris@69: OPUSFILE_EXAMPLE_OBJS:= ${OPUSFILE_EXAMPLE_CSOURCES:%.c=${WORKDIR}/%.o} Chris@69: SEEKING_EXAMPLE_OBJS:= ${SEEKING_EXAMPLE_CSOURCES:%.c=${WORKDIR}/%.o} Chris@69: #TODO: tests Chris@69: FOO_OBJS:= ${FOO_CSOURCES:%.c=${WORKDIR}/%.o} Chris@69: ALL_OBJS:= \ Chris@69: ${LIBOPUSFILE_OBJS} \ Chris@69: ${LIBOPUSURL_OBJS} \ Chris@69: ${OPUSFILE_EXAMPLE_OBJS} \ Chris@69: ${SEEKING_EXAMPLE_OBJS} \ Chris@69: Chris@69: #TODO: tests Chris@69: # ${FOO_OBJS} Chris@69: Chris@69: # Create the dependency file list Chris@69: ALL_DEPS:= ${ALL_OBJS:%.o=%.d} Chris@69: # Prepend source path to file names. Chris@69: LIBOPUSFILE_CSOURCES:= ${LIBOPUSFILE_CSOURCES:%=${LIBSRCDIR}/%} Chris@69: LIBOPUSFILE_CHEADERS:= ${LIBOPUSFILE_CHEADERS:%=${LIBSRCDIR}/%} Chris@69: LIBOPUSURL_CSOURCES:= ${LIBOPUSURL_CSOURCES:%=${LIBSRCDIR}/%} Chris@69: LIBOPUSURL_CHEADERS:= ${LIBOPUSURL_CHEADERS:%=${LIBSRCDIR}/%} Chris@69: OPUSFILE_EXAMPLE_CSOURCES:= ${OPUSFILE_EXAMPLE_CSOURCES:%=${BINSRCDIR}/%} Chris@69: SEEKING_EXAMPLE_CSOURCES:= ${SEEKING_EXAMPLE_CSOURCES:%=${BINSRCDIR}/%} Chris@69: #TODO: tests Chris@69: FOO_CSOURCES:= ${FOO_CSOURCES:%=${TESTSRCDIR}/%} Chris@69: ALL_CSOURCES:= \ Chris@69: ${LIBOPUSFILE_CSOURCES} \ Chris@69: ${LIBOPUSURL_CSOURCES} \ Chris@69: ${OPUSFILE_EXAMPLE_CSOURCES} \ Chris@69: ${SEEKING_EXAMPLE_CSOURCES} \ Chris@69: Chris@69: #TODO: tests Chris@69: # ${FOO_CSOURCES} \ Chris@69: # Prepand target path to file names. Chris@69: LIBOPUSFILE_TARGET:= ${TARGETLIBDIR}/${LIBOPUSFILE_TARGET} Chris@69: LIBOPUSURL_TARGET:= ${TARGETLIBDIR}/${LIBOPUSURL_TARGET} Chris@69: OPUSFILE_EXAMPLE_TARGET:= ${TARGETBINDIR}/${OPUSFILE_EXAMPLE_TARGET}${EXEEXT} Chris@69: SEEKING_EXAMPLE_TARGET:= ${TARGETBINDIR}/${SEEKING_EXAMPLE_TARGET}${EXEEXT} Chris@69: # Prepend test path to file names. Chris@69: #TODO: tests Chris@69: FOO_TARGET:= ${TESTBINDIR}/${FOO_TARGET} Chris@69: # Complete set of targets Chris@69: ALL_TARGETS:= \ Chris@69: ${LIBOPUSFILE_TARGET} \ Chris@69: ${LIBOPUSURL_TARGET} \ Chris@69: ${OPUSFILE_EXAMPLE_TARGET} \ Chris@69: ${SEEKING_EXAMPLE_TARGET} \ Chris@69: Chris@69: #TODO: tests Chris@69: # ${FOO_TARGET} \ Chris@69: Chris@69: # Targets: Chris@69: # Everything (default) Chris@69: all: ${ALL_TARGETS} Chris@69: Chris@69: # libopusfile Chris@69: ${LIBOPUSFILE_TARGET}: ${LIBOPUSFILE_OBJS} Chris@69: mkdir -p ${TARGETLIBDIR} Chris@69: $(AR) cqs $@ ${LIBOPUSFILE_OBJS} Chris@69: -$(RANLIB) $@ Chris@69: Chris@69: # libopusurl Chris@69: ${LIBOPUSURL_TARGET}: ${LIBOPUSURL_OBJS} Chris@69: mkdir -p ${TARGETLIBDIR} Chris@69: $(AR) cqs $@ ${LIBOPUSURL_OBJS} Chris@69: -$(RANLIB) $@ Chris@69: Chris@69: # opusfile_example Chris@69: ${OPUSFILE_EXAMPLE_TARGET}: ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \ Chris@69: ${LIBOPUSURL_TARGET} Chris@69: mkdir -p ${TARGETBINDIR} Chris@69: ${CC} ${CFLAGS} ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \ Chris@69: ${LIBOPUSURL_TARGET} ${LIBS} -o $@ Chris@69: Chris@69: # seeking_example Chris@69: ${SEEKING_EXAMPLE_TARGET}: ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \ Chris@69: ${LIBOPUSURL_TARGET} Chris@69: mkdir -p ${TARGETBINDIR} Chris@69: ${CC} ${CFLAGS} ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \ Chris@69: ${LIBOPUSURL_TARGET} ${LIBS} -o $@ Chris@69: Chris@69: #TODO: Chris@69: #tests: foo Chris@69: # Chris@69: #${FOO_TARGET}: ${FOO_OBJS} Chris@69: # mkdir -p ${TESTBINDIR} Chris@69: # ${CC} ${CFLAGS} ${FOO_OBJS} ${FOO_LIBS} -o $@ Chris@69: # Chris@69: #tests-clean: Chris@69: # -rmdir ${TESTBINDIR} Chris@69: Chris@69: # Assembly listing Chris@69: ALL_ASM := ${ALL_OBJS:%.o=%.s} Chris@69: asm: ${ALL_ASM} Chris@69: Chris@69: # Check that build is complete. Chris@69: check: all Chris@69: Chris@69: # Remove all targets. Chris@69: clean: Chris@69: ${RM} ${ALL_ASM} ${ALL_OBJS} ${ALL_DEPS} Chris@69: ${RM} ${ALL_TARGETS} Chris@69: -rmdir ${WORKDIR} Chris@69: Chris@69: # Make everything depend on changes in the Makefile Chris@69: # This vpath directive needs to be before any include statements Chris@69: vpath Makefile $(dir $(lastword $(MAKEFILE_LIST))) Chris@69: ${ALL_ASM} ${ALL_OBJS} ${ALL_DEPS} ${ALL_TARGETS} : Makefile Chris@69: Chris@69: # Specify which targets are phony for GNU make Chris@69: .PHONY : all clean check Chris@69: Chris@69: # Rules Chris@69: ${WORKDIR}/%.d: ${LIBSRCDIR}/%.c Chris@69: mkdir -p ${dir $@} Chris@69: ${MAKEDEPEND} ${CINCLUDE} ${CFLAGS} $< -MT ${@:%.d=%.o} > $@ Chris@69: ${MAKEDEPEND} ${CINCLUDE} ${CFLAGS} $< -MT ${@:%.d=%.s} >> $@ Chris@69: ${MAKEDEPEND} ${CINCLUDE} ${CFLAGS} $< -MT $@ >> $@ Chris@69: ${WORKDIR}/%.s: ${LIBSRCDIR}/%.c Chris@69: mkdir -p ${dir $@} Chris@69: ${CC} ${CINCLUDE} ${CFLAGS} -S -o $@ $< Chris@69: ${WORKDIR}/%.o: ${LIBSRCDIR}/%.c Chris@69: mkdir -p ${dir $@} Chris@69: ${CC} ${CINCLUDE} ${CFLAGS} -c -o $@ $< Chris@69: Chris@69: ${WORKDIR}/%.d : ${BINSRCDIR}/%.c Chris@69: mkdir -p ${dir $@} Chris@69: ${MAKEDEPEND} ${CINCLUDE} ${CFLAGS} $< -MT ${@:%.d=%.o} > $@ Chris@69: ${WORKDIR}/%.s : ${BINSRCDIR}/%.c ${WORKDIR}/%.o Chris@69: mkdir -p ${dir $@} Chris@69: ${CC} ${CINCLUDE} ${CFLAGS} -S -o $@ $< Chris@69: ${WORKDIR}/%.o : ${BINSRCDIR}/%.c Chris@69: mkdir -p ${dir $@} Chris@69: ${CC} ${CINCLUDE} ${CFLAGS} -c -o $@ $< Chris@69: Chris@69: # Include header file dependencies, except when cleaning Chris@69: ifneq ($(MAKECMDGOALS),clean) Chris@69: include ${ALL_DEPS} Chris@69: endif