diff --git a/Makefile b/Makefile index 46acaaa5a..c416c3133 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,20 @@ -include build/config.mak - # Disable default Make rules .SUFFIXES: -object_for = $(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(basename $(1)))) - # Define the default recipe - default: -# Define a standard rule helper -# If passed a last parameter value of with_local_version, we also define an -# extra rule that can build source files within the $(BUILD_DIR). This is useful -# for rules that can be applied for intermediate objects (for example, when -# going .png -> .cpp -> .o). +include build/config.mak +include build/defaults.mak +include build/platform.$(PLATFORM).mak +include build/toolchain.$(TOOLCHAIN).mak +include build/variants.mak +include build/helpers.mk -define rule_label -@ echo "$(shell printf "%-8s" $(strip $(1)))$(@:$(BUILD_DIR)/%=%)" +define foo endef -define rule_for -ifeq ($(strip $(5)),with_local_version) -$(addprefix $$(BUILD_DIR)/,$(strip $(2))): $(addprefix $$(BUILD_DIR)/,$(strip $(3))) | $(if $(findstring official,${MAKECMDGOALS}),official_authorization) - @ echo "$(shell printf "%-8s" $(strip $(1)))$$(@:$$(BUILD_DIR)/%=%)" - $(Q) $(4) -endif -$(addprefix $$(BUILD_DIR)/,$(strip $(2))): $(strip $(3)) | $$$$(@D)/. $(if $(findstring official,${MAKECMDGOALS}),official_authorization) - @ echo "$(shell printf "%-8s" $(strip $(1)))$$(@:$$(BUILD_DIR)/%=%)" - $(Q) $(4) -endef +$(eval $(call foo)) .PHONY: info info: @@ -83,7 +69,9 @@ $(BUILD_DIR)%/.: # Each sub-Makefile can either add sources to $(%_src) variables or define a # new executable target. The $(%_src) variables list the sources that can be # built and linked to executables being generated. - +ifndef USE_LIBA + $(error platform.mak should define USE_LIBA) +endif ifeq ($(USE_LIBA),0) include liba/Makefile.bridge else @@ -102,7 +90,7 @@ include build/struct_layout/Makefile include build/scenario/Makefile include quiz/Makefile # Quiz needs to be included at the end -all_src = $(apps_all_src) $(escher_src) $(ion_all_src) $(kandinsky_src) $(liba_src) $(libaxx_src) $(poincare_src) $(python_src) $(runner_src) $(ion_target_device_flasher_light_src) $(ion_target_device_flasher_verbose_src) $(ion_target_device_bench_src) $(tests_src) +all_src = $(apps_src) $(escher_src) $(ion_src) $(kandinsky_src) $(liba_src) $(libaxx_src) $(poincare_src) $(python_src) $(runner_src) $(ion_device_flasher_src) $(ion_device_bench_src) $(tests_src) all_objs = $(call object_for,$(all_src)) .SECONDARY: $(all_objs) diff --git a/apps/Makefile b/apps/Makefile index dc9e4c63e..c1402113f 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -10,8 +10,14 @@ apps = # (path to the apps header). $(foreach i,${EPSILON_APPS},$(eval include apps/$(i)/Makefile)) -app_src += $(addprefix apps/,\ +apps_src += $(addprefix apps/,\ apps_container.cpp \ + apps_container_launch_default.cpp:-onboarding \ + apps_container_launch_on_boarding.cpp:+onboarding \ + apps_container_prompt_beta.cpp:+beta \ + apps_container_prompt_none.cpp:-beta \ + apps_container_prompt_none.cpp:-update \ + apps_container_prompt_update.cpp:+update \ apps_container_storage.cpp \ apps_window.cpp \ backlight_dimming_timer.cpp \ @@ -19,6 +25,8 @@ app_src += $(addprefix apps/,\ battery_view.cpp \ empty_battery_window.cpp \ exam_pop_up_controller.cpp \ + exam_mode_configuration_official.cpp:+official \ + exam_mode_configuration_non_official.cpp:-official \ global_preferences.cpp \ i18n.py \ lock_view.cpp \ @@ -32,14 +40,6 @@ app_src += $(addprefix apps/,\ ) tests_src += apps/exam_mode_configuration_official.cpp -apps_official += apps/exam_mode_configuration_official.cpp -apps_non_official += apps/exam_mode_configuration_non_official.cpp - -apps_launch_on_boarding_src += apps/apps_container_launch_on_boarding.cpp -apps_launch_default_src += apps/apps_container_launch_default.cpp -apps_prompt_none_src += apps/apps_container_prompt_none.cpp -apps_prompt_beta_src += apps/apps_container_prompt_beta.cpp -apps_prompt_update_src += apps/apps_container_prompt_update.cpp snapshots_declaration = $(foreach i,$(apps),$(i)::Snapshot m_snapshot$(subst :,,$(i))Snapshot;) apps_declaration = $(foreach i,$(apps),$(i) m_$(subst :,,$(i));) @@ -89,28 +89,11 @@ $(BUILD_DIR)/apps/i18n.h: $(BUILD_DIR)/apps/i18n.cpp $(eval $(call depends_on_image,apps/title_bar_view.cpp,apps/exam_icon.png)) -all_app_src = $(app_src)(apps_launch_on_boarding_src) $(apps_launch_default_src) $(apps_prompt_none_src) $(apps_prompt_update_src) $(apps_prompt_beta_src) $(apps_official) $(apps_non_official) $(tests_src) - -$(call object_for,$(all_app_src)): $(BUILD_DIR)/apps/i18n.h -$(call object_for,$(all_app_src)): $(BUILD_DIR)/python/port/genhdr/qstrdefs.generated.h +$(call object_for,$(apps_src) $(tests_src)): $(BUILD_DIR)/apps/i18n.h +$(call object_for,$(apps_src) $(tests_src)): $(BUILD_DIR)/python/port/genhdr/qstrdefs.generated.h apps_tests_src = $(app_calculation_test_src) $(app_code_test_src) $(app_probability_test_src) $(app_regression_test_src) $(app_sequence_test_src) $(app_shared_test_src) $(app_statistics_test_src) $(app_settings_test_src) $(app_solver_test_src) apps_tests_src += $(addprefix apps/,\ global_preferences.cpp \ ) - -# Configure variants -apps_all_src = $(app_src) -apps_all_src += $(apps_official) $(apps_non_official) -apps_all_src += $(apps_launch_default_src) $(apps_launch_on_boarding_src) -apps_all_src += $(apps_prompt_none_src) $(apps_prompt_update_src) $(apps_prompt_beta_src) - -apps_default_src = $(app_src) $(apps_non_official) $(apps_launch_default_src) $(apps_prompt_none_src) -apps_official_default_src = $(app_src) $(apps_official) $(apps_launch_default_src) $(apps_prompt_none_src) -apps_onboarding_src = $(app_src) $(apps_non_official) $(apps_launch_on_boarding_src) $(apps_prompt_none_src) -apps_official_onboarding_src = $(app_src) $(apps_official) $(apps_launch_on_boarding_src) $(apps_prompt_none_src) -apps_onboarding_update_src = $(app_src) $(apps_non_official) $(apps_launch_on_boarding_src) $(apps_prompt_update_src) -apps_official_onboarding_update_src = $(app_src) $(apps_official) $(apps_launch_on_boarding_src) $(apps_prompt_update_src) -apps_onboarding_beta_src = $(app_src) $(apps_non_official) $(apps_launch_on_boarding_src) $(apps_prompt_beta_src) -apps_official_onboarding_beta_src = $(app_src) $(apps_official) $(apps_launch_on_boarding_src) $(apps_prompt_beta_src) diff --git a/apps/calculation/Makefile b/apps/calculation/Makefile index bd0615e4a..ef4c9d36d 100644 --- a/apps/calculation/Makefile +++ b/apps/calculation/Makefile @@ -30,7 +30,7 @@ app_calculation_src = $(addprefix apps/calculation/,\ ) app_calculation_src += $(app_calculation_test_src) -app_src += $(app_calculation_src) +apps_src += $(app_calculation_src) i18n_files += $(addprefix apps/calculation/,\ base.de.i18n\ diff --git a/apps/code/Makefile b/apps/code/Makefile index 33b60f68b..aa61accc9 100644 --- a/apps/code/Makefile +++ b/apps/code/Makefile @@ -27,7 +27,7 @@ app_code_src = $(addprefix apps/code/,\ ) app_code_src += $(app_code_test_src) -app_src += $(app_code_src) +apps_src += $(app_code_src) i18n_files += $(addprefix apps/code/,\ base.de.i18n\ diff --git a/apps/graph/Makefile b/apps/graph/Makefile index 5284a2dac..482528ad2 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -31,7 +31,7 @@ app_graph_src = $(addprefix apps/graph/,\ values/values_controller.cpp \ ) -app_src += $(app_graph_src) +apps_src += $(app_graph_src) i18n_files += $(addprefix apps/graph/,\ base.de.i18n\ diff --git a/apps/hardware_test/Makefile b/apps/hardware_test/Makefile index 339b8887c..960ebcc3c 100644 --- a/apps/hardware_test/Makefile +++ b/apps/hardware_test/Makefile @@ -16,4 +16,4 @@ app_hardware_test_src = $(addprefix apps/hardware_test/,\ vblank_test_controller.cpp \ ) -app_src += $(app_hardware_test_src) +apps_src += $(app_hardware_test_src) diff --git a/apps/home/Makefile b/apps/home/Makefile index 5f4b7eb59..d052cada2 100644 --- a/apps/home/Makefile +++ b/apps/home/Makefile @@ -4,7 +4,7 @@ app_home_src = $(addprefix apps/home/,\ controller.cpp \ ) -app_src += $(app_home_src) +apps_src += $(app_home_src) i18n_files += $(addprefix apps/home/,\ base.de.i18n \ diff --git a/apps/on_boarding/Makefile b/apps/on_boarding/Makefile index 723d19d76..7942bd97f 100644 --- a/apps/on_boarding/Makefile +++ b/apps/on_boarding/Makefile @@ -7,7 +7,7 @@ app_on_boarding_src = $(addprefix apps/on_boarding/,\ power_on_self_test.cpp \ ) -app_src += $(app_on_boarding_src) +apps_src += $(app_on_boarding_src) i18n_files += $(addprefix apps/on_boarding/,\ base.de.i18n\ diff --git a/apps/probability/Makefile b/apps/probability/Makefile index 436828add..c2d1080dc 100644 --- a/apps/probability/Makefile +++ b/apps/probability/Makefile @@ -38,7 +38,7 @@ app_probability_src = $(addprefix apps/probability/,\ ) app_probability_src += $(app_probability_test_src) -app_src += $(app_probability_src) +apps_src += $(app_probability_src) i18n_files += $(addprefix apps/probability/,\ base.de.i18n\ diff --git a/apps/regression/Makefile b/apps/regression/Makefile index 580f13cd4..2fd71b5a0 100644 --- a/apps/regression/Makefile +++ b/apps/regression/Makefile @@ -37,7 +37,7 @@ app_regression_src = $(addprefix apps/regression/,\ ) app_regression_src += $(app_regression_test_src) -app_src += $(app_regression_src) +apps_src += $(app_regression_src) i18n_files += $(addprefix apps/regression/,\ base.de.i18n\ diff --git a/apps/sequence/Makefile b/apps/sequence/Makefile index ecdb7326b..4320815e7 100644 --- a/apps/sequence/Makefile +++ b/apps/sequence/Makefile @@ -26,7 +26,7 @@ app_sequence_src = $(addprefix apps/sequence/,\ ) app_sequence_src += $(app_sequence_test_src) -app_src += $(app_sequence_src) +apps_src += $(app_sequence_src) i18n_files += $(addprefix apps/sequence/,\ base.de.i18n\ diff --git a/apps/settings/Makefile b/apps/settings/Makefile index b8197213e..5334f862c 100644 --- a/apps/settings/Makefile +++ b/apps/settings/Makefile @@ -5,7 +5,15 @@ app_settings_src = $(addprefix apps/settings/,\ app.cpp \ cell_with_separator.cpp \ main_controller.cpp \ + main_controller_prompt_beta.cpp:+beta \ + main_controller_prompt_none.cpp:-beta \ + main_controller_prompt_none.cpp:-update \ + main_controller_prompt_update.cpp:+update \ sub_menu/about_controller.cpp \ + sub_menu/about_controller_official.cpp:+official \ + sub_menu/about_controller_non_official.cpp:-official \ + sub_menu/exam_mode_controller_official.cpp:+official \ + sub_menu/exam_mode_controller_non_official.cpp:-official \ sub_menu/display_mode_controller.cpp \ sub_menu/exam_mode_controller.cpp \ sub_menu/generic_sub_controller.cpp \ @@ -15,24 +23,7 @@ app_settings_src = $(addprefix apps/settings/,\ ) app_settings_src += $(app_settings_test_src) -app_src += $(app_settings_src) - -apps_prompt_none_src += apps/settings/main_controller_prompt_none.cpp -apps_prompt_beta_src += apps/settings/main_controller_prompt_beta.cpp -apps_prompt_update_src += apps/settings/main_controller_prompt_update.cpp - -apps_settings_official += $(addprefix apps/settings/,\ - sub_menu/about_controller_official.cpp \ - sub_menu/exam_mode_controller_official.cpp \ -) - -apps_settings_non_official += $(addprefix apps/settings/,\ - sub_menu/about_controller_non_official.cpp \ - sub_menu/exam_mode_controller_non_official.cpp \ -) - -apps_official += $(apps_settings_official) -apps_non_official += $(apps_settings_non_official) +apps_src += $(app_settings_src) i18n_files += $(addprefix apps/settings/,\ base.de.i18n\ diff --git a/apps/shared/Makefile b/apps/shared/Makefile index b406d41cb..4056c9dbd 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -84,4 +84,4 @@ app_shared_src = $(addprefix apps/shared/,\ ) app_shared_src += $(app_shared_test_src) -app_src += $(app_shared_src) +apps_src += $(app_shared_src) diff --git a/apps/solver/Makefile b/apps/solver/Makefile index 05273744b..f9fea9bf3 100644 --- a/apps/solver/Makefile +++ b/apps/solver/Makefile @@ -16,7 +16,7 @@ app_solver_src = $(addprefix apps/solver/,\ ) app_solver_src += $(app_solver_test_src) -app_src += $(app_solver_src) +apps_src += $(app_solver_src) i18n_files += $(addprefix apps/solver/,\ base.de.i18n\ diff --git a/apps/statistics/Makefile b/apps/statistics/Makefile index c1b0c158a..34e9cb878 100644 --- a/apps/statistics/Makefile +++ b/apps/statistics/Makefile @@ -27,7 +27,7 @@ app_statistics_src = $(addprefix apps/statistics/,\ ) app_statistics_src += $(app_statistics_test_src) -app_src += $(app_statistics_src) +apps_src += $(app_statistics_src) i18n_files += $(addprefix apps/statistics/,\ base.de.i18n\ diff --git a/apps/usb/Makefile b/apps/usb/Makefile index c539f947c..4e4a6449b 100644 --- a/apps/usb/Makefile +++ b/apps/usb/Makefile @@ -3,7 +3,7 @@ app_usb_src = $(addprefix apps/usb/,\ usb_connected_controller.cpp \ ) -app_src += $(app_usb_src) +apps_src += $(app_usb_src) i18n_files += $(addprefix apps/usb/,\ base.de.i18n\ diff --git a/build/config.mak b/build/config.mak index 9c8ff7b5d..1d2822bcd 100644 --- a/build/config.mak +++ b/build/config.mak @@ -3,22 +3,9 @@ PLATFORM ?= device DEBUG ?= 0 -include build/defaults.mak -include build/platform.$(PLATFORM).mak - EPSILON_VERSION ?= 13.0.0 EPSILON_APPS ?= calculation graph code statistics probability solver sequence regression settings EPSILON_I18N ?= en fr es de pt EPSILON_GETOPT ?= 0 EPSILON_TELEMETRY ?= 0 ESCHER_LOG_EVENTS_BINARY ?= 0 - -ifndef USE_LIBA - $(error platform.mak should define USE_LIBA) -endif -include build/toolchain.$(TOOLCHAIN).mak - -SFLAGS += -DDEBUG=$(DEBUG) -SFLAGS += -DEPSILON_GETOPT=$(EPSILON_GETOPT) -SFLAGS += -DEPSILON_TELEMETRY=$(EPSILON_TELEMETRY) -SFLAGS += -DESCHER_LOG_EVENTS_BINARY=$(ESCHER_LOG_EVENTS_BINARY) diff --git a/build/defaults.mak b/build/defaults.mak index d8a0c8c0d..6a4ad3e0b 100644 --- a/build/defaults.mak +++ b/build/defaults.mak @@ -2,6 +2,11 @@ HOSTCC = gcc HOSTCXX = g++ PYTHON = python3 +SFLAGS += -DDEBUG=$(DEBUG) +SFLAGS += -DEPSILON_GETOPT=$(EPSILON_GETOPT) +SFLAGS += -DEPSILON_TELEMETRY=$(EPSILON_TELEMETRY) +SFLAGS += -DESCHER_LOG_EVENTS_BINARY=$(ESCHER_LOG_EVENTS_BINARY) + # Language-specific flags CFLAGS = -std=c99 CXXFLAGS = -std=c++11 -fno-exceptions -fno-rtti -fno-threadsafe-statics diff --git a/build/helpers.mk b/build/helpers.mk new file mode 100644 index 000000000..f0b68cf28 --- /dev/null +++ b/build/helpers.mk @@ -0,0 +1,36 @@ +# Define a standard rule helper +# If passed a last parameter value of with_local_version, we also define an +# extra rule that can build source files within the $(BUILD_DIR). This is useful +# for rules that can be applied for intermediate objects (for example, when +# going .png -> .cpp -> .o). + +define rule_label +@ echo "$(shell printf "%-8s" $(strip $(1)))$(@:$(BUILD_DIR)/%=%)" +endef + +define rule_for +ifeq ($(strip $(5)),with_local_version) +$(addprefix $$(BUILD_DIR)/,$(strip $(2))): $(addprefix $$(BUILD_DIR)/,$(strip $(3))) + @ echo "$(shell printf "%-8s" $(strip $(1)))$$(@:$$(BUILD_DIR)/%=%)" + $(Q) $(4) +endif +$(addprefix $$(BUILD_DIR)/,$(strip $(2))): $(strip $(3)) | $$$$(@D)/. + @ echo "$(shell printf "%-8s" $(strip $(1)))$$(@:$$(BUILD_DIR)/%=%)" + $(Q) $(4) +endef + +# Helper functions to work with variants + +define direct_object_for +$(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(basename $(1)))) +endef + +# Objects for source files in $(1) matching flavor $(2). A flavor is a dot +# separated list of variants (e.g. large.speed). +define flavored_object_for +$(call direct_object_for,$(call filter_variants,$(1),$(sort $(subst ., ,$(2))))) +endef + +define object_for +$(call direct_object_for,$(call any_variant,$(1))) +endef diff --git a/build/rules.mk b/build/rules.mk index d08285bc5..2826a3746 100644 --- a/build/rules.mk +++ b/build/rules.mk @@ -1,16 +1,5 @@ # Define standard compilation rules -.PHONY: official_authorization -ifeq ($(ACCEPT_OFFICIAL_TOS),1) -official_authorization: -else -official_authorization: - @echo "CAUTION: You are trying to build an official NumWorks firmware." - @echo "Distribution of such firmware by a third party is prohibited." - @echo "Please set the ACCEPT_OFFICIAL_TOS environment variable to proceed." - @exit -1 -endif - $(eval $(call rule_for, \ AS, %.o, %.s, \ $$(CC) $$(SFLAGS) -c $$< -o $$@ \ @@ -22,12 +11,34 @@ $(eval $(call rule_for, \ with_local_version \ )) +$(eval $(call rule_for, \ + CPP, %, %.inc, \ + $$(CPP) -P $$< $$@ \ +)) + $(eval $(call rule_for, \ CXX, %.o, %.cpp, \ $$(CXX) $$(CXXFLAGS) $$(SFLAGS) -c $$< -o $$@, \ with_local_version \ )) +$(eval $(call rule_for, \ + DFUSE, %.dfu, %.elf, \ + $$(PYTHON) build/device/elf2dfu.py $$< $$@, \ + with_local_version \ +)) + +$(eval $(call rule_for, \ + OBJCOPY, %.hex, %.elf, \ + $$(OBJCOPY) -O ihex $$< $$@ \ +)) + +$(eval $(call rule_for, \ + OBJCOPY, %.bin, %.elf, \ + $$(OBJCOPY) -O binary $$< $$@, \ + with_local_version \ +)) + $(eval $(call rule_for, \ OCC, %.o, %.m, \ $$(CC) $$(CFLAGS) $$(SFLAGS) -c $$< -o $$@ \ @@ -39,8 +50,8 @@ $(eval $(call rule_for, \ )) $(eval $(call rule_for, \ - CPP, %, %.inc, \ - $$(CPP) -P $$< $$@ \ + WINDRES, %.o, %.rc, \ + $$(WINDRES) $$< -O coff -o $$@ \ )) ifdef EXE @@ -61,8 +72,3 @@ $(eval $(call rule_for, \ )) endif endif - -$(eval $(call rule_for, \ - WINDRES, %.o, %.rc, \ - $$(WINDRES) $$< -O coff -o $$@ \ -)) diff --git a/build/targets.device.mak b/build/targets.device.mak index 3a54b7554..3ad973562 100644 --- a/build/targets.device.mak +++ b/build/targets.device.mak @@ -3,23 +3,6 @@ include build/targets.device.$(MODEL).mak HANDY_TARGETS += flasher.light flasher.verbose bench.ram bench.flash HANDY_TARGETS_EXTENSIONS += dfu hex bin -$(eval $(call rule_for, \ - DFUSE, %.dfu, %.$$(EXE), \ - $$(PYTHON) build/device/elf2dfu.py $$< $$@, \ - with_local_version \ -)) - -$(eval $(call rule_for, \ - OBJCOPY, %.hex, %.$$(EXE), \ - $$(OBJCOPY) -O ihex $$< $$@ \ -)) - -$(eval $(call rule_for, \ - OBJCOPY, %.bin, %.$$(EXE), \ - $$(OBJCOPY) -O binary $$< $$@, \ - with_local_version \ -)) - .PHONY: %_size %_size: $(BUILD_DIR)/%.$(EXE) @echo "========= BUILD OUTPUT ========" @@ -47,16 +30,16 @@ openocd: # The flasher target is defined here because otherwise $(%_src) has not been # fully filled +flasher_src = $(ion_src) $(ion_device_flasher_src) $(liba_src) $(kandinsky_src) +$(BUILD_DIR)/flasher.light.$(EXE): $(call flavored_object_for,$(flasher_src),light usbxip) +$(BUILD_DIR)/flasher.verbose.$(EXE): $(call flavored_object_for,$(flasher_src),usbxip) $(BUILD_DIR)/flasher.%.$(EXE): LDFLAGS += -Lion/src/$(PLATFORM)/flasher $(BUILD_DIR)/flasher.%.$(EXE): LDSCRIPT = ion/src/$(PLATFORM)/shared/ram.ld -flasher_base_src = $(ion_xip_src) $(liba_src) $(kandinsky_src) -$(BUILD_DIR)/flasher.light.$(EXE): $(call object_for,$(flasher_base_src) $(ion_target_device_flasher_light_src)) -$(BUILD_DIR)/flasher.verbose.$(EXE): $(call object_for,$(flasher_base_src) $(ion_target_device_flasher_verbose_src)) #TODO Do not build all apps... Put elsewhere? +bench_src = $(ion_src) $(liba_src) $(kandinsky_src) $(poincare_src) $(libaxx_src) $(app_shared_src) $(ion_device_bench_src) +$(BUILD_DIR)/bench.ram.$(EXE): $(call flavored_object_for,$(bench_src),consoleuart usbxip) $(BUILD_DIR)/bench.ram.$(EXE): LDFLAGS += -Lion/src/$(PLATFORM)/bench $(BUILD_DIR)/bench.ram.$(EXE): LDSCRIPT = ion/src/$(PLATFORM)/shared/ram.ld +$(BUILD_DIR)/bench.flash.$(EXE): $(call flavored_object_for,$(bench_src),consoleuart usbxip) $(BUILD_DIR)/bench.flash.$(EXE): LDSCRIPT = ion/src/$(PLATFORM)/$(MODEL)/internal_flash.ld -bench_src = $(ion_xip_src) $(liba_src) $(kandinsky_src) $(poincare_src) $(libaxx_src) $(app_shared_src) $(ion_target_device_bench_src) -$(BUILD_DIR)/bench.ram.$(EXE): $(call object_for,$(bench_src)) -$(BUILD_DIR)/bench.flash.$(EXE): $(call object_for,$(bench_src)) diff --git a/build/targets.mak b/build/targets.mak index ca7b9d97c..cf77a3460 100644 --- a/build/targets.mak +++ b/build/targets.mak @@ -1,28 +1,8 @@ -# Define standard Epsilon targets -base_src = $(liba_src) $(kandinsky_src) $(escher_src) $(libaxx_src) $(poincare_src) $(python_src) - -epsilon_src = $(base_src) $(ion_default_src) $(apps_default_src) -epsilon_official_src = $(base_src) $(ion_default_src) $(apps_official_default_src) - -$(BUILD_DIR)/epsilon.$(EXE): $(call object_for,$(epsilon_src)) -$(BUILD_DIR)/epsilon.official.$(EXE): $(call object_for,$(epsilon_official_src)) -$(BUILD_DIR)/epsilon.onboarding.$(EXE): $(call object_for, $(base_src) $(ion_default_src) $(apps_onboarding_src)) -$(BUILD_DIR)/epsilon.official.onboarding.$(EXE): $(call object_for,$(base_src) $(ion_default_src) $(apps_official_onboarding_src)) -$(BUILD_DIR)/epsilon.onboarding.update.$(EXE): $(call object_for, $(base_src) $(ion_default_src) $(apps_onboarding_update_src)) -$(BUILD_DIR)/epsilon.official.onboarding.update.$(EXE): $(call object_for,$(base_src) $(ion_default_src) $(apps_official_onboarding_update_src)) -$(BUILD_DIR)/epsilon.onboarding.beta.$(EXE): $(call object_for, $(base_src) $(ion_default_src) $(apps_onboarding_beta_src)) -$(BUILD_DIR)/epsilon.official.onboarding.beta.$(EXE): $(call object_for,$(base_src) $(ion_default_src) $(apps_official_onboarding_beta_src)) - -test_base_src = $(base_src) $(apps_tests_src) $(runner_src) $(tests_src) - -test_runner_src = $(test_base_src) $(ion_console_on_screen_src) -$(BUILD_DIR)/test.$(EXE): $(call object_for,$(test_runner_src)) - # Define handy targets # Those can be built easily by simply invoking "make target.ext". The named file # will be built in $(BUILD_DIR). -HANDY_TARGETS += epsilon epsilon.official epsilon.onboarding epsilon.official.onboarding epsilon.onboarding.update epsilon.official.onboarding.update epsilon.onboarding.beta epsilon.official.onboarding.beta test +HANDY_TARGETS += HANDY_TARGETS_EXTENSIONS += $(EXE) define handy_target_rule @@ -30,10 +10,70 @@ define handy_target_rule $(1).$(2): $$(BUILD_DIR)/$(1).$(2) endef +# Epsilon base target + +base_src = $(ion_src) $(liba_src) $(kandinsky_src) $(escher_src) $(libaxx_src) $(poincare_src) $(python_src) + +epsilon_src = $(base_src) $(apps_src) + +$(BUILD_DIR)/epsilon.$(EXE): $(call flavored_object_for,$(epsilon_src)) + +HANDY_TARGETS += epsilon + +# Epsilon flavored targets + +epsilon_flavors = \ + onboarding \ + onboarding.update \ + onboarding.beta + +define rule_for_epsilon_flavor +$$(BUILD_DIR)/epsilon.$(1).$$(EXE): $$(call flavored_object_for,$$(epsilon_src),$(1)) +endef + +$(foreach flavor,$(epsilon_flavors),$(eval $(call rule_for_epsilon_flavor,$(flavor)))) + +HANDY_TARGETS += $(foreach flavor,$(epsilon_flavors),epsilon.$(flavor)) + +# Epsilon official targets + +epsilon_official_flavors = \ + official \ + official.onboarding \ + official.onboarding.update \ + official.onboarding.beta + +define rule_for_unconfirmed_official_flavor +$$(BUILD_DIR)/epsilon.$(1).$$(EXE): + @echo "CAUTION: You are trying to build an official NumWorks firmware." + @echo "Distribution of such firmware by a third party is prohibited." + @echo "Please set the ACCEPT_OFFICIAL_TOS environment variable to proceed." + @exit -1 +endef + +ifeq ($(ACCEPT_OFFICIAL_TOS),1) +rule_for_official_epsilon_flavor = rule_for_epsilon_flavor +else +rule_for_official_epsilon_flavor = rule_for_unconfirmed_official_flavor +endif + +$(foreach flavor,$(epsilon_official_flavors),$(eval $(call $(rule_for_official_epsilon_flavor),$(flavor)))) + +HANDY_TARGETS += $(foreach flavor,$(epsilon_official_flavors),epsilon.$(flavor)) + +# Test + +test_runner_src = $(base_src) $(apps_tests_src) $(runner_src) $(tests_src) + +$(BUILD_DIR)/test.$(EXE): $(call flavored_object_for,$(test_runner_src),consoledisplay) + +HANDY_TARGETS += test + # Load platform-specific targets # We include them before the standard ones to give them precedence. -include build/targets.$(PLATFORM).mak +# Generate handy targets rules $(foreach extension,$(HANDY_TARGETS_EXTENSIONS),$(foreach executable,$(HANDY_TARGETS),$(eval $(call handy_target_rule,$(executable),$(extension))))) include build/targets.all.mak diff --git a/build/targets.simulator.mak b/build/targets.simulator.mak index 1d6573daf..942822600 100644 --- a/build/targets.simulator.mak +++ b/build/targets.simulator.mak @@ -1,10 +1,10 @@ # Headless targets -epsilon_headless_src = $(base_src) $(ion_headless_src) $(apps_default_src) -$(BUILD_DIR)/epsilon.headless.$(EXE): $(call object_for,$(epsilon_headless_src)) +$(eval $(call rule_for_epsilon_flavor,headless)) -test_runner_headless_src = $(test_base_src) $(ion_headless_src) -$(BUILD_DIR)/test.headless.$(EXE): $(call object_for,$(test_runner_headless_src)) +HANDY_TARGETS += epsilon.headless -HANDY_TARGETS += epsilon.headless test.headless +$(BUILD_DIR)/test.headless.$(EXE): $(call flavored_object_for,$(test_runner_src),headless) + +HANDY_TARGETS += test.headless -include build/targets.simulator.$(TARGET).mak diff --git a/build/variants.mak b/build/variants.mak new file mode 100644 index 000000000..9ac18566e --- /dev/null +++ b/build/variants.mak @@ -0,0 +1,63 @@ +# Helper functions to work with variants +# Make variants_test for an example + +define available_variants_in +$(sort $(patsubst +%,%,$(filter +%,$(subst :, ,$(1))))) +endef + +define without_any_variant_specifier +$(filter-out $(foreach variant,$(call available_variants_in,$(1)),%:-$(variant) %:+$(variant)),$(1)) +endef + +define with_variant_specifier_matching +$(foreach variant,$(3),$(patsubst %:$(1)$(variant),%,$(filter %:$(1)$(variant),$(2)))) +endef + +define without_any_variant_specifier_matching +$(filter-out \ + $(call with_variant_specifier_matching,$(1),$(2),$(3)), \ + $(foreach variant,$(call available_variants_in,$(2)),$(call with_variant_specifier_matching,$(1),$(2),$(variant))) \ +) +endef + +# Return files in $(1) that match the variant $(2) +define filter_variants +$(sort \ + $(call without_any_variant_specifier,$(1)) \ + $(call with_variant_specifier_matching,+,$(1),$(2)) \ + $(call without_any_variant_specifier_matching,-,$(1),$(2)) \ +) +endef + +# Return all files in $(1) no matter their variant +define any_variant +$(sort $(filter-out -%,$(filter-out +%,$(subst :, ,$(1))))) +endef + +# Examples + +variants_test_src = base.cpp +variants_test_src += color/green.cpp:+green +variants_test_src += color/red.cpp:+red +variants_test_src += color/blue.cpp:-red +variants_test_src += color/blue.cpp:-green +variants_test_src += engine/fast.cpp:+nitro +variants_test_src += engine/slow.cpp:-nitro + +.PHONY: variants_test +variants_test: + $(info AVAILABLE_VARIANTS_IN) + $(info --result: $(call available_variants_in,$(variants_test_src),)) + $(info --expected: green nitro red) + $(info FILTER_VARIANTS) + $(info --result: $(call filter_variants,$(variants_test_src),)) + $(info --expected: base.cpp color/blue.cpp engine/slow.cpp) + $(info FILTER_VARIANTS red) + $(info --result: $(call filter_variants,$(variants_test_src),red)) + $(info --expected: base.cpp color/red.cpp engine/slow.cpp) + $(info FILTER_VARIANTS green speed) + $(info --result: $(call filter_variants,$(variants_test_src),green nitro)) + $(info --expected: base.cpp color/green.cpp engine/fast.cpp) + $(info ANY_VARIANT) + $(info --result: $(call any_variant,$(variants_test_src))) + $(info --expected: base.cpp color/blue.cpp color/green.cpp color/red.cpp engine/fast.cpp engine/slow.cpp) diff --git a/ion/Makefile b/ion/Makefile index 7dc08544e..1c325ebc6 100644 --- a/ion/Makefile +++ b/ion/Makefile @@ -15,8 +15,6 @@ include ion/src/$(PLATFORM)/Makefile -include ion/test/$(PLATFORM)/Makefile include ion/src/shared/tools/Makefile -ion_console_display_src += ion/src/shared/console_display.cpp - # We need to work around a GCC bug (concerning versions < 5.1). It is valid in # C++11 to initialize a character array by providing a string litteral (e.g. # char test[4]= "ab"; is valid and should initialize test to 'a','b',0,0). @@ -25,10 +23,13 @@ initializer_list = $(shell echo $(1) | sed "s/\(.\)/'\1',/g")0 $(call object_for,ion/src/shared/platform_info.cpp): SFLAGS += -DPATCH_LEVEL="$(call initializer_list,$(PATCH_LEVEL))" -DEPSILON_VERSION="$(call initializer_list,$(EPSILON_VERSION))" ion_src += $(addprefix ion/src/shared/, \ + console_display.cpp:+consoledisplay \ console_line.cpp \ crc32_eat_byte.cpp \ decompress.cpp \ events.cpp \ + events_keyboard.cpp \ + events_modifier.cpp \ platform_info.cpp \ storage.cpp \ unicode/utf8_decoder.cpp\ @@ -49,14 +50,3 @@ tests_src += $(addprefix ion/test/,\ ifdef ION_STORAGE_LOG SFLAGS += -DION_STORAGE_LOG=1 endif - -# Configure variants -ion_all_src = $(ion_src) -ion_all_src += $(ion_simulator_sdl_src) $(ion_simulator_headless_src) -ion_all_src += $(ion_device_dfu_relocated_src) $(ion_device_dfu_xip_src) -ion_all_src += $(ion_console_display_src) $(ion_console_stdio_src) $(ion_console_uart_src) - -ion_default_src = $(ion_src) $(ion_simulator_sdl_src) $(ion_device_dfu_relocated_src) $(ion_console_stdio_src) -ion_console_on_screen_src = $(ion_src) $(ion_simulator_sdl_src) $(ion_device_dfu_relocated_src) $(ion_console_display_src) -ion_xip_src = $(ion_src) $(ion_simulator_sdl_src) $(ion_device_dfu_xip_src) $(ion_console_uart_src) -ion_headless_src = $(ion_src) $(ion_simulator_headless_src) $(ion_device_dfu_relocated_src) $(ion_console_stdio_src) diff --git a/ion/src/device/Makefile b/ion/src/device/Makefile index 56d222ecc..4a3a96426 100644 --- a/ion/src/device/Makefile +++ b/ion/src/device/Makefile @@ -6,22 +6,12 @@ include ion/src/device/$(MODEL)/Makefile $(call object_for,ion/src/shared/platform_info.cpp): SFLAGS += -DHEADER_SECTION="__attribute__((section(\".header\")))" -ion_src += $(addprefix ion/src/shared/, \ - console_line.cpp \ - events_keyboard.cpp \ - events_modifier.cpp \ -) - ifeq ($(EPSILON_TELEMETRY),1) ion_src += ion/src/shared/telemetry_console.cpp endif -# If you need to benchmark execution, you can replace events_keyboard with -# events_benchmark. -# If you need to profile execution, you can replace events_keyboard with -# events_replay.o and dummy/events_modifier.o - ION_DEVICE_SFLAGS = -Iion/src/device/$(MODEL) -Iion/src/device/shared -$(call object_for,$(sort $(ion_device_src) $(dfu_src) $(ion_target_device_flasher_light_src) $(ion_target_device_flasher_verbose_src) $(usb_src) $(ion_target_device_bench_src) $(ion_device_dfu_xip_src) $(ion_device_dfu_relocated_src) $(ion_console_uart_src))): SFLAGS += $(ION_DEVICE_SFLAGS) +$(call object_for,$(ion_device_src) $(ion_device_flasher_src) $(ion_device_bench_src)): SFLAGS += $(ION_DEVICE_SFLAGS) + ion_src += $(ion_device_src) diff --git a/ion/src/device/bench/Makefile b/ion/src/device/bench/Makefile index be49a87f2..523883299 100644 --- a/ion/src/device/bench/Makefile +++ b/ion/src/device/bench/Makefile @@ -1,11 +1,11 @@ -ion_target_device_bench_src += $(addprefix ion/src/device/bench/, \ +ion_device_bench_src += $(addprefix ion/src/device/bench/, \ bench.cpp \ command_handler.cpp \ command_list.cpp \ runner.cpp \ ) -ion_target_device_bench_src += $(addprefix ion/src/device/bench/command/, \ +ion_device_bench_src += $(addprefix ion/src/device/bench/command/, \ adc.cpp \ backlight.cpp \ charge.cpp \ diff --git a/ion/src/device/flasher/Makefile b/ion/src/device/flasher/Makefile index 840b63d2c..c9164faee 100644 --- a/ion/src/device/flasher/Makefile +++ b/ion/src/device/flasher/Makefile @@ -1,9 +1,5 @@ -ion_target_device_flasher_light_src = $(addprefix ion/src/device/flasher/, \ +ion_device_flasher_src = $(addprefix ion/src/device/flasher/, \ main.cpp \ - display_light.cpp \ -) - -ion_target_device_flasher_verbose_src = $(addprefix ion/src/device/flasher/, \ - main.cpp \ - display_verbose.cpp \ + display_light.cpp:+light \ + display_verbose.cpp:-light \ ) diff --git a/ion/src/device/shared/drivers/Makefile b/ion/src/device/shared/drivers/Makefile index ea02cce02..386b519dd 100644 --- a/ion/src/device/shared/drivers/Makefile +++ b/ion/src/device/shared/drivers/Makefile @@ -3,6 +3,8 @@ ion_device_src += $(addprefix ion/src/device/shared/drivers/, \ battery.cpp \ base64.cpp \ board.cpp \ + console.cpp:+consoleuart \ + console_dummy.cpp:-consoleuart \ crc32.cpp \ display.cpp \ events_keyboard_platform.cpp \ @@ -21,7 +23,3 @@ ion_device_src += $(addprefix ion/src/device/shared/drivers/, \ usb.cpp \ wakeup.cpp \ ) - -ion_console_uart_src = ion/src/device/shared/drivers/console.cpp -ion_console_stdio_src += ion/src/device/shared/drivers/console_dummy.cpp -ion_console_display_src += ion/src/device/shared/drivers/console_dummy.cpp diff --git a/ion/src/device/shared/usb/Makefile b/ion/src/device/shared/usb/Makefile index df9d1f6c2..21c46dcbe 100644 --- a/ion/src/device/shared/usb/Makefile +++ b/ion/src/device/shared/usb/Makefile @@ -1,9 +1,11 @@ -usb_src += $(addprefix ion/src/device/shared/usb/, \ +# USB code + +ion_device_usb_src += $(addprefix ion/src/device/shared/usb/, \ calculator.cpp \ dfu_interface.cpp\ ) -usb_src += $(addprefix ion/src/device/shared/usb/stack/, \ +ion_device_usb_src += $(addprefix ion/src/device/shared/usb/stack/, \ device.cpp\ endpoint0.cpp \ interface.cpp\ @@ -12,7 +14,7 @@ usb_src += $(addprefix ion/src/device/shared/usb/stack/, \ streamable.cpp\ ) -usb_src += $(addprefix ion/src/device/shared/usb/stack/descriptor/, \ +ion_device_usb_src += $(addprefix ion/src/device/shared/usb/stack/descriptor/, \ bos_descriptor.cpp\ configuration_descriptor.cpp \ descriptor.cpp\ @@ -29,22 +31,19 @@ usb_src += $(addprefix ion/src/device/shared/usb/stack/descriptor/, \ webusb_platform_descriptor.cpp\ ) -# Sources required to execute DFU in place -ion_device_dfu_xip_src += ion/src/device/shared/usb/dfu_xip.cpp -ion_device_dfu_xip_src += $(usb_src) +# DFU code -# Sources required to execute DFU in RAM -dfu_src += liba/src/assert.c -dfu_src += liba/src/strlen.c -dfu_src += liba/src/strlcpy.c -dfu_src += liba/src/memset.c -dfu_src += liba/src/memcpy.c -dfu_src += libaxx/src/cxxabi/pure_virtual.cpp -dfu_src += ion/src/device/shared/usb/boot.cpp -dfu_src += ion/src/device/$(MODEL)/drivers/board.cpp -dfu_src += ion/src/device/$(MODEL)/drivers/cache.cpp -dfu_src += ion/src/device/$(MODEL)/drivers/reset.cpp -dfu_src += $(addprefix ion/src/device/shared/drivers/, \ +ion_device_dfu_src += liba/src/assert.c +ion_device_dfu_src += liba/src/strlen.c +ion_device_dfu_src += liba/src/strlcpy.c +ion_device_dfu_src += liba/src/memset.c +ion_device_dfu_src += liba/src/memcpy.c +ion_device_dfu_src += libaxx/src/cxxabi/pure_virtual.cpp +ion_device_dfu_src += ion/src/device/shared/usb/boot.cpp +ion_device_dfu_src += ion/src/device/$(MODEL)/drivers/board.cpp +ion_device_dfu_src += ion/src/device/$(MODEL)/drivers/cache.cpp +ion_device_dfu_src += ion/src/device/$(MODEL)/drivers/reset.cpp +ion_device_dfu_src += $(addprefix ion/src/device/shared/drivers/, \ backlight.cpp \ battery.cpp \ base64.cpp \ @@ -68,8 +67,14 @@ dfu_src += $(addprefix ion/src/device/shared/drivers/, \ wakeup.cpp \ ) +# Sources required to execute DFU in place +ion_device_src += ion/src/device/shared/usb/dfu_xip.cpp:+usbxip +ion_device_src += $(addsuffix :+usbxip,$(ion_device_usb_src)) + +# Sources required to execute DFU in RAM + $(BUILD_DIR)/ion/src/device/shared/usb/dfu.elf: LDSCRIPT = ion/src/device/shared/usb/dfu.ld -$(BUILD_DIR)/ion/src/device/shared/usb/dfu.elf: $(call object_for,$(usb_src) $(dfu_src)) +$(BUILD_DIR)/ion/src/device/shared/usb/dfu.elf: $(call object_for,$(ion_device_usb_src) $(ion_device_dfu_src)) # In order to link the dfu bootloader inside the epsilon firmware, we need to # turn the dfu binary (dfu.bin) into an elf object. @@ -83,5 +88,5 @@ $(BUILD_DIR)/ion/src/device/shared/usb/dfu.o: $(BUILD_DIR)/ion/src/device/shared $(call rule_label,OBJCOPY) $(Q) cd $(dir $<) ; $(OBJCOPY) -I binary -O elf32-littlearm -B arm --rename-section .data=.rodata.dfu_bootloader --redefine-sym _binary_dfu_bin_start=_dfu_bootloader_flash_start --redefine-sym _binary_dfu_bin_end=_dfu_bootloader_flash_end $(notdir $<) $(notdir $@) -ion_device_dfu_relocated_src += ion/src/device/shared/usb/dfu.cpp -ion_device_dfu_relocated_src += ion/src/device/shared/usb/dfu_relocated.cpp +ion_device_src += ion/src/device/shared/usb/dfu.cpp:-usbxip +ion_device_src += ion/src/device/shared/usb/dfu_relocated.cpp:-usbxip diff --git a/ion/src/simulator/Makefile b/ion/src/simulator/Makefile index 74ae93666..a0b4645fb 100644 --- a/ion/src/simulator/Makefile +++ b/ion/src/simulator/Makefile @@ -1,9 +1,5 @@ -# TODO ion_src += $(addprefix ion/src/shared/, \ crc32.cpp \ - events.cpp \ - events_keyboard.cpp \ - events_modifier.cpp \ power.cpp \ random.cpp \ timing.cpp \ @@ -18,24 +14,19 @@ ion_src += $(addprefix ion/src/shared/, \ dummy/usb.cpp \ ) -ion_simulator_sdl_src += $(addprefix ion/src/simulator/shared/, \ - display.cpp \ - events_keyboard.cpp \ +ion_src += $(addprefix ion/src/simulator/shared/, \ + console_stdio.cpp:-consoledisplay \ + display.cpp:-headless \ + events_keyboard.cpp:-headless \ + events_stdin.cpp:+headless \ framebuffer_base.cpp \ - keyboard_sdl.cpp \ - main_sdl.cpp \ - layout.cpp \ + framebuffer_png.cpp:+headless \ + keyboard_dummy.cpp:+headless \ + keyboard_sdl.cpp:-headless \ + layout.cpp:-headless \ + main_headless.cpp:+headless \ + main_sdl.cpp:-headless \ ) -ion_simulator_headless_src += $(addprefix ion/src/simulator/shared/, \ - events_stdin.cpp \ - framebuffer_base.cpp \ - framebuffer_png.cpp \ - keyboard_dummy.cpp \ - main_headless.cpp \ -) - -ion_console_stdio_src = ion/src/simulator/shared/console_stdio.cpp - include ion/src/simulator/$(TARGET)/Makefile include ion/src/simulator/external/Makefile