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
36libdirs = ['math', 'common', 'fenv', 'ld']
37
38if have_complex
39  libdirs = libdirs + ['complex']
40endif
41
42libnames = libdirs
43
44libm_machine_dir = 'machine' / host_cpu_family
45if fs.is_dir(libm_machine_dir)
46  libdirs = [libm_machine_dir] + libdirs
47  libnames = ['machine'] + libnames
48else
49  srcs_libm_machine = []
50endif
51
52inc = [include_directories('common'), inc]
53
54foreach libdir : libdirs
55  subdir(libdir)
56endforeach
57
58src_mpart = []
59
60foreach libname : libnames
61  src_mpart += get_variable('src_libm_' + libname, [])
62endforeach
63
64foreach target : targets
65  value = get_variable('target_' + target)
66  libobjs = []
67  libsrcs_target = []
68
69  foreach libname : libnames
70    if is_variable('lib_' + libname + target)
71      libobjs += get_variable('lib_' + libname + target).extract_all_objects(recursive:true)
72    endif
73    libsrcs_target += get_variable('src_libm_' + libname + target, [])
74  endforeach
75
76  set_variable('src_mpart_' + target, libsrcs_target)
77
78  if target == ''
79    libmpart_name = 'mpart'
80  else
81    libmpart_name = 'mpart' + '_' + target
82  endif
83
84  if libobjs != []
85    local_lib_mpart_target = static_library(libmpart_name,
86					    pic: false,
87					    objects : libobjs,
88					    include_directories: inc,
89					    c_args: value[1] + c_args)
90    set_variable('lib_mpart' + target, local_lib_mpart_target)
91  endif
92endforeach
93
94