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#
35machine_dirs = {
36		 'a29k': 'a29k',
37		 'aarch64': 'aarch64',
38		 'arc': 'arc',
39		 'arm': 'arm',
40		 'bfin': 'bfin',
41		 'cr16': 'cr16',
42		 'cris': 'cris',
43		 'crisv32': 'cris',
44		 'crx': 'crx',
45		 'd10v': 'd10v',
46		 'd30v': 'd30v',
47		 'epiphany': 'epiphany',
48		 'fido': 'm68k',
49		 'fr30': 'fr30',
50		 'frv': 'frv',
51		 'ft32': 'ft32',
52		 'h8300': 'h8300',
53		 'h8500': 'h8500',
54		 'hppa': 'hppa',
55		 'i960': 'i960',
56		 'i386': 'i386',
57		 'i486': 'i386',
58		 'i586': 'i386',
59		 'i686': 'i386',
60		 'iq2000': 'iq2000',
61		 'lm32': 'lm32',
62		 'm32c': 'm32c',
63		 'm32r': 'm32r',
64		 'm6811': 'm68hc11',
65		 'm6812': 'm68hc11',
66		 'm68hc11': 'm68hc11',
67		 'm68hc12': 'm68hc11',
68		 'm68k': 'm68k',
69		 'm88k': 'm88k',
70		 'm88110': 'm88k',
71		 'microblaze': 'microblaze',
72		 'mep': 'mep',
73		 'mips': 'mips',
74		 'mn10200': 'mn10200',
75		 'mn10300': 'mn10300',
76		 'moxie': 'moxie',
77		 'msp430': 'msp430',
78		 'mt': 'mt',
79		 'nds32': 'nds32',
80		 'nios2': 'nios2',
81		 'nvptx': 'nvptx',
82		 'or1k': 'or1k',
83		 'or1knd': 'or1k',
84		 'powerpc': 'powerpc',
85		 'riscv': 'riscv',
86		 'riscv64': 'riscv',
87		 'rl78': 'rl78',
88		 'rx': 'rx',
89		 'sh': 'sh',
90		 'sh64': 'sh',
91		 'sparc': 'sparc',
92		 'c4x': 'tic4x',
93		 'tic4x': 'tic4x',
94		 'tic6x': 'tic6x',
95		 'tic80': 'tic80',
96		 'v850': 'v850',
97		 'visium': 'visium',
98		 'w65': 'w65',
99		 'x86_64': 'x86_64',
100		 'xc16x': 'xc16x',
101		 'xstormy16': 'xstormy16',
102		 'xtensa': 'xtensa',
103		 'z8k': 'z8k',
104		 'spu': 'spu',
105	       }
106
107libdirs = ['argz', 'ctype', 'errno', 'iconv', 'misc', 'search',
108	   'signal', 'ssp', 'stdlib', 'string', 'time',
109	   'xdr', 'locale']
110
111if enable_picolib
112  libdirs += 'picolib'
113endif
114
115if newlib_tinystdio
116  libdirs += 'tinystdio'
117else
118  libdirs += ['stdio', 'reent']
119endif
120
121if newlib_supplied_syscalls
122  libdirs += 'syscalls'
123endif
124
125libnames = libdirs
126
127need_generic_fenv_h = true
128
129if machine_dirs.has_key(host_cpu)
130  machine_dir = join_paths('machine', machine_dirs[host_cpu])
131  fenv_file_check = join_paths(machine_dir, 'sys', 'fenv.h')
132  if run_command('test', '-f', fenv_file_check).returncode() == 0
133    need_generic_fenv_h = false
134  else
135    need_generic_fenv_h = true
136  endif
137
138  machine_inc_dir = join_paths(machine_dir, 'include')
139
140  if run_command('test', '-d', machine_inc_dir).returncode() == 0
141    inc = [include_directories(machine_inc_dir), inc]
142  endif
143
144  inc = [include_directories(machine_dir), inc]
145
146  libdirs = [machine_dir] + libdirs
147  libnames = ['machine'] + libnames
148else
149  warning('No libc machine directory for cpu ' + host_cpu)
150  need_generic_fenv_h = true
151endif
152
153foreach libdir : libdirs
154  subdir(libdir)
155endforeach
156
157subdir('include')
158
159foreach target : targets
160  value = get_variable('target_' + target)
161  libobjs = []
162
163  foreach libname : libnames
164    libobjs += get_variable('lib_' + libname + target).extract_all_objects(recursive:true)
165  endforeach
166
167  instdir = join_paths(get_option('libdir'), value[0])
168
169  if target == ''
170    libc_name = 'c'
171  else
172    libc_name = join_paths(target, 'libc')
173  endif
174
175  set_variable('lib_c' + target,
176	       static_library(libc_name,
177			      install : true,
178			      install_dir : instdir,
179			      pic: false,
180			      objects : libobjs))
181endforeach
182
183