.include "cx88.ver"

PREFIX ?= /usr/local
LOCALBASE ?= /usr/local
EZXML_HEADER ?= $(LOCALBASE)/include
LIBTUNER_HEADER ?= ../libtuner
LIBTUNER_LIB ?= ../libtuner
INSTALLDIR ?= $(PREFIX)
EXAMPLESDIR ?= $(PREFIX)/share/examples/cx88
CXXFLAGS ?= -O2
CXXFLAGS += -Wall -I$(LOCALBASE)/include -I../mpeg -I../audio -I../video -I../common -I./analog -I./mpeg -I./drivers -I./ -I$(LIBTUNER_HEADER) -I$(EZXML_HEADER)

STRIPFLAGS := -s

.if defined(DIAGNOSTIC)
CXXFLAGS+= -g -D_DIAGNOSTIC
STRIPFLAGS :=
.endif

.if defined(CX88_USE_IIC)
CXXFLAGS+= -DCX88_USE_IIC
.endif

MAN=

LDADD = -L$(LIBTUNER_LIB) -ltuner_static -lezxml -lpthread -ledit

JSON_CFLAGS != pkgconf --cflags json-c
JSON_LDFLAGS != pkgconf --libs json-c
CXXFLAGS += $(JSON_CFLAGS)
LDADD += $(JSON_LDFLAGS)

.if defined(WITH_LINUX_COMPAT)
CXXFLAGS += -D_WITH_LINUX_COMPAT
LDADD += -L$(LOCALBASE)/lib -lcuse

.if defined(WITH_HAL)
CXXFLAGS += -D_WITH_HAL
HAL_CFLAGS != pkgconf --cflags hal
HAL_LDFLAGS != pkgconf --libs hal
CXXFLAGS += $(HAL_CFLAGS)
LDADD += $(HAL_LDFLAGS)
.endif

.endif

.if defined(DEFAULT_XML_CONFIG)
CXXFLAGS += -DDEFAULT_XML_CONFIG="\"$(DEFAULT_XML_CONFIG)\""
.endif

CX88_TIMESTAMP != date "+%Y-%m-%d %H:%M:%S"

CXXFLAGS += -DCX88_VERSION="\"$(CX88_MAJOR).$(CX88_MINOR).$(CX88_REV) ($(CX88_TIMESTAMP))\""

.PATH: ${.CURDIR} ${.CURDIR}/mpeg ${.CURDIR}/analog ${.CURDIR}/drivers ${.CURDIR}/dvb ${.CURDIR}/v4l ${.CURDIR}/hal

SRCS = cx88_capture.h cx88_capture.cpp \
       cx88_url_capture.h cx88_url_capture.cpp \
       cx88_file_capture.h cx88_file_capture.cpp \
       cx88_audio_capture.h cx88_audio_capture.cpp \
       cx88_debug.h cx88_xml_config.h cx88_xml_config.cpp \
       cx88_driver.h cx88_driver.cpp \
       cx88_mpeg_driver.h cx88_mpeg_driver.cpp \
       cx88_mpeg_driver_factory.h cx88_mpeg_driver_factory.cpp \
       cx88_analog_driver.h cx88_analog_driver.cpp \
       cx88_analog_driver_factory.h cx88_analog_driver_factory.cpp \
       cx88_capture_factory.h cx88_capture_factory.cpp \
       cx88_debug.cpp \
       cx88_json.h \
       cx88.cpp

DRIVERS != cd drivers && ls *.h *.cpp

SRCS += $(DRIVERS)

.if defined(WITH_LINUX_COMPAT)
SRCS += \
       cx88_dvb_buffer.h cx88_dvb_buffer.cpp \
       cx88_dvb_demux_feed.h cx88_dvb_demux_feed.cpp \
       cx88_dvb_demux.h cx88_dvb_demux.cpp \
       cx88_dvb_frontend.h cx88_dvb_frontend.cpp \
       cx88_dvb_capture.h cx88_dvb_capture.cpp \
       cx88_radio_capture.h cx88_radio_capture.cpp

.if defined(WITH_HAL)
SRCS += \
       cx88_hal.h cx88_hal.cpp \
       cx88_dvb_hal.h cx88_dvb_hal.cpp
.endif

.endif

PROG_CXX = cx88

install:
	mkdir -p $(EXAMPLESDIR)
	install $(STRIPFLAGS) cx88 $(INSTALLDIR)/bin/
	cp cx88.xml.sample $(EXAMPLESDIR)/
	cp -r ../utils/* $(EXAMPLESDIR)/
	cp -r ../tests/* $(EXAMPLESDIR)/

.include <bsd.prog.mk>
