Makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Makefile for nolibc installation and tests
  3. include ../../scripts/Makefile.include
  4. # we're in ".../tools/include/nolibc"
  5. ifeq ($(srctree),)
  6. srctree := $(patsubst %/tools/include/,%,$(dir $(CURDIR)))
  7. endif
  8. # when run as make -C tools/ nolibc_<foo> the arch is not set
  9. ifeq ($(ARCH),)
  10. include $(srctree)/scripts/subarch.include
  11. ARCH = $(SUBARCH)
  12. endif
  13. # OUTPUT is only set when run from the main makefile, otherwise
  14. # it defaults to this nolibc directory.
  15. OUTPUT ?= $(CURDIR)/
  16. ifeq ($(V),1)
  17. Q=
  18. else
  19. Q=@
  20. endif
  21. nolibc_arch := $(patsubst arm64,aarch64,$(ARCH))
  22. arch_file := arch-$(nolibc_arch).h
  23. all_files := \
  24. compiler.h \
  25. crt.h \
  26. ctype.h \
  27. errno.h \
  28. nolibc.h \
  29. signal.h \
  30. stackprotector.h \
  31. std.h \
  32. stdarg.h \
  33. stdbool.h \
  34. stdint.h \
  35. stdlib.h \
  36. string.h \
  37. sys.h \
  38. time.h \
  39. types.h \
  40. unistd.h \
  41. stdio.h \
  42. # install all headers needed to support a bare-metal compiler
  43. all: headers
  44. install: help
  45. help:
  46. @echo "Supported targets under nolibc:"
  47. @echo " all call \"headers\""
  48. @echo " clean clean the sysroot"
  49. @echo " headers prepare a sysroot in tools/include/nolibc/sysroot"
  50. @echo " headers_standalone like \"headers\", and also install kernel headers"
  51. @echo " help this help"
  52. @echo ""
  53. @echo "These targets may also be called from tools as \"make nolibc_<target>\"."
  54. @echo ""
  55. @echo "Currently using the following variables:"
  56. @echo " ARCH = $(ARCH)"
  57. @echo " OUTPUT = $(OUTPUT)"
  58. @echo ""
  59. # Note: when ARCH is "x86" we concatenate both x86_64 and i386
  60. headers:
  61. $(Q)mkdir -p $(OUTPUT)sysroot
  62. $(Q)mkdir -p $(OUTPUT)sysroot/include
  63. $(Q)cp $(all_files) $(OUTPUT)sysroot/include/
  64. $(Q)if [ "$(ARCH)" = "x86" ]; then \
  65. sed -e \
  66. 's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
  67. arch-x86_64.h; \
  68. sed -e \
  69. 's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \
  70. arch-i386.h; \
  71. elif [ -e "$(arch_file)" ]; then \
  72. cat $(arch_file); \
  73. else \
  74. echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
  75. exit 1; \
  76. fi > $(OUTPUT)sysroot/include/arch.h
  77. headers_standalone: headers
  78. $(Q)$(MAKE) -C $(srctree) headers
  79. $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
  80. clean:
  81. $(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"