Makefile 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # SPDX-License-Identifier: GPL-3.0-or-later
  2. #
  3. # Copyright (C) 2022, 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  4. # Copyright (C) 2022 Leah Rowe <leah@libreboot.org>
  5. .POSIX:
  6. # Commands
  7. all: config clean prepbox genbox box
  8. include ./config.mk
  9. config:
  10. @echo "VERSION = $(VERSION)"
  11. @echo "CFLAGS = $(CFLAGS)"
  12. @echo "CC = $(CC)"
  13. @echo "DESTDIR = $(DESTDIR)"
  14. @echo "PREFIX = $(PREFIX)"
  15. @echo "INCLUDE_EXTRA = $(INCLUDE_EXTRA)"
  16. genbox:
  17. cat "box-templates/box_1-23.c" > box.c
  18. test ${INCLUDE_CORE} == n || for u in ${CORE}; do echo "int $${u%.c}_main(int, char**);" | sed "s/\[_/test_/g"; done>> box.c
  19. test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo "int $${u%.c}_main(int, char**);"; done>> box.c
  20. cat "box-templates/box_45-49.c" >> box.c
  21. test ${INCLUDE_CORE} == n || for u in ${CORE}; do echo " else if(!strcmp(basename(argv[0]), \"$${u%.c}\")) return $${u%.c}_main(argc, argv);" | sed "s/\[_/test_/g"; done >> box.c
  22. test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo " else if(!strcmp(argv[0], \"$${u%.c}\")) return $${u%.c}_main(argc, argv);"; done >> box.c
  23. cat "box-templates/box_70-73.c" >> box.c
  24. test ${INCLUDE_CORE} == n || for u in ${CORE}; do echo " printf(\"$${u%.c} \");"; done >> box.c
  25. test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo " printf(\"$${u%.c} \");"; done >> box.c
  26. test ${INCLUDE_CORE} == n && test ${INCLUDE_EXTRA} == n && echo " printf(\"¯\\\\_(ツ)_/¯ No commands found.\");" >> box.c || true
  27. cat "box-templates/box_94-96.c" >> box.c
  28. echo "/* Generated on $$(date) */" >> box.c
  29. prepbox:
  30. mkdir -p box_tmp
  31. test ${INCLUDE_CORE} == n || for f in ${CORE}; do (sed "s/^int main(/int $$(echo "$$f")_main(/" < "core/"$$f".c" | sed "s/\"..\/common/\"common/g" | sed "s/\[_/test_/g") > "box_tmp/"$$f"_box.c"; done
  32. rm -f "box_tmp/[_box.c"
  33. test ${INCLUDE_EXTRA} == n || for f in ${EXTRA}; do sed "s/^int main(/int $$(echo "$$f")_main(/" < "extras/"$$f".c" | sed "s/printUsage()/$$(echo "$$f")_printUsage()/g" > "box_tmp/"$$f"_box.c"; done
  34. box: box.o
  35. test ${INCLUDE_CORE} = n && test ${INCLUDE_EXTRA} = n && $(CC) $(CFLAGS) common/common.c box.o -o box || $(CC) $(CFLAGS) box_tmp/*.c common/common.c box.o -o box
  36. rm -f version.h
  37. clean:
  38. rm -f box *.o
  39. rm -Rf box_tmp
  40. for f in $(CORE); do rm -f core/$$f; done
  41. for f in $(EXTRA); do rm -f extras/$$f; done
  42. install:
  43. mkdir -p $(DESTDIR)$(PREFIX)/bin
  44. cp -r core/bin/* $(DESTDIR)$(PREFIX)/bin
  45. install-box:
  46. mkdir -p $(DESTDIR)$(PREFIX)/bin
  47. cp -r box $(DESTDIR)$(PREFIX)/bin
  48. links:
  49. for u in ${CORE}; do ln -s "$(DESTDIR)$(PREFIX)/bin/box" "$(DESTDIR)$(PREFIX)/bin/$$u"; done
  50. remove:
  51. rm -f $(DESTDIR)$(PREFIX)/bin/box
  52. for u in ${CORE}; do rm -f "$(DESTDIR)$(PREFIX)/bin/$$u"; done
  53. # Utilities
  54. # =========
  55. box.o: prepbox
  56. $(CC) $(CFLAGS) $(NOLINKER) box.c -o box.o