-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathatom.mk
More file actions
146 lines (117 loc) · 5.49 KB
/
atom.mk
File metadata and controls
146 lines (117 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_HOST_MODULE := mavgen
mavgen_files := \
$(call all-files-under,pymavlink,.py) \
$(call all-files-under,pymavlink,.xsd) \
$(call all-files-under,pymavlink,.h) \
$(call all-files-under,message_definitions,.xml)
# Install files in host staging directory
LOCAL_COPY_FILES := \
$(foreach __f,$(mavgen_files), \
$(__f):$(HOST_OUT_STAGING)/usr/lib/mavgen/$(__f) \
)
# Needed to force a build order of LOCAL_COPY_FILES
LOCAL_EXPORT_PREREQUISITES := \
$(foreach __f,$(mavgen_files), \
$(HOST_OUT_STAGING)/usr/lib/mavgen/$(__f) \
)
include $(BUILD_CUSTOM)
###############################################################################
## Custom macro that can be used in LOCAL_CUSTOM_MACROS of a module to
## create automatically rules to generate files from xml.
## Note : in the context of the macro, LOCAL_XXX variables refer to the module
## that use the macro, not this module defining the macro.
## As the content of the macro is 'eval' after, most of variable ref shall be
## escaped (hence the $$). Only $1, $2... variables can be used directly.
## Note : no 'global' variable shall be used except the ones defined by
## alchemy (TARGET_XXX and HOST_XXX variables). Otherwise the macro will no
## work when integrated in a SDK (using local-register-custom-macro).
## Note : rules should NOT use any variables defined in the context of the
## macro (for the same reason PRIVATE_XXX variables shall be used in place of
## LOCAL_XXX variables).
## Note : if you need a script or a binary, please install it in host staging
## directory and execute it from there. This way it will also work in the
## context of a SDK.
###############################################################################
# Before mavgen is installed, we need it during makefile parsing phase
# We define this variable to find it in $(LOCAL_PATH) if not found yet in
# host staging directory
mavgen-macro-path := $(LOCAL_PATH)
# $1: language (C)
# $2: output directory (Relative to build directory unless an absolute path is
# given (ex LOCAL_PATH).
# $3: input xml file
define mavgen-macro
# Setup some internal variables
mavgen_xml_file := $3
mavgen_module_build_dir := $(call local-get-build-dir)
mavgen_out_dir := $(if $(call is-path-absolute,$2),$2,$$(mavgen_module_build_dir)/$2)
mavgen_done_file := $$(mavgen_module_build_dir)/$$(notdir $$(mavgen_xml_file)).done
mavgen_dep_file := $$(mavgen_module_build_dir)/$$(notdir $$(mavgen_xml_file)).d
# Actual generation rule
# The copy of xml is staging is done in 2 steps because several modules could use
# the same xml the move ensure atomicity of the copy.
$$(mavgen_done_file): PRIVATE_OUT_DIR := $$(mavgen_out_dir)/mavlink
$$(mavgen_done_file): PRIVATE_DEP_FILE := $$(mavgen_dep_file)
$$(mavgen_done_file): $$(mavgen_xml_file)
@echo "$$(PRIVATE_MODULE): Generating mavlink files from $$(call path-from-top,$3)"
$(Q) cd $(HOST_OUT_STAGING)/usr/lib/mavgen && python -m pymavlink.tools.mavgen \
--lang $1 -o $$(PRIVATE_OUT_DIR) $3
@mkdir -p $(TARGET_OUT_STAGING)/usr/share/mavlink
$(Q) cp -af $3 $(TARGET_OUT_STAGING)/usr/share/mavlink/$(notdir $3).$$(PRIVATE_MODULE)
$(Q) mv -f $(TARGET_OUT_STAGING)/usr/share/mavlink/$(notdir $3).$$(PRIVATE_MODULE) \
$(TARGET_OUT_STAGING)/usr/share/mavlink/$(notdir $3)
@mkdir -p $$(dir $$@)
@:>$$(PRIVATE_DEP_FILE)
@for header in $$$$(find $$(PRIVATE_OUT_DIR) -name '*.h'); do \
echo "$$$${header}: $$@" >> $$(PRIVATE_DEP_FILE); \
echo -e "\t@:" >> $$(PRIVATE_DEP_FILE); \
done
@touch $$@
@mkdir -p $(TARGET_OUT_BUILD)/mavlink/wireshark/plugins
$(Q) cd $(HOST_OUT_STAGING)/usr/lib/mavgen && python -m pymavlink.tools.mavgen --lang=WLua \
-o $(TARGET_OUT_BUILD)/mavlink/wireshark/plugins/mymavlink.lua $3
-include $$(mavgen_dep_file)
# Update alchemy variables for the module
LOCAL_CLEAN_FILES += $$(mavgen_done_file) $$(mavgen_dep_file)
LOCAL_EXPORT_PREREQUISITES += $$(mavgen_done_file)
LOCAL_CUSTOM_TARGETS += $$(mavgen_done_file)
LOCAL_DEPENDS_HOST_MODULES += host.mavgen
LOCAL_C_INCLUDES += $$(mavgen_out_dir)
endef
# Register the macro in alchemy
$(call local-register-custom-macro,mavgen-macro)
include $(CLEAR_VARS)
LOCAL_MODULE := apm-mavlink-ardupilotmega
LOCAL_MODULE_FILENAME := $(LOCAL_MODULE).done
LOCAL_DESCRIPTION := Mavlink generated files for boards using the ardupilotmega\
messages definition
LOCAL_CATEGORY_PATH := apm
MAVLINK_APM_ARDUPILOTMEGA_BUILD_DIR := $(call local-get-build-dir)
LOCAL_EXPORT_C_INCLUDES := \
$(MAVLINK_APM_ARDUPILOTMEGA_BUILD_DIR) \
$(MAVLINK_APM_ARDUPILOTMEGA_BUILD_DIR)/GCS_MAVLink/
# Make sure the -C parameter come after
# $(LINUX_MAKE_ARGS) to override default value
$(MAVLINK_APM_ARDUPILOTMEGA_BUILD_DIR)/$(LOCAL_MODULE_FILENAME):$(LOCAL_PATH)/message_definitions/v1.0/ardupilotmega.xml
@echo "Generating mavlink files for APM:plane ardupilotmega"
$(Q) PYTHONPATH=$(PRIVATE_PATH) python \
$(PRIVATE_PATH)/pymavlink/tools/mavgen.py --lang=C \
--wire-protocol=2.0 \
--output=$(MAVLINK_APM_ARDUPILOTMEGA_BUILD_DIR)/GCS_MAVLink/include/mavlink/v2.0/ \
$<
@touch $@
include $(BUILD_CUSTOM)
include $(CLEAR_VARS)
LOCAL_MODULE := mavlink-parrot
LOCAL_MODULE_FILENAME := $(LOCAL_MODULE).done
LOCAL_DESCRIPTION := Mavlink generated files for Parrot drones
LOCAL_CATEGORY_PATH := libs
# the two following lines are for generating mavlink C headers
LOCAL_CUSTOM_MACROS := \
mavgen-macro:C,generated,$(LOCAL_PATH)/message_definitions/v1.0/parrot.xml
# export mavlink messages
LOCAL_EXPORT_C_INCLUDES += \
$(call local-get-build-dir)/generated
include $(BUILD_CUSTOM)