Import('env', 'qt_env', 'arch', 'common', 'messaging', 'gpucommon', 'visionipc', 'cereal', 'NEOS')

src = ['ui.cc', 'paint.cc', 'sidebar.cc', '#phonelibs/nanovg/nanovg.c']
libs = [common, 'zmq', 'czmq', 'capnp', 'kj', 'm', cereal, messaging, gpucommon, visionipc]


if qt_env is None:
  if NEOS:
    libs += ['EGL', 'GLESv3', 'c++_shared', 'framebuffer2', 'OpenCL']
    forcelib = File('/system/lib64/liblzma.so')
    # OpenCL is a vendor lib
    # Does this fix preload issue?
    # Think main scons does against /system/lib64 also, check
    linkflags = ['-Wl,-rpath=/vendor/lib64,-rpath=/data/data/com.termux/files/usr/lib']
  else:
    libs += ['EGL', 'GLESv3', 'gnustl_shared', 'log', 'utils', 'gui', 'hardware', 'ui', 'CB', 'gsl', 'adreno_utils', 'OpenSLES', 'cutils', 'uuid', 'OpenCL']
    forcelib = []
    linkflags = ['-Wl,-rpath=/system/lib64,-rpath=/system/comma/usr/lib']

  src += ["android/ui.cc"]
  env.Program('_ui', src,
    LINKFLAGS=linkflags,
    FORCELIB=forcelib,
    LIBS=libs)

else:
  qt_libs = ["pthread"]

  if arch == "Darwin":
    qt_env["FRAMEWORKS"] += ["QtWidgets", "QtGui", "QtCore", "QtDBus", "QtMultimedia"]
  else:
    qt_libs += ["Qt5Widgets", "Qt5Gui", "Qt5Core", "Qt5DBus", "Qt5Multimedia"]

  if arch == "larch64":
    qt_libs += ["GLESv2"]
  else:
    qt_libs += ["GL"]

  qt_src = ["qt/ui.cc", "qt/window.cc", "qt/settings.cc", "qt/qt_sound.cc"] + src
  qt_env.Program("_ui", qt_src, LIBS=qt_libs + libs)
