Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Copyright 2024 NXP
  2. # NXP Proprietary. This software is owned or controlled by NXP and may only be used strictly in
  3. # accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
  4. # activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
  5. # comply with and are bound by, such license terms. If you do not agree to be bound by the applicable license
  6. # terms, then you may not retain, install, activate or otherwise use the software.
  7. makefile_name := $(abspath $(lastword $(MAKEFILE_LIST)))
  8. makefile_path := $(strip $(patsubst %/,% , $(dir $(makefile_name))))
  9. libfile_path := $(makefile_path)/../lib/native
  10. CC := gcc
  11. PRJ_DIR := $(makefile_path)/..
  12. LVGL_DIR := $(PRJ_DIR)
  13. SIMULATOR_DIR := $(makefile_path)
  14. LVGL_DIR_NAME ?= lvgl
  15. AFLAGS := -MMD -MP -DLV_CONF_INCLUDE_SIMPLE=1 -I$(makefile_path)/
  16. CFLAGS := -O3 -g0 -I$(LVGL_DIR)/ -I$(makefile_path)/ -I$(makefile_path)/modules/rlottie -c -fmessage-length=0
  17. CFLAGS += -I$(LVGL_DIR)/$(LVGL_DIR_NAME)/ -I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src -I$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/misc
  18. ifeq ($(OS),Windows_NT)
  19. -include $(SIMULATOR_DIR)/gg_external_data/freemaster/freemaster.mk
  20. -include $(SIMULATOR_DIR)/gg_external_data/gg_external_data.mk
  21. LDFLAGS := -lSDL2 -L$(libfile_path) -ldecoder -lopenh264 -lrlottie -lpthread -lstdc++ -ljansson -lcurl -lm
  22. else
  23. LDFLAGS := -lSDL2 -L$(libfile_path) -ldecoder -lopenh264 -lrlottie -lpthread -lstdc++ -lm -ldl
  24. endif
  25. BUILD_DIR := build/
  26. OBJ_DIR := $(BUILD_DIR)object/
  27. GEN_OBJ_DIR := $(OBJ_DIR)generated/
  28. BIN_DIR := $(BUILD_DIR)bin/
  29. NORMAL_OUT := 1
  30. RM := rm -f
  31. RMDIR := rm -rf
  32. ifeq ($(OS),Windows_NT)
  33. LDFLAGS += -L$(SIMULATOR_DIR)\modules\SDL2\i686-w64-mingw32\lib
  34. SIMULATOR_EXE = simulator.exe
  35. SIMULATOR_DLL = simulator.dll
  36. BUILD_ENV := build\object build\bin
  37. NULL_OUT := nul
  38. MKDIR_P = @if not exist "$(1)" mkdir "$(1)"
  39. else
  40. SIMULATOR_EXE = simulator
  41. NULL_OUT := /dev/null
  42. MKDIR_P = @if [ ! -d "$(1)" ]; then mkdir -p "$(1)"; fi
  43. endif
  44. CFLAGS += -DLV_CONF_INCLUDE_SIMPLE=1 $(EXTRA_CFLAGS)
  45. #Collect the files to compile
  46. LVGL_PATH := $(LVGL_DIR)/$(LVGL_DIR_NAME)
  47. -include $(LVGL_DIR)/$(LVGL_DIR_NAME)/lvgl.mk
  48. -include $(PRJ_DIR)/generated/generated.mk
  49. -include $(PRJ_DIR)/custom/custom.mk
  50. CSRCS += main.c simulator_icon.c
  51. DEPPATH += --dep-path $(makefile_path)/
  52. VPATH += :$(makefile_path)/
  53. #SDL2
  54. ifeq ($(OS),Windows_NT)
  55. CFLAGS += "-I$(SIMULATOR_DIR)\modules\SDL2\i686-w64-mingw32\include" -MMD -MP
  56. endif
  57. OBJEXT := .o
  58. AOBJS = $(notdir $(ASRCS:.S=$(OBJEXT)))
  59. COBJS = $(notdir $(CSRCS:.c=$(OBJEXT)))
  60. GEN_AOBJS = $(notdir $(GEN_ASRCS:.S=$(OBJEXT)))
  61. GEN_COBJS = $(notdir $(GEN_CSRCS:.c=$(OBJEXT)))
  62. SRCS = $(ASRCS) $(CSRCS)
  63. OBJS = $(addprefix $(OBJ_DIR), $(AOBJS) $(COBJS))
  64. DEPS = $(OBJS:$(OBJEXT)=.d)
  65. GEN_SRCS = $(GEN_ASRCS) $(GEN_CSRCS)
  66. GEN_OBJS = $(addprefix $(GEN_OBJ_DIR), $(GEN_AOBJS) $(GEN_COBJS))
  67. DEPS += $(GEN_OBJS:$(OBJEXT)=.d)
  68. .PHONY: all env clean default cp_lib clean_gen run
  69. ifeq ($(OS),Windows_NT)
  70. all: env default cp_lib
  71. else
  72. all: env default
  73. endif
  74. # monitor header files
  75. -include $(DEPS)
  76. env:
  77. $(call MKDIR_P,build/bin)
  78. $(call MKDIR_P,build/object/generated)
  79. $(OBJ_DIR)%.o: %.S
  80. @echo "Compiling $<"
  81. @$(CC) $(AFLAGS) -c $< -o $@
  82. $(OBJ_DIR)%.o: %.c
  83. @echo "Compiling $<"
  84. @$(CC) $(CFLAGS) -c $< -o $@
  85. $(GEN_OBJ_DIR)%.o: %.c
  86. @echo "Compiling $<"
  87. $(call MKDIR_P,$(dir $@))
  88. @$(CC) $(CFLAGS) -c $< -o $@
  89. default: $(OBJS) $(GEN_OBJS)
  90. @echo "Linking $(SIMULATOR_EXE)"
  91. @ar -csr $(GEN_OBJ_DIR)/libgenerated.a $(GEN_OBJS)
  92. @$(CC) -o $(BIN_DIR)$(SIMULATOR_EXE) $(OBJS) -L$(GEN_OBJ_DIR) -lgenerated $(LDFLAGS)
  93. ifeq ($(OS),Windows_NT)
  94. @echo "Linking $(SIMULATOR_DLL)"
  95. @$(CC) --shared -o $(BIN_DIR)$(SIMULATOR_DLL) $(OBJS) -L$(GEN_OBJ_DIR) -lgenerated $(LDFLAGS) --entry=_DllMainCRTStartup@12
  96. endif
  97. cp_lib:
  98. -@cp modules/SDL2/lib/SDL2.dll build/bin/SDL2.dll $(NORMAL_OUT)>$(NULL_OUT)
  99. -@cp modules/SDL2/lib/libopenh264.dll build/bin/libopenh264.dll $(NORMAL_OUT)>$(NULL_OUT)
  100. -@cp modules/multi_thread/libgcc_s_dw2-1.dll build/bin/libgcc_s_dw2-1.dll $(NORMAL_OUT)>$(NULL_OUT)
  101. -@cp modules/multi_thread/pthreadGC-3.dll build/bin/pthreadGC-3.dll $(NORMAL_OUT)>$(NULL_OUT)
  102. -@cp modules/multi_thread/libjansson-4.dll build/bin/libjansson-4.dll $(NORMAL_OUT)>$(NULL_OUT)
  103. -@cp modules/multi_thread/libcurl.dll build/bin/libcurl.dll $(NORMAL_OUT)>$(NULL_OUT)
  104. clean:
  105. -@$(RMDIR) build
  106. gen_images := $(wildcard $(PRJ_DIR)/generated/images/*.c)
  107. gen_srcs := $(gen_images) $(wildcard $(PRJ_DIR)/generated/*.c) $(wildcard $(PRJ_DIR)/generated/*.h)
  108. ifeq ($(OS),Windows_NT)
  109. clean_gen_img:
  110. -@rm $(gen_images)
  111. clean_gen: clean_gen_img
  112. -@rm $(gen_srcs)
  113. run:
  114. build\bin\simulator.exe
  115. else
  116. clean_gen_img:
  117. $(RM) $(LVGL_DIR)/generated/images/*.c
  118. clean_gen: clean_gen_img
  119. $(RM) $(LVGL_DIR)/generated/*.c
  120. $(RM) $(LVGL_DIR)/generated/*.h
  121. run:
  122. ./build/bin/simulator
  123. endif