Makefile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 := ctype.h errno.h nolibc.h signal.h std.h stdio.h stdlib.h string.h \
  24. sys.h time.h types.h unistd.h
  25. # install all headers needed to support a bare-metal compiler
  26. all: headers
  27. install: help
  28. help:
  29. @echo "Supported targets under nolibc:"
  30. @echo " all call \"headers\""
  31. @echo " clean clean the sysroot"
  32. @echo " headers prepare a sysroot in tools/include/nolibc/sysroot"
  33. @echo " headers_standalone like \"headers\", and also install kernel headers"
  34. @echo " help this help"
  35. @echo ""
  36. @echo "These targets may also be called from tools as \"make nolibc_<target>\"."
  37. @echo ""
  38. @echo "Currently using the following variables:"
  39. @echo " ARCH = $(ARCH)"
  40. @echo " OUTPUT = $(OUTPUT)"
  41. @echo ""
  42. # Note: when ARCH is "x86" we concatenate both x86_64 and i386
  43. headers:
  44. $(Q)mkdir -p $(OUTPUT)sysroot
  45. $(Q)mkdir -p $(OUTPUT)sysroot/include
  46. $(Q)cp $(all_files) $(OUTPUT)sysroot/include/
  47. $(Q)if [ "$(ARCH)" = "x86" ]; then \
  48. sed -e \
  49. 's,^#ifndef _NOLIBC_ARCH_X86_64_H,#if !defined(_NOLIBC_ARCH_X86_64_H) \&\& defined(__x86_64__),' \
  50. arch-x86_64.h; \
  51. sed -e \
  52. 's,^#ifndef _NOLIBC_ARCH_I386_H,#if !defined(_NOLIBC_ARCH_I386_H) \&\& !defined(__x86_64__),' \
  53. arch-i386.h; \
  54. elif [ -e "$(arch_file)" ]; then \
  55. cat $(arch_file); \
  56. else \
  57. echo "Fatal: architecture $(ARCH) not yet supported by nolibc." >&2; \
  58. exit 1; \
  59. fi > $(OUTPUT)sysroot/include/arch.h
  60. headers_standalone: headers
  61. $(Q)$(MAKE) -C $(srctree) headers
  62. $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot
  63. clean:
  64. $(call QUIET_CLEAN, nolibc) rm -rf "$(OUTPUT)sysroot"