component.mk 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #
  2. # Component Makefile
  3. #
  4. # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
  5. # esp_app_desc structure is added as an undefined symbol because otherwise the
  6. # linker will ignore this structure as it has no other files depending on it.
  7. COMPONENT_ADD_LDFLAGS += -u esp_app_desc
  8. ifndef IS_BOOTLOADER_BUILD
  9. # If ``CONFIG_APP_PROJECT_VER_FROM_CONFIG`` option is set, the value of ``CONFIG_APP_PROJECT_VER`` will be used
  10. # Else, if ``PROJECT_VER`` variable set in project Makefile file, its value will be used.
  11. # Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``.
  12. # Else, if the project is located inside a Git repository, the output of git describe will be used.
  13. # Otherwise, ``PROJECT_VER`` will be "1".
  14. ifdef CONFIG_APP_PROJECT_VER_FROM_CONFIG
  15. PROJECT_VER:= $(CONFIG_APP_PROJECT_VER)
  16. else
  17. ifneq ("${PROJECT_VER}", "")
  18. PROJECT_VER:= $(PROJECT_VER)
  19. else
  20. ifneq ("$(wildcard ${PROJECT_PATH}/version.txt)","")
  21. PROJECT_VER := $(shell cat ${PROJECT_PATH}/version.txt)
  22. else
  23. GIT_PROJECT_VER := $(shell cd ${PROJECT_PATH} && git describe --always --tags --dirty 2> /dev/null)
  24. ifeq ("${GIT_PROJECT_VER}", "")
  25. PROJECT_VER := "1"
  26. $(info Project is not inside a git repository, or git repository has no commits)
  27. $(info will not use 'git describe' to determine PROJECT_VER.)
  28. else
  29. PROJECT_VER:= $(GIT_PROJECT_VER)
  30. endif # a git repository
  31. endif # version.txt
  32. endif # PROJECT_VER
  33. endif # CONFIG_APP_PROJECT_VER_FROM_CONFIG
  34. # cut PROJECT_VER and PROJECT_NAME to required 32 characters.
  35. PROJECT_VER_CUT := $(shell echo "$(PROJECT_VER)" | cut -c 1-31)
  36. PROJECT_NAME_CUT := $(shell echo "$(PROJECT_NAME)" | cut -c 1-31)
  37. $(info App "$(PROJECT_NAME_CUT)" version: $(PROJECT_VER_CUT))
  38. NEW_DEFINES:= "$(PROJECT_VER_CUT) $(PROJECT_NAME_CUT) $(IDF_VER)"
  39. ifeq ("$(wildcard ${TMP_DEFINES})","")
  40. OLD_DEFINES:= ""
  41. else
  42. OLD_DEFINES:= "$(shell cat $(TMP_DEFINES))"
  43. endif
  44. # If NEW_DEFINES (PROJECT_VER, PROJECT_NAME) were changed then rebuild only esp_app_desc.
  45. ifneq (${NEW_DEFINES}, ${OLD_DEFINES})
  46. $(shell echo $(NEW_DEFINES) > $(TMP_DEFINES); rm -f esp_app_desc.o;)
  47. endif
  48. esp_app_desc.o: CPPFLAGS += -D PROJECT_VER=\""$(PROJECT_VER_CUT)"\" -D PROJECT_NAME=\""$(PROJECT_NAME_CUT)"\"
  49. endif # IS_BOOTLOADER_BUILD