Import('RTT_ROOT')
Import('rtconfig')
from building import *

# The set of source files associated with this SConscript file.
dfs = Split("""
src/dfs.c
src/dfs_fs.c
src/dfs_file.c
src/dfs_posix.c
""")

# DFS-ELMFAT options
elmfat = Split("""
filesystems/elmfat/dfs_elm.c
filesystems/elmfat/ff.c
""")

# DFS-ROMFS options
romfs = Split("""
filesystems/romfs/dfs_romfs.c
""")
if not GetDepend('DFS_ROMFS_ROOT'):
    romfs = romfs + Split('filesystems/romfs/romfs.c')

# DFS-DeviceFS options
devfs = Split("""
filesystems/devfs/devfs.c
filesystems/devfs/console.c
""")

# DFS-YAFFS2 options
yaffs2_src = Split("""
filesystems/yaffs2/dfs_yaffs2.c
filesystems/yaffs2/yaffs_osglue.c
filesystems/yaffs2/yaffs_nandcfg.c

filesystems/yaffs2/yaffs/yaffs_allocator.c
filesystems/yaffs2/yaffs/yaffs_bitmap.c
filesystems/yaffs2/yaffs/yaffs_checkptrw.c
filesystems/yaffs2/yaffs/yaffs_ecc.c  
filesystems/yaffs2/yaffs/yaffs_guts.c
filesystems/yaffs2/yaffs/yaffs_nameval.c
filesystems/yaffs2/yaffs/yaffs_nand.c
filesystems/yaffs2/yaffs/yaffs_packedtags1.c
filesystems/yaffs2/yaffs/yaffs_packedtags2.c
filesystems/yaffs2/yaffs/yaffs_summary.c
filesystems/yaffs2/yaffs/yaffs_tagscompat.c
filesystems/yaffs2/yaffs/yaffs_verify.c
filesystems/yaffs2/yaffs/yaffs_yaffs1.c
filesystems/yaffs2/yaffs/yaffs_yaffs2.c

filesystems/yaffs2/yaffs/direct/yaffs_attribs.c
filesystems/yaffs2/yaffs/direct/yaffs_hweight.c
filesystems/yaffs2/yaffs/direct/yaffs_nandif.c
filesystems/yaffs2/yaffs/direct/yaffs_qsort.c
filesystems/yaffs2/yaffs/direct/yaffsfs.c

""")

nfs = Split('''
filesystems/nfs/mount_clnt.c
filesystems/nfs/mount_xdr.c
filesystems/nfs/nfs_clnt.c
filesystems/nfs/nfs_xdr.c
filesystems/nfs/dfs_nfs.c
filesystems/nfs/rpc/auth_none.c
filesystems/nfs/rpc/clnt_generic.c
filesystems/nfs/rpc/clnt_udp.c
filesystems/nfs/rpc/rpc_prot.c
filesystems/nfs/rpc/pmap.c
filesystems/nfs/rpc/xdr.c
filesystems/nfs/rpc/xdr_mem.c
''')

uffs = Split('''
filesystems/uffs/src/uffs/uffs_badblock.c
filesystems/uffs/src/uffs/uffs_blockinfo.c
filesystems/uffs/src/uffs/uffs_buf.c
filesystems/uffs/src/uffs/uffs_debug.c
filesystems/uffs/src/uffs/uffs_device.c
filesystems/uffs/src/uffs/uffs_ecc.c
filesystems/uffs/src/uffs/uffs_crc.c
filesystems/uffs/src/uffs/uffs_fd.c
filesystems/uffs/src/uffs/uffs_find.c
filesystems/uffs/src/uffs/uffs_flash.c
filesystems/uffs/src/uffs/uffs_fs.c
filesystems/uffs/src/uffs/uffs_init.c
filesystems/uffs/src/uffs/uffs_mem.c
filesystems/uffs/src/uffs/uffs_mtb.c
filesystems/uffs/src/uffs/uffs_pool.c
filesystems/uffs/src/uffs/uffs_public.c
filesystems/uffs/src/uffs/uffs_tree.c
filesystems/uffs/src/uffs/uffs_utils.c
filesystems/uffs/src/uffs/uffs_version.c

filesystems/uffs/dfs_uffs.c
filesystems/uffs/uffs_nandif.c
filesystems/uffs/uffs_rtthread.c
''')

jffs2 = Split('''
filesystems/jffs2/dfs_jffs2.c
filesystems/jffs2/porting.c

filesystems/jffs2/cyg/compress/src/adler32.c
filesystems/jffs2/cyg/compress/src/compress.c
filesystems/jffs2/cyg/compress/src/deflate.c
filesystems/jffs2/cyg/compress/src/infback.c
filesystems/jffs2/cyg/compress/src/inffast.c
filesystems/jffs2/cyg/compress/src/inflate.c
filesystems/jffs2/cyg/compress/src/inftrees.c
filesystems/jffs2/cyg/compress/src/trees.c
filesystems/jffs2/cyg/compress/src/uncompr.c
filesystems/jffs2/cyg/compress/src/zutil.c

filesystems/jffs2/cyg/crc/crc16.c
filesystems/jffs2/cyg/crc/crc32.c
filesystems/jffs2/cyg/crc/posix_crc.c
filesystems/jffs2/kernel/rbtree.c
filesystems/jffs2/src/build.c
filesystems/jffs2/src/compr.c
filesystems/jffs2/src/compr_rtime.c
filesystems/jffs2/src/compr_rubin.c
filesystems/jffs2/src/compr_zlib.c
filesystems/jffs2/src/debug.c
filesystems/jffs2/src/dir-ecos.c
filesystems/jffs2/src/erase.c
filesystems/jffs2/src/flashio.c
filesystems/jffs2/src/fs-ecos.c
filesystems/jffs2/src/gc.c
filesystems/jffs2/src/gcthread.c
filesystems/jffs2/src/malloc-ecos.c
filesystems/jffs2/src/nodelist.c
filesystems/jffs2/src/nodemgmt.c
filesystems/jffs2/src/read.c
filesystems/jffs2/src/readinode.c
filesystems/jffs2/src/scan.c
filesystems/jffs2/src/write.c
''')

src_local = dfs
CPPDEFINES = []

# The set of source files associated with this SConscript file.
path = [RTT_ROOT + '/components/dfs', RTT_ROOT + '/components/dfs/include']

if GetDepend('RT_USING_DFS_YAFFS2'):
    src_local = src_local + yaffs2_src
    path = path + [RTT_ROOT + '/components/dfs/filesystems/yaffs2/yaffs', \
                   RTT_ROOT + '/components/dfs/filesystems/yaffs2/yaffs/direct' ]

if GetDepend('RT_USING_DFS_ELMFAT'):
    if GetDepend('RT_DFS_ELM_USE_LFN'):
        if GetDepend('RT_DFS_ELM_CODE_PAGE_FILE'):
            elmfat += ['filesystems/elmfat/option/ccfile.c']
        else:
            if GetConfigValue('RT_DFS_ELM_CODE_PAGE') == 932:
                elmfat += ['filesystems/elmfat/option/cc932.c']
            elif GetConfigValue('RT_DFS_ELM_CODE_PAGE') == 936:
                elmfat += ['filesystems/elmfat/option/cc936.c']
            elif GetConfigValue('RT_DFS_ELM_CODE_PAGE') == 949:
                elmfat += ['filesystems/elmfat/option/cc949.c']
            elif GetConfigValue('RT_DFS_ELM_CODE_PAGE') == 950:
                elmfat += ['filesystems/elmfat/option/cc950.c']
            else:
                elmfat += ['filesystems/elmfat/option/ccsbcs.c']
    src_local = src_local + elmfat

if GetDepend(['RT_USING_DFS_NFS', 'RT_USING_LWIP']):
    src_local = src_local + nfs
    path = path + [RTT_ROOT + '/components/dfs/filesystems/nfs']

if GetDepend('RT_USING_DFS_ROMFS'):
    src_local = src_local + romfs
    path = path + [RTT_ROOT + '/components/dfs/filesystems/romfs']

if GetDepend('RT_USING_DFS_DEVFS'):
    src_local = src_local + devfs
    path = path + [RTT_ROOT + '/components/dfs/filesystems/devfs']

if GetDepend('RT_USING_DFS_UFFS'):
    src_local = src_local + uffs
    path = path + [RTT_ROOT + '/components/dfs/filesystems/uffs/src/inc', \
        RTT_ROOT + '/components/dfs/filesystems/uffs'] #, \
        # RTT_ROOT + '/components/dfs/filesystems/uffs/flash']

if GetDepend('RT_USING_DFS_JFFS2'):
    src_local = src_local + jffs2
    path = path + [RTT_ROOT + '/components/dfs/filesystems/jffs2/src', \
        RTT_ROOT + '/components/dfs/filesystems/jffs2/kernel', \
        RTT_ROOT + '/components/dfs/filesystems/jffs2/include', \
        RTT_ROOT + '/components/dfs/filesystems/jffs2', \
        RTT_ROOT + '/components/dfs/filesystems/jffs2/cyg/compress']

group = DefineGroup('Filesystem', src_local, depend = ['RT_USING_DFS'], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
