Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. ifeq ($(VERSION), 1)
  2. filename_archlinux_arm = ArchLinuxARM-rpi-latest.tar.gz
  3. endif
  4. ifeq ($(VERSION), 2)
  5. filename_archlinux_arm = ArchLinuxARM-rpi-2-latest.tar.gz
  6. endif
  7. ifeq ($(VERSION), 3)
  8. filename_archlinux_arm = ArchLinuxARM-rpi-3-latest.tar.gz
  9. endif
  10. .DELETE_ON_ERROR:
  11. .EXPORT_ALL_VARIABLES:
  12. .PHONY: all backup restore erase partition filesystems mount unpack-custom install chroot-setup chroot-teardown chroot package unpack umount fsck clean checkargs checkargs-version checkargs-path update-config-txt help
  13. all: mount install clean package umount ## Install VideoPi for RPi version VERSION to device DEVICE and then create a disk image.
  14. backup: checkargs ## Create an image of the whole DEVICE and store it to backup/.
  15. -mkdir -p backup
  16. dd if=$(DEVICE) bs=1024 conv=noerror,sync | pv | gzip -c -9 > "backup/video-pi-backup-`date +%Y%m%d-%H%M%S`.img.gz"
  17. restore: checkargs checkargs-path ## Install an image PATH of the whole device to DEVICE.
  18. -gunzip -c $(PATH) | dd of=$(DEVICE) bs=4M status=progress
  19. sync
  20. erase: checkargs ## Overwrite the whole DEVICE with zeros.
  21. # pv --timer --rate --stop-at-size -s "$$(blockdev --getsize64 $(DEVICE))" /dev/zero > $(DEVICE)
  22. dd if=/dev/zero of="$(DEVICE)" iflag=nocache oflag=direct bs=4096
  23. partition: checkargs
  24. sh -c "sfdisk $(DEVICE) < disk.dump"
  25. filesystems: checkargs partition ## Create partitions and filesystems on the DEVICE.
  26. mkfs.vfat "$(DEVICE)1"
  27. mkfs.ext4 "$(DEVICE)2"
  28. mount: | tmp/root tmp/boot
  29. tmp/boot: checkargs
  30. mkdir -p tmp/boot
  31. mount "$(DEVICE)1" tmp/boot
  32. tmp/root: checkargs
  33. mkdir -p tmp/root
  34. mount "$(DEVICE)2" tmp/root
  35. cache/%:
  36. mkdir -p cache
  37. cd cache; wget -c "http://archlinuxarm.org/os/$$(echo '$@' | sed -r 's/^cache\/(.+)$$/\1/')"
  38. tmp/root/bin/bash: checkargs-version | cache/$(filename_archlinux_arm)
  39. su -c "bsdtar -xpf cache/$(filename_archlinux_arm) -C tmp/root"
  40. sync
  41. -rm -r tmp/boot/*
  42. -mv tmp/root/boot/* tmp/boot
  43. tmp/root/home/alarm/install/Makefile: | tmp/root/bin/bash
  44. cp -af src/* tmp/root
  45. mv tmp/root/boot/* tmp/boot
  46. tmp/root/var/cache/pacman/pkg/PUT_DOWNLOADED_PACKAGES_HERE_TO_SPEED_UP_BUILDS: checkargs-version | tmp/root/home/alarm/install/Makefile
  47. cp -af src-rpi$(VERSION)/* tmp/root
  48. unpack-custom: | tmp/root/var/cache/pacman/pkg/PUT_DOWNLOADED_PACKAGES_HERE_TO_SPEED_UP_BUILDS
  49. ifneq (,$(CUSTOM))
  50. for dir in $(CUSTOM); do cp -af src-custom/$$dir/* tmp/root; done
  51. -mv tmp/root/boot/* tmp/boot
  52. endif
  53. chroot-setup: checkargs
  54. ifeq ($(VERSION),3)
  55. -[[ -f tmp/root/usr/bin/qemu-aarch64-static ]] || \
  56. update-binfmts --importdir /var/lib/binfmts/ --import; \
  57. update-binfmts --display qemu-aarch64; \
  58. update-binfmts --enable qemu-aarch64
  59. [[ -f tmp/root/usr/bin ]] || cp /usr/bin/qemu-aarch64-static tmp/root/usr/bin
  60. else
  61. -[[ -f tmp/root/usr/bin/qemu-arm-static ]] || \
  62. update-binfmts --importdir /var/lib/binfmts/ --import; \
  63. update-binfmts --display qemu-arm; \
  64. update-binfmts --enable qemu-arm
  65. [[ -f tmp/root/usr/bin ]] || cp /usr/bin/qemu-arm-static tmp/root/usr/bin
  66. endif
  67. -umount tmp/root/dev
  68. -umount tmp/root/proc
  69. -umount tmp/root/sys
  70. mount "$(DEVICE)1" tmp/root/boot
  71. chroot-teardown:
  72. umount tmp/root/boot
  73. tmp/root/usr/bin/devmon: | unpack-custom chroot-setup
  74. ifeq ($(VERSION),3)
  75. -arch-chroot tmp/root /usr/bin/qemu-aarch64-static /bin/bash -c "/home/alarm/install/install.sh; exit"
  76. else
  77. -arch-chroot tmp/root /usr/bin/qemu-arm-static /bin/bash -c "/home/alarm/install/install.sh; exit"
  78. endif
  79. $(MAKE) chroot-teardown
  80. chroot: | chroot-setup
  81. ifeq ($(VERSION),3)
  82. -arch-chroot tmp/root /usr/bin/qemu-aarch64-static /bin/bash
  83. else
  84. -arch-chroot tmp/root /usr/bin/qemu-arm-static /bin/bash
  85. endif
  86. $(MAKE) chroot-teardown
  87. clean: ## Remove temp files created during the installation.
  88. -rm tmp/root/home/alarm/.bash_history
  89. -rm -r tmp/root/home/alarm/install
  90. -rm tmp/root/home/alarm/webcam/*
  91. -rm tmp/root/root/.bash_history
  92. -rm tmp/root/var/log/pacman.log
  93. -rm -r tmp/root/var/cache/pacman/pkg/*
  94. update-config-txt:
  95. cp -f src/boot/cmdline* tmp/boot/
  96. cp -f src/boot/config* tmp/boot/
  97. dist/video-pi-rpi%.tar.bz2: checkargs
  98. mount "$(DEVICE)1" tmp/root/boot
  99. mkdir -p dist
  100. cd tmp/root; su -c "bsdtar -cjf ../../$@ *"
  101. umount tmp/root/boot
  102. package: checkargs-version | dist/video-pi-rpi$(VERSION).tar.bz2
  103. install: | tmp/root/usr/bin/devmon
  104. unpack: checkargs-version
  105. su -c "bsdtar -xpf dist/video-pi-rpi$(VERSION).tar.bz2 -C tmp/root"
  106. chown root.root tmp/root/etc/sudoers
  107. sync
  108. -rm -r tmp/boot/*
  109. mv tmp/root/boot/* tmp/boot
  110. umount:
  111. -umount -R tmp/root
  112. -rmdir tmp/root
  113. -umount tmp/boot
  114. -rmdir tmp/boot
  115. fsck: checkargs
  116. fsck.vfat -a "$(DEVICE)1"
  117. fsck.ext4 -a "$(DEVICE)2"
  118. checkargs:
  119. ifeq (,$(DEVICE))
  120. @echo "You must set the DEVICE variable."
  121. @echo "Example: make backup DEVICE=/dev/sdX"
  122. @exit 1
  123. endif
  124. checkargs-version:
  125. ifeq (,$(VERSION))
  126. @echo "You must set the VERSION variable."
  127. @echo "Example: make build VERSION=3"
  128. @exit 1
  129. endif
  130. checkargs-path:
  131. ifeq (,$(PATH))
  132. @echo "You must set the PATH variable."
  133. @echo "Example: make restore PATH=/tmp/my_videopi.img"
  134. @exit 1
  135. endif
  136. help: # https://gist.github.com/jhermsmeier/2d831eb8ad2fb0803091
  137. @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-14s\033[0m %s\n", $$1, $$2}'