#FIXME - reorganize this big mess
ID3v22 = \
figures/id3v22/header.pdf \
figures/id3v22/frame.pdf \
figures/id3v22/frames.pdf \
figures/id3v22/com.pdf \
figures/id3v22/com-example.pdf \
figures/id3v22/geo.pdf \
figures/id3v22/pic.pdf \
figures/id3v22/pic-example.pdf \
figures/id3v22/t__.pdf \
figures/id3v22/t__-example.pdf \
figures/id3v22/txx.pdf \
figures/id3v22/ult.pdf \
figures/id3v22/w__.pdf \
figures/id3v22/wxx.pdf

ID3v23 = \
figures/id3v23/header.pdf \
figures/id3v23/frame.pdf \
figures/id3v23/frames.pdf \
figures/id3v23/apic.pdf \
figures/id3v23/apic-example.pdf \
figures/id3v23/comm.pdf \
figures/id3v23/comm-example.pdf \
figures/id3v23/geob.pdf \
figures/id3v23/t___.pdf \
figures/id3v23/t___-example.pdf \
figures/id3v23/txxx.pdf \
figures/id3v23/uslt.pdf \
figures/id3v23/w___.pdf \
figures/id3v23/wxxx.pdf

ID3v24 = \
figures/id3v24/header.pdf \
figures/id3v24/frame.pdf \
figures/id3v24/frames.pdf \
figures/id3v24/apic.pdf \
figures/id3v24/apic-example.pdf \
figures/id3v24/comm.pdf \
figures/id3v24/comm-example.pdf \
figures/id3v24/geob.pdf \
figures/id3v24/size.pdf \
figures/id3v24/t___.pdf \
figures/id3v24/t___-example.pdf \
figures/id3v24/txxx.pdf \
figures/id3v24/uslt.pdf \
figures/id3v24/w___.pdf \
figures/id3v24/wxxx.pdf

FLAC = \
flac/algorithms/decode_flac.tex \
flac/algorithms/read_metadata.tex \
flac/algorithms/decode_frame.tex \
flac/algorithms/read_frame_header.tex \
flac/algorithms/read_utf8.tex \
flac/algorithms/decode_block_size.tex \
flac/algorithms/decode_sample_rate.tex \
flac/algorithms/decode_bps.tex \
flac/algorithms/decode_channels.tex \
flac/algorithms/decode_subframe.tex \
flac/algorithms/decode_constant.tex \
flac/algorithms/decode_verbatim.tex \
flac/algorithms/decode_fixed.tex \
flac/algorithms/decode_lpc.tex \
flac/algorithms/decode_residual.tex \
flac/algorithms/decorrelate_channels.tex \
flac/algorithms/encode_flac.tex \
flac/algorithms/write_metadata.tex \
flac/algorithms/encode_frame.tex \
flac/algorithms/write_frame_header.tex \
flac/algorithms/encode_block_size.tex \
flac/algorithms/encode_sample_rate.tex \
flac/algorithms/encode_bps.tex \
flac/algorithms/write_utf8.tex \
flac/algorithms/encode_subframe.tex \
flac/algorithms/calculate_wastedbps.tex \
flac/algorithms/write_subframe_header.tex \
flac/algorithms/encode_fixed_subframe.tex \
flac/algorithms/encode_residual.tex \
flac/algorithms/calculate_residual_partitions.tex \
flac/algorithms/encode_lpc_subframe.tex \
flac/algorithms/calculate_qlp_precision.tex \
flac/algorithms/encode_window_samples.tex \
flac/algorithms/encode_autocorrelate.tex \
flac/algorithms/encode_lp_coeffs.tex \
flac/algorithms/encode_best_order.tex \
flac/algorithms/encode_quantize_coeffs.tex \
flac/algorithms/write_lpc_subframe.tex \
flac/figures/application.pdf \
flac/figures/block_header.pdf \
flac/figures/constant.pdf \
flac/figures/cuesheet.pdf \
flac/figures/cuesheet-example.pdf \
flac/figures/fixed.pdf \
flac/figures/fixed2.pdf \
flac/figures/fixed-enc-example.pdf \
flac/figures/fixed-parse.pdf \
flac/figures/frame.pdf \
flac/figures/frames.pdf \
flac/figures/header-example.pdf \
flac/figures/lag0.pdf \
flac/figures/lag1.pdf \
flac/figures/lag2.pdf \
flac/figures/lag3.pdf \
flac/figures/lpc.pdf \
flac/figures/lpc2.pdf \
flac/figures/lpc-parse.pdf \
flac/figures/lpc-parse2.pdf \
flac/figures/metadata.pdf \
flac/figures/metadata-blocks.pdf \
flac/figures/padding.pdf \
flac/figures/picture.pdf \
flac/figures/picture-example.pdf \
flac/figures/read_utf8.pdf \
flac/figures/residual.pdf \
flac/figures/residual-example1.pdf \
flac/figures/residual-example2.pdf \
flac/figures/residual-example3.pdf \
flac/figures/residual-example4.pdf \
flac/figures/residual-example5.pdf \
flac/figures/residual-parse.pdf \
flac/figures/residuals-enc-example.pdf \
flac/figures/seektable.pdf \
flac/figures/seektable-example.pdf \
flac/figures/stream.pdf \
flac/figures/stream2.pdf \
flac/figures/stream3.pdf \
flac/figures/streaminfo.pdf \
flac/figures/streaminfo-example.pdf \
flac/figures/subframes.pdf \
flac/figures/tukey.pdf \
flac/figures/utf8.pdf \
flac/figures/verbatim.pdf \
flac/figures/vorbiscomment.pdf \
flac/figures/vorbiscomment-example.pdf \
flac/figures/write_utf8.pdf \
figures/oggflac_stream.pdf


M4A = figures/m4a/quicktime.pdf \
figures/m4a/alb-example.pdf \
figures/m4a/atom.pdf \
figures/m4a/atom2.pdf \
figures/m4a/atoms.pdf \
figures/m4a/data.pdf \
figures/m4a/dinf.pdf \
figures/m4a/disk.pdf \
figures/m4a/disk-example.pdf \
figures/m4a/dref.pdf \
figures/m4a/dref-example.pdf \
figures/m4a/free.pdf \
figures/m4a/ftyp.pdf \
figures/m4a/ftyp-example.pdf \
figures/m4a/hdlr.pdf \
figures/m4a/hdlr-example.pdf \
figures/m4a/ilst.pdf \
figures/m4a/mdat.pdf \
figures/m4a/mdhd.pdf \
figures/m4a/mdhd-example.pdf \
figures/m4a/mdhd-example2.pdf \
figures/m4a/mdia.pdf \
figures/m4a/mdia-tree.pdf \
figures/m4a/meta.pdf \
figures/m4a/meta_atoms.pdf \
figures/m4a/meta-example.pdf \
figures/m4a/minf.pdf \
figures/m4a/minf-tree.pdf \
figures/m4a/moov.pdf \
figures/m4a/moov-tree.pdf \
figures/m4a/mp4a.pdf \
figures/m4a/mvhd.pdf \
figures/m4a/mvhd-example.pdf \
figures/m4a/nam-example.pdf \
figures/m4a/smhd.pdf \
figures/m4a/smhd-example.pdf \
figures/m4a/stbl.pdf \
figures/m4a/stbl-tree.pdf \
figures/m4a/stco.pdf \
figures/m4a/stco-example.pdf \
figures/m4a/stsc.pdf \
figures/m4a/stsc-example.pdf \
figures/m4a/stsd.pdf \
figures/m4a/stsd-example.pdf \
figures/m4a/stsz.pdf \
figures/m4a/stsz-example.pdf \
figures/m4a/stts.pdf \
figures/m4a/stts-example.pdf \
figures/m4a/tkhd.pdf \
figures/m4a/tkhd-example.pdf \
figures/m4a/trak.pdf \
figures/m4a/trak-tree.pdf \
figures/m4a/trkn.pdf \
figures/m4a/trkn-example.pdf \
figures/m4a/udta.pdf


WAVPACK = \
wavpack/algorithms/decode_wavpack.tex \
wavpack/algorithms/decode_block.tex \
wavpack/algorithms/read_block_header.tex \
wavpack/algorithms/decode_sample_rate.tex \
wavpack/algorithms/read_block_parameters.tex \
wavpack/algorithms/read_decorrelation_terms.tex \
wavpack/algorithms/read_decorrelation_weights.tex \
wavpack/algorithms/read_decorrelation_samples.tex \
wavpack/algorithms/decode_wv_exp2.tex \
wavpack/algorithms/read_entropy.tex \
wavpack/algorithms/read_bitstream.tex \
wavpack/algorithms/read_egc.tex \
wavpack/algorithms/read_residual.tex \
wavpack/algorithms/decode_base_add.tex \
wavpack/algorithms/decorrelate_channels.tex \
wavpack/algorithms/decorrelate_1ch.tex \
wavpack/algorithms/decorrelate_2ch.tex \
wavpack/algorithms/decorrelate_2ch_1.tex \
wavpack/algorithms/decorrelate_2ch_2.tex \
wavpack/algorithms/decorrelate_2ch_3.tex \
wavpack/algorithms/update_weight.tex \
wavpack/algorithms/undo_joint_stereo.tex \
wavpack/algorithms/checksum_calculation.tex \
wavpack/algorithms/read_extended_integers.tex \
wavpack/algorithms/apply_extended_integers.tex \
wavpack/algorithms/encode_wavpack.tex \
wavpack/algorithms/encoding_parameters.tex \
wavpack/algorithms/encode_block.tex \
wavpack/algorithms/calculate_max_magnitude.tex \
wavpack/algorithms/calculate_wasted_bps.tex \
wavpack/algorithms/apply_joint_stereo.tex \
wavpack/algorithms/write_block_parameters.tex \
wavpack/algorithms/write_sub_block_header.tex \
wavpack/algorithms/write_decorrelation_terms.tex \
wavpack/algorithms/write_decorrelation_weights.tex \
wavpack/algorithms/write_decorrelation_samples.tex \
wavpack/algorithms/encode_wv_log2.tex \
wavpack/algorithms/write_entropy_variables.tex \
wavpack/algorithms/correlate_channels.tex \
wavpack/algorithms/correlate_1ch.tex \
wavpack/algorithms/correlate_2ch.tex \
wavpack/algorithms/correlate_2ch_1.tex \
wavpack/algorithms/correlate_2ch_2.tex \
wavpack/algorithms/correlate_2ch_3.tex \
wavpack/algorithms/flush_residual.tex \
wavpack/algorithms/write_egc.tex \
wavpack/algorithms/write_bitstream.tex \
wavpack/algorithms/encode_residual.tex \
wavpack/algorithms/encode_bitstream.tex \
wavpack/algorithms/encode_zeroes.tex \
wavpack/algorithms/write_block_header.tex \
wavpack/algorithms/roundtrip_weights.tex \
wavpack/algorithms/roundtrip_samples.tex \
wavpack/figures/block_channels.pdf \
wavpack/figures/block_header.pdf \
wavpack/figures/block_header2.pdf \
wavpack/figures/block_header_parse.pdf \
wavpack/figures/channel_info.pdf \
wavpack/figures/decoding_params.pdf \
wavpack/figures/decorr_samples.pdf \
wavpack/figures/decorr_samples_encode.pdf \
wavpack/figures/decorr_samples_parse.pdf \
wavpack/figures/decorr_terms.pdf \
wavpack/figures/decorr_weights.pdf \
wavpack/figures/decorr_weights_parse.pdf \
wavpack/figures/decorrelation0.pdf \
wavpack/figures/decorrelation1.pdf \
wavpack/figures/decorrelation2.pdf \
wavpack/figures/decorrelation3.pdf \
wavpack/figures/decorrelation4.pdf \
wavpack/figures/decorrelation5.pdf \
wavpack/figures/decorrelation0.fig \
wavpack/figures/decorrelation1.fig \
wavpack/figures/decorrelation2.fig \
wavpack/figures/decorrelation3.fig \
wavpack/figures/decorrelation4.fig \
wavpack/figures/decorrelation5.fig \
wavpack/figures/entropy_vars.pdf \
wavpack/figures/entropy_vars_parse.pdf \
wavpack/figures/extended_integers.pdf \
wavpack/figures/md5sum.pdf \
wavpack/figures/pcm_sandwich.pdf \
wavpack/figures/residuals.pdf \
wavpack/figures/residuals_parse.pdf \
wavpack/figures/residuals_parse2.pdf \
wavpack/figures/sample_rate.pdf \
wavpack/figures/stream.pdf \
wavpack/figures/subblock.pdf \
wavpack/figures/subblock_header.pdf \
wavpack/figures/subblock_parse.pdf \
wavpack/figures/terms_parse.pdf \
wavpack/figures/typical_block.pdf

SHORTEN = \
shorten/algorithms/read_unsigned.tex \
shorten/algorithms/read_signed.tex \
shorten/algorithms/read_long.tex \
shorten/algorithms/decode_shorten.tex \
shorten/algorithms/process_commands.tex \
shorten/algorithms/process_audio_command.tex \
shorten/algorithms/process_qlpc_command.tex \
shorten/algorithms/process_verbatim.tex \
shorten/algorithms/write_unsigned.tex \
shorten/algorithms/write_signed.tex \
shorten/algorithms/write_long.tex \
shorten/algorithms/encode_shorten.tex \
shorten/algorithms/write_shorten_header.tex \
shorten/algorithms/encode_audio.tex \
shorten/algorithms/calculate_wasted_bps.tex \
shorten/algorithms/compute_diff.tex \
shorten/figures/block1.pdf \
shorten/figures/block2.pdf \
shorten/figures/filetype.pdf \
shorten/figures/header_parse.pdf \
shorten/figures/qlpc.pdf \
shorten/figures/qlpc1.pdf \
shorten/figures/stream.pdf \
shorten/figures/verbatim.pdf

ALAC = \
alac/algorithms/alac_decode.tex \
alac/algorithms/decode_frameset.tex \
alac/algorithms/decode_frame.tex \
alac/algorithms/decode_compressed_frame.tex \
alac/algorithms/read_subframe_header.tex \
alac/algorithms/read_residuals.tex \
alac/algorithms/truncate.tex \
alac/algorithms/read_residual.tex \
alac/algorithms/decode_subframe.tex \
alac/algorithms/channel_decorrelation.tex \
alac/algorithms/alac_encode.tex \
alac/algorithms/encode_frameset.tex \
alac/algorithms/encode_frame.tex \
alac/algorithms/encode_uncompressed_frame.tex \
alac/algorithms/encode_compressed_frame.tex \
alac/algorithms/encode_noninterlaced_frame.tex \
alac/algorithms/encode_interlaced_frame.tex \
alac/algorithms/write_subframe_header.tex \
alac/algorithms/correlate_channels.tex \
alac/algorithms/compute_qlp_coeffs.tex \
flac/algorithms/encode_window_samples.tex \
flac/algorithms/encode_autocorrelate.tex \
flac/algorithms/encode_lp_coeffs.tex \
alac/algorithms/quantize_coeffs.tex \
alac/algorithms/encode_compute_residual.tex \
alac/algorithms/write_residuals.tex \
alac/algorithms/write_residual.tex \
alac/figures/alac_atom.pdf \
alac/figures/alac-atom-parse.pdf \
alac/figures/atom.pdf \
alac/figures/atoms.pdf \
alac/figures/interlaced_frame.pdf \
alac/figures/mdhd.pdf \
alac/figures/mdhd-parse.pdf \
alac/figures/noninterlaced_frame.pdf \
alac/figures/residual-build.pdf \
alac/figures/residual-parse.pdf \
alac/figures/stream.pdf \
alac/figures/frameset.pdf \
alac/figures/frame.pdf \
alac/figures/subframe-build.pdf \
alac/figures/subframe-parse.pdf \
alac/figures/subframe_header.pdf \
alac/figures/uncompressed_frame.pdf

MLP = figures/mlp/channel_parameters.pdf \
figures/mlp/codebook1.pdf \
figures/mlp/codebook2.pdf \
figures/mlp/codebook3.pdf \
figures/mlp/decoding_params.pdf \
figures/mlp/filter_params_fir.pdf \
figures/mlp/filter_params_iir.pdf \
figures/mlp/major_sync.pdf \
figures/mlp/matrix_params.pdf \
figures/mlp/output_shifts.pdf \
figures/mlp/parameter_presence_flags.pdf \
figures/mlp/quant_steps.pdf \
figures/mlp/residuals.pdf \
figures/mlp/restart_header.pdf \
figures/mlp/stream.pdf \
figures/mlp/substream.pdf \
figures/mlp/substream_size.pdf

DVDA = dvda/algorithms/ats_xx_ifo.tex \
dvda/algorithms/mlp_decoding.tex \
dvda/algorithms/decode_frame.tex \
dvda/algorithms/read_major_sync.tex \
dvda/algorithms/read_substream_info.tex \
dvda/algorithms/decode_substream.tex \
dvda/algorithms/decode_block.tex \
dvda/algorithms/read_restart_header.tex \
dvda/algorithms/read_decoding_parameters.tex \
dvda/algorithms/read_matrix_parameters.tex \
dvda/algorithms/read_channel_parameters.tex \
dvda/algorithms/default_channel_parameters.tex \
dvda/algorithms/read_fir_parameters.tex \
dvda/algorithms/read_iir_parameters.tex \
dvda/algorithms/read_residual.tex \
dvda/algorithms/filter_channels.tex \
dvda/algorithms/rematrix_channels.tex \
dvda/algorithms/apply_output_shifts.tex \
dvda/algorithms/unify_substreams.tex \
figures/dvda/aob_mlp_payload.pdf \
figures/dvda/aob_pack_header.pdf \
figures/dvda/aob_pcm_payload.pdf \
figures/dvda/ats_sectors.pdf \
figures/dvda/ats_title.pdf \
figures/dvda/ats_xx_0.pdf \
figures/dvda/ats_xx_x.pdf \
figures/dvda/audio_packet.pdf \
figures/dvda/audio_ts_ifo.pdf \
figures/dvda/layout.pdf \
figures/dvda/mlp_channel_params.pdf \
figures/dvda/mlp_codebook1.pdf \
figures/dvda/mlp_codebook2.pdf \
figures/dvda/mlp_codebook3.pdf \
figures/dvda/mlp_block_parse.pdf \
figures/dvda/mlp_decoding_params.pdf \
figures/dvda/mlp_decoding_params_parse.pdf \
figures/dvda/mlp_frame.pdf \
figures/dvda/mlp_iir_filter_params.pdf \
figures/dvda/mlp_fir_filter_params.pdf \
figures/dvda/mlp_matrix_params.pdf \
figures/dvda/mlp_major_sync.pdf \
figures/dvda/mlp_major_sync_parse.pdf \
figures/dvda/mlp_parity_parse.pdf \
figures/dvda/mlp_residuals.pdf \
figures/dvda/mlp_restart_header.pdf \
figures/dvda/mlp_restart_header_parse1.pdf \
figures/dvda/mlp_restart_header_parse2.pdf \
figures/dvda/mlp_stream.pdf \
figures/dvda/mlp_substream.pdf \
figures/dvda/mlp_substream_info.pdf \
figures/dvda/mlp_substream_info_parse.pdf

AOBPCM = figures/aobpcm/24bps_1ch.pdf \
figures/aobpcm/24bps_2ch.pdf \
figures/aobpcm/24bps_3ch.pdf \
figures/aobpcm/24bps_4ch.pdf \
figures/aobpcm/24bps_5ch.pdf \
figures/aobpcm/24bps_6ch.pdf

OGG = figures/ogg/packets.pdf \
figures/ogg/stream.pdf

VORBIS = figures/vorbis/stream.pdf \
figures/vorbis/codebooks.pdf \
figures/vorbis/comment.pdf \
figures/vorbis/comment-example.pdf \
figures/vorbis/float32.pdf \
figures/vorbis/huffman_example1.pdf \
figures/vorbis/huffman_example2.pdf \
figures/vorbis/huffman_example3.pdf \
figures/vorbis/huffman_example4.pdf \
figures/vorbis/identification.pdf \
figures/vorbis/identification_example.pdf \
figures/vorbis/ordered_entries.pdf \
figures/vorbis/setup_packet.pdf

BASICS = figures/diagram.pdf \
figures/diagram2.pdf \
figures/big_endian.pdf \
figures/little_endian.pdf \
figures/unary1.pdf

MP3 = figures/mp3/frame_header.pdf \
figures/mp3/granule.pdf \
figures/mp3/id3v1.pdf \
figures/mp3/id3v11.pdf \
figures/mp3/id3v11-example.pdf \
figures/mp3/id3v2_stream.pdf \
figures/mp3/id3v2_stream-example.pdf \
figures/mp3/main_data.pdf \
figures/mp3/scalefactors.pdf \
figures/mp3/side_data_1ch.pdf \
figures/mp3/side_data_2ch.pdf \
figures/mp3/stream.pdf \
figures/mp3/stream2.pdf \
figures/mp3/xing.pdf

WAVE = \
figures/wav/stream.pdf \
figures/wav/fmt.pdf \
figures/wav/fmtext.pdf \
figures/wav/data.pdf

AIFF = \
figures/aiff/stream.pdf \
figures/aiff/comm.pdf \
figures/aiff/ssnd.pdf

APE = \
figures/ape/stream.pdf \
figures/ape/descriptor.pdf \
figures/ape/descriptor-example.pdf \
figures/ape/header.pdf \
figures/ape/header-example.pdf

TTA = \
tta/algorithms/decode_tta.tex \
tta/algorithms/decode_frame.tex \
tta/algorithms/decode_hybrid_filter.tex \
tta/algorithms/decode_fixed_prediction.tex \
tta/algorithms/decorrelate.tex \
tta/algorithms/encode_tta.tex \
tta/algorithms/encode_frame.tex \
tta/algorithms/correlate.tex \
tta/algorithms/encode_fixed_prediction.tex \
tta/algorithms/encode_hybrid_filter.tex \
tta/figures/header.pdf \
tta/figures/header-example.pdf \
tta/figures/seektable.pdf \
tta/figures/seektable-example.pdf \
tta/figures/frames.pdf \
tta/figures/residuals.pdf

APEV2 = \
figures/apev2/footer-example.pdf \
figures/apev2/footer-flags.pdf \
figures/apev2/full-example.pdf \
figures/apev2/header.pdf \
figures/apev2/header-flags.pdf \
figures/apev2/item.pdf \
figures/apev2/item-example1.pdf \
figures/apev2/item-example2.pdf \
figures/apev2/item-example3.pdf \
figures/apev2/tag.pdf

MUSEPACK = \
figures/musepack/sv7_stream.pdf \
figures/musepack/sv8_stream.pdf \
figures/musepack/sv8_sh.pdf \
figures/musepack/sv8_rg.pdf \
figures/musepack/sv8_ei.pdf \
figures/musepack/sv8_nut.pdf

FREEDB = \
figures/freedb/sequence.pdf \
figures/freedb/discid.pdf \

MUSICBRAINZ = \
figures/musicbrainz/discid.pdf \
figures/musicbrainz/xml.pdf \

ACCURATERIP = \
figures/accuraterip-data.pdf \
figures/accuraterip-data-example.pdf

FIGURES = \
$(BASICS) \
$(WAVE) \
$(AIFF) \
figures/au_stream.pdf \
$(SHORTEN) \
$(FLAC) \
$(TTA) \
$(WAVPACK) \
$(APEV2) \
$(APE) \
$(MP3) \
$(OGG) \
$(ID3v22) \
$(ID3v23) \
$(ID3v24) \
$(M4A) \
$(ALAC) \
$(VORBIS) \
figures/speex_header.pdf \
$(MUSEPACK) \
$(ACCURATERIP) \
$(DVDA) \
$(FREEDB) \
$(MUSICBRAINZ)


CHAPTERS = \
introduction.tex \
basics.tex \
wav.tex \
aiff.tex \
au.tex \
shorten.tex \
shorten/decode.tex \
shorten/encode.tex \
flac.tex \
flac/metadata.tex \
flac/decode.tex \
flac/encode.tex \
flac/encode/fixed.tex \
flac/encode/residual.tex \
flac/encode/lpc.tex \
tta.tex \
tta/metadata.tex \
tta/decode.tex \
tta/encode.tex \
wavpack.tex \
wavpack/decode.tex \
wavpack/decode/terms.tex \
wavpack/decode/weights.tex \
wavpack/decode/samples.tex \
wavpack/decode/entropy.tex \
wavpack/decode/bitstream.tex \
wavpack/decode/decorrelation.tex \
wavpack/encode.tex \
wavpack/encode/correlation.tex \
wavpack/encode/terms.tex \
wavpack/encode/weights.tex \
wavpack/encode/samples.tex \
wavpack/encode/entropy.tex \
wavpack/encode/bitstream.tex \
apev2.tex \
ape.tex \
mp3.tex \
m4a.tex \
alac.tex \
alac/decode.tex \
alac/encode.tex \
alac/encode/atoms.tex \
alac/encode/lpc.tex \
alac/encode/residual.tex \
vorbis.tex \
oggflac.tex \
speex.tex \
musepack.tex \
dvda2.tex \
freedb.tex \
musicbrainz.tex \
musicbrainz_mmd.tex \
accuraterip.tex \
replaygain.tex \
references.tex \
license.tex

PS_DIR = pseudocode-src

PSEUDOCODE_OBJECTS = \
$(PS_DIR)/statement.o \
$(PS_DIR)/expression.o \
$(PS_DIR)/variable.o \
$(PS_DIR)/latex.o

all: audioformats-letter.pdf audioformats-a4.pdf

clean:
	rm -f *.toc *.aux *.log *.out $(FIGURES)
	rm -f figures/pcm.fig flac/figures/tukey.fig
	rm -f audioformats-a4.tex audioformats-letter.tex
	rm -f audioformats-a4.pdf audioformats-letter.pdf
	rm -f pseudocode $(PS_DIR)/pseudocode.tab.c $(PS_DIR)/lex.yy.c $(PSEUDOCODE_OBJECTS)
	rm -f $(PS_DIR)/pseudocode.tab.h

audioformats-letter.pdf: audioformats-letter.tex $(CHAPTERS) $(FIGURES)
	python pdflatexbuild.py -halt-on-error audioformats-letter.tex
	python ../pdftag.py "--title=Audio Formats Reference" "--author=Brian Langenberger" $@

audioformats-a4.pdf: audioformats-a4.tex $(CHAPTERS) $(FIGURES)
	python pdflatexbuild.py -halt-on-error audioformats-a4.tex
	python ../pdftag.py "--title=Audio Formats Reference" "--author=Brian Langenberger" $@

pseudocode: $(PS_DIR)/pseudocode.tab.c $(PS_DIR)/lex.yy.c $(PSEUDOCODE_OBJECTS)
	$(CC) -g -Wall $(PS_DIR)/pseudocode.tab.c $(PS_DIR)/lex.yy.c $(PSEUDOCODE_OBJECTS) -ll -o $@

$(PS_DIR)/pseudocode.tab.c: $(PS_DIR)/pseudocode.y
	bison -d $(PS_DIR)/pseudocode.y -o $@

$(PS_DIR)/pseudocode.tab.h: $(PS_DIR)/pseudocode.y
	bison -d $(PS_DIR)/pseudocode.y -o $@

$(PS_DIR)/lex.yy.c: $(PS_DIR)/pseudocode.l $(PS_DIR)/pseudocode.tab.h
	flex -o $@ $(PS_DIR)/pseudocode.l

$(PS_DIR)/statement.o: $(PS_DIR)/statement.h $(PS_DIR)/statement.c $(PS_DIR)/types.h
	$(CC) -g -c -Wall $(PS_DIR)/statement.c -o $@

$(PS_DIR)/expression.o: $(PS_DIR)/expression.h $(PS_DIR)/expression.c $(PS_DIR)/types.h
	$(CC) -g -c -Wall $(PS_DIR)/expression.c -o $@

$(PS_DIR)/variable.o: $(PS_DIR)/variable.h $(PS_DIR)/variable.c $(PS_DIR)/types.h
	$(CC) -g -c -Wall $(PS_DIR)/variable.c -o $@

$(PS_DIR)/latex.o: $(PS_DIR)/latex.h $(PS_DIR)/latex.c
	$(CC) -g -c -Wall $(PS_DIR)/latex.c -o $@

mp3_decode.pdf: mp3_decode.tex $(MP3)
	python pdflatexbuild.py -halt-on-error $<

flac-codec.tex: flac-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

flac-codec.pdf: flac-codec.tex flac.tex $(FLAC)
	python pdflatexbuild.py -halt-on-error $<

alac-codec.tex: alac-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

alac-codec.pdf: alac-codec.tex alac.tex $(ALAC)
	python pdflatexbuild.py -halt-on-error $<

wavpack-codec.tex: wavpack-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

wavpack-codec.pdf: wavpack-codec.tex wavpack.tex $(WAVPACK)
	python pdflatexbuild.py -halt-on-error $<

shorten-codec.tex: shorten-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

shorten-codec.pdf: shorten-codec.tex shorten.tex $(SHORTEN)
	python pdflatexbuild.py -halt-on-error $<

dvda-codec.tex: dvda-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

dvda-codec.pdf: dvda-codec.tex dvda2.tex $(DVDA)
	python pdflatexbuild.py -halt-on-error $<

mp3-codec.tex: mp3-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

mp3-codec.pdf: mp3-codec.tex mp3.tex $(MP3) $(ID3v22) $(ID3v23) $(ID3v24)

ogg-codec.tex: ogg-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=lettepaper $< > $@

ogg-codec.pdf: ogg-codec.tex ogg.tex $(OGG)
	python pdflatexbuild.py -halt-on-error $<

vorbis-codec.tex: vorbis-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

vorbis-codec.pdf: vorbis-codec.tex vorbis.tex $(VORBIS)
	python pdflatexbuild.py -halt-on-error $<

ape-codec.tex: ape-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

ape-codec.pdf: ape-codec.tex ape.tex $(APE)
	python pdflatexbuild.py -halt-on-error $<

tta-codec.tex: tta-codec.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

tta-codec.pdf: tta-codec.tex tta.tex $(TTA)
	python pdflatexbuild.py -halt-on-error $<

accuraterip-short.tex: accuraterip-short.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

accuraterip-short.pdf: accuraterip-short.tex accuraterip.tex $(ACCURATERIP)
	python pdflatexbuild.py -halt-on-error $<

m4a-atoms.tex: m4a-atoms.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

m4a-atoms.pdf: m4a-atoms.tex m4a.tex $(M4A)
	python pdflatexbuild.py -halt-on-error $<

audioformats-letter.tex: audioformats.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=letterpaper $< > $@

audioformats-a4.tex: audioformats.template header.tex footer.tex
	python simple-template.py -D PAPERSIZE=a4paper $< > $@

figures/pcm.pdf: figures/pcm.fig
	fig2dev -Z 3 -L pdf $< $@

figures/pcm.fig: figures/pcm.plot
	./figures/pcm.plot > $@

flac/figures/tukey.pdf: flac/figures/tukey.fig
	fig2dev -Z 3 -L pdf $< $@

flac/figures/tukey.fig: flac/figures/tukey.plot
	./flac/figures/tukey.plot > $@

flac/figures/lag0.pdf: flac/figures/lag0.fig
	fig2dev -Z 3.5 -L pdf $< $@

flac/figures/lag1.pdf: flac/figures/lag1.fig
	fig2dev -Z 3.5 -L pdf $< $@

flac/figures/lag2.pdf: flac/figures/lag2.fig
	fig2dev -Z 3.5 -L pdf $< $@

flac/figures/lag3.pdf: flac/figures/lag3.fig
	fig2dev -Z 3.5 -L pdf $< $@

figures/freedb/sequence.pdf: figures/freedb/sequence.fig
	fig2dev -Z 4 -L pdf $< $@

figures/musicbrainz/xml.pdf: figures/musicbrainz/xml.fig
	fig2dev -Z 4 -L pdf $< $@

figures/m4a/atoms.pdf: figures/m4a/atoms.fig
	fig2dev -Z 6 -L pdf $< $@

figures/m4a/meta_atoms.pdf: figures/m4a/meta_atoms.fig
	fig2dev -Z 3 -L pdf $< $@

figures/m4a/moov-tree.pdf: figures/m4a/moov-tree.fig
	fig2dev -Z 6 -L pdf $< $@

figures/m4a/trak-tree.pdf: figures/m4a/trak-tree.fig
	fig2dev -Z 6 -L pdf $< $@

figures/m4a/mdia-tree.pdf: figures/m4a/mdia-tree.fig
	fig2dev -Z 6 -L pdf $< $@

figures/m4a/minf-tree.pdf: figures/m4a/minf-tree.fig
	fig2dev -Z 6 -L pdf $< $@

figures/m4a/stbl-tree.pdf: figures/m4a/stbl-tree.fig
	fig2dev -Z 6 -L pdf $< $@

alac/figures/atoms.pdf: alac/figures/atoms.fig
	fig2dev -Z 5 -L pdf $< $@

figures/bitstream_bigendian.pdf: figures/bitstream_bigendian.fig
	fig2dev -Z 6 -L pdf $< $@

figures/bitstream_littleendian.pdf: figures/bitstream_littleendian.fig
	fig2dev -Z 6 -L pdf $< $@

figures/bitstream_littleendian_alt.pdf: figures/bitstream_littleendian_alt.fig
	fig2dev -Z 6 -L pdf $< $@

figures/vorbis/ordered_entries.pdf: figures/vorbis/ordered_entries.dot
	dot -Tpdf $< -o $@

%.pdf: %.bdx
	./bitdiagram.py -i $< -o $@

%.pdf: %.bpx
	./bitparse.py -i $< -o $@

%.pdf: %.bypx
	./byteparse.py -i $< -o $@

%.pdf: %.dot
	dot -Tpdf $< -o $@

%.tex: %.pfl pseudocode
	./pseudocode $< -o $@

figures/m4a/data.pdf: figures/m4a/data.bdx
	./bitdiagram.py -w 306 -i $< -o $@

alac/figures/atom.pdf: figures/m4a/atom.bdx
	./bitdiagram.py -w 324 -i $< -o $@

alac/figures/alac-atom-parse.pdf: alac/figures/alac-atom-parse.bpx
	./bitparse.py -w 480 -b 24 -i $< -o $@

alac/figures/mdhd.pdf: figures/m4a/mdhd.bdx
	./bitdiagram.py -i $< -o $@

# alac/figures/subframe-parse.pdf: alac/figures/subframe-parse.bpx
# 	./bitparse.py -w 500 -b 24 -i $< -o $@

alac/figures/subframe-parse.pdf: alac/figures/subframe-parse.bpx
	./bitparse.py -w 432 -b 16 -i $< -o $@

alac/figures/residual-parse.pdf: alac/figures/residual-parse.bpx
	./bitparse.py -w 490 -b 24 -i $< -o $@

alac/figures/residual-build.pdf: alac/figures/residual-build.bpx
	./bitparse.py -w 490 -b 24 -i $< -o $@

# wavpack/figures/block_header_parse.pdf: wavpack/figures/block_header_parse.bpx
# 	./bitparse.py -w 480 -b 24 -i $< -o $@

wavpack/figures/decorrelation0.fig: wavpack/figures/decorrelation1.plot wavpack/figures/decorr_pass0.dat
	./wavpack/figures/decorrelation0.plot > $@

wavpack/figures/decorrelation0.pdf: wavpack/figures/decorrelation0.fig
	fig2dev -Z 3 -L pdf $< $@

wavpack/figures/decorrelation1.fig: wavpack/figures/decorrelation1.plot wavpack/figures/decorr_pass1.dat
	./wavpack/figures/decorrelation1.plot > $@

wavpack/figures/decorrelation1.pdf: wavpack/figures/decorrelation1.fig
	fig2dev -Z 3 -L pdf $< $@

wavpack/figures/decorrelation2.fig: wavpack/figures/decorrelation2.plot
	./wavpack/figures/decorrelation2.plot > $@

wavpack/figures/decorrelation2.pdf: wavpack/figures/decorrelation2.fig
	fig2dev -Z 3 -L pdf $< $@

wavpack/figures/decorrelation3.fig: wavpack/figures/decorrelation3.plot
	./wavpack/figures/decorrelation3.plot > $@

wavpack/figures/decorrelation3.pdf: wavpack/figures/decorrelation3.fig
	fig2dev -Z 3 -L pdf $< $@

wavpack/figures/decorrelation4.fig: wavpack/figures/decorrelation4.plot
	./wavpack/figures/decorrelation4.plot > $@

wavpack/figures/decorrelation4.pdf: wavpack/figures/decorrelation4.fig
	fig2dev -Z 3 -L pdf $< $@

wavpack/figures/decorrelation5.fig: wavpack/figures/decorrelation5.plot
	./wavpack/figures/decorrelation5.plot > $@

wavpack/figures/decorrelation5.pdf: wavpack/figures/decorrelation5.fig
	fig2dev -Z 3 -L pdf $< $@

wavpack/figures/residuals_parse.pdf: wavpack/figures/residuals_parse.bpx
	./bitparse.py -i $< -o $@ -b 24 -w 480

wavpack/figures/block_header_parse.pdf: wavpack/figures/block_header_parse.bpx
	./bitparse.py -i $< -o $@ -b 24 -w 500

flac/figures/utf8.pdf: flac/figures/utf8.bpx
	./bitparse.py -i $< -o $@ -b 8 -w 170

flac/figures/lpc-parse2.pdf: flac/figures/lpc-parse2.bpx
	./bitparse.py -i $< -o $@ -b 24 -w 480

shorten/figures/filetype.pdf: shorten/figures/filetype.bpx
	./bitparse.py -w 140 -b 7 -i $< -o $@

basics-info.tex: basics-info.m4 header.tex footer.tex
	m4 -D PAPERSIZE=letterpaper $< > $@

basics-info.pdf: basics-info.tex basics.tex $(BASICS)
	python pdflatexbuild.py -halt-on-error $<

flac/figures/cuesheet-example.pdf: flac/figures/cuesheet-example.bypx
	./byteparse.py --no-ascii --digits-per-row 20 -i $< -o $@

figures/apev2/header-flags.pdf: figures/apev2/header-flags.bpx
	./bitparse.py --bit-width=50 --bits-per-row=8 -i $< -o $@

figures/apev2/footer-flags.pdf: figures/apev2/footer-flags.bpx
	./bitparse.py --bit-width=50 --bits-per-row=8 -i $< -o $@

tta/figures/residuals.pdf: tta/figures/residuals.bpx
	./bitparse.py -w 640 -b 32 -i $< -o $@
