Import('env', 'arch', 'cereal', 'messaging', 'common', 'gpucommon', 'visionipc', 'webcam', 'QCOM_REPLAY')

libs = ['m', 'pthread', common, 'jpeg', 'OpenCL', cereal, messaging, 'czmq', 'zmq', 'capnp', 'kj', visionipc, gpucommon]

if arch == "aarch64":
  libs += ['gsl', 'CB', 'adreno_utils', 'EGL', 'GLESv3', 'cutils', 'ui']
  if QCOM_REPLAY:
    cameras = ['cameras/camera_frame_stream.cc']
  else:
    cameras = ['cameras/camera_qcom.cc']
elif arch == "larch64":
  libs += []
  cameras = ['cameras/camera_qcom2.c']
else:
  if webcam:
    libs += ['opencv_core', 'opencv_highgui', 'opencv_imgproc', 'opencv_videoio']
    cameras = ['cameras/camera_webcam.cc']
    env = env.Clone()
    env.Append(CXXFLAGS = '-DWEBCAM')
    env.Append(CFLAGS = '-DWEBCAM')
    env.Append(CPPPATH = '/usr/local/include/opencv4')
  else:
    libs += []
    cameras = ['cameras/camera_frame_stream.cc']
  if arch == "Darwin":
    del libs[libs.index('OpenCL')]
    env = env.Clone()
    env['FRAMEWORKS'] = ['OpenCL']

env.SharedLibrary('snapshot/visionipc',
  ["#selfdrive/common/visionipc.c", "#selfdrive/common/ipc.c"])

env.Program('camerad', [
    'main.cc',
    'transforms/rgb_to_yuv.c',
    'imgproc/utils.cc',
    cameras,
  ], LIBS=libs)
