Amend log entry with omitted file.
[jlayton/glibc.git] / sysdeps / unix / sysv / linux / mips / Makefile
1 ifeq ($(subdir),signal)
2 #sysdep_routines += sigsuspend
3 endif
4
5 ifeq ($(subdir),misc)
6 sysdep_routines += cachectl cacheflush sysmips _test_and_set
7
8 sysdep_headers += sys/cachectl.h sys/sysmips.h sys/tas.h
9
10 no_syscall_list_h = 1
11
12 # A callable macro that expands to a shell command.  Preprocess file $(1)
13 # using ABI option $(2) and see which macros it defines.  Print FOO for each
14 # macro of the form __NR$(3)_FOO, filtering out ABI-specific __NR macros
15 # that have a prefix other than $(3).
16 mips_list_syscalls =    $(filter-out -m%,$(CC)) -E -x c $(+includes) \
17                             $(sysincludes) -D_LIBC -dM -mabi=$(2) $(1) | \
18                         sed -n 's@^\#define __NR$(3)_\([^ ]*\) .*@\1@p' | \
19                         sed -e '/^[ON]32_/d' -e '/^N64_/d' -e '/^64_/d' | \
20                         LC_ALL=C sort
21
22 # Generate a list of SYS_* macros from the linux __NR macros.
23 #
24 # Before version 2.6, linux had separate 32-bit and 64-bit MIPS ports,
25 # each with its own set of headers.  The ports were merged for 2.6 and
26 # this merged port defines the syscalls in a slightly different way.
27 # There are therefore three sets of headers that we need to consider:
28 #
29 #    (1) Headers from the separate 32-bit MIPS port.  They just define
30 #        a single list of __NR macros.
31 #
32 #    (2) Headers from the separate 64-bit MIPS port.  They unconditionally
33 #        define syscalls for all three ABIs, with o32 syscalls prefixed
34 #        by __NR_O32, n32 syscalls prefixed by __NR_N32 and n64 syscalls
35 #        prefixed by plain __NR.
36 #
37 #    (3) Headers from the combined port.  They use the _MIPS_SIM macro to
38 #        define the right set of syscalls for the current ABI.  The syscalls
39 #        themselves have no special ABI prefix, but the headers also define:
40 #
41 #           __NR_O32_Linux{,_syscalls}
42 #           __NR_N32_Linux{,_syscalls}
43 #           __NR_64_Linux{,_syscalls}
44 #
45 # In case (1) we just want a simple list of SYS_* macros.  In cases (2)
46 # and (3) we want a file that will work for all three ABIs, regardless
47 # of which ABI we are currently using.  We also want the file to work
48 # if the user later moves from (2) to (3).  Thus the file we create
49 # for (2) and (3) has the form:
50 #
51 #    #if _MIPS_SIM == _ABIN32
52 #    # ifdef __NR_N32_open
53 #    #  define SYS_n32syscall1 __NR_N32_n32syscall1
54 #    #  ...
55 #    # else
56 #    #  define SYS_n32syscall1 __NR_n32syscall1
57 #    #  ...
58 #    # endif
59 #    #elif _MIPS_SIM == _ABI64
60 #    # define SYS_n64syscall1 __NR_n64syscall1
61 #    # ...
62 #    #else
63 #    # ifdef __NR_O32_open
64 #    #  define SYS_o32syscall1 __NR_O32_o32syscall1
65 #    #  ...
66 #    # else
67 #    #  define SYS_o32syscall1 __NR_o32syscall1
68 #    #  ...
69 #    # endif
70 #    #endif
71 #
72 # Here, __NR_N32_open and __NR_O32_open are used to detect case (2)
73 # over case (3).  The n64 SYS_* macros can always use the normal
74 # ABI-less names.
75 $(objpfx)syscall-%.h $(objpfx)syscall-%.d: ../sysdeps/unix/sysv/linux/mips/sys/syscall.h
76         $(make-target-directory)
77         $(CC) -E -x c $(+includes) $(sysincludes) -D_LIBC $< -MD -MP \
78               -MF $(@:.h=.d)-t -MT '$(@:.d=.h) $(@:.h=.d)' > /dev/null
79         { \
80          echo '/* Generated at libc build time from kernel syscall list.  */';\
81          echo ''; \
82          echo '#ifndef _SYSCALL_H'; \
83          echo '# error "Never use <bits/syscall.h> directly; include <sys/syscall.h> instead."'; \
84          echo '#endif'; \
85          echo ''; \
86          echo '#include <sgidefs.h>'; \
87          rm -f $(@:.d=.h).new32 $(@:.d=.h).newn32 $(@:.d=.h).new64; \
88          $(call mips_list_syscalls,$<,n32,_N32) > $(@:.d=.h).newn32; \
89          if test -s $(@:.d=.h).newn32; then \
90            if grep open $(@:.d=.h).newn32 > /dev/null; then \
91              $(call mips_list_syscalls,$<,32,_O32) > $(@:.d=.h).new32; \
92              $(call mips_list_syscalls,$<,64,) > $(@:.d=.h).new64; \
93            else \
94              $(call mips_list_syscalls,$<,32,) > $(@:.d=.h).new32; \
95              $(call mips_list_syscalls,$<,n32,) > $(@:.d=.h).newn32; \
96              $(call mips_list_syscalls,$<,64,) > $(@:.d=.h).new64; \
97            fi; \
98            echo '#if _MIPS_SIM == _ABIN32'; \
99            echo '# ifdef __NR_N32_open'; \
100            sed 's@\(.*\)@#  define SYS_\1 __NR_N32_\1@' < $(@:.d=.h).newn32; \
101            echo '# else'; \
102            sed 's@\(.*\)@#  define SYS_\1 __NR_\1@' < $(@:.d=.h).newn32; \
103            echo '# endif'; \
104            echo '#elif _MIPS_SIM == _ABI64'; \
105            sed 's@\(.*\)@# define SYS_\1 __NR_\1@' < $(@:.d=.h).new64; \
106            echo '#else'; \
107            echo '# ifdef __NR_O32_open'; \
108            sed 's@\(.*\)@#  define SYS_\1 __NR_O32_\1@' < $(@:.d=.h).new32; \
109            echo '# else'; \
110            sed 's@\(.*\)@#  define SYS_\1 __NR_\1@' < $(@:.d=.h).new32; \
111            echo '# endif'; \
112            echo '#endif'; \
113          else \
114            $(CC) -E -x c $(+includes) $(sysincludes) -D_LIBC -dM $< | \
115            sed -n 's@^\#define __NR_\([^ ]*\) .*@\#define SYS_\1 __NR_\1@p' | \
116            LC_ALL=C sort; \
117          fi; \
118          rm -f $(@:.d=.h).new32 $(@:.d=.h).newn32 $(@:.d=.h).new64; \
119         } > $(@:.d=.h).new
120         mv -f $(@:.d=.h).new $(@:.d=.h)
121 ifneq (,$(objpfx))
122         sed $(sed-remove-objpfx) $(@:.h=.d)-t > $(@:.h=.d)-t2
123         rm -f $(@:.h=.d)-t
124         mv -f $(@:.h=.d)-t2 $(@:.h=.d)
125 else
126         mv -f $(@:.h=.d)-t $(@:.h=.d)
127 endif
128 endif