1from building import *
2import rtconfig
3import os
4
5src = []
6inc = []
7group = []
8
9cwd = GetCurrentDir() # get current dir path
10
11port_src = Glob('*.c')
12port_inc = [cwd]
13group = group + DefineGroup('LVGL-port', port_src, depend = ['PKG_USING_LVGL'], CPPPATH = port_inc)
14
15# check if .h or .hpp files exists
16def check_h_hpp_exists(path):
17    file_dirs = os.listdir(path)
18    for file_dir in file_dirs:
19        if os.path.splitext(file_dir)[1] in ['.h', '.hpp']:
20            return True
21    return False
22
23lvgl_cwd = cwd + '/../../'
24
25lvgl_src_cwd = lvgl_cwd + 'src/'
26inc = inc + [lvgl_src_cwd]
27src = src + Glob(os.path.join(lvgl_src_cwd,'*.c'))
28for root, dirs, files in os.walk(lvgl_src_cwd):
29    for dir in dirs:
30        current_path = os.path.join(root, dir)
31        if current_path == os.path.join(lvgl_src_cwd, 'libs', 'thorvg', 'rapidjson', 'msinttypes'): # exclude the msinttypes folder
32            continue
33        src = src + Glob(os.path.join(current_path,'*.c')) # add all .c files
34        if check_h_hpp_exists(current_path): # add .h and .hpp path
35            inc = inc + [current_path]
36
37
38if GetDepend('PKG_LVGL_USING_EXAMPLES'):
39    lvgl_src_cwd = lvgl_cwd + 'examples/'
40    inc = inc + [lvgl_src_cwd]
41    for root, dirs, files in os.walk(lvgl_src_cwd):
42        for dir in dirs:
43            current_path = os.path.join(root, dir)
44            src = src + Glob(os.path.join(current_path,'*.c'))
45            if check_h_hpp_exists(current_path):
46                inc = inc + [current_path]
47
48if GetDepend('PKG_LVGL_USING_DEMOS'):
49    lvgl_src_cwd = lvgl_cwd + 'demos/'
50    inc = inc + [lvgl_src_cwd]
51    for root, dirs, files in os.walk(lvgl_src_cwd):
52        for dir in dirs:
53            current_path = os.path.join(root, dir)
54            src = src + Glob(os.path.join(current_path,'*.c'))
55            if check_h_hpp_exists(current_path):
56                inc = inc + [current_path]
57
58LOCAL_CFLAGS = ''
59if rtconfig.PLATFORM == 'gcc' or rtconfig.PLATFORM == 'armclang': # GCC or Keil AC6
60    LOCAL_CFLAGS += ' -std=c99'
61elif rtconfig.PLATFORM == 'armcc': # Keil AC5
62    LOCAL_CFLAGS += ' --c99 --gnu'
63
64group = group + DefineGroup('LVGL', src, depend = ['PKG_USING_LVGL'], CPPPATH = inc, LOCAL_CFLAGS = LOCAL_CFLAGS)
65
66list = os.listdir(cwd)
67for d in list:
68    path = os.path.join(cwd, d)
69    if os.path.isfile(os.path.join(path, 'SConscript')):
70        group = group + SConscript(os.path.join(d, 'SConscript'))
71
72Return('group')
73