Skip to content

Commit

Permalink
Makefiles: Docker USB passthrough in Linux only
Browse files Browse the repository at this point in the history
Detect if we run on Linux. If so, dockerize Makefile targets that need access to
USB devices. If we run on anything else, attempt to execute natively.

This will enable non-Linux Unixes like macOS to run the chainboot target, given
they install the needed Ruby dependencies.
  • Loading branch information
andre-richter committed Apr 11, 2020
1 parent 3a79444 commit 0895657
Show file tree
Hide file tree
Showing 20 changed files with 524 additions and 458 deletions.
25 changes: 12 additions & 13 deletions 01_wait_forever/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ COMPILER_ARGS = --target=$(TARGET) \
--features bsp_$(BSP) \
--release

RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)

CARGO_OUTPUT = target/$(TARGET)/release/kernel

CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
OBJCOPY_CMD = cargo objcopy \
-- \
--strip-all \
-O binary

KERNEL_ELF = target/$(TARGET)/release/kernel

DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD = docker run -it --rm
DOCKER_ARG_DIR_TUT = -v $(shell pwd):/work -w /work
DOCKER_EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work/tutorial -w /work/tutorial

DOCKER_QEMU = $(DOCKER_CMD) $(DOCKER_IMAGE)

EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)

.PHONY: all doc qemu clippy clean readelf objdump nm

all: clean $(OUTPUT)

$(CARGO_OUTPUT): $(SOURCES)
$(KERNEL_ELF): $(SOURCES)
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)

$(OUTPUT): $(CARGO_OUTPUT)
$(OUTPUT): $(KERNEL_ELF)
cp $< .
$(OBJCOPY_CMD) $< $(OUTPUT)

Expand All @@ -70,9 +71,7 @@ qemu:
@echo "This board is not yet supported for QEMU."
else
qemu: all
@$(DOCKER_CMD) $(DOCKER_ARG_DIR_TUT) $(DOCKER_IMAGE) \
$(DOCKER_EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
-kernel $(OUTPUT)
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(OUTPUT)
endif

clippy:
Expand Down
25 changes: 12 additions & 13 deletions 02_runtime_init/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ COMPILER_ARGS = --target=$(TARGET) \
--features bsp_$(BSP) \
--release

RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)

CARGO_OUTPUT = target/$(TARGET)/release/kernel

CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
OBJCOPY_CMD = cargo objcopy \
-- \
--strip-all \
-O binary

KERNEL_ELF = target/$(TARGET)/release/kernel

DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD = docker run -it --rm
DOCKER_ARG_DIR_TUT = -v $(shell pwd):/work -w /work
DOCKER_EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work/tutorial -w /work/tutorial

DOCKER_QEMU = $(DOCKER_CMD) $(DOCKER_IMAGE)

EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)

.PHONY: all doc qemu clippy clean readelf objdump nm

all: clean $(OUTPUT)

$(CARGO_OUTPUT): $(SOURCES)
$(KERNEL_ELF): $(SOURCES)
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)

$(OUTPUT): $(CARGO_OUTPUT)
$(OUTPUT): $(KERNEL_ELF)
cp $< .
$(OBJCOPY_CMD) $< $(OUTPUT)

Expand All @@ -70,9 +71,7 @@ qemu:
@echo "This board is not yet supported for QEMU."
else
qemu: all
@$(DOCKER_CMD) $(DOCKER_ARG_DIR_TUT) $(DOCKER_IMAGE) \
$(DOCKER_EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
-kernel $(OUTPUT)
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(OUTPUT)
endif

clippy:
Expand Down
25 changes: 12 additions & 13 deletions 03_hacky_hello_world/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ COMPILER_ARGS = --target=$(TARGET) \
--features bsp_$(BSP) \
--release

RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)

CARGO_OUTPUT = target/$(TARGET)/release/kernel

CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
OBJCOPY_CMD = cargo objcopy \
-- \
--strip-all \
-O binary

KERNEL_ELF = target/$(TARGET)/release/kernel

DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD = docker run -it --rm
DOCKER_ARG_DIR_TUT = -v $(shell pwd):/work -w /work
DOCKER_EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work/tutorial -w /work/tutorial

DOCKER_QEMU = $(DOCKER_CMD) $(DOCKER_IMAGE)

EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)

.PHONY: all doc qemu clippy clean readelf objdump nm

all: clean $(OUTPUT)

$(CARGO_OUTPUT): $(SOURCES)
$(KERNEL_ELF): $(SOURCES)
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)

$(OUTPUT): $(CARGO_OUTPUT)
$(OUTPUT): $(KERNEL_ELF)
cp $< .
$(OBJCOPY_CMD) $< $(OUTPUT)

Expand All @@ -70,9 +71,7 @@ qemu:
@echo "This board is not yet supported for QEMU."
else
qemu: all
@$(DOCKER_CMD) $(DOCKER_ARG_DIR_TUT) $(DOCKER_IMAGE) \
$(DOCKER_EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
-kernel $(OUTPUT)
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(OUTPUT)
endif

clippy:
Expand Down
25 changes: 12 additions & 13 deletions 04_zero_overhead_abstraction/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ COMPILER_ARGS = --target=$(TARGET) \
--features bsp_$(BSP) \
--release

RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)

CARGO_OUTPUT = target/$(TARGET)/release/kernel

CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
OBJCOPY_CMD = cargo objcopy \
-- \
--strip-all \
-O binary

KERNEL_ELF = target/$(TARGET)/release/kernel

DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD = docker run -it --rm
DOCKER_ARG_DIR_TUT = -v $(shell pwd):/work -w /work
DOCKER_EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work/tutorial -w /work/tutorial

DOCKER_QEMU = $(DOCKER_CMD) $(DOCKER_IMAGE)

EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)

.PHONY: all doc qemu clippy clean readelf objdump nm

all: clean $(OUTPUT)

$(CARGO_OUTPUT): $(SOURCES)
$(KERNEL_ELF): $(SOURCES)
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)

$(OUTPUT): $(CARGO_OUTPUT)
$(OUTPUT): $(KERNEL_ELF)
cp $< .
$(OBJCOPY_CMD) $< $(OUTPUT)

Expand All @@ -70,9 +71,7 @@ qemu:
@echo "This board is not yet supported for QEMU."
else
qemu: all
@$(DOCKER_CMD) $(DOCKER_ARG_DIR_TUT) $(DOCKER_IMAGE) \
$(DOCKER_EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
-kernel $(OUTPUT)
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(OUTPUT)
endif

clippy:
Expand Down
25 changes: 12 additions & 13 deletions 05_safe_globals/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ COMPILER_ARGS = --target=$(TARGET) \
--features bsp_$(BSP) \
--release

RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)

CARGO_OUTPUT = target/$(TARGET)/release/kernel

CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
OBJCOPY_CMD = cargo objcopy \
-- \
--strip-all \
-O binary

KERNEL_ELF = target/$(TARGET)/release/kernel

DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD = docker run -it --rm
DOCKER_ARG_DIR_TUT = -v $(shell pwd):/work -w /work
DOCKER_EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work/tutorial -w /work/tutorial

DOCKER_QEMU = $(DOCKER_CMD) $(DOCKER_IMAGE)

EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)

.PHONY: all doc qemu clippy clean readelf objdump nm

all: clean $(OUTPUT)

$(CARGO_OUTPUT): $(SOURCES)
$(KERNEL_ELF): $(SOURCES)
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)

$(OUTPUT): $(CARGO_OUTPUT)
$(OUTPUT): $(KERNEL_ELF)
cp $< .
$(OBJCOPY_CMD) $< $(OUTPUT)

Expand All @@ -70,9 +71,7 @@ qemu:
@echo "This board is not yet supported for QEMU."
else
qemu: all
@$(DOCKER_CMD) $(DOCKER_ARG_DIR_TUT) $(DOCKER_IMAGE) \
$(DOCKER_EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
-kernel $(OUTPUT)
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(OUTPUT)
endif

clippy:
Expand Down
25 changes: 12 additions & 13 deletions 06_drivers_gpio_uart/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ COMPILER_ARGS = --target=$(TARGET) \
--features bsp_$(BSP) \
--release

RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)

CARGO_OUTPUT = target/$(TARGET)/release/kernel

CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
OBJCOPY_CMD = cargo objcopy \
-- \
--strip-all \
-O binary

KERNEL_ELF = target/$(TARGET)/release/kernel

DOCKER_IMAGE = rustembedded/osdev-utils
DOCKER_CMD = docker run -it --rm
DOCKER_ARG_DIR_TUT = -v $(shell pwd):/work -w /work
DOCKER_EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
DOCKER_CMD = docker run -it --rm -v $(shell pwd):/work/tutorial -w /work/tutorial

DOCKER_QEMU = $(DOCKER_CMD) $(DOCKER_IMAGE)

EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)

.PHONY: all doc qemu clippy clean readelf objdump nm

all: clean $(OUTPUT)

$(CARGO_OUTPUT): $(SOURCES)
$(KERNEL_ELF): $(SOURCES)
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)

$(OUTPUT): $(CARGO_OUTPUT)
$(OUTPUT): $(KERNEL_ELF)
cp $< .
$(OBJCOPY_CMD) $< $(OUTPUT)

Expand All @@ -70,9 +71,7 @@ qemu:
@echo "This board is not yet supported for QEMU."
else
qemu: all
@$(DOCKER_CMD) $(DOCKER_ARG_DIR_TUT) $(DOCKER_IMAGE) \
$(DOCKER_EXEC_QEMU) $(QEMU_RELEASE_ARGS) \
-kernel $(OUTPUT)
@$(DOCKER_QEMU) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(OUTPUT)
endif

clippy:
Expand Down
Loading

0 comments on commit 0895657

Please sign in to comment.