component.mk 2.0 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. GET_PROJECT_VER ?=
  10. ifeq ("${PROJECT_VER}", "")
  11. ifeq ("$(wildcard ${PROJECT_PATH}/version.txt)","")
  12. GET_PROJECT_VER := $(shell cd ${PROJECT_PATH} && git describe --always --tags --dirty 2> /dev/null)
  13. ifeq ("${GET_PROJECT_VER}", "")
  14. GET_PROJECT_VER := "1"
  15. $(info Project is not inside a git repository, will not use 'git describe' to determine PROJECT_VER.)
  16. endif
  17. else
  18. # read from version.txt
  19. GET_PROJECT_VER := $(shell cat ${PROJECT_PATH}/version.txt)
  20. endif
  21. endif
  22. # If ``PROJECT_VER`` variable set in project Makefile file, its value will be used.
  23. # Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``.
  24. # Else, if the project is located inside a Git repository, the output of git describe will be used.
  25. # Otherwise, ``PROJECT_VER`` will be "1".
  26. ifeq ("${PROJECT_VER}", "")
  27. PROJECT_VER:= $(GET_PROJECT_VER)
  28. else
  29. PROJECT_VER:= $(PROJECT_VER)
  30. endif
  31. # cut PROJECT_VER and PROJECT_NAME to required 32 characters.
  32. PROJECT_VER_CUT := $(shell echo "$(PROJECT_VER)" | cut -c 1-31)
  33. PROJECT_NAME_CUT := $(shell echo "$(PROJECT_NAME)" | cut -c 1-31)
  34. $(info App "$(PROJECT_NAME_CUT)" version: $(PROJECT_VER_CUT))
  35. NEW_DEFINES:= "$(PROJECT_VER_CUT) $(PROJECT_NAME_CUT) $(IDF_VER)"
  36. ifeq ("$(wildcard ${TMP_DEFINES})","")
  37. OLD_DEFINES:= ""
  38. else
  39. OLD_DEFINES:= "$(shell cat $(TMP_DEFINES))"
  40. endif
  41. # If NEW_DEFINES (PROJECT_VER, PROJECT_NAME) were changed then rebuild only esp_app_desc.
  42. ifneq (${NEW_DEFINES}, ${OLD_DEFINES})
  43. $(shell echo $(NEW_DEFINES) > $(TMP_DEFINES); rm -f esp_app_desc.o;)
  44. endif
  45. esp_app_desc.o: CPPFLAGS += -D PROJECT_VER=\""$(PROJECT_VER_CUT)"\" -D PROJECT_NAME=\""$(PROJECT_NAME_CUT)"\"
  46. endif