1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# -*- mode: python -*-
#
# Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
def make_toolchain(filename, arch, sdk_prefix, sdk):
with open(filename, 'w') as f:
flags = "-arch %s" % arch
print("set(CMAKE_SYSTEM_NAME Darwin)", file=f)
print("set(CMAKE_SYSTEM_PROCESSOR %s)" % arch, file=f)
print("set(CMAKE_C_COMPILER gcc)", file=f)
print("set(CMAKE_CXX_COMPILER g++)", file=f)
print("set(AS as)", file=f)
print("set(AR as)", file=f)
print("set(OBJCOPY objcopy)", file=f)
print("set(OBJDUMP objdump)", file=f)
print("set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})", file=f)
print("set(CMAKE_OSX_SYSROOT %s/MacOSX%s.sdk)" % (sdk_prefix, sdk), file=f)
print('set(CMAKE_C_FLAGS "-std=gnu99 -fdata-sections -ffunction-sections %s" CACHE INTERNAL "c compiler flags")' % flags, file=f)
print('set(CMAKE_CXX_FLAGS "-fdata-sections -ffunction-sections %s" CACHE INTERNAL "cxx compiler flags")' % flags, file=f)
print('set(CMAKE_ASM_FLAGS "" CACHE INTERNAL "asm compiler flags")', file=f)
print('set(CMAKE_EXE_LINKER_FLAGS "-dead_strip" CACHE INTERNAL "exe link flags")', file=f)
print('SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags")', file=f)
print('SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags")', file=f)
print('SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags")', file=f)
print('SET(CMAKE_C_FLAGS_RELEASE "-O2 -g -ggdb3" CACHE INTERNAL "c release compiler flags")', file=f)
print('SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -ggdb3" CACHE INTERNAL "cxx release compiler flags")', file=f)
print('SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")', file=f)
print('SET(CMAKE_SKIP_RPATH YES)', file=f)
def build(target, options):
if target.platform == 'linux':
type = 'generic'
build_suffix = type
blockdev = 'linux'
ext = 'a'
device = 'dev'
elif target.platform == 'osx':
if target.arch == 'x86_64':
type = 'osx'
elif target.arch == 'arm64':
type = 'osx-arm64'
build_suffix = 'osx'
make_toolchain('toolchain/%s.cmake' % type, target.arch, target.sdk_prefix, target.sdk)
blockdev = 'linux'
ext = 'dylib'
device = 'dev'
elif target.platform == 'windows':
type = 'mingw' if target.bits == 64 else 'mingw-32'
build_suffix = type
blockdev = 'windows'
ext = 'dll'
device = 'windows'
target.command('mkdir -p %s/include/lwext4' % target.directory)
target.command('cp -r include/* %s/include/lwext4' % target.directory)
target.command('make %s' % type)
target.command('make -j%d -C build_%s' % (target.parallel, build_suffix))
target.command('cp -r build_%s/include/generated %s/include/lwext4' % (build_suffix, target.directory))
target.command('cp blockdev/%s/file_%s.h %s/include/lwext4' % (blockdev, device, target.directory))
target.command('mkdir -p %s/lib' % target.directory)
target.command('cp build_%s/src/liblwext4.%s %s/lib' % (build_suffix, ext, target.directory))
target.command('cp build_%s/blockdev/libblockdev.%s %s/lib' % (build_suffix, ext, target.directory))
|