# generate utest Makefile
#
# params:
#     $SRS_OBJS the objs directory. ie. objs
#     $SRS_MAKEFILE the makefile name. ie. Makefile
#

FILE=${SRS_OBJS}/${SRS_MAKEFILE}.utest

cat << END > ${FILE}
# A sample Makefile for building Google Test and using it in user
# tests.  Please tweak it to suit your environment and project.  You
# may want to move it to your project's root directory.
#
# SYNOPSIS:
#
#   make [all]  - makes everything.
#   make TARGET - makes the given target.
#   make clean  - removes all files generated by make.

# Please tweak the following variable definitions as needed by your
# project, except GTEST_HEADERS, which you can use in your own targets
# but shouldn't modify.

# Points to the root of Google Test, relative to where this file is.
# Remember to tweak this if you move this file.
GTEST_DIR = gtest-1.6.0

# Where to find user code.
USER_DIR = .

# Flags passed to the preprocessor.
CPPFLAGS += -I\$(GTEST_DIR)/include

# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -O0

# All tests produced by this Makefile.  Remember to add new tests you
# created to the list.
TESTS = smart_utest

# All Google Test headers.  Usually you shouldn't change this
# definition.
GTEST_HEADERS = \$(GTEST_DIR)/include/gtest/*.h \\
                \$(GTEST_DIR)/include/gtest/internal/*.h

# House-keeping build targets.

all : \$(TESTS)

clean :
	rm -f \$(TESTS) gtest.a gtest_main.a *.o

# Builds gtest.a and gtest_main.a.

# Usually you shouldn't tweak such internal variables, indicated by a
# trailing _.
GTEST_SRCS_ = \$(GTEST_DIR)/src/*.cc \$(GTEST_DIR)/src/*.h \$(GTEST_HEADERS)

# For simplicity and to avoid depending on Google Test's
# implementation details, the dependencies specified below are
# conservative and not optimized.  This is fine as Google Test
# compiles fast and for ordinary users its source rarely changes.
gtest-all.o : \$(GTEST_SRCS_)
	\$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\
            \$(GTEST_DIR)/src/gtest-all.cc

gtest_main.o : \$(GTEST_SRCS_)
	\$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\
            \$(GTEST_DIR)/src/gtest_main.cc

gtest.a : gtest-all.o
	\$(AR) \$(ARFLAGS) \$@ \$^

gtest_main.a : gtest-all.o gtest_main.o
	\$(AR) \$(ARFLAGS) \$@ \$^

# Builds a sample test.  A test should link with either gtest.a or
# gtest_main.a, depending on whether it defines its own main()
# function.

SMART_DIR=../objs
ST_DIR=\$(SMART_DIR)/st-1.9/obj
SSL_LINK = \$(SMART_DIR)/openssl-1.0.1c/libssl.a \$(SMART_DIR)/openssl-1.0.1c/libcrypto.a -ldl

smart_objs_o = objs/src/core/smt_public.o objs/src/core/smt_error_code.o objs/src/core/smt_log.o objs/src/core/smt_app.o objs/src/core/smt_utility.o objs/src/core/smt_process.o objs/src/core/smt_bytes_pool.o objs/src/core/smt_config.o objs/src/core/smt_buffer_manager.o objs/src/core/smt_connection.o objs/src/core/smt_descriptor.o objs/src/core/smt_tearup_ret.o objs/src/core/smt_context.o objs/src/core/smt_empty_app.o objs/src/core/smt_serialize.o objs/src/app/smt_app_process_handler.o objs/src/app/smt_app_smart_app.o objs/src/app/smt_app_connection.o objs/src/app/smt_app_socket_stream.o objs/src/app/smt_app_handshake.o objs/src/app/smt_app_context.o objs/src/app/smt_app_endpoint_switch.o objs/src/app/smt_app_edge.o objs/src/app/smt_app_edge_cache.o objs/src/app/smt_app_edge_stream.o objs/src/app/smt_app_utility.o objs/src/app/smt_app_edge_proxy.o objs/src/app/smt_app_api.o objs/src/app/smt_app_vhost_statistic.o objs/src/app/smt_app_bandwidth_check.o objs/src/protocol/rtmp/smt_rtmp_utility.o objs/src/protocol/rtmp/smt_rtmp_description_builder.o objs/src/protocol/rtmp/smt_rtmp_interfaces.o objs/src/protocol/rtmp/smt_rtmp_api.o objs/src/protocol/rtmp/smt_rtmp_chunk_packet.o objs/src/protocol/rtmp/smt_rtmp_handshake_packet.o objs/src/protocol/rtmp/smt_rtmp_message_packet.o objs/src/protocol/rtmp/smt_rtmp_farm.o objs/src/protocol/rtmp/smt_rtmp_crypto.o objs/src/protocol/rtmp/smt_rtmp_amf3.o objs/src/protocol/rtmp/smt_rtmp_bytes_pool.o objs/src/os/st/smt_st_process_model.o objs/src/os/st/smt_st_process_spawner.o objs/src/os/st/smt_st_process_channel.o objs/src/os/st/smt_st_utility.o objs/src/os/st/smt_st_pipe.o objs/src/os/st/smt_st_signal_channel.o objs/src/os/st/smt_st_server_listener.o objs/src/os/st/smt_st_connection.o objs/src/os/st/smt_st_connection_farm.o objs/src/os/st/smt_st_fd_auto_closer.o objs/src/log/smt_log_simple_log.o objs/src/log/smt_log_fast_log.o objs/src/amf0/smt_amf0_public.o objs/src/amf0/smt_amf0_packet.o objs/src/amf0/smt_amf0_codec.o objs/src/amf0/smt_amf0_utility.o objs/src/config/smt_config_app_args.o objs/src/config/smt_config_options_parser.o objs/src/config/smt_config_file_parser.o objs/src/stream/smt_stream_source.o objs/src/stream/smt_stream_vod_cache.o objs/src/stream/smt_stream_live_stream.o objs/src/stream/smt_stream_flv_muxer.o objs/src/stream/smt_stream_f4v_muxer.o objs/src/stream/smt_stream_vod_stream.o objs/src/stream/smt_stream_public_api.o objs/src/stream/smt_stream_internal_api.o objs/src/stream/smt_stream_utility.o objs/src/stream/smt_stream_buffer_manager.o objs/src/stream/smt_stream_factory.o objs/src/stream/smt_stream_file_stream.o objs/src/stream/smt_stream_strategy.o objs/src/stream/smt_stream_source_pool.o
smart_objs = \$(addprefix \$(SMART_DIR)/../, \$(smart_objs_o))

SMART_INC = -I\$(SMART_DIR)/inc -I\$(ST_DIR)
SSL_LINK = \$(SMART_DIR)/openssl-1.0.1c/libssl.a \$(SMART_DIR)/openssl-1.0.1c/libcrypto.a -ldl

smart_refer_utest.o : \$(smart_objs) smart_refer_utest.cpp
	\$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_refer_utest.cpp -o \$@
smart_app_utest.o : \$(smart_objs) smart_app_utest.cpp
	\$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_app_utest.cpp -o \$@
smart_reload_utest.o : \$(smart_objs) smart_reload_utest.cpp
	\$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_reload_utest.cpp -o \$@
smart_process_pool_utest.o : \$(smart_objs) smart_process_pool_utest.cpp
	\$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_process_pool_utest.cpp -o \$@
smart_config_utest.o : \$(smart_objs) smart_config_utest.cpp
	\$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_config_utest.cpp -o \$@
smart_utest.o : \$(smart_objs) smart_utest.cpp
	@echo "ensure the smart-server is updated: (cd .. && make all)"
	\$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_utest.cpp -o \$@
utest_objs = smart_utest.o smart_config_utest.o smart_process_pool_utest.o smart_reload_utest.o smart_app_utest.o smart_refer_utest.o
smart_utest : \$(utest_objs) gtest_main.a \$(smart_objs)
	@echo \$(smart_objs)
	@echo "===================="
	@echo "the utest must run in centos6, for we depends on -lssl, that used in smart-server is openssl-1.0.1c"
	\$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) -lpthread \$^ \$(ST_DIR)/libst.a \$(SSL_LINK) -o \$@
END

# parent Makefile, to create module output dir before compile it.
echo "	mkdir -p ${SRS_OBJS}/utest" >> ${SRS_MAKEFILE}

echo -n "generate utest ok"; echo '!';