1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Fix several usability problems in the Makefile

Allow "make run" and "make gdb" to be used on Linux, not just
non-Linux.

Allow the user to set the go binary from the commandline.

Pass GOROOT in to make different Go installs use the right
Go root.

Check that xorriso is installed, because if it is not, grub-mkrescue
will silently exit.
This commit is contained in:
Jeff Allen 2017-06-14 11:29:33 +02:00
parent d8c040cf27
commit e428d6c672

View File

@ -12,8 +12,12 @@ export SHELL := /bin/bash -o pipefail
LD := ld LD := ld
AS := nasm AS := nasm
# If your go is called something else set it on the commandline, like
# this: make run GO=go1.8
GO ?= go
GOOS := linux GOOS := linux
GOARCH := amd64 GOARCH := amd64
GOROOT := $(shell $(GO) env GOROOT)
LD_FLAGS := -n -T $(BUILD_DIR)/linker.ld -static --no-ld-generated-unwind-info LD_FLAGS := -n -T $(BUILD_DIR)/linker.ld -static --no-ld-generated-unwind-info
AS_FLAGS := -g -f elf64 -F dwarf -I arch/$(ARCH)/asm/ AS_FLAGS := -g -f elf64 -F dwarf -I arch/$(ARCH)/asm/
@ -36,12 +40,13 @@ go.o:
@mkdir -p $(BUILD_DIR) @mkdir -p $(BUILD_DIR)
@echo "[go] compiling go sources into a standalone .o file" @echo "[go] compiling go sources into a standalone .o file"
@GOARCH=$(GOARCH) GOOS=$(GOOS) go build -n 2>&1 | sed \ @GOARCH=$(GOARCH) GOOS=$(GOOS) $(GO) build -n 2>&1 | sed \
-e "1s|^|set -e\n|" \ -e "1s|^|set -e\n|" \
-e "1s|^|export GOOS=$(GOOS)\n|" \ -e "1s|^|export GOOS=$(GOOS)\n|" \
-e "1s|^|export GOARCH=$(GOARCH)\n|" \ -e "1s|^|export GOARCH=$(GOARCH)\n|" \
-e "1s|^|export GOROOT=$(GOROOT)\n|" \
-e "1s|^|WORK='$(BUILD_ABS_DIR)'\n|" \ -e "1s|^|WORK='$(BUILD_ABS_DIR)'\n|" \
-e "1s|^|alias pack='go tool pack'\n|" \ -e "1s|^|alias pack='$(GO) tool pack'\n|" \
-e "/^mv/d" \ -e "/^mv/d" \
-e "s|-extld|-tmpdir='$(BUILD_ABS_DIR)' -linkmode=external -extldflags='-nostartfiles -nodefaultlibs -nostdlib -r' -extld|g" \ -e "s|-extld|-tmpdir='$(BUILD_ABS_DIR)' -linkmode=external -extldflags='-nostartfiles -nodefaultlibs -nostdlib -r' -extld|g" \
| sh 2>&1 | sed -e "s/^/ | /g" | sh 2>&1 | sed -e "s/^/ | /g"
@ -59,6 +64,9 @@ binutils_version_check:
@echo "[binutils] checking that installed objcopy version is >= $(MIN_OBJCOPY_VERSION)" @echo "[binutils] checking that installed objcopy version is >= $(MIN_OBJCOPY_VERSION)"
@if [ "$(HAVE_VALID_OBJCOPY)" != "y" ]; then echo "[binutils] error: a more up to date binutils installation is required" ; exit 1 ; fi @if [ "$(HAVE_VALID_OBJCOPY)" != "y" ]; then echo "[binutils] error: a more up to date binutils installation is required" ; exit 1 ; fi
xorriso_check:
@if xorriso --version >/dev/null 2>&1; then exit 0; else echo "Install xorriso via 'sudo apt install xorriso'." ; exit 1 ; fi
linker_script: linker_script:
@echo "[sed] extracting LMA and VMA from constants.inc" @echo "[sed] extracting LMA and VMA from constants.inc"
@echo "[gcc] pre-processing arch/$(ARCH)/script/linker.ld.in" @echo "[gcc] pre-processing arch/$(ARCH)/script/linker.ld.in"
@ -73,7 +81,7 @@ $(BUILD_DIR)/arch/$(ARCH)/asm/%.o: arch/$(ARCH)/asm/%.s
iso: $(iso_target) iso: $(iso_target)
$(iso_target): $(kernel_target) $(iso_target): xorriso_check $(kernel_target)
@echo "[grub] building ISO kernel-$(ARCH).iso" @echo "[grub] building ISO kernel-$(ARCH).iso"
@mkdir -p $(BUILD_DIR)/isofiles/boot/grub @mkdir -p $(BUILD_DIR)/isofiles/boot/grub
@ -93,6 +101,8 @@ kernel:
iso: iso:
vagrant ssh -c 'cd $(VAGRANT_SRC_FOLDER); make iso' vagrant ssh -c 'cd $(VAGRANT_SRC_FOLDER); make iso'
endif
run: iso run: iso
qemu-system-$(ARCH) -cdrom $(iso_target) qemu-system-$(ARCH) -cdrom $(iso_target)
@ -108,7 +118,6 @@ gdb: iso
-ex 'target remote localhost:1234' \ -ex 'target remote localhost:1234' \
-ex 'set arch i386:x86-64:intel' -ex 'set arch i386:x86-64:intel'
@killall qemu-system-$(ARCH) || true @killall qemu-system-$(ARCH) || true
endif
clean: clean:
@test -d $(BUILD_DIR) && rm -rf $(BUILD_DIR) || true @test -d $(BUILD_DIR) && rm -rf $(BUILD_DIR) || true
@ -134,8 +143,8 @@ lint: lint-check-deps
./... ./...
lint-check-deps: lint-check-deps:
@go get -u gopkg.in/alecthomas/gometalinter.v1 @$(GO) get -u gopkg.in/alecthomas/gometalinter.v1
@gometalinter.v1 --install >/dev/null @gometalinter.v1 --install >/dev/null
test: test:
go test -cover ./... $(GO) test -cover ./...