SUBDIRS=tools \
	decoder playlists encoder protocols stream lang \
	ogg_formats converters operators sources conversions outputs io \
	visualization synth harbor lang_encoders encoder_formats

DISTFILES = $(wildcard *.mli) Makefile $(wildcard *.ml) META.in

ocaml_progs= liquidsoap

top_srcdir := $(if $(top_srcdir), $(top_srcdir), ..)
include $(top_srcdir)/Makefile.defs

liquidsoap_c_files = tools/unix_c.c \
  $(if $(W_OSS),io/oss_io_c.c)

ogg_demuxer = \
  $(if $(W_SPEEX),ogg_formats/liq_speex_decoder.ml) \
  $(if $(W_VORBIS),ogg_formats/liq_vorbis_decoder.ml) \
  $(if $(W_OPUS),ogg_formats/liq_opus_decoder.ml) \
  $(if $(W_THEORA),ogg_formats/liq_theora_decoder.ml) \
  $(if $(W_FLAC_OGG),ogg_formats/liq_flac_ogg_decoder.ml)

ogg_muxer = \
  $(if $(W_OGG),ogg_formats/ogg_muxer.ml encoder/ogg_encoder.ml) \
  $(if $(W_SPEEX),ogg_formats/speex_encoder.ml) \
  $(if $(W_VORBIS),ogg_formats/vorbis_encoder.ml) \
  $(if $(W_OPUS),ogg_formats/opus_encoder.ml) \
  $(if $(W_THEORA),ogg_formats/theora_encoder.ml) \
  $(if $(W_FLAC_OGG),ogg_formats/ogg_flac_encoder.ml)

audio_converters = \
	converters/audio/native_audio_converter.ml \
	$(if $(W_SAMPLERATE),converters/audio/libsamplerate_converter.ml) \
	$(if $(W_FFMPEG),converters/audio/ffmpeg_audio_converter.ml)

video_converters = \
	converters/video/native_video_converter.ml \
	$(if $(W_FFMPEG),converters/video/ffmpeg_video_converter.ml)

decoders = \
	decoder/wav_aiff_decoder.ml decoder/midi_decoder.ml \
	decoder/image_decoder.ml decoder/image/ppm_decoder.ml \
	decoder/external_decoder.ml decoder/raw_audio_decoder.ml \
	$(if $(W_FFMPEG),decoder/ffmpeg_decoder_common.ml decoder/ffmpeg_internal_decoder.ml decoder/ffmpeg_raw_decoder.ml decoder/ffmpeg_copy_decoder.ml decoder/ffmpeg_decoder.ml decoder/image/ffmpeg_image_decoder.ml) \
	$(if $(W_FLAC),decoder/liq_flac_decoder.ml) \
	$(if $(W_FAAD),decoder/aac_decoder.ml) \
	$(if $(W_OGG),decoder/liq_ogg_decoder.ml) \
	$(if $(W_MAD),decoder/mad_decoder.ml) \
	$(if $(W_VORBIS),decoder/vorbisduration.ml) \
	$(if $(W_FLAC),decoder/flacduration.ml) \
	$(if $(W_FLAC_OGG),decoder/ogg_flac_duration.ml) \
	$(if $(W_TAGLIB),decoder/taglib_plug.ml) \
        decoder/id3v2_plug.ml \
	$(if $(W_CAMLIMAGES),decoder/image/camlimages_decoder.ml) \
	$(if $(W_SDL_IMAGE),decoder/image/sdlimage_decoder.ml) \
	$(if $(W_GSTREAMER),decoder/gstreamer_decoder.ml)

playlists = \
	playlists/playlist_basic.ml \
	$(if $(W_XMLPLAYLIST),playlists/playlist_xml.ml)

protocols = \
	protocols/annotate.ml \
	protocols/mpd.ml

sources = \
	sources/synthesized.ml sources/noise.ml sources/blank.ml sources/debug_sources.ml \
	sources/audio_gen.ml sources/request_source.ml sources/latest_metadata.ml \
	sources/request_simple.ml sources/generated.ml \
	harbor/harbor_base.ml harbor/harbor.ml sources/harbor_input.ml \
	$(if $(W_SSL),harbor/harbor_ssl.ml sources/harbor_input_ssl.ml) \
	$(if $(W_OSX_SECURE_TRANSPORT),harbor/harbor_secure_transport.ml sources/harbor_input_secure_transport.ml) \
        tools/external_input.ml sources/external_input_audio.ml sources/external_input_video.ml \
	tools/sandbox.ml \
	$(if $(W_BJACK),sources/bjack_in.ml) \
	$(if $(W_ALSA),sources/alsa_in.ml)

operators = \
	operators/insert_metadata.ml operators/map_metadata.ml \
	operators/on_end.ml operators/on_frame.ml operators/delay.ml \
	operators/max_duration.ml operators/sequence.ml operators/add.ml \
	operators/switch.ml operators/cross.ml \
	operators/pitch.ml operators/pipe.ml operators/filter.ml \
	operators/fir_filter.ml operators/iir_filter.ml operators/filter_rc.ml \
	operators/biquad_filter.ml operators/cuepoint.ml \
	operators/map_op.ml operators/flanger.ml operators/comb.ml \
	operators/compress.ml operators/compress_old.ml operators/compress_exp.ml operators/clip.ml \
	operators/amplify.ml operators/normalize.ml operators/echo.ml operators/gate.ml \
	operators/append.ml operators/pan.ml operators/ms_stereo.ml \
	operators/dyn_op.ml operators/video_effects.ml operators/video_fade.ml \
	operators/noblank.ml operators/compand.ml operators/on_offset.ml \
	operators/prepend.ml operators/lufs.ml operators/available.ml \
	operators/midi_routing.ml operators/sleeper.ml \
	operators/time_warp.ml operators/resample.ml \
	operators/chord.ml operators/video_text.ml operators/window_op.ml \
	operators/rms_smooth.ml operators/delay_line.ml \
	operators/video_text_native.ml operators/accelerate.ml \
	operators/still_frame.ml operators/dtmf.ml \
	$(if $(W_SOUNDTOUCH),operators/soundtouch_op.ml) \
	$(if $(W_SOUNDTOUCH),operators/st_bpm.ml) \
	$(if $(W_LADSPA),operators/ladspa_op.ml) \
	$(if $(W_LILV),operators/lilv_op.ml) \
	$(if $(W_FREI0R),operators/frei0r_op.ml) \
	$(if $(W_GD),operators/video_text_gd.ml) \
	$(if $(W_SDL_TTF),operators/video_text_sdl.ml) \
	$(if $(W_GSTREAMER),operators/video_text_gstreamer.ml)

conversions = \
	conversions/conversion.ml conversions/audio_to_stereo.ml conversions/drop.ml \
	conversions/swap.ml conversions/mean.ml conversions/mux.ml

encoders = \
	encoder/wav_encoder.ml \
	encoder/avi_encoder.ml \
	encoder/lame_encoder.ml \
	encoder/fdkaac_encoder.ml \
	encoder/external_encoder.ml \
	$(if $(W_LAME_DYN),encoder/lame_encoder_dynlink.ml) \
	$(if $(W_FDKAAC_DYN),encoder/fdkaac_encoder_dynlink.ml) \
	$(if $(W_SHINE),encoder/shine_encoder.ml) \
	$(if $(W_LAME),encoder/lame_encoder_builtin.ml) \
	$(if $(W_FLAC),encoder/flac_encoder.ml) \
        $(if $(W_FFMPEG),encoder/ffmpeg_encoder_common.ml encoder/ffmpeg_internal_encoder.ml encoder/ffmpeg_copy_encoder.ml encoder/ffmpeg_encoder.ml) \
	$(if $(W_FDKAAC),encoder/fdkaac_encoder_builtin.ml) \
	$(if $(W_TAGLIB),encoder/taglib_id3v2.ml) \
	$(if $(W_GSTREAMER),encoder/gstreamer_encoder.ml)

lang_encoders = \
  lang/lang_encoders.ml \
  lang_encoders/lang_avi.ml lang_encoders/lang_external_encoder.ml lang_encoders/lang_fdkaac.ml \
  lang_encoders/lang_ffmpeg.ml $(if $(W_FFMPEG),lang_encoders/lang_ffmpeg_opt.ml) lang_encoders/lang_flac.ml lang_encoders/lang_gstreamer.ml \
  lang_encoders/lang_mp3.ml lang_encoders/lang_opus.ml lang_encoders/lang_shine.ml \
  lang_encoders/lang_speex.ml lang_encoders/lang_theora.ml lang_encoders/lang_vorbis.ml \
  lang_encoders/lang_wav.ml

encoder_formats = \
  encoder_formats.ml \
  encoder_formats/meta_format.ml \
  encoder_formats/avi_format.ml \
  encoder_formats/external_encoder_format.ml \
  encoder_formats/fdkaac_format.ml \
  encoder_formats/flac_format.ml \
  encoder_formats/ffmpeg_format.ml \
  encoder_formats/gstreamer_format.ml \
  encoder_formats/mp3_format.ml \
  encoder_formats/opus_format.ml \
  encoder_formats/shine_format.ml \
  encoder_formats/speex_format.ml \
  encoder_formats/theora_format.ml \
  encoder_formats/vorbis_format.ml \
  encoder_formats/ogg_format.ml \
  encoder_formats/wav_format.ml

outputs = outputs/output.ml \
	outputs/pipe_output.ml outputs/hls_output.ml \
	outputs/harbor_output.ml \
	$(if $(W_SSL),outputs/harbor_output_ssl.ml) \
	$(if $(W_OSX_SECURE_TRANSPORT),outputs/harbor_output_secure_transport.ml) \
	$(if $(W_AO),outputs/ao_out.ml) \
	$(if $(W_CRY),outputs/icecast2.ml) \
	$(if $(W_GRAPHICS),outputs/graphics_out.ml) \
	$(if $(W_BJACK),outputs/bjack_out.ml) \
	$(if $(W_SDL),outputs/sdl_out.ml) \
	$(if $(W_ALSA),outputs/alsa_out.ml)

io = io/udp_io.ml \
	$(if $(W_SRT),io/srt_io.ml) \
	$(if $(W_OSS),io/oss_io.ml) \
	$(if $(W_PULSEAUDIO),io/pulseaudio_io.ml) \
	$(if $(W_PORTAUDIO),io/portaudio_io.ml) \
	$(if $(W_ALSA),io/alsa_io.ml) \
	$(if $(W_GSTREAMER),io/gstreamer_io.ml) \
	$(if $(W_FFMPEG),io/ffmpeg_filter_io.ml) \
	$(if $(W_FFMPEG),io/ffmpeg_io.ml)

tools = tools/extralib.ml tools/lifecycle.ml \
	tools/stringView.ml tools/strings.ml tools/runtime_error.ml \
        tools/utils.ml tools/JSON.ml tools/doc.ml tools/plug.ml \
	tools/rqueue.ml tools/unifier.ml \
	$(if $(W_FFMPEG),tools/liqavdevice.ml) \
	$(if $(W_LAME_DYN),tools/lame_dynlink.ml) \
	$(if $(W_FDKAAC_DYN),tools/fdkaac_dynlink.ml) \
	tools/wav_aiff.ml tools/tutils.ml \
	tools/file_watcher.ml tools/file_watcher_mtime.ml \
	$(if $(W_DYNLINK),tools/dyntools.ml) \
	configure.ml tools/console.ml tools/process_handler.ml \
	tools/http.ml \
	$(if $(W_CURL),tools/liqcurl.ml) \
	$(if $(W_SSL),tools/https.ml) \
	$(if $(W_OSX_SECURE_TRANSPORT),tools/https_secure_transport.ml) \
	tools/pool.ml tools/sha1.ml tools/websocket.ml tools/id3v2.ml \
	$(if $(W_INOTIFY),tools/file_watcher_inotify.ml) \
	$(if $(W_PROMETHEUS),tools/liq_prometheus.ml)

stream = stream/frame_settings.ml stream/frame_content.ml \
         stream/frame.ml stream/aFrame.ml stream/vFrame.ml stream/mFrame.ml \
         stream/generator.ml \
	 $(if $(W_FFMPEG), stream/ffmpeg_content_base.ml stream/ffmpeg_copy_content.ml) \
         $(if $(W_FFMPEG), stream/ffmpeg_raw_content.ml) \
         $(if $(W_GSTREAMER),tools/gstreamer_utils.ml)

visualization = \
	visualization/midimeter.ml \
	visualization/video_volume.ml \
	$(if $(W_GRAPHICS),visualization/vis_volume.ml)

synth = synth/keyboard.ml synth/synth_op.ml \
	$(if $(W_DSSI),synth/dssi_op.ml) \
	$(if $(W_SDL),synth/keyboard_sdl.ml)

builtins = lang/lang_builtins.ml \
           lang/builtins_ref.ml \
           lang/builtins_bool.ml lang/builtins_list.ml \
           lang/builtins_string.ml lang/builtins_json.ml \
           lang/builtins_request.ml lang/builtins_error.ml \
           lang/builtins_null.ml lang/builtins_settings.ml \
           lang/builtins_time.ml lang/builtins_callbacks.ml \
           lang/builtins_server.ml lang/builtins_math.ml \
	   lang/builtins_files.ml lang/builtins_resolvers.ml \
           lang/builtins_thread.ml lang/builtins_process.ml \
           lang/builtins_source.ml lang/builtins_getter.ml \
           lang/builtins_profiler.ml lang/builtins_eval.ml \
	   $(if $(W_CURL),lang/builtins_http.ml) \
           lang/builtins_harbor.ml \
           $(if $(W_SSL),lang/builtins_harbor_ssl.ml) \
           $(if $(W_OSX_SECURE_TRANSPORT),lang/builtins_harbor_secure_transport.ml) \
           $(if $(W_LO),lang/builtins_lo.ml) \
           $(if $(W_MAGIC),lang/builtins_magic.ml) \
           $(if $(W_CRY),lang/builtins_cry.ml) \
           $(if $(W_LASTFM),lang/builtins_lastfm.ml) \
           $(if $(W_PROMETHEUS),lang/builtins_prometheus.ml) \
           lang/builtins_ffmpeg_base.ml \
           $(if $(W_FFMPEG),lang/builtins_ffmpeg_encoder.ml lang/builtins_ffmpeg_decoder.ml lang/builtins_ffmpeg_filters.ml)

liquidsoap_sources= \
	tools/log.ml $(tools) converters/audio_converter.ml $(stream) \
	$(if $(W_FFMPEG),tools/ffmpeg_utils.ml tools/ffmpeg_avfilter_utils.ml) \
        converters/video_converter.ml \
	decoder/decoder_utils.ml decoder/decoder.ml \
        tools/liq_time.ml $(if $(W_POSIX_TIME2),tools/liq_posix_time.ml) \
        request.ml tools/server.ml \
        source.ml clock.ml playlist_parser.ml \
	$(encoder_formats) encoder.ml \
	tools/server_builtins.ml \
	$(if $(W_SDL),tools/sdl_utils.ml) \
	$(if $(W_LASTFM),tools/liqfm.ml) \
	$(if $(W_ALSA), alsa_settings.ml)

liquidsoap_sources += \
	lang/type.ml lang/typing.ml lang/profiler.ml lang/term.ml \
	lang/environment.ml lang/typechecking.ml lang/evaluation.ml \
	$(lang_encoders) lang/parser_helper.ml lang/parser.ml lang/lexer.ml \
	lang/preprocessor.ml lang/error.ml lang/documentation.ml \
	lang/lang.ml lang/runtime.ml lang/modules.ml \
        tools/child_support.ml \
        tools/start_stop.ml tools/ioRing.ml \
	tools/icecast_utils.ml tools/avi.ml \
	$(video_converters) $(audio_converters) $(protocols) \
	$(sources) $(outputs) tools/producer_consumer.ml \
	$(conversions) $(operators) \
	$(encoders) $(decoders) $(ogg_demuxer) $(ogg_muxer) \
	$(playlists) $(visualization) $(synth) $(io) \
	shebang.ml $(builtins) main.ml \
	$(if $(W_WINSVC),runner_service.ml,runner.ml)

include $(top_srcdir)/Makefile.rules

configure.ml:
	@echo
	@echo " ERROR Missing src/configure.ml, Please run ./configure first!"
	@if [ -f ../configure-with-options ] ; then \
	  echo "       Note that you can source configure-with-options" ; \
	  echo "       for running configure with the same options as last time." \
	; fi
	@echo
	@exit 1

OCAML_CFLAGS= -thread $(patsubst %,-I %,$(SUBDIRS))
DEP_OPTS= $(patsubst %,-I %,$(SUBDIRS))

install-local: all-auto
	$(INSTALL) -d $(bindir)
	$(INSTALL_PROGRAM) liquidsoap$(EXEEXT) $(bindir)
ifneq ($(BYTE),)
  ifneq ($(NO_CUSTOM),)
	$(OCAMLFIND) install liquidsoap META dllliquidsoap.so
  else
	$(OCAMLFIND) install liquidsoap META
  endif
endif

profile:
	$(MAKE) OCAMLC="$(OCAMLC) -S -p"
