Skip to content

Commit 47a97dc

Browse files
committed
[build] Keep top-level script in cwd with different outpath
1 parent 61847ae commit 47a97dc

File tree

13 files changed

+92
-72
lines changed

13 files changed

+92
-72
lines changed

examples/nucleo_f103rb/blink/project.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
<options>
44
<option name="modm:build:build.path">../../../build/nucleo_f103rb/blink</option>
55
</options>
6+
<!-- This just tests the lbuild outpath, don't copy this! -->
7+
<outpath>../generated/blink</outpath>
68
<modules>
79
<module>modm:build:scons</module>
10+
<module>modm:build:make</module>
811
<module>modm:processing:timer</module>
912
</modules>
1013
</library>

repo.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ from os.path import normpath
2424

2525
# Check for miminum required lbuild version
2626
import lbuild
27-
min_lbuild_version = "1.17.0"
27+
min_lbuild_version = "1.20.0"
2828
if StrictVersion(getattr(lbuild, "__version__", "0.1.0")) < StrictVersion(min_lbuild_version):
2929
print("modm requires at least lbuild v{}, please upgrade!\n"
3030
" pip3 install -U lbuild".format(min_lbuild_version))

src/modm/platform/core/avr/module.lb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def build(env):
3535

3636
env.outbasepath = "modm/link"
3737
env.copy("linkerscript.ld")
38-
env.collect(":build:linkflags", "-L{project_source_dir}", "-Tmodm/link/linkerscript.ld")
38+
env.collect(":build:linkflags", "-L{project_source_dir}",
39+
"-T{}".format(env.relcwdoutpath("modm/link/linkerscript.ld")))
3940

4041
env.substitutions = {
4142
"target": target.identifier,

src/modm/platform/core/cortex/module.lb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,9 @@ def build(env):
343343

344344
env.collect(":build:linkflags", "-Wl,--no-wchar-size-warning", "-L{project_source_dir}")
345345
# Linkerscript
346-
linkerscript_override_option = env["linkerscript.override"]
347-
if linkerscript_override_option:
348-
env.collect(":build:linkflags", "-T{}".format(linkerscript_override_option))
349-
else:
350-
env.collect(":build:linkflags", "-Tmodm/link/linkerscript.ld")
346+
linkerscript = env["linkerscript.override"]
347+
env.collect(":build:linkflags", "-T{}".format(env.relcwdoutpath(
348+
linkerscript if linkerscript else "modm/link/linkerscript.ld")))
351349

352350
# Compilation for FPU
353351
core = env[":target"].get_driver("core")["type"]

test/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
# License, v. 2.0. If a copy of the MPL was not distributed with this
1010
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
1111

12-
# LBUILD = python3 ../../library-builder/scripts/lbuild
13-
# LBUILD = lbuild
12+
# LBUILD = python3 ../../lbuild
1413
LBUILD = $(shell which lbuild)
1514
# SCONS = python3 `which scons`
1615
SCONS = scons
1716

1817
define compile-test
1918
@$(RM) -r ../build/generated-unittest/$(1)
20-
$(LBUILD) -c config/$(1).xml $(3) -p ../build/generated-unittest/$(1) build --no-log
19+
$(LBUILD) -p ../build/generated-unittest/$(1) -c config/$(1).xml $(3) \
20+
-C ../build/generated-unittest/$(1) build --no-log
2121
$(SCONS) -C ../build/generated-unittest/$(1) $(2)
2222
endef
2323
define run-test

test/all/run_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def run(self):
145145

146146
lbuild_command += ["-D:target={}".format(self.device),
147147
"-D:build:build.path={}/build".format(tempdir),
148-
"-p", str(tempdir),
148+
"-p", str(tempdir), "-C", str(tempdir),
149149
"build",
150150
"--no-log"]
151151

tools/build_script_generator/make/module.lb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,21 @@ def post_build(env):
5656
subs["memories"] = []
5757
# Add SCons specific data
5858
linkerscript = env.get(":platform:cortex-m:linkerscript.override")
59-
linkerscript = env.relative_outpath(linkerscript) if linkerscript \
59+
linkerscript = linkerscript if linkerscript \
6060
else "modm/link/linkerscript.ld"
6161
subs.update({
62-
"build_path": env.relative_outpath(env["::build.path"]),
63-
"generated_paths": repositories,
62+
"build_path": env.relcwdoutpath(env["::build.path"]),
63+
"modm_path": env.relcwdoutpath("modm"),
64+
"outpath": env.relcwdoutpath(""),
65+
"repositories": repositories,
6466
"linkerscript": linkerscript,
6567
"is_unittest": is_unittest,
6668
"program_extension": "exe" if env[":target"].identifier.family == "windows" else "elf",
6769
})
6870
if is_unittest:
69-
subs["unittest_source"] = env.relative_outpath(env["::unittest.source"])
71+
subs["unittest_source"] = env.relcwdoutpath(env["::unittest.source"])
7072
if len(env["::image.source"]):
71-
subs["image_source"] = env.relative_outpath(env["::image.source"])
73+
subs["image_source"] = env.relcwdoutpath(env["::image.source"])
7274
if subs["platform"] == "avr":
7375
subs.update(env.query("::avrdude_options"))
7476
if subs["platform"] == "sam":
@@ -83,6 +85,8 @@ def post_build(env):
8385
nflag = fmt(flag)
8486
if nflag: return nflag;
8587
return flag
88+
def relocate(path):
89+
return env.relcwdoutpath(path).replace(subs["modm_path"], "$(MODM_PATH)")
8690

8791
for repo in repositories:
8892
files = []
@@ -115,17 +119,17 @@ def post_build(env):
115119
# Generate library SConscript
116120
env.outbasepath = repo
117121
env.template("resources/repo.mk.in", "repo.mk",
118-
filters={"flags_format": flags_format,
122+
filters={"flags_format": flags_format, "relocate": relocate,
119123
"objectify": lambda f: f.rsplit(".", 1)[0]+".o"})
120124

121125
env.outbasepath = "modm"
122-
env.template("resources/config.mk.in", "config.mk")
126+
env.template("resources/config.mk.in", "config.mk", filters={"relocate": relocate})
123127
env.template("resources/compiler.mk.in", "compiler.mk")
124128

125129
# these are the ONLY files that are allowed to NOT be namespaced with modm!
126-
env.outbasepath = "."
130+
env.outbasepath = env.cwdpath(".")
127131
if env["include_makefile"]:
128-
env.template("resources/Makefile.in", "Makefile")
132+
env.template("resources/Makefile.in", "Makefile", filters={"relocate": relocate})
129133

130134

131135
# ============================ Option Descriptions ============================

tools/build_script_generator/make/resources/Makefile.in

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@
2121
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2222
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2323

24+
MODM_PATH := {{modm_path}}
2425
%% if is_unittest
2526
unittest_runner.cpp:
26-
@python3 modm/modm_tools/unit_test.py {{ unittest_source }}
27+
@python3 $(MODM_PATH)/modm_tools/unit_test.py {{ unittest_source }}
2728
APP_SRC := unittest_runner.cpp
2829
%% else
2930
APP_SRC := $(shell find . -type f \( -name '*.c' -o -iname '*.s' -o -name '*.sx' \
3031
-o -name '*.cpp' -o -name '*.cxx' -o -name '*.c++' -o -name '*.cc' \) )
3132
%% endif
3233
%#
33-
include modm/config.mk
34-
%% for path in generated_paths
35-
include {{path}}/repo.mk
34+
include $(MODM_PATH)/config.mk
35+
%% for repo in repositories
36+
include {{ repo | relocate }}/repo.mk
3637
%% endfor
3738
%#
3839
%% if platform == "hosted"
@@ -73,14 +74,14 @@ size: build
7374
port?=auto
7475
.PHONY: program
7576
program: build
76-
@python3 modm/modm_tools/avrdude.py -p $(CONFIG_AVRDUDE_DEVICE) \
77+
@python3 $(MODM_PATH)/modm_tools/avrdude.py -p $(CONFIG_AVRDUDE_DEVICE) \
7778
$(CONFIG_AVRDUDE_PROGRAMMER) $(CONFIG_AVRDUDE_OPTIONS) \
7879
-P $(if $(CONFIG_AVRDUDE_PORT),$(CONFIG_AVRDUDE_PORT),$(port)) \
7980
$(CONFIG_AVRDUDE_BAUDRATE) $(ELF_FILE)
8081

8182
.PHONY: program-fuses
8283
program-fuses: build
83-
@python3 modm/modm_tools/avrdude.py -p $(CONFIG_AVRDUDE_DEVICE) \
84+
@python3 $(MODM_PATH)/modm_tools/avrdude.py -p $(CONFIG_AVRDUDE_DEVICE) \
8485
$(CONFIG_AVRDUDE_PROGRAMMER) $(CONFIG_AVRDUDE_OPTIONS) \
8586
-P $(if $(CONFIG_AVRDUDE_PORT),$(CONFIG_AVRDUDE_PORT),$(port)) \
8687
$(CONFIG_AVRDUDE_BAUDRATE) $(ELF_FILE) \
@@ -90,17 +91,17 @@ program-fuses: build
9091
.PHONY: size
9192
size: build
9293
@echo "Memory usage···" $(ELF_FILE)
93-
@python3 modm/modm_tools/size.py $(ELF_FILE) $(CONFIG_DEVICE_MEMORY)
94+
@python3 $(MODM_PATH)/modm_tools/size.py $(ELF_FILE) $(CONFIG_DEVICE_MEMORY)
9495

9596
port?=auto
9697
.PHONY: program
9798
program: build
98-
@python3 modm/modm_tools/openocd.py $(ELF_FILE) \
99+
@python3 $(MODM_PATH)/modm_tools/openocd.py $(ELF_FILE) \
99100
$(addprefix -f ,$(MODM_OPENOCD_CONFIGFILES))
100101

101102
.PHONY: program-bmp
102103
program-bmp: build
103-
@python3 modm/modm_tools/bmp.py -p $(port) $(ELF_FILE)
104+
@python3 $(MODM_PATH)/modm_tools/bmp.py -p $(port) $(ELF_FILE)
104105

105106
delay?=5
106107
.PHONY: program-dfu
@@ -110,49 +111,49 @@ program-dfu: bin
110111
%% if platform in ["sam"]
111112
.PHONY: program-bossac
112113
program-bossac: bin
113-
@python3 modm/modm_tools/bossac.py -p $(port) \
114+
@python3 $(MODM_PATH)/modm_tools/bossac.py -p $(port) \
114115
--offset $(if $($(MODM_BOSSAC_OFFSET) < 4096),4096,$(MODM_BOSSAC_OFFSET)) \
115116
$(MODM_BOSSAC_OPTIONS) $(BIN_FILE)
116117
%% endif
117118
%#
118119
.PHONY: reset
119120
reset:
120-
@python3 modm/modm_tools/openocd.py --reset \
121+
@python3 $(MODM_PATH)/modm_tools/openocd.py --reset \
121122
$(addprefix -f ,$(MODM_OPENOCD_CONFIGFILES))
122123

123124
.PHONY: reset-bmp
124125
reset-bmp:
125-
@python3 modm/modm_tools/bmp.py -p $(port) --reset
126+
@python3 $(MODM_PATH)/modm_tools/bmp.py -p $(port) --reset
126127

127128
ui?=tui
128129
.PHONY: debug
129130
debug: build
130-
@python3 modm/modm_tools/gdb.py $(addprefix -x ,$(MODM_GDBINIT)) \
131+
@python3 $(MODM_PATH)/modm_tools/gdb.py $(addprefix -x ,$(MODM_GDBINIT)) \
131132
$(addprefix -x ,$(MODM_OPENOCD_GDBINIT)) \
132133
$(ELF_FILE) --ui=$(ui) \
133134
openocd $(addprefix -f ,$(MODM_OPENOCD_CONFIGFILES))
134135

135136
.PHONY: debug-bmp
136137
debug-bmp: build
137-
@python3 modm/modm_tools/gdb.py $(addprefix -x ,$(MODM_GDBINIT)) \
138+
@python3 $(MODM_PATH)/modm_tools/gdb.py $(addprefix -x ,$(MODM_GDBINIT)) \
138139
$(ELF_FILE) --ui=$(ui) \
139140
bmp -p $(port)
140141

141142
coredump?=coredump.txt
142143
.PHONY: debug-coredump
143144
debug-coredump: build
144-
@python3 modm/modm_tools/gdb.py $(addprefix -x ,$(MODM_GDBINIT)) \
145+
@python3 $(MODM_PATH)/modm_tools/gdb.py $(addprefix -x ,$(MODM_GDBINIT)) \
145146
$(ELF_FILE) --ui=$(ui) \
146-
crashdebug --binary-path modm/ext/crashcatcher/bins \
147+
crashdebug --binary-path $(MODM_PATH)/ext/crashcatcher/bins \
147148
--dump $(coredump)
148149

149150
fcpu?=0
150151
.PHONY: log-itm
151152
log-itm:
152-
@python3 modm/modm_tools/log.py itm openocd -f modm/openocd.cfg --fcpu $(fcpu)
153+
@python3 $(MODM_PATH)/modm_tools/log.py itm openocd -f $(MODM_PATH)/openocd.cfg --fcpu $(fcpu)
153154

154155
channel?=0
155156
.PHONY: log-rtt
156157
log-rtt:
157-
@python3 modm/modm_tools/log.py rtt openocd -f modm/openocd.cfg --channel $(channel)
158+
@python3 $(MODM_PATH)/modm_tools/log.py rtt openocd -f $(MODM_PATH)/openocd.cfg --channel $(channel)
158159
%% endif

tools/build_script_generator/make/resources/config.mk.in

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ CONFIG_AVRDUDE_OPTIONS := {{ avrdude_options }}
3838
CONFIG_AVRDUDE_BAUDRATE := -b {{ avrdude_baudrate }}
3939
%% endif
4040
%% elif core.startswith("cortex-m")
41-
MODM_OPENOCD_CONFIGFILES += modm/openocd.cfg
42-
MODM_OPENOCD_GDBINIT += modm/openocd_gdbinit
43-
MODM_GDBINIT += modm/gdbinit
41+
MODM_OPENOCD_CONFIGFILES += $(MODM_PATH)/openocd.cfg
42+
MODM_OPENOCD_GDBINIT += $(MODM_PATH)/openocd_gdbinit
43+
MODM_GDBINIT += $(MODM_PATH)/gdbinit
4444
%% if platform == "sam"
4545
%% if bossac_offset
4646
MODM_BOSSAC_OFFSET := {{ bossac_offset }}
@@ -51,19 +51,19 @@ MODM_BOSSAC_OPTIONS := {{ bossac_options }}
5151
%% endif
5252
%% endif
5353
%#
54-
include modm/compiler.mk
54+
include $(MODM_PATH)/compiler.mk
5555

5656
# Application sources
5757
APP_SRC := $(APP_SRC:./%=%)
58-
%% for repo in generated_paths
59-
APP_SRC := $(filter-out {{repo}}/%,$(APP_SRC))
58+
%% for repo in repositories
59+
APP_SRC := $(filter-out {{ repo | relocate }}/%,$(APP_SRC))
6060
%% endfor
6161
CPPDEFINES += -I.
6262
%% if options["::info.git"] != "Disabled"
6363
%#
6464
# Git information
65-
INFO_GIT_FILE := modm/src/info_git.c
66-
$(INFO_GIT_FILE): $(shell python3 modm/modm_tools/info.py \
65+
INFO_GIT_FILE := $(MODM_PATH)/src/info_git.c
66+
$(INFO_GIT_FILE): $(shell python3 $(MODM_PATH)/modm_tools/info.py \
6767
-o $(INFO_GIT_FILE) -t {{ "git_status" if "Status" in options["::info.git"] else "git" }} --check-rebuild);
6868
APP_SRC += $(INFO_GIT_FILE)
6969
CLEAN_FILES += $(INFO_GIT_FILE)
@@ -72,9 +72,9 @@ CPPDEFINES += -DMODM_GIT_INFO{% if "Status" in options["::info.git"] %} -DMODM_G
7272
%% if options["::info.build"]
7373
%#
7474
# Build information
75-
INFO_BUILD_FILE := modm/src/info_build.c
75+
INFO_BUILD_FILE := $(MODM_PATH)/src/info_build.c
7676
$(INFO_BUILD_FILE):
77-
@python3 modm/modm_tools/info.py -o $(INFO_BUILD_FILE) -t build --compiler $(CC) \
77+
@python3 $(MODM_PATH)/modm_tools/info.py -o $(INFO_BUILD_FILE) -t build --compiler $(CC) \
7878
--additions MODM_BUILD_PROJECT_NAME="$(MODM_PROJECT_NAME)"
7979
APP_SRC += $(INFO_BUILD_FILE)
8080
CLEAN_FILES += $(INFO_BUILD_FILE)
@@ -86,7 +86,7 @@ CPPDEFINES += -DMODM_BUILD_INFO
8686
IMAGE_SOURCE := {{image_source}}
8787
.PRECIOUS: $(IMAGE_SOURCE)/%.cpp
8888
$(IMAGE_SOURCE)/%.cpp: $(IMAGE_SOURCE)/%.pbm
89-
@python3 modm/modm_tools/bitmap.py $^ -o $(dir $^)
89+
@python3 $(MODM_PATH)/modm_tools/bitmap.py $^ -o $(dir $^)
9090
IMAGE_PBM := $(wildcard $(IMAGE_SOURCE)/*.pbm)
9191
APP_SRC += $(IMAGE_PBM:.pbm=.cpp)
9292
CPPDEFINES += -I$(IMAGE_SOURCE)
@@ -98,11 +98,11 @@ APP_OBJS := $(addprefix $(BUILDPATH)/,$(APP_SRC))
9898
%% for suffix in ["cpp", "cxx", "c++", "cc", "c", "sx", "s", "S"]
9999
APP_OBJS := $(APP_OBJS:.{{suffix}}=.o)
100100
%% endfor
101-
LIBRARIES :={% for repo in generated_paths %} $(BUILDPATH)/{{repo}}/lib{{repo}}.a{% endfor %}
101+
LIBRARIES :={% for repo in repositories %} $(BUILDPATH)/{{repo}}/lib{{repo}}.a{% endfor %}
102102

103103
# Application linking
104104
.PRECIOUS: $(BUILDPATH)/%.{{program_extension}}
105-
$(BUILDPATH)/%.{{program_extension}}: $(APP_OBJS) $(LIBRARIES){% if platform != "hosted" %} {{ linkerscript }}{% endif %}
105+
$(BUILDPATH)/%.{{program_extension}}: $(APP_OBJS) $(LIBRARIES){% if platform != "hosted" %} {{ linkerscript | relocate }}{% endif %}
106106
@echo "Linking········" $@
107107
@$(CXX) -o $@ $(LINKFLAGS) $(filter %.o,$^) $(LIBPATH) \
108108
%% if platform != "hosted"
@@ -131,13 +131,25 @@ compile_asm = \
131131
.PRECIOUS: $(BUILDPATH)/%.o $(BUILDPATH)/%.a
132132
$(BUILDPATH)/%.o : %.c
133133
@$(call compile_c,$@,$<,)
134+
%% if outpath != "."
135+
$(BUILDPATH)/%.o : {{outpath}}/%.c
136+
@$(call compile_c,$@,$<,)
137+
%% endif
134138
%% for suffix in ["cc", "cpp", "cxx", "c++"]
135139
$(BUILDPATH)/%.o : %.{{suffix}}
136140
@$(call compile_cpp,$@,$<,)
141+
%% if outpath != "."
142+
$(BUILDPATH)/%.o : {{outpath}}/%.{{suffix}}
143+
@$(call compile_cpp,$@,$<,)
144+
%% endif
137145
%% endfor
138146
%% for suffix in ["sx", "s", "S"]
139147
$(BUILDPATH)/%.o : %.{{suffix}}
140148
@$(call compile_asm,$@,$<,)
149+
%% if outpath != "."
150+
$(BUILDPATH)/%.o : {{outpath}}/%.{{suffix}}
151+
@$(call compile_asm,$@,$<,)
152+
%% endif
141153
%% endfor
142154
%#
143155
.PRECIOUS: $(BUILDPATH)/%.bin

tools/build_script_generator/make/resources/repo.mk.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ LINKFLAGS += $(ARCHFLAGS)
4848
# Include paths
4949
CPPDEFINES += \
5050
%% for path in include_paths | sort
51-
-I{{ path | modm.windowsify(escape_level=0) }}{% if not loop.last %} \{% endif %}
51+
-I{{ path | relocate }}{% if not loop.last %} \{% endif %}
5252
%% endfor
5353
%% endif
5454

@@ -57,7 +57,7 @@ CPPDEFINES += \
5757
# Repo sources
5858
{{ repo|upper }}_OBJS += \
5959
%% for file, _ in sources
60-
$(BUILDPATH)/{{ file | modm.windowsify(escape_level=0) | objectify }}{% if not loop.last %} \{% endif %}
60+
$(BUILDPATH)/{{ file | objectify }}{% if not loop.last %} \{% endif %}
6161
%% endfor
6262

6363
# Include header dependencies files
@@ -66,7 +66,7 @@ CPPDEFINES += \
6666
# Custom build rules for repo sources
6767
%% for file, flags in sources
6868
%% if flags | length
69-
$(BUILDPATH)/{{ file | modm.windowsify(escape_level=0) | objectify }}: {{ file | modm.windowsify(escape_level=0) }}
69+
$(BUILDPATH)/{{ file | objectify }}: {{ file }}
7070
%% set ext = {"sx":"asm","s":"asm","S":"asm"}.get(file.split(".")[-1],file.split(".")[-1])
7171
@$(call compile_{{ ext }},$@,$<,{% for key, profiles in flags.items() if "" in profiles %} {{ profiles[""] | join(" ") }}{% endfor %} \
7272
%% for key, profiles in flags.items()
@@ -101,7 +101,7 @@ LIBS += \
101101
# Repo library paths
102102
LIBPATH += \
103103
%% for library in library_paths | sort
104-
-L{{ library | modm.windowsify(escape_level=0) }}{% if not loop.last %} \{% endif %}
104+
-L{{ library | relocate }}{% if not loop.last %} \{% endif %}
105105
%% endfor
106106
%% endif
107107

0 commit comments

Comments
 (0)