2016-08-29 02:38:53 +02:00
|
|
|
ARCH?=x86_64
|
2016-08-14 02:21:46 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
# Kernel variables
|
|
|
|
KTARGET=$(ARCH)-unknown-none
|
|
|
|
KBUILD=build/kernel
|
|
|
|
KRUSTC=./krustc.sh
|
2016-09-17 17:23:55 +02:00
|
|
|
KRUSTCFLAGS=--target $(KTARGET).json -C soft-float
|
2016-09-10 03:08:04 +02:00
|
|
|
KCARGO=RUSTC="$(KRUSTC)" cargo
|
2016-09-17 17:23:55 +02:00
|
|
|
KCARGOFLAGS=--target $(KTARGET).json -- -C soft-float
|
2016-09-10 03:08:04 +02:00
|
|
|
|
|
|
|
# Userspace variables
|
|
|
|
TARGET=$(ARCH)-unknown-redox
|
|
|
|
BUILD=build/userspace
|
|
|
|
RUSTC=./rustc.sh
|
2016-09-23 00:15:09 +02:00
|
|
|
RUSTCFLAGS=--target $(TARGET).json -C opt-level=2 --cfg redox
|
2016-09-10 03:08:04 +02:00
|
|
|
CARGO=RUSTC="$(RUSTC)" cargo
|
2016-09-23 00:15:09 +02:00
|
|
|
CARGOFLAGS=--target $(TARGET).json -- -C opt-level=2 --cfg redox
|
2016-09-10 03:08:04 +02:00
|
|
|
|
|
|
|
# Default targets
|
|
|
|
.PHONY: all clean qemu bochs FORCE
|
|
|
|
|
|
|
|
all: $(KBUILD)/harddrive.bin
|
2016-08-26 01:03:01 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
clean:
|
|
|
|
cargo clean
|
|
|
|
cargo clean --manifest-path libstd/Cargo.toml
|
2016-09-20 16:47:16 +02:00
|
|
|
cargo clean --manifest-path drivers/ps2d/Cargo.toml
|
2016-09-11 23:56:48 +02:00
|
|
|
cargo clean --manifest-path drivers/pcid/Cargo.toml
|
2016-09-21 05:52:45 +02:00
|
|
|
cargo clean --manifest-path drivers/vesad/Cargo.toml
|
2016-09-22 18:10:27 +02:00
|
|
|
cargo clean --manifest-path programs/init/Cargo.toml
|
|
|
|
cargo clean --manifest-path programs/ion/Cargo.toml
|
|
|
|
cargo clean --manifest-path programs/login/Cargo.toml
|
2016-09-21 00:23:28 +02:00
|
|
|
cargo clean --manifest-path schemes/example/Cargo.toml
|
2016-09-21 05:52:45 +02:00
|
|
|
rm -rf initfs/bin
|
2016-09-10 03:08:04 +02:00
|
|
|
rm -rf build
|
|
|
|
|
|
|
|
FORCE:
|
2016-09-01 23:31:39 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
# Emulation
|
|
|
|
QEMU=qemu-system-$(ARCH)
|
|
|
|
QEMUFLAGS=-serial mon:stdio -d guest_errors
|
2016-08-26 01:03:01 +02:00
|
|
|
ifeq ($(ARCH),arm)
|
|
|
|
LD=$(ARCH)-none-eabi-ld
|
|
|
|
QEMUFLAGS+=-cpu arm1176 -machine integratorcp
|
|
|
|
QEMUFLAGS+=-nographic
|
2016-09-10 03:08:04 +02:00
|
|
|
|
2016-09-22 00:46:16 +02:00
|
|
|
%.list: %
|
2016-09-10 03:08:04 +02:00
|
|
|
$(ARCH)-none-eabi-objdump -C -D $< > $@
|
|
|
|
|
2016-09-11 06:06:09 +02:00
|
|
|
$(KBUILD)/harddrive.bin: $(KBUILD)/kernel
|
2016-09-10 03:08:04 +02:00
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
qemu: $(KBUILD)/harddrive.bin
|
|
|
|
$(QEMU) $(QEMUFLAGS) -kernel $<
|
2016-08-26 01:03:01 +02:00
|
|
|
else
|
|
|
|
LD=ld
|
2016-09-11 23:02:35 +02:00
|
|
|
QEMUFLAGS+=-machine q35 -smp 4
|
2016-09-11 23:13:09 +02:00
|
|
|
ifeq ($(kvm),yes)
|
|
|
|
QEMUFLAGS+=-enable-kvm -cpu host
|
|
|
|
endif
|
|
|
|
ifeq ($(vga),no)
|
|
|
|
QEMUFLAGS+=-nographic -vga none
|
|
|
|
endif
|
2016-08-26 01:03:01 +02:00
|
|
|
#,int,pcall
|
|
|
|
#-device intel-iommu
|
|
|
|
|
|
|
|
UNAME := $(shell uname)
|
|
|
|
ifeq ($(UNAME),Darwin)
|
|
|
|
LD=$(ARCH)-elf-ld
|
|
|
|
endif
|
2016-08-20 17:44:14 +02:00
|
|
|
|
2016-09-22 00:46:16 +02:00
|
|
|
%.list: %
|
2016-09-10 03:08:04 +02:00
|
|
|
objdump -C -M intel -D $< > $@
|
2016-08-14 02:58:31 +02:00
|
|
|
|
2016-09-11 06:06:09 +02:00
|
|
|
$(KBUILD)/harddrive.bin: $(KBUILD)/kernel bootloader/$(ARCH)/**
|
|
|
|
nasm -f bin -o $@ -D ARCH_$(ARCH) -ibootloader/$(ARCH)/ bootloader/$(ARCH)/harddrive.asm
|
2016-08-14 02:58:31 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
qemu: $(KBUILD)/harddrive.bin
|
|
|
|
$(QEMU) $(QEMUFLAGS) -drive file=$<,format=raw,index=0,media=disk
|
|
|
|
endif
|
2016-08-14 02:21:46 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
bochs: $(KBUILD)/harddrive.bin
|
2016-08-14 02:21:46 +02:00
|
|
|
bochs -f bochs.$(ARCH)
|
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
# Kernel recipes
|
|
|
|
$(KBUILD)/libcore.rlib: rust/src/libcore/lib.rs
|
|
|
|
mkdir -p $(KBUILD)
|
|
|
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
2016-08-14 02:21:46 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
$(KBUILD)/librand.rlib: rust/src/librand/lib.rs $(KBUILD)/libcore.rlib
|
|
|
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
2016-08-15 02:16:56 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
$(KBUILD)/liballoc.rlib: rust/src/liballoc/lib.rs $(KBUILD)/libcore.rlib
|
|
|
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
2016-09-10 01:13:16 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
$(KBUILD)/librustc_unicode.rlib: rust/src/librustc_unicode/lib.rs $(KBUILD)/libcore.rlib
|
|
|
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
2016-08-15 19:29:53 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
$(KBUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/librustc_unicode.rlib
|
|
|
|
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
|
2016-08-15 19:29:53 +02:00
|
|
|
|
2016-09-18 03:01:34 +02:00
|
|
|
$(KBUILD)/libkernel.a: kernel/** $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/libcollections.rlib $(BUILD)/initfs.rs FORCE
|
2016-09-10 03:08:04 +02:00
|
|
|
$(KCARGO) rustc $(KCARGOFLAGS) -o $@
|
2016-08-15 19:29:53 +02:00
|
|
|
|
2016-09-11 06:06:09 +02:00
|
|
|
$(KBUILD)/kernel: $(KBUILD)/libkernel.a
|
2016-09-10 03:08:04 +02:00
|
|
|
$(LD) --gc-sections -z max-page-size=0x1000 -T arch/$(ARCH)/src/linker.ld -o $@ $<
|
2016-09-09 03:09:58 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
# Userspace recipes
|
|
|
|
$(BUILD)/libcore.rlib: rust/src/libcore/lib.rs
|
|
|
|
mkdir -p $(BUILD)
|
|
|
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
2016-09-09 03:09:58 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
$(BUILD)/librand.rlib: rust/src/librand/lib.rs $(BUILD)/libcore.rlib
|
|
|
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
2016-08-14 02:21:46 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
$(BUILD)/liballoc.rlib: rust/src/liballoc/lib.rs $(BUILD)/libcore.rlib
|
|
|
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
2016-08-14 02:21:46 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
$(BUILD)/librustc_unicode.rlib: rust/src/librustc_unicode/lib.rs $(BUILD)/libcore.rlib
|
|
|
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
2016-08-26 01:03:01 +02:00
|
|
|
|
2016-09-10 03:08:04 +02:00
|
|
|
$(BUILD)/libcollections.rlib: rust/src/libcollections/lib.rs $(BUILD)/libcore.rlib $(BUILD)/liballoc.rlib $(BUILD)/librustc_unicode.rlib
|
|
|
|
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
|
2016-08-26 01:03:01 +02:00
|
|
|
|
2016-09-23 00:15:09 +02:00
|
|
|
openlibm/libopenlibm.a:
|
2016-09-23 00:57:26 +02:00
|
|
|
CFLAGS=-fno-stack-protector make -C openlibm
|
2016-09-23 00:15:09 +02:00
|
|
|
|
|
|
|
$(BUILD)/libopenlibm.a: openlibm/libopenlibm.a
|
|
|
|
mkdir -p $(BUILD)
|
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
$(BUILD)/libstd.rlib: libstd/Cargo.toml libstd/src/** $(BUILD)/libcore.rlib $(BUILD)/liballoc.rlib $(BUILD)/librustc_unicode.rlib $(BUILD)/libcollections.rlib $(BUILD)/librand.rlib $(BUILD)/libopenlibm.a
|
2016-09-10 03:08:04 +02:00
|
|
|
$(CARGO) rustc --verbose --manifest-path $< $(CARGOFLAGS) -o $@
|
|
|
|
cp libstd/target/$(TARGET)/debug/deps/*.rlib $(BUILD)
|
2016-08-14 02:21:46 +02:00
|
|
|
|
2016-09-21 05:52:45 +02:00
|
|
|
initfs/bin/%: drivers/%/Cargo.toml drivers/%/src/** $(BUILD)/libstd.rlib
|
|
|
|
mkdir -p initfs/bin
|
2016-09-19 04:17:08 +02:00
|
|
|
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
|
|
|
strip $@
|
2016-09-21 05:52:45 +02:00
|
|
|
rm $@.d
|
2016-09-19 04:17:08 +02:00
|
|
|
|
2016-09-22 16:43:22 +02:00
|
|
|
initfs/bin/%: programs/%/Cargo.toml programs/%/src/** $(BUILD)/libstd.rlib
|
2016-09-21 05:52:45 +02:00
|
|
|
mkdir -p initfs/bin
|
2016-09-21 00:23:28 +02:00
|
|
|
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
|
|
|
strip $@
|
2016-09-21 05:52:45 +02:00
|
|
|
rm $@.d
|
|
|
|
|
2016-09-23 03:38:09 +02:00
|
|
|
initfs/bin/%: programs/coreutils/Cargo.toml programs/coreutils/src/bin/%.rs $(BUILD)/libstd.rlib
|
|
|
|
mkdir -p initfs/bin
|
|
|
|
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
|
|
|
|
strip $@
|
|
|
|
rm $@.d
|
|
|
|
|
2016-09-22 16:43:22 +02:00
|
|
|
initfs/bin/%: schemes/%/Cargo.toml schemes/%/src/** $(BUILD)/libstd.rlib
|
2016-09-21 05:56:40 +02:00
|
|
|
mkdir -p initfs/bin
|
|
|
|
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
|
|
|
strip $@
|
|
|
|
rm $@.d
|
2016-09-21 05:52:45 +02:00
|
|
|
|
2016-09-23 03:38:09 +02:00
|
|
|
coreutils: \
|
|
|
|
initfs/bin/cat \
|
|
|
|
initfs/bin/echo \
|
|
|
|
initfs/bin/env \
|
|
|
|
initfs/bin/ls \
|
|
|
|
initfs/bin/printenv \
|
|
|
|
initfs/bin/pwd
|
|
|
|
|
2016-09-21 05:52:45 +02:00
|
|
|
$(BUILD)/initfs.rs: \
|
|
|
|
initfs/bin/pcid \
|
|
|
|
initfs/bin/ps2d \
|
|
|
|
initfs/bin/vesad \
|
2016-09-22 16:43:22 +02:00
|
|
|
initfs/bin/init \
|
|
|
|
initfs/bin/ion \
|
|
|
|
initfs/bin/login \
|
2016-09-23 03:38:09 +02:00
|
|
|
coreutils \
|
2016-09-22 16:43:22 +02:00
|
|
|
initfs/bin/example
|
2016-09-21 05:52:45 +02:00
|
|
|
echo 'use collections::BTreeMap;' > $@
|
|
|
|
echo 'pub fn gen() -> BTreeMap<&'"'"'static [u8], &'"'"'static [u8]> {' >> $@
|
|
|
|
echo ' let mut files: BTreeMap<&'"'"'static [u8], &'"'"'static [u8]> = BTreeMap::new();' >> $@
|
|
|
|
find initfs -type f -o -type l | cut -d '/' -f2- | sort \
|
|
|
|
| awk '{printf(" files.insert(b\"%s\", include_bytes!(\"../../initfs/%s\"));\n", $$0, $$0)}' \
|
|
|
|
>> $@
|
|
|
|
echo ' files' >> $@
|
|
|
|
echo '}' >> $@
|