Makefile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # Copyright (C) 1991-2026 Free Software Foundation, Inc.
  2. # This file is part of the GNU C Library.
  3. # The GNU C Library is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU Lesser General Public
  5. # License as published by the Free Software Foundation; either
  6. # version 2.1 of the License, or (at your option) any later version.
  7. # The GNU C Library is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. # Lesser General Public License for more details.
  11. # You should have received a copy of the GNU Lesser General Public
  12. # License along with the GNU C Library; if not, see
  13. # <https://www.gnu.org/licenses/>.
  14. subdir := mach
  15. include ../Makeconfig
  16. headers = mach_init.h mach.h mach_error.h mach-shortcuts.h mach/mach_traps.h \
  17. $(interface-headers) mach/mach.h mach/mig_support.h mach/error.h \
  18. $(lock-headers) machine-sp.h bits/mach/param.h
  19. lock = spin-solid spin-lock mutex-init
  20. lock-headers = lock-intern.h spin-lock.h
  21. routines = $(mach-syscalls) $(mach-shortcuts) \
  22. mach_init mig_strncpy mig_strlen mig_memcpy msg \
  23. mig-alloc mig-dealloc mig-reply \
  24. msg-destroy msgserver \
  25. mach_error errstring error_compat errsystems \
  26. devstream setup-thread $(lock)
  27. # The RPC interfaces go in a separate library.
  28. interface-library := libmachuser
  29. # We produce mach_interface.h from mach.defs because there is already a
  30. # <mach/mach.h> that is not the interface header (thanks CMU).
  31. mach-interface-list := $(patsubst mach,mach_interface,$(mach-interface-list))
  32. mach/mach_interface.defs = mach/mach.defs
  33. # Similarly for memory_object_user vs. memory_object
  34. mach-interface-list := $(patsubst memory_object,memory_object_user,\
  35. $(mach-interface-list))
  36. mach/memory_object_user.defs = mach/memory_object.defs
  37. user-interfaces := $(addprefix mach/,$(mach-interface-list) \
  38. mach_port mach_host exc \
  39. )\
  40. $(addprefix device/,device device_request)
  41. server-interfaces := mach/exc
  42. # Clear any environment value.
  43. generated =
  44. # Avoid ssp before TLS is initialized.
  45. CFLAGS-mach_init.o = $(no-stack-protector)
  46. CFLAGS-RPC_vm_statistics.o = $(no-stack-protector)
  47. CFLAGS-RPC_vm_map.o = $(no-stack-protector)
  48. CFLAGS-RPC_vm_protect.o = $(no-stack-protector)
  49. CFLAGS-RPC_i386_set_gdt.o = $(no-stack-protector)
  50. CFLAGS-RPC_i386_set_ldt.o = $(no-stack-protector)
  51. CFLAGS-RPC_task_get_special_port.o = $(no-stack-protector)
  52. CFLAGS-RPC_thread_set_state.o = $(no-stack-protector)
  53. # Translate GNU names for CPUs into the names used in Mach header files.
  54. mach-machine = $(patsubst powerpc,ppc,$(base-machine))
  55. # Define mach-syscalls and sysno-*.
  56. ifndef inhibit_mach_syscalls
  57. -include $(objpfx)mach-syscalls.mk
  58. endif
  59. $(objpfx)mach-syscalls.mk: syscalls.awk Makefile libc-modules.h
  60. # Go kludges!!!
  61. $(make-target-directory)
  62. # We must use $(CFLAGS) to get -O flags that affect #if's in header files.
  63. echo '#include <mach/syscall_sw.h>' | \
  64. $(CC) $(CFLAGS) $(CPPFLAGS) -E -MD -MP -MF $@-dep -MT $@ \
  65. -x c-header - \
  66. -D_MACH_`echo $(mach-machine) | tr a-z A-Z`_SYSCALL_SW_H_=1 | \
  67. sed -n -e 's/^kernel_trap(\(.*\),\([-0-9]*\),\([0-9]*\))$$/\1 \2 \3/p'\
  68. | $(AWK) -f $< > $@-new
  69. ifneq (,$(objpfx))
  70. sed $(sed-remove-objpfx) $@-dep >> $@-new
  71. else
  72. cat $@-dep >> $@-new
  73. endif
  74. rm -f $@-dep
  75. mv -f $@-new $@
  76. generated += mach-syscalls.mk
  77. ifndef mach-syscalls
  78. # We cannot make the deps properly until we know how to make the system
  79. # call functions, and for that we must know what they all are.
  80. no_deps=t
  81. else
  82. $(mach-syscalls:%=$(objpfx)%.S): $(objpfx)%.S: $(objpfx)mach-syscalls.mk
  83. (echo '#include <sysdep.h>'; \
  84. echo 'kernel_trap (__$*,$(sysno-$*),$(nargs-$*))'; \
  85. echo 'weak_alias (__$*, $*)'; \
  86. echo 'libc_hidden_def (__$*)') > $@-new
  87. mv -f $@-new $@
  88. generated += $(mach-syscalls:=.S)
  89. endif # mach-syscalls
  90. # These syscalls that look like RPCs actually have no RPC equivalents.
  91. mach-shortcuts := $(filter-out device_writev_request \
  92. device_read_overwrite_request \
  93. device_read_overwrite \
  94. vm_read_overwrite \
  95. thread_switch \
  96. ,\
  97. $(patsubst syscall_%,%,$(filter syscall_%,$(mach-syscalls))))
  98. ifndef mach-shortcuts
  99. # Forget about mach_interface.defs for this run. On the next run,
  100. # $(mach-shortcuts) will be set, and that will change how
  101. # mach_interface.defs is processed: it will get the -D flags below.
  102. user-interfaces := $(filter-out $(mach-interface-list:%=mach/%) \
  103. mach/mach_port mach/mach_host mach/mach4 mach/gnumach \
  104. device/device_request,\
  105. $(user-interfaces))
  106. endif
  107. # For some reason, the calls in this file are `protected' by an ifdef.
  108. MIGFLAGS-mach/mach4 = -DMACH_PCSAMPLE
  109. MIGFLAGS-device/device = -DDEVICE_ENABLE_DEVICE_OPEN_NEW
  110. # Make the MiG stubs for $(mach-shortcuts) be CALL_rpc.
  111. migdefines += $(foreach call,$(mach-shortcuts),-D$(call)=$(call)_rpc)
  112. $(mach-interface-list:%=mach/%.uh) \
  113. mach/mach_host.uh mach/mach_port.uh: $(objpfx)mach-syscalls.mk
  114. ifdef mach-shortcuts
  115. $(mach-shortcuts:%=$(objpfx)%.c): $(objpfx)%.c: shortcut.awk \
  116. $(objpfx)RPC_%_rpc.c
  117. $(AWK) -v alias=$* -v call=__$* -v rpc=__$*_rpc \
  118. -v syscall=__syscall_$* -f $^ > $@-new
  119. mv -f $@-new $@
  120. generated += $(mach-shortcuts:%=%.c)
  121. endif # mach-shortcuts
  122. # Generate mach-shortcuts.h, which will contain the prototypes for the
  123. # shortcutted kernel RPC functions.
  124. $(objpfx)mach-shortcuts.h: $(mach-interface-list:%=$(objpfx)mach/%.h) \
  125. $(objpfx)mach/mach_host.h \
  126. $(objpfx)mach/mach_port.h
  127. # The first line gets us one paragraph per line, with @s separating real lines.
  128. # The second line selects paragraphs for the shortcutted functions.
  129. # The third line removes `_rpc' from the names and reconstitutes the lines.
  130. ( echo "#include <mach/mach_types.h>" ; \
  131. echo "#include <mach/message.h>" ; \
  132. echo ; \
  133. cat $^ | tr \\012 @ | sed s/@@/@%/g | tr % \\012 \
  134. | grep '^/\* Routine [a-z0-9_]*_rpc \*/' \
  135. | sed 's/_rpc//g' | tr @ \\012 ) > $@-new
  136. mv -f $@-new $@
  137. generated += mach-shortcuts.h
  138. before-compile += $(objpfx)mach-shortcuts.h
  139. include Machrules
  140. include ../Rules
  141. # A gcc bug prevents the generated file from working properly,
  142. # so we have one in the distribution for the time being.
  143. generated += errsystems.c
  144. $(objpfx)errsystems.c: errsystems.awk err_*.sub \
  145. $(wildcard $(addsuffix /err_*.sub,$(+sysdep_dirs)))
  146. $(AWK) -v subsys='$(filter-out $<,$^)' -f $^ > $@.n
  147. mv -f $@.n $@
  148. # Convenient target to update all the generated source files.
  149. .PHONY: generated
  150. generated: $(addprefix $(common-objpfx),$(common-generated)) \
  151. $(addprefix $(objpfx),$(generated))
  152. .PHONY: mach-before-compile
  153. mach-before-compile: $(mach-before-compile)