#!/usr/bin/env python
import os

Import('envsplit')
package = envsplit['PACKAGE'] # contrib
project = envsplit['PROJECT'] # splitRangeSpectrum
install_src = os.path.join(envsplit['PRJ_SCONS_INSTALL'], package, project, 'src')
build_lib_dir = envsplit['PRJ_LIB_DIR']

listFiles=['splitRangeSpectrum']

cppFiles = [f+'.cc' for f in listFiles]
objFiles = [f+'.o' for f in listFiles]
envsplit['SPLITSPECTRUM_OBJ_LIST'] = objFiles

envsplit['CMAKE_CXX_STANDARD'] = '11'

# Build shared objects to PRJ_SCONS_INSTALL/library/src
for i in range(len(listFiles)):
    envsplit.SharedObject(target=os.path.join(install_src,objFiles[i]), source=cppFiles[i])

envsplit.Append(CXXFLAGS=['-fopenmp', '-O3'])
if envsplit['GDALISCXX11']:
    envsplit.Append(CXXFLAGS=['-std=c++11'])

envsplit.Append(LIBS=['fftw3f', 'gomp', 'm', 'fftw3f_threads'])
# We want to reuse the objects we just built, otherwise scons will rebuild them as static objects before building the static
# library (clutters up build system)
built_obj_files = [os.path.join(install_src,f) for f in objFiles]
#built_obj_files = [os.path.join(install_src, 'splitSpectrum.o')]
envsplit.Library(target=os.path.join(build_lib_dir,'libsplitSpectrum.a'), source=built_obj_files)

