# Makefile for use on Windows
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
# 
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
# 
# The Original Code is the MPEG TS, PS and ES tools.
# 
# The Initial Developer of the Original Code is Amino Communications Ltd.
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
# 
# Contributor(s):
#   Amino Communications Ltd, Swavesey, Cambridge UK
# 
# ***** END LICENSE BLOCK *****

.SUFFIXES:

!if "$(DEBUG)"==""
DEBUG=0
!endif

DEBUG_OBJDIR=w32\debug
PLAIN_OBJDIR=w32\obj

!if $(DEBUG)
OBJDIR=$(DEBUG_OBJDIR)
COPT=/Od /Zi /MTd
LOPT=/DEBUG /INCREMENTAL:NO /NOLOGO
# /NODEFAULTLIB:CMT
!else
OBJDIR=$(PLAIN_OBJDIR)
COPT=/O2b2 /MT /DNDEBUG
LOPT=/INCREMENTAL:NO /NOLOGO
# /NODEFAULTLIB:CMT
!endif
EXEDIR=w32\bin
LIBDIR=$(OBJDIR)
LIBFILE=$(LIBDIR)\libtstools.lib

CC = cl /c /W3 /WX /GF /Fd$(OBJDIR)\ $(COPT)
#CC=cl /nologo /c /WX /GF /Fd$(OBJDIR)\ $(COPT)


.SUFFIXES: .c .cpp .obj .exe {$(OBJDIR)}.obj

# ------------------------------------------------------------
# Rules

.c{$(OBJDIR)}.obj::
	$(CC) /Fo$(OBJDIR)\ $<

{$(OBJDIR)}.obj{$(EXEDIR)}.exe:
	link /out:$@ $(LOPT) $<

# ------------------------------------------------------------
# Things to build

PROGS = \
    $(EXEDIR)\es2ts.exe       \
    $(EXEDIR)\esdots.exe      \
    $(EXEDIR)\esfilter.exe    \
    $(EXEDIR)\esmerge.exe     \
    $(EXEDIR)\esreport.exe    \
    $(EXEDIR)\esreverse.exe   \
    $(EXEDIR)\m2ts2ts.exe     \
    $(EXEDIR)\pcapreport.exe  \
    $(EXEDIR)\ps2ts.exe       \
    $(EXEDIR)\psdots.exe      \
    $(EXEDIR)\psreport.exe    \
    $(EXEDIR)\stream_type.exe \
    $(EXEDIR)\ts2es.exe       \
    $(EXEDIR)\ts_packet_insert.exe      \
    $(EXEDIR)\tsdvbsub.exe    \
    $(EXEDIR)\tsinfo.exe      \
    $(EXEDIR)\tsplay.exe      \
    $(EXEDIR)\tsreport.exe    \
    $(EXEDIR)\tsserve.exe

# Object files for the library
LIB_OBJS = \
 $(OBJDIR)\accessunit.obj \
 $(OBJDIR)\ac3.obj \
 $(OBJDIR)\adts.obj \
 $(OBJDIR)\avs.obj \
 $(OBJDIR)\audio.obj \
 $(OBJDIR)\bitdata.obj \
 $(OBJDIR)\es.obj \
 $(OBJDIR)\ethernet.obj \
 $(OBJDIR)\filter.obj \
 $(OBJDIR)\fmtx.obj \
 $(OBJDIR)\h222.obj \
 $(OBJDIR)\h262.obj \
 $(OBJDIR)\ipv4.obj \
 $(OBJDIR)\l2audio.obj \
 $(OBJDIR)\misc.obj \
 $(OBJDIR)\nalunit.obj \
 $(OBJDIR)\pcap.obj \
 $(OBJDIR)\pes.obj \
 $(OBJDIR)\pidint.obj \
 $(OBJDIR)\printing.obj \
 $(OBJDIR)\ps.obj \
 $(OBJDIR)\reverse.obj \
 $(OBJDIR)\ts.obj \
 $(OBJDIR)\tsplay_innards.obj \
 $(OBJDIR)\tswrite.obj

# Object files for the programs
PROG_OBJS = \
  $(OBJDIR)/es2ts.obj \
  $(OBJDIR)/esdots.obj \
  $(OBJDIR)/esfilter.obj \
  $(OBJDIR)/esmerge.obj \
  $(OBJDIR)/esreport.obj \
  $(OBJDIR)/esreverse.obj \
  $(OBJDIR)/m2ts2ts.obj \
  $(OBJDIR)/pcapreport.obj \
  $(OBJDIR)/ps2ts.obj \
  $(OBJDIR)/psdots.obj      \
  $(OBJDIR)/psreport.obj \
  $(OBJDIR)/stream_type.obj \
  $(OBJDIR)/ts2es.obj \
  $(OBJDIR)/ts_packet_insert.obj      \
  $(OBJDIR)\tsdvbsub.obj \
  $(OBJDIR)/tsinfo.obj \
  $(OBJDIR)/tsplay.obj \
  $(OBJDIR)/tsreport.obj \
  $(OBJDIR)/tsserve.obj

# ------------------------------------------------------------
# Targets

all: $(OBJDIR) $(EXEDIR) $(LIBDIR) $(PROGS)

ac3_fns.h: audio_fns.h
accessunit_defns.h: nalunit_defns.h es_defns.h
accessunit_fns.h: accessunit_defns.h
adts_defns.h: audio_defns.h
adts_fns.h: adts_defns.h audio_fns.h
audio_defns.h: h222_defns.h
audio_fns.h: audio_defns.h
avs_defns.h: compat.h es_defns.h ts_defns.h reverse_defns.h
avs_fns.h: avs_defns.h
bitdata_defns.h: compat.h
bitdata_fns.h: bitdata_defns.h
es_defns.h: compat.h pes_defns.h
es_fns.h: es_defns.h
ethernet.h: compat.h pcap.h
filter_defns.h: compat.h es_defns.h h262_defns.h accessunit_defns.h reverse_defns.h
filter_fns.h: filter_defns.h
h222_defns.h: h222_fns.h
h262_defns.h: compat.h es_defns.h ts_defns.h
h262_fns.h: h262_defns.h
ipv4.h: compat.h
l2audio_fns.h: audio_defns.h
misc_defns.h: tswrite_defns.h video_defns.h
misc_fns.h: misc_defns.h es_defns.h compat.h
nalunit_defns.h: compat.h es_defns.h bitdata_defns.h
nalunit_fns.h: nalunit_defns.h
pcap.h: compat.h
pes_defns.h: compat.h pidint_defns.h ps_defns.h ts_defns.h tswrite_defns.h
pes_fns.h: pes_defns.h es_defns.h
pidint_defns.h: compat.h
pidint_fns.h: pidint_defns.h
printing_fns.h: printing_defns.h
ps_defns.h: compat.h h222_defns.h tswrite_defns.h
ps_fns.h: compat.h h222_defns.h tswrite_defns.h ps_defns.h
reverse_defns.h: compat.h es_defns.h h262_defns.h accessunit_defns.h
reverse_fns.h: accessunit_defns.h reverse_defns.h h262_defns.h
ts_defns.h: compat.h
ts_fns.h: compat.h h222_defns.h tswrite_defns.h pidint_defns.h ts_defns.h
tsplay_fns.h: tswrite_defns.h tsplay_defns.h
tswrite_defns.h: compat.h ts_defns.h h222_defns.h
tswrite_fns.h: tswrite_defns.h
version.h: printing_fns.h
video_defns.h: h222_defns.h


$(OBJDIR)\ac3.obj: compat.h printing_fns.h misc_fns.h ac3_fns.h
$(OBJDIR)\accessunit.obj: compat.h printing_fns.h es_fns.h ts_fns.h nalunit_fns.h accessunit_fns.h reverse_fns.h
$(OBJDIR)\adts.obj: compat.h printing_fns.h misc_fns.h adts_fns.h
$(OBJDIR)\audio.obj: compat.h printing_fns.h audio_fns.h adts_fns.h l2audio_fns.h ac3_fns.h
$(OBJDIR)\avs.obj: compat.h printing_fns.h avs_fns.h es_fns.h ts_fns.h reverse_fns.h misc_fns.h
$(OBJDIR)\bitdata.obj: compat.h bitdata_fns.h printing_fns.h
$(OBJDIR)\es.obj: compat.h printing_fns.h misc_fns.h pes_fns.h tswrite_fns.h es_fns.h printing_fns.h
$(OBJDIR)\es2ts.obj: compat.h es_fns.h ts_fns.h tswrite_fns.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\esdots.obj: compat.h es_fns.h pes_fns.h accessunit_fns.h h262_fns.h avs_fns.h printing_fns.h misc_fns.h version.h
$(OBJDIR)\esfilter.obj: compat.h es_fns.h pes_fns.h nalunit_fns.h ts_fns.h accessunit_fns.h h262_fns.h misc_fns.h printing_fns.h tswrite_fns.h filter_fns.h version.h
$(OBJDIR)\esmerge.obj: compat.h es_fns.h accessunit_fns.h avs_fns.h audio_fns.h ts_fns.h tswrite_fns.h misc_fns.h printing_fns.h version.h pes_fns.h
$(OBJDIR)\esreport.obj: compat.h es_fns.h nalunit_fns.h ts_fns.h pes_fns.h accessunit_fns.h h262_fns.h avs_fns.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\esreverse.obj: compat.h es_fns.h nalunit_fns.h accessunit_fns.h h262_fns.h ts_fns.h tswrite_fns.h pes_fns.h reverse_fns.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\ethernet.obj: ethernet.h misc_fns.h
$(OBJDIR)\filter.obj: compat.h es_fns.h ts_fns.h accessunit_fns.h h262_fns.h misc_fns.h printing_fns.h filter_fns.h
$(OBJDIR)\fmtx.obj: compat.h fmtx.h
$(OBJDIR)\h222.obj: h222_fns.h
$(OBJDIR)\h262.obj: compat.h printing_fns.h h262_fns.h es_fns.h ts_fns.h reverse_fns.h misc_fns.h
$(OBJDIR)\ipv4.obj: ipv4.h misc_fns.h
$(OBJDIR)\l2audio.obj: compat.h misc_fns.h printing_fns.h l2audio_fns.h
$(OBJDIR)\m2ts2ts.obj: compat.h ts_defns.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\misc.obj: compat.h misc_fns.h es_fns.h pes_fns.h printing_fns.h
$(OBJDIR)\nalunit.obj: compat.h printing_fns.h es_fns.h ts_fns.h bitdata_fns.h nalunit_fns.h misc_fns.h printing_fns.h
$(OBJDIR)\pcap.obj: pcap.h misc_fns.h
$(OBJDIR)\pcapreport.obj: compat.h pcap.h ethernet.h ipv4.h version.h misc_fns.h ts_fns.h fmtx.h
$(OBJDIR)\pes.obj: compat.h ts_fns.h ps_fns.h es_fns.h pes_fns.h pidint_fns.h h262_fns.h tswrite_fns.h printing_fns.h misc_fns.h
$(OBJDIR)\pidint.obj: compat.h pidint_fns.h misc_fns.h printing_fns.h ts_fns.h h222_defns.h
$(OBJDIR)\printing.obj: compat.h printing_fns.h
$(OBJDIR)\ps.obj: compat.h ps_fns.h ts_fns.h pes_fns.h pidint_fns.h misc_fns.h printing_fns.h
$(OBJDIR)\ps2ts.obj: compat.h pes_fns.h ps_fns.h ts_fns.h tswrite_fns.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\psdots.obj: compat.h ps_fns.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\psreport.obj: compat.h ps_fns.h pes_fns.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\reverse.obj: compat.h misc_defns.h printing_fns.h es_fns.h h262_fns.h nalunit_fns.h accessunit_fns.h ts_fns.h tswrite_fns.h reverse_fns.h
$(OBJDIR)\stream_type.obj: compat.h es_fns.h ts_fns.h nalunit_fns.h h262_fns.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\test_es_unit_list.obj: compat.h es_fns.h
$(OBJDIR)\test_nal_unit_list.obj: compat.h nalunit_fns.h
$(OBJDIR)\test_pes.obj: compat.h pes_fns.h pidint_fns.h misc_fns.h ps_fns.h ts_fns.h es_fns.h h262_fns.h tswrite_fns.h version.h
$(OBJDIR)\test_printing.obj: printing_fns.h version.h
$(OBJDIR)\ts.obj: compat.h ts_fns.h tswrite_fns.h misc_fns.h printing_fns.h pidint_fns.h pes_fns.h
$(OBJDIR)\ts2es.obj: compat.h ts_fns.h misc_fns.h printing_fns.h pidint_fns.h es_fns.h pes_fns.h version.h
$(OBJDIR)\ts2ps.obj: compat.h ps_fns.h ts_fns.h misc_fns.h printing_fns.h pidint_fns.h pes_fns.h version.h
$(OBJDIR)\ts_packet_insert.obj: compat.h misc_fns.h printing_fns.h version.h
$(OBJDIR)\tsdvbsub.obj: compat.h ts_fns.h misc_fns.h printing_fns.h pidint_fns.h es_fns.h pes_fns.h version.h fmtx.h
$(OBJDIR)\tsfilter.obj: compat.h ts_fns.h misc_fns.h printing_fns.h pidint_fns.h version.h tswrite_defns.h tswrite_fns.h
$(OBJDIR)\tsinfo.obj: compat.h ts_fns.h misc_fns.h printing_fns.h pidint_fns.h version.h
$(OBJDIR)\tsplay.obj: compat.h printing_fns.h tsplay_fns.h tswrite_fns.h printing_fns.h misc_fns.h version.h ps_fns.h pes_fns.h pidint_fns.h
$(OBJDIR)\tsplay_innards.obj: compat.h printing_fns.h ts_fns.h ps_fns.h pes_fns.h misc_fns.h printing_fns.h tsplay_fns.h tswrite_fns.h pidint_fns.h
$(OBJDIR)\tsreport.obj: compat.h ts_fns.h pes_fns.h misc_fns.h printing_fns.h pidint_fns.h fmtx.h version.h
$(OBJDIR)\tsserve.obj: compat.h ts_fns.h ps_fns.h pes_fns.h accessunit_fns.h nalunit_fns.h misc_fns.h printing_fns.h tswrite_fns.h es_fns.h h262_fns.h filter_fns.h reverse_fns.h version.h
$(OBJDIR)\tswrite.obj: compat.h misc_fns.h printing_fns.h tswrite_fns.h


$(LIBFILE): $(LIBDIR) $(LIB_OBJS)
	lib /nologo /out:$@ $(LIB_OBJS)

$(EXEDIR)\esfilter.exe: $(OBJDIR)\esfilter.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\esmerge.exe: $(OBJDIR)\esmerge.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\ts2es.exe:    $(OBJDIR)\ts2es.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\es2ts.exe:    $(OBJDIR)\es2ts.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\esdots.exe:   $(OBJDIR)\esdots.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\esreport.exe: $(OBJDIR)\esreport.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\esreverse.exe: $(OBJDIR)\esreverse.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\m2ts2ts.exe: $(OBJDIR)\m2ts2ts.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\stream_type.exe: $(OBJDIR)\stream_type.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\pcapreport.exe: $(OBJDIR)\pcapreport.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\psreport.exe: $(OBJDIR)\psreport.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\ps2ts.exe:    $(OBJDIR)\ps2ts.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\psdots.exe:   $(OBJDIR)\psdots.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\ts_packet_insert.exe:   $(OBJDIR)\ts_packet_insert.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\tsdvbsub.exe:   $(OBJDIR)\tsdvbsub.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\tsinfo.exe:   $(OBJDIR)\tsinfo.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\tsreport.exe: $(OBJDIR)\tsreport.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\tsplay.exe:   $(OBJDIR)\tsplay.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

$(EXEDIR)\tsserve.exe:   $(OBJDIR)\tsserve.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

# For the moment, ts2ps is not an official program, so must
# be built separately
ts2ps:	$(EXEDIR)\ts2ps.exe

$(EXEDIR)\ts2ps.exe:    $(OBJDIR)\ts2ps.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib

# Only build test_pes if explicitly asked to do so
test_pes: $(EXEDIR)\test_pes.exe

$(EXEDIR)\test_pes.exe:   $(OBJDIR)\test_pes.obj $(LIBFILE)
	link /out:$@ $(LOPT) $** wsock32.lib


# ------------------------------------------------------------
# Directories

$(OBJDIR):
	$(COMSPEC) /x /c md $(OBJDIR)

!if "$(LIBDIR)" != "$(OBJDIR)"
$(LIBDIR):
	$(COMSPEC) /x /c md $(LIBDIR)
!endif

!if "$(EXEDIR)" != "$(OBJDIR)"
$(EXEDIR):
	$(COMSPEC) /x /c md $(EXEDIR)
!endif

# ------------------------------------------------------------
# Tidying up
clean:
	-del /q $(OBJDIR)\*.obj
	-del /q $(OBJDIR)\*.lib

distclean: clean
	-del /q $(DEBUG_OBJDIR)\*.obj
	-del /q $(DEBUG_OBJDIR)\*.lib
	-del /q $(PLAIN_OBJDIR)\*.obj
	-del /q $(PLAIN_OBJDIR)\*.lib
	-del /q $(EXEDIR)\*.exe
	-del /q $(EXEDIR)\*.pdb
