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 exsit
16def check_h_hpp_exsit(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]
27for root, dirs, files in os.walk(lvgl_src_cwd):
28    for dir in dirs:
29        current_path = os.path.join(root, dir)
30        src = src + Glob(os.path.join(current_path,'*.c')) # add all .c files
31        if check_h_hpp_exsit(current_path): # add .h and .hpp path
32            inc = inc + [current_path]
33
34
35if GetDepend('PKG_LVGL_USING_EXAMPLES'):
36    lvgl_src_cwd = lvgl_cwd + 'examples/'
37    inc = inc + [lvgl_src_cwd]
38    for root, dirs, files in os.walk(lvgl_src_cwd):
39        for dir in dirs:
40            current_path = os.path.join(root, dir)
41            src = src + Glob(os.path.join(current_path,'*.c'))
42            if check_h_hpp_exsit(current_path):
43                inc = inc + [current_path]
44
45if GetDepend('PKG_LVGL_USING_DEMOS'):
46    lvgl_src_cwd = lvgl_cwd + 'demos/'
47    inc = inc + [lvgl_src_cwd]
48    for root, dirs, files in os.walk(lvgl_src_cwd):
49        for dir in dirs:
50            current_path = os.path.join(root, dir)
51            src = src + Glob(os.path.join(current_path,'*.c'))
52            if check_h_hpp_exsit(current_path):
53                inc = inc + [current_path]
54
55LOCAL_CFLAGS = ''
56if rtconfig.PLATFORM == 'gcc' or rtconfig.PLATFORM == 'armclang': # GCC or Keil AC6
57    LOCAL_CFLAGS += ' -std=c99'
58elif rtconfig.PLATFORM == 'armcc': # Keil AC5
59    LOCAL_CFLAGS += ' --c99 --gnu'
60
61group = group + DefineGroup('LVGL', src, depend = ['PKG_USING_LVGL'], CPPPATH = inc, LOCAL_CFLAGS = LOCAL_CFLAGS)
62
63list = os.listdir(cwd)
64for d in list:
65    path = os.path.join(cwd, d)
66    if os.path.isfile(os.path.join(path, 'SConscript')):
67        group = group + SConscript(os.path.join(d, 'SConscript'))
68
69Return('group')
70