1#
2# SPDX-License-Identifier: BSD-3-Clause
3#
4# Copyright © 2019 Keith Packard
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12#
13# 2. Redistributions in binary form must reproduce the above
14#    copyright notice, this list of conditions and the following
15#    disclaimer in the documentation and/or other materials provided
16#    with the distribution.
17#
18# 3. Neither the name of the copyright holder nor the names of its
19#    contributors may be used to endorse or promote products derived
20#    from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33# OF THE POSSIBILITY OF SUCH DAMAGE.
34#
35
36has_arm_semihost = false
37
38src_semihost = []
39
40machine_dir = 'machine' / host_cpu_family
41if fs.is_dir(machine_dir)
42  subdir(machine_dir)
43endif
44
45# If host_cpu_family supports ARM-style semihosting, the meson.build
46# will add the support files to src_semihost.  Check to see if that
47# happened and add the rest of the needed files
48
49if src_semihost != []
50  src_semihost += files([
51    'close.c',
52    'exit.c',
53    'fstat.c',
54    'getentropy.c',
55    'gettimeofday.c',
56    'isatty.c',
57    'kill.c',
58    'lseek.c',
59    'lseek64.c',
60    'open.c',
61    'read.c',
62    'sysconf.c',
63    'times.c',
64    'unlink.c',
65    'write.c',
66    'sys_clock.c',
67    'sys_close.c',
68    'sys_elapsed.c',
69    'sys_errno.c',
70    'sys_exit.c',
71    'sys_exit_extended.c',
72    'sys_feature.c',
73    'sys_flen.c',
74    'sys_get_cmdline.c',
75    'sys_getc.c',
76    'sys_heapinfo.c',
77    'sys_iserror.c',
78    'sys_istty.c',
79    'sys_open.c',
80    'sys_putc.c',
81    'sys_read.c',
82    'sys_remove.c',
83    'sys_rename.c',
84    'sys_seek.c',
85    'sys_system.c',
86    'sys_tickfreq.c',
87    'sys_time.c',
88    'sys_tmpnam.c',
89    'sys_write.c',
90    'sys_write0.c',
91  ])
92
93  if tinystdio
94    src_semihost += 'iob.c'
95  else
96    src_semihost += 'mapstdio.c'
97  endif
98
99  install_headers('semihost.h',
100		  install_dir: include_dir
101		 )
102
103  inc = [inc, include_directories('.')]
104
105  has_semihost = true
106
107  has_arm_semihost = true
108
109  foreach target : targets
110    value = get_variable('target_' + target)
111
112    instdir = join_paths(lib_dir, value[0])
113
114    if target == ''
115      libsemihost_name = 'semihost'
116    else
117      libsemihost_name = join_paths(target, 'libsemihost')
118    endif
119
120    set_variable('lib_semihost' + target,
121		 static_library(libsemihost_name,
122				src_semihost,
123				install : true,
124				install_dir : instdir,
125				include_directories : inc,
126				c_args : value[1]))
127
128  endforeach
129endif
130
131if not has_semihost and get_option('fake-semihost')
132  subdir('fake')
133endif
134