Makefile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # Makefile for FunKey-OS
  2. #
  3. # Copyright (C) 2020 by Michel Stempin <michel.stempin@funkey-project.com>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. #
  19. BRMAKE = buildroot/utils/brmake -C buildroot
  20. BR = make -C buildroot
  21. # Strip quotes and then whitespaces
  22. qstrip = $(strip $(subst ",,$(1)))
  23. #"))
  24. # MESSAGE Macro -- display a message in bold type
  25. MESSAGE = echo "$(shell date +%Y-%m-%dT%H:%M:%S) $(TERM_BOLD)\#\#\# $(call qstrip,$(1))$(TERM_RESET)"
  26. TERM_BOLD := $(shell tput smso 2>/dev/null)
  27. TERM_RESET := $(shell tput rmso 2>/dev/null)
  28. .PHONY: fun source image update defconfig clean distclean
  29. .IGNORE: _Makefile_
  30. all: image update
  31. @:
  32. _Makefile_:
  33. @:
  34. %/Makefile:
  35. @:
  36. buildroot: buildroot/.git
  37. @:
  38. buildroot/.git:
  39. @$(call MESSAGE,"Getting buildroot")
  40. @git submodule init
  41. @git submodule update
  42. fun: buildroot Recovery/output/.config FunKey/output/.config
  43. @$(call MESSAGE,"Making fun")
  44. @$(call MESSAGE,"Making fun in Recovery")
  45. @$(BRMAKE) BR2_EXTERNAL=../Recovery O=../Recovery/output
  46. @$(call MESSAGE,"Making fun in FunKey")
  47. @$(BRMAKE) BR2_EXTERNAL=../FunKey O=../FunKey/output
  48. sdk: buildroot SDK/output/.config
  49. @$(call MESSAGE,"Making FunKey SDK")
  50. @$(BRMAKE) BR2_EXTERNAL=../SDK O=../SDK/output prepare-sdk
  51. @$(call MESSAGE,"Generating SDK tarball")
  52. @export LC_ALL=C; \
  53. SDK=FunKey-sdk-$(shell cat FunKey/board/funkey/rootfs-overlay/etc/sw-versions | cut -f 2); \
  54. grep -lr "$(shell pwd)/SDK/output/host" SDK/output/host | while read -r FILE ; do \
  55. if file -b --mime-type "$${FILE}" | grep -q '^text/'; then \
  56. sed -i "s|$(shell pwd)/SDK/output/host|/opt/$${SDK}|g" "$${FILE}"; \
  57. fi; \
  58. done; \
  59. mkdir -p images; \
  60. tar czf "images/$${SDK}.tar.gz" \
  61. --owner=0 --group=0 --numeric-owner \
  62. --transform="s#^$(patsubst /%,%,$(shell pwd))/SDK/output/host#$${SDK}#" \
  63. -C / "$(patsubst /%,%,$(shell pwd))/SDK/output/host"; \
  64. rm -f download/toolchain-external-custom/$${SDK}.tar.gz; \
  65. mkdir -p download/toolchain-external-custom; \
  66. ln -s ../../images/$${SDK}.tar.gz download/toolchain-external-custom/
  67. FunKey/%: FunKey/output/.config
  68. @$(call MESSAGE,"Making $(notdir $@) in $(subst /,,$(dir $@))")
  69. @$(BR) BR2_EXTERNAL=../FunKey O=../FunKey/output $(notdir $@)
  70. Recovery/%: Recovery/output/.config
  71. @$(call MESSAGE,"Making $(notdir $@) in $(subst /,,$(dir $@))")
  72. @$(BR) BR2_EXTERNAL=../Recovery O=../Recovery/output $(notdir $@)
  73. SDK/%: SDK/output/.config
  74. @$(call MESSAGE,"Making $(notdir $@) in $(subst /,,$(dir $@))")
  75. @$(BR) BR2_EXTERNAL=../SDK O=../SDK/output $(notdir $@)
  76. #%: FunKey/output/.config
  77. # @$(call MESSAGE,"Making $@ in FunKey")
  78. # @$(BR) BR2_EXTERNAL=../FunKey O=../FunKey/output $@
  79. source:
  80. @$(call MESSAGE,"Getting sources")
  81. @$(BR) BR2_EXTERNAL=../SDK O=../SDK/output source
  82. @$(BR) BR2_EXTERNAL=../Recovery O=../Recovery/output source
  83. @$(BR) BR2_EXTERNAL=../FunKey O=../FunKey/output source
  84. image: fun
  85. @$(call MESSAGE,"Creating disk image")
  86. @rm -rf root tmp
  87. @mkdir -p root tmp
  88. @./Recovery/output/host/bin/genimage --loglevel 0 --inputpath .
  89. @rm -rf root tmp
  90. @mv images/sdcard.img images/FunKey-sdcard-$(shell cat FunKey/board/funkey/rootfs-overlay/etc/sw-versions | cut -f 2).img
  91. image-prod: fun
  92. @$(call MESSAGE,"Creating disk image")
  93. @rm -rf root tmp
  94. @mkdir -p root tmp
  95. @./Recovery/output/host/bin/genimage --loglevel 0 --config "genimage-prod.cfg" --inputpath .
  96. @rm -rf root tmp
  97. @mv images/sdcard-prod.img images/FunKey-sdcard-prod-$(shell cat FunKey/board/funkey/rootfs-overlay/etc/sw-versions | cut -f 2).img
  98. update: fun
  99. @$(call MESSAGE,"Creating update file")
  100. @rm -rf tmp
  101. @mkdir -p tmp
  102. @cp FunKey/board/funkey/sw-description tmp/
  103. @cp FunKey/board/funkey/update_partition tmp/
  104. @cd FunKey/output/images && \
  105. rm -f rootfs.ext2.gz && \
  106. gzip -k rootfs.ext2 &&\
  107. mv rootfs.ext2.gz ../../../tmp/
  108. @cd tmp && \
  109. echo sw-description rootfs.ext2.gz update_partition | \
  110. tr " " "\n" | \
  111. cpio -o -H crc --quiet > ../images/FunKey-rootfs-$(shell cat FunKey/board/funkey/rootfs-overlay/etc/sw-versions | cut -f 2).fwu
  112. @rm -rf tmp
  113. defconfig:
  114. @$(call MESSAGE,"Updating default configs")
  115. @$(call MESSAGE,"Updating default configs in SDK")
  116. @$(BR) BR2_EXTERNAL=../SDK O=../SDK/output savedefconfig
  117. @$(call MESSAGE,"Updating default configs in Recovery")
  118. @$(BR) BR2_EXTERNAL=../Recovery O=../Recovery/output savedefconfig linux-update-defconfig uboot-update-defconfig busybox-update-config
  119. @$(call MESSAGE,"Updating default configs in FunKey")
  120. @$(BR) BR2_EXTERNAL=../FunKey O=../FunKey/output savedefconfig linux-update-defconfig busybox-update-config
  121. clean:
  122. @$(call MESSAGE,"Clean everything")
  123. @$(BR) BR2_EXTERNAL=../SDK O=../SDK/output distclean
  124. @$(BR) BR2_EXTERNAL=../Recovery O=../Recovery/output distclean
  125. @$(BR) BR2_EXTERNAL=../FunKey O=../FunKey/output distclean
  126. @rm -f br.log
  127. distclean: clean
  128. @$(call MESSAGE,"Really clean everything")
  129. @rm -rf download images
  130. FunKey/output/.config:
  131. @$(call MESSAGE,"Configure FunKey")
  132. @mkdir -p FunKey/board/funkey/patches
  133. @$(BR) BR2_EXTERNAL=../FunKey O=../FunKey/output funkey_defconfig
  134. Recovery/output/.config:
  135. @$(call MESSAGE,"Configure Recovery")
  136. @mkdir -p Recovery/board/funkey/patches
  137. @$(BR) BR2_EXTERNAL=../Recovery O=../Recovery/output recovery_defconfig
  138. SDK/output/.config:
  139. @$(call MESSAGE,"Configure SDK")
  140. @mkdir -p SDK/board/funkey/patches
  141. @$(BR) BR2_EXTERNAL=../SDK O=../SDK/output funkey_defconfig