Skip to content
Permalink
Browse files
Makefiles: Docker USB passthrough in Linux only
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 089565762a60462c527a907fba2caeee583fa58d
Show file tree
Hide file tree
Showing 20 changed files with 524 additions and 458 deletions.
@@ -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)

@@ -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:
@@ -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)

@@ -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:
@@ -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)

@@ -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:
@@ -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)

@@ -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:
@@ -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)

@@ -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:
@@ -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)

@@ -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:

0 comments on commit 0895657

Please sign in to comment.