# Makefile.w32 - Makefile for MinGW
# Copyright (c) 2007 Michael Riepe
#  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#  
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#  
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# $Id$

TOP = `cd .. && pwd`

QTDIR = ../../qt-3

PATH := $(QTDIR)/bin:$(PATH)

%.h: %.ui
	uic -o $@ $<

uic_%.cpp: %.h
	uic -impl $< -o $@ $*.ui

moc_%.cpp: %.h
	moc -o $@ $<

MOC = \
	moc_dvbcut.cpp \
	moc_dvbcutbase.cpp \
	moc_exportdialog.cpp \
	moc_exportdialogbase.cpp \
	moc_mplayererrorbase.cpp \
	moc_progressstatusbar.cpp \
	moc_progresswindow.cpp \
	moc_progresswindowbase.cpp

UIC = \
	uic_dvbcutbase.cpp \
	uic_exportdialogbase.cpp \
	uic_mplayererrorbase.cpp \
	uic_progresswindowbase.cpp

SRCS = \
	avframe.cpp differenceimageprovider.cpp buffer.cpp \
	dvbcut.cpp eventlistitem.cpp exception.cpp exportdialog.cpp \
	imageprovider.cpp index.cpp lavfmuxer.cpp logoutput.cpp \
	main.cpp mpegmuxer.cpp mpgfile.cpp playaudio.cpp \
	progressstatusbar.cpp progresswindow.cpp psfile.cpp \
	pts.cpp streamdata.cpp tsfile.cpp settings.cpp $(MOC) $(UIC) \
	gettext.cpp ../import/stdlib.cpp

HDRS = \
	avframe.h buffer.h busyindicator.h defines.h \
	differenceimageprovider.h dvbcut.h eventlistitem.h \
	exception.h exportdialog.h imageprovider.h index.h lavfmuxer.h \
	logoutput.h mpegmuxer.h mpgfile.h muxer.h playaudio.h port.h \
	progressstatusbar.h progresswindow.h psfile.h pts.h settings.h \
	stream.h streamdata.h streamhandle.h tsfile.h types.h gettext.h

OBJS = $(SRCS:.cpp=.o)

CXX = g++
CXXFLAGS = -O2 -Wall -g
CPPFLAGS = -I../ffmpeg/include/ffmpeg -I../import -I/usr/local/include \
	-I. -DQT3_SUPPORT -DHAVE_LIB_MAD -DHAVE_LIB_A52 -DHAVE_LIB_AO \
	-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS \
	-I$(QTDIR)/include/Qt -I$(QTDIR)/include/QtCore \
	-I$(QTDIR)/include/QtGui -I$(QTDIR)/include/Qt3Support \
	-I$(QTDIR)/include
LDFLAGS = -L$(QTDIR)/lib -L../ffmpeg/lib -L/usr/local/lib
LDLIBS = -lavformat -lavcodec -lavutil -lqt-mt -lmad -la52 -lao -lwinmm -lmpeg2

all: ../bin/dvbcut.exe

../bin/dvbcut.exe: dvbcut.exe
	-rm -f $@
	cp dvbcut.exe $@
	strip $@

dvbcut.exe: ../ffmpeg/lib/libavcodec.a $(SRCS) $(OBJS)
	$(CXX) -o $@ $(LDFLAGS) $(OBJS) $(LDLIBS)

OPT.ffmpeg = \
	--prefix=$(TOP)/ffmpeg \
	--enable-mingw32 \
	--enable-gpl \
	--disable-decoders \
	--enable-memalign-hack \
	--disable-encoders \
	--disable-ffplay \
	--disable-ffserver \
	--disable-vhook \
	--disable-zlib \
	--disable-network \
	--disable-dv1394 \
	--disable-bktr \
	--disable-v4l \
	--disable-audio-beos \
	--disable-audio-oss \
	--enable-codec=mpeg2encoder \
	--enable-codec=mp2_encoder \
	--enable-codec=ac3_decoder \
	--enable-codec=ac3_encoder \
	--enable-a52 \
	--disable-mmx \
	--disable-debug

../ffmpeg/lib/libavcodec.a:
	if cd ../ffmpeg.src; then \
	  ./configure $(OPT.ffmpeg) || exit 1; \
	  $(MAKE) installlib || exit 1; \
	fi
clean:
	-rm -f *.o
	-cd ../ffmpeg.src && $(MAKE) clean

distclean: clean
	# remove moc/uic generated files and ffmpeg as well
	-rm -f $(MOC) $(UIC)
	-rm -rf ../ffmpeg/lib ../ffmpeg/include
	-rm -f .depend stamp-depend

dep: stamp-depend
stamp-depend: $(SRCS)
	-@rm -f .depend $@
	-$(CXX) -MM $(CPPFLAGS) $(SRCS) > .depend
	echo timestamp > $@

-include .depend

# static dependencies:

moc_dvbcut.cpp: dvbcut.h
moc_dvbcutbase.cpp: dvbcutbase.h
moc_exportdialog.cpp: exportdialog.h
moc_exportdialogbase.cpp: exportdialogbase.h
moc_mplayererrorbase.cpp: mplayererrorbase.h
moc_progressstatusbar.cpp: progressstatusbar.h
moc_progresswindow.cpp: progresswindow.h
moc_progresswindowbase.cpp: progresswindowbase.h
uic_dvbcutbase.cpp: dvbcutbase.h
uic_exportdialogbase.cpp: exportdialogbase.h
uic_mplayererrorbase.cpp: mplayererrorbase.h
uic_progresswindowbase.cpp: progresswindowbase.h
dvbcutbase.h: dvbcutbase.ui
exportdialogbase.h: exportdialogbase.ui
mplayererrorbase.h: mplayererrorbase.ui
progresswindowbase.h: progresswindowbase.ui

dvbcut.o: version.h
version.h: $(SRCS) $(HDRS) Makefile.w32
	../setversion.sh $^
