
# applications
bin_PROGRAMS =

# rules
noinst_HEADERS=

# executables definition:
MEGACMD = mega-cmd mega-exec mega-cmd-server
if BUILD_MEGACMD_TESTS
TESTS = mega-cmd-unit-tests mega-cmd-integration-tests
endif
bin_PROGRAMS += $(MEGACMD) $(TESTS)

# establish dependency with libmega
$(MEGACMD): $(top_builddir)/sdk/src/libmega.la

#scripst (to install and where)
megacmdcompletiondir = $(sysconfdir)/bash_completion.d/
megacmdcompletion_DATA = src/client/megacmd_completion.sh
megacmdscripts_bindir = $(bindir)
megacmdscripts_bin_SCRIPTS = src/client/mega-attr src/client/mega-cd src/client/mega-confirm src/client/mega-cp src/client/mega-debug src/client/mega-du src/client/mega-df src/client/mega-proxy src/client/mega-export src/client/mega-find src/client/mega-get src/client/mega-help src/client/mega-https src/client/mega-webdav src/client/mega-permissions src/client/mega-deleteversions src/client/mega-transfers src/client/mega-import src/client/mega-invite src/client/mega-ipc src/client/mega-killsession src/client/mega-lcd src/client/mega-log src/client/mega-login src/client/mega-logout src/client/mega-lpwd src/client/mega-ls src/client/mega-backup src/client/mega-mkdir src/client/mega-mount src/client/mega-mv src/client/mega-passwd src/client/mega-preview src/client/mega-put src/client/mega-speedlimit src/client/mega-pwd src/client/mega-quit src/client/mega-reload src/client/mega-rm src/client/mega-session src/client/mega-share src/client/mega-showpcr src/client/mega-signup src/client/mega-sync src/client/mega-exclude src/client/mega-thumbnail src/client/mega-userattr src/client/mega-users src/client/mega-version src/client/mega-whoami src/client/mega-cat src/client/mega-tree src/client/mega-mediainfo src/client/mega-graphics src/client/mega-ftp src/client/mega-cancel src/client/mega-confirmcancel src/client/mega-errorcode

lib_LTLIBRARIES =
noinst_LTLIBRARIES  =

if BUILD_MEGACMD_TESTS
############################    INSTRUMENTS LIBRARY      #####################################
noinst_LTLIBRARIES += src/libmegacmdinstruments.la
noinst_HEADERS += tests/common/Instruments.h

src_libmegacmdinstruments_la_CXXFLAGS = -DMEGACMD_TESTING_CODE=1 -std=c++17 #required for instruments stuff
src_libmegacmdinstruments_la_SOURCES = tests/common/Instruments.cpp
##############################################################################################
endif

###############################    SERVER LIBRARY        #####################################
noinst_LTLIBRARIES += src/libmegacmdserver.la
src_libmegacmdserver_la_LDFLAGS=

noinst_HEADERS += src/comunicationsmanager.h src/configurationmanager.h src/megacmd.h src/megacmdlogger.h src/megacmdsandbox.h src/megacmdutils.h src/megacmdcommonutils.h src/listeners.h src/megacmdexecuter.h src/deferred_single_trigger.h src/megacmd_events.h src/megacmdtransfermanager.h src/megacmdversion.h src/megacmdplatform.h src/comunicationsmanagerportsockets.h
src_libmegacmdserver_la_SOURCES = src/megacmd.cpp src/megacmd_server_main.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/megacmdcommonutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/megacmd_events.cpp src/megacmdtransfermanager.cpp src/comunicationsmanagerportsockets.cpp
src_libmegacmdserver_la_CXXFLAGS = $(LMEGAINC) $(DB_CXXFLAGS)

if USE_PCRE
src_libmegacmdserver_la_CXXFLAGS += -DUSE_PCRE=1
endif

src_libmegacmdserver_la_LIBADD = $(DB_LDFLAGS) $(DB_LIBS) $(PCRE_LIBS) $(top_builddir)/sdk/src/libmega.la

if !WIN32
src_libmegacmdserver_la_SOURCES += src/comunicationsmanagerfilesockets.cpp
noinst_HEADERS += src/comunicationsmanagerfilesockets.h sdk/include/mega/thread/posixthread.h sdk/include/mega/logging.h
else
src_libmegacmdserver_la_SOURCES += src/comunicationsmanagernamedpipes.cpp
src_libmegacmdserver_la_CXXFLAGS += -D_WIN32=1 -Isdk/include/ -Isdk/include/mega/win32
endif

if DARWIN
src_libmegacmdserver_la_SOURCES += src/megacmdplatform.mm
endif

if BUILD_MEGACMD_TESTS
src_libmegacmdserver_la_CXXFLAGS += -DMEGACMD_TESTING_CODE=1
src_libmegacmdserver_la_CXXFLAGS += -std=c++17 #required for instruments stuff
src_libmegacmdserver_la_LIBADD += $(top_builddir)/src/libmegacmdinstruments.la
endif
##############################################################################################

###############################          SERVER         ######################################
mega_cmd_server_SOURCES = src/megacmd_server_main.cpp
mega_cmd_server_LDADD = $(DB_LDFLAGS) $(DB_LIBS) $(LIBS_EXTRA) $(top_builddir)/src/libmegacmdserver.la

if DARWIN
mega_cmd_server_LDFLAGS = -framework Cocoa -framework Security
endif

mega_cmd_server_CXXFLAGS = $(LMEGAINC) $(DB_CXXFLAGS)
##############################################################################################

#############################   COMMS AND COMMON UTILS LIBRARY  ##############################
noinst_LTLIBRARIES += src/libmegacmdcomms.la
noinst_HEADERS += src/megacmdcommonutils.h src/megacmdshell/megacmdshellcommunications.h src/megacmdshell/megacmdshell.h
src_libmegacmdcomms_la_SOURCES = src/megacmdcommonutils.cpp src/megacmdshell/megacmdshellcommunications.cpp

if WIN32
src_libmegacmdcomms_la_SOURCES += src/megacmdshell/megacmdshellcommunicationsnamedpipes.cpp sdk/src/thread/win32thread.cpp sdk/src/logging.cpp
else
src_libmegacmdcomms_la_SOURCES += sdk/src/thread/posixthread.cpp sdk/src/logging.cpp
endif

src_libmegacmdcomms_la_CXXFLAGS = $(LMEGAINC) $(DB_CXXFLAGS)

if BUILD_MEGACMD_TESTS
src_libmegacmdcomms_la_CXXFLAGS += -DMEGACMD_TESTING_CODE=1
endif

##############################################################################################
###############################   CLIENT LIBRARY #############################################
noinst_LTLIBRARIES += src/libmegacmdclient.la
src_libmegacmdclient_la_LDFLAGS=

noinst_HEADERS += src/client/megacmdclient.h src/megacmdcommonutils.h
src_libmegacmdclient_la_SOURCES = src/client/megacmdclient.cpp src/megacmdcommonutils.cpp

src_libmegacmdclient_la_LIBADD = $(top_builddir)/src/libmegacmdcomms.la

if BUILD_MEGACMD_TESTS
src_libmegacmdclient_la_CXXFLAGS = -DMEGACMD_TESTING_CODE=1
src_libmegacmdclient_la_CXXFLAGS += -std=c++17 #required for instruments stuff
src_libmegacmdclient_la_LIBADD += $(top_builddir)/src/libmegacmdinstruments.la
endif

####################################   CLIENT  ###############################################
noinst_HEADERS +=
mega_exec_SOURCES = src/client/megacmd_client_main.cpp

mega_exec_CXXFLAGS = -Isdk/include/ $(LMEGAINC)
mega_exec_LDADD = $(top_builddir)/src/libmegacmdclient.la
##############################################################################################

###############################   SHELL  #####################################################
noinst_HEADERS += src/megacmdshell/megacmdshell.h
mega_cmd_SOURCES = src/megacmdshell/megacmdshell.cpp

mega_cmd_CXXFLAGS = $(RL_CXXFLAGS) -Isdk/include/ $(LMEGAINC)
mega_cmd_LDADD = $(RL_LDFLAGS) $(RL_LIBS) $(TERMCAP_LDFLAGS) $(TERMCAP_LIBS)
mega_cmd_LDADD += $(top_builddir)/src/libmegacmdcomms.la

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

if BUILD_MEGACMD_TESTS
###################    Common Tests LIBRARY        ###########################################
noinst_LTLIBRARIES += src/libmegacmdtestscommon.la
noinst_HEADERS += tests/common/TestUtils.h

src_libmegacmdtestscommon_la_CXXFLAGS = -DMEGACMD_TESTING_CODE=1 -std=c++17 #required for testscommon stuff
src_libmegacmdtestscommon_la_SOURCES = \
    tests/common/TestUtils.cpp
##############################################################################################

############################### Unit Tests  ##################################################
mega_cmd_unit_tests_SOURCES = \
    tests/unit/StringUtilsTests.cpp \
    tests/unit/UtilsTests.cpp \
    tests/unit/PlatformDirectoriesTest.cpp \
    tests/unit/main.cpp

mega_cmd_unit_tests_CXXFLAGS = -DMEGACMD_TESTING_CODE=1 -Itests/common/ -Itests/unit/ -Isdk/include/ $(LMEGAINC)
mega_cmd_unit_tests_CXXFLAGS += -std=c++17

mega_cmd_unit_tests_LDADD = -L/$(GTEST_DIR)/lib/ -lgtest -lgtest_main -lgmock # Note, the trailing / in GTEST_DIR is to allow simple --with-gtest (evalving to "yes")
mega_cmd_unit_tests_LDADD += $(top_builddir)/src/libmegacmdserver.la #to include dependencies of unit-tested code
mega_cmd_unit_tests_LDADD += $(top_builddir)/src/libmegacmdinstruments.la
mega_cmd_unit_tests_LDADD += $(top_builddir)/src/libmegacmdtestscommon.la
##############################################################################################

##############################  Integration Tests  ###########################################
mega_cmd_integration_tests_SOURCES = \
    tests/integration/BasicTests.cpp \
    tests/integration/ExportTests.cpp \
    tests/integration/MegaCmdTestingTools.cpp \
    tests/integration/main.cpp

mega_cmd_integration_tests_CXXFLAGS = -DMEGACMD_TESTING_CODE=1 -Itests/common/ -Itests/integration/ -Isdk/include/ $(LMEGAINC)
mega_cmd_integration_tests_CXXFLAGS += -std=c++17

mega_cmd_integration_tests_LDADD = -L/$(GTEST_DIR)/lib/ -lgtest -lgtest_main -lgmock # Note, the trailing / is to allow simple --with-gtest (evalving to "yes")
mega_cmd_integration_tests_LDADD += $(top_builddir)/src/libmegacmdserver.la
mega_cmd_integration_tests_LDADD += $(top_builddir)/src/libmegacmdclient.la
mega_cmd_integration_tests_LDADD += $(top_builddir)/src/libmegacmdinstruments.la
mega_cmd_integration_tests_LDADD += $(top_builddir)/src/libmegacmdtestscommon.la

##############################################################################################
endif #BUILD_MEGACMD_TESTS


