# Import construction environment
Import('ctrl_type')
# Import('env_test')
# Import('env_sim')

sources = Split("""
src/simple_msgs/ur_joint_cmd.cpp
src/simple_msgs/ur_config_cmd.cpp
src/simple_msgs/ur_state_data.cpp
src/ur_joint_cmd_handler.cpp
src/ur_config_cmd_handler.cpp
src/ur_controller_iface.cpp
src/run_controller.cpp
src/simple_message/byte_array.cpp
src/simple_message/joint_data.cpp
src/simple_message/joint_traj.cpp
src/simple_message/joint_traj_pt.cpp
src/simple_message/joint_traj_pt_full.cpp
src/simple_message/message_handler.cpp
src/simple_message/message_manager.cpp
src/simple_message/ping_handler.cpp
src/simple_message/ping_message.cpp
src/simple_message/robot_status.cpp
src/simple_message/simple_comms_fault_handler.cpp
src/simple_message/simple_message.cpp
src/simple_message/smpl_msg_connection.cpp
src/simple_message/messages/joint_message.cpp
src/simple_message/messages/joint_traj_pt_message.cpp
src/simple_message/messages/joint_traj_pt_full_message.cpp
src/simple_message/messages/robot_status_message.cpp
src/simple_message/socket/simple_socket.cpp
src/simple_message/socket/tcp_client.cpp
src/simple_message/socket/tcp_server.cpp
src/simple_message/socket/tcp_socket.cpp
src/simple_message/socket/udp_client.cpp
src/simple_message/socket/udp_server.cpp
src/simple_message/socket/udp_socket.cpp
""")

libpath = ['./include/ur_c_api']
libs = ['robotcomm', 'kinematics', 'configuration', 'dev', 'collision', 'm', 'math', 'legacy']
ccflags = '-O2 -Wall -m32'
cpppath = ['./include', './include/ur_c_api']

###############################################################################

if ctrl_type == 'HARDWARE_CONTROLLER':
    ctrl_file = 'src/ur_hardware_controller.cpp'
    target_name = '#bin/ur_ctrl_server'
elif ctrl_type == 'SIMULATION_CONTROLLER':
    ctrl_file = 'src/ur_sim_controller.cpp'
    target_name = '#bin/ur_sim_server'
elif ctrl_type == 'TEST_CONTROLLER':
    ctrl_file = 'src/ur_test_controller.cpp'
    target_name = '#bin/ur_test_server'

VariantDir('build', 'src', duplicate=0)

cppdefines = ['NDEBUG', 'LINUXSOCKETS', 'FLOAT64', ctrl_type]
sources_all = sources + [ctrl_file]
env_hw = Environment(CPPPATH=cpppath, 
                     CPPDEFINES=cppdefines, 
                     CCFLAGS='-O2 -Wall')
objects_hw = env_hw.Object(source=sources_all)
env_hw.Program(target=target_name,
               source=objects_hw,
               LIBPATH=libpath,
               LIBS=libs, 
               CCFLAGS=ccflags)
