Makefile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. DOWNLOADER ?= curl
  2. PLATFORM ?= linux
  3. BINOUT := bin
  4. STDLIB := stdlib
  5. QBE_SRC := https://c9x.me/compile
  6. HARE_SRC := https://git.sr.ht/~sircmpwn/hare
  7. HAREC_SRC := https://git.sr.ht/~sircmpwn/harec
  8. QBE_VERSION := 1.2
  9. HARE_VERSION := 0.24.2
  10. HAREC_VERSION := 0.24.2
  11. .PHONY: all
  12. all: ${BINOUT}/hare ${BINOUT}/harec ${BINOUT}/qbe
  13. # download function should downlad file ${1} from url ${2}
  14. ifeq (${DOWNLOADER},curl)
  15. download = curl -Lo '${1}' -- '${2}'
  16. else # if curl
  17. ifeq (${DOWNLOADER},wget)
  18. download = wget -O '${1}' -- '${2}'
  19. endif # if wget
  20. endif # if curl
  21. sh_pwd = "$${PWD:-$$(pwd)}/${1}"
  22. # $1 - archive
  23. # $2 - url
  24. # $3 - name
  25. # $4 - out bin
  26. # $5 - cmd
  27. define dl_install
  28. set -x \
  29. && tmp="$$(mktemp -d)" \
  30. && { bin="$$( : \
  31. && set -ue \
  32. && cd "$${tmp}" \
  33. && $(call download,${1},${2}) \
  34. && tar xf ${1} \
  35. && cd ${3}-*/ \
  36. && `# temporary fix:` \
  37. && ( [ ! -f scripts/version ] || sed 's/\(VERSION:\)\([^-]\)/\1-\2/' -i scripts/version; ) \
  38. && { ${5}; } 1>&2 \
  39. && echo $(call sh_pwd,${4}) \
  40. )" \
  41. && install -Dm755 "$${bin}" ${@} \
  42. ; } \
  43. && rm -rf "$${tmp}" # if failed tmdir will remain
  44. endef
  45. .MAKE_DIR := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
  46. .HARE_COMPILE := : \
  47. && dst='${.MAKE_DIR}' \
  48. && ln -s configs/${PLATFORM}.mk config.mk \
  49. && make LDFLAGS='-O3 -static -Wl,-s' \
  50. QBE='${.MAKE_DIR}/${BINOUT}/qbe' \
  51. HAREC='${.MAKE_DIR}/${BINOUT}/harec' \
  52. .bin/hare \
  53. && make DESTDIR="$${dst}/" STDLIB='${STDLIB}' install-mods
  54. ${BINOUT}/hare: ${BINOUT}/harec ${BINOUT}/qbe
  55. $(call dl_install,hare.tar.gz,${HARE_SRC}/archive/${HARE_VERSION}.tar.gz,\
  56. hare,.bin/hare,${.HARE_COMPILE})
  57. .QBE_COMPILE := make LDFLAGS='-O3 -static -Wl,-s'
  58. ${BINOUT}/qbe:
  59. $(call dl_install,qbe.tar.xz,${QBE_SRC}/release/qbe-${QBE_VERSION}.tar.xz,\
  60. qbe,qbe,${.QBE_COMPILE})
  61. .HAREC_COMPILE := : \
  62. && ln -s configs/${PLATFORM}.mk config.mk \
  63. && make LDFLAGS='-O3 -static -Wl,-s'
  64. ${BINOUT}/harec:
  65. $(call dl_install,harec.tar.gz,${HAREC_SRC}/archive/${HAREC_VERSION}.tar.gz,\
  66. harec,.bin/harec,${.HAREC_COMPILE})