host.mk 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #
  2. # Copyright (C) 2007-2015 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. TMP_DIR ?= $(TOPDIR)/tmp
  8. ifeq ($(if $(TARGET_BUILD),,$(DUMP)),)
  9. -include $(TMP_DIR)/.host.mk
  10. endif
  11. ifneq ($(__host_inc),1)
  12. __host_inc:=1
  13. try-run = $(shell set -e; \
  14. TMP_F="$(TMP_DIR)/try-run.$$$$.tmp"; \
  15. if ($(1)) >/dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi; \
  16. rm -f "$$TMP_F"; \
  17. )
  18. host-cc-option = $(call try-run, \
  19. $(HOSTCC) $(HOST_CFLAGS) $(1) -c -xc /dev/null -o "$$TMP_F",$(1),$(2) \
  20. )
  21. .PRECIOUS: $(TMP_DIR)/.host.mk
  22. $(TMP_DIR)/.host.mk: $(TOPDIR)/include/host.mk
  23. @mkdir -p $(TMP_DIR)
  24. @( \
  25. HOST_OS=`uname`; \
  26. case "$$HOST_OS" in \
  27. Linux) HOST_ARCH=`uname -m`;; \
  28. Darwin) HOST_ARCH=`uname -m`;; \
  29. *) HOST_ARCH=`uname -p`;; \
  30. esac; \
  31. GNU_HOST_NAME=`gcc -dumpmachine`; \
  32. [ -z "$$GNU_HOST_NAME" -o "$$HOST_OS" = "Darwin" ] && \
  33. GNU_HOST_NAME=`$(TOPDIR)/scripts/config.guess`; \
  34. echo "HOST_OS:=$$HOST_OS" > $@; \
  35. echo "HOST_ARCH:=$$HOST_ARCH" >> $@; \
  36. echo "GNU_HOST_NAME:=$$GNU_HOST_NAME" >> $@; \
  37. if gfind -L /dev/null || find -L /dev/null; then \
  38. echo "FIND_L=find -L \$$(1)" >> $@; \
  39. else \
  40. echo "FIND_L=find \$$(1) -follow" >> $@; \
  41. fi \
  42. ) >/dev/null 2>/dev/null
  43. endif