redox/Makefile

324 lines
9.6 KiB
Makefile
Raw Normal View History

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-29 04:57:55 +02:00
KRUSTCFLAGS=--target $(KTARGET).json -C opt-level=s -C soft-float
2016-09-10 03:08:04 +02:00
KCARGO=RUSTC="$(KRUSTC)" cargo
2016-09-29 04:57:55 +02:00
KCARGOFLAGS=--target $(KTARGET).json -- -C opt-level=s -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-29 04:57:55 +02:00
RUSTCFLAGS=--target $(TARGET).json -C opt-level=s --cfg redox
2016-09-10 03:08:04 +02:00
CARGO=RUSTC="$(RUSTC)" cargo
2016-09-29 04:57:55 +02:00
CARGOFLAGS=--target $(TARGET).json -- -C opt-level=s --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-27 01:13:35 +02:00
cargo clean --manifest-path drivers/ahcid/Cargo.toml
cargo clean --manifest-path drivers/ps2d/Cargo.toml
2016-09-11 23:56:48 +02:00
cargo clean --manifest-path drivers/pcid/Cargo.toml
cargo clean --manifest-path drivers/vesad/Cargo.toml
cargo clean --manifest-path programs/init/Cargo.toml
cargo clean --manifest-path programs/ion/Cargo.toml
2016-09-23 05:13:17 +02:00
cargo clean --manifest-path programs/coreutils/Cargo.toml
2016-09-28 19:07:54 +02:00
cargo clean --manifest-path programs/extrautils/Cargo.toml
2016-10-07 18:42:17 +02:00
cargo clean --manifest-path programs/userutils/Cargo.toml
cargo clean --manifest-path programs/smith/Cargo.toml
cargo clean --manifest-path schemes/example/Cargo.toml
2016-09-28 18:29:47 +02:00
cargo clean --manifest-path schemes/redoxfs/Cargo.toml
rm -rf initfs/bin
2016-09-28 05:56:29 +02:00
rm -rf filesystem/bin
2016-09-10 03:08:04 +02:00
rm -rf build
FORCE:
2016-09-10 03:08:04 +02:00
# Emulation
QEMU=qemu-system-$(ARCH)
2016-09-27 19:14:27 +02:00
QEMUFLAGS=-serial mon:stdio -d cpu_reset -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
%.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-30 17:16:09 +02:00
QEMUFLAGS+=-machine q35 -smp 4 -m 1024
2016-09-28 06:00:34 +02:00
ifneq ($(kvm),no)
QEMUFLAGS+=-enable-kvm -cpu host
endif
2016-10-08 04:18:05 +02:00
ifeq ($(net),no)
QEMUFLAGS+=-net none
else
QEMUFLAGS+=-net nic,model=e1000 -net user -net dump,file=$(KBUILD)/network.pcap
endif
2016-09-29 20:25:43 +02:00
ifeq ($(storage),usb)
QEMUFLAGS+=-device usb-ehci,id=flash_bus -drive id=flash_drive,file=$(KBUILD)/harddrive.bin,format=raw,if=none -device usb-storage,drive=flash_drive,bus=flash_bus.0
else
2016-09-30 00:03:59 +02:00
QEMUFLAGS+=-drive file=$(KBUILD)/harddrive.bin,format=raw
2016-09-29 20:25:43 +02:00
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
%.list: %
2016-09-10 03:08:04 +02:00
objdump -C -M intel -D $< > $@
2016-08-14 02:58:31 +02:00
2016-09-28 05:56:29 +02:00
$(KBUILD)/harddrive.bin: $(KBUILD)/kernel $(BUILD)/filesystem.bin bootloader/$(ARCH)/**
2016-09-11 06:06:09 +02:00
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
2016-09-29 20:25:43 +02:00
$(QEMU) $(QEMUFLAGS)
qemu_no_build:
2016-09-29 20:25:43 +02:00
$(QEMU) $(QEMUFLAGS)
2016-09-10 03:08:04 +02:00
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 03:08:04 +02:00
$(KBUILD)/librustc_unicode.rlib: rust/src/librustc_unicode/lib.rs $(KBUILD)/libcore.rlib
$(KRUSTC) $(KRUSTCFLAGS) -o $@ $<
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 $@ $<
$(KBUILD)/libkernel.a: kernel/** $(KBUILD)/libcore.rlib $(KBUILD)/liballoc.rlib $(KBUILD)/libcollections.rlib $(BUILD)/initfs.rs FORCE
2016-09-29 04:57:55 +02:00
$(KCARGO) rustc $(KCARGOFLAGS) -C opt-level=s -C lto -o $@
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-10 03:08:04 +02:00
# Userspace recipes
$(BUILD)/libcore.rlib: rust/src/libcore/lib.rs
mkdir -p $(BUILD)
$(RUSTC) $(RUSTCFLAGS) -o $@ $<
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
initfs/bin/%: drivers/%/Cargo.toml drivers/%/src/** $(BUILD)/libstd.rlib
mkdir -p initfs/bin
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
strip $@
rm $@.d
initfs/bin/%: programs/%/Cargo.toml programs/%/src/** $(BUILD)/libstd.rlib
mkdir -p initfs/bin
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
strip $@
rm $@.d
initfs/bin/%: schemes/%/Cargo.toml schemes/%/src/** $(BUILD)/libstd.rlib
2016-09-21 05:56:40 +02:00
mkdir -p initfs/bin
2016-09-28 05:20:14 +02:00
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
2016-09-21 05:56:40 +02:00
strip $@
rm $@.d
2016-09-28 05:56:29 +02:00
initfs_drivers: \
2016-09-28 05:20:14 +02:00
initfs/bin/ahcid \
2016-09-28 17:00:28 +02:00
initfs/bin/pcid
2016-09-28 05:20:14 +02:00
2016-09-28 05:56:29 +02:00
initfs_schemes: \
2016-09-28 05:20:14 +02:00
initfs/bin/redoxfs
2016-09-28 17:00:28 +02:00
$(BUILD)/initfs.rs: \
initfs/bin/init \
initfs_drivers \
initfs_schemes
echo 'use collections::BTreeMap;' > $@
echo 'pub fn gen() -> BTreeMap<&'"'"'static [u8], (&'"'"'static [u8], bool)> {' >> $@
echo ' let mut files: BTreeMap<&'"'"'static [u8], (&'"'"'static [u8], bool)> = BTreeMap::new();' >> $@
for folder in `find initfs -type d | sort`; do \
name=$$(echo $$folder | sed 's/initfs//' | cut -d '/' -f2-) ; \
echo -n ' files.insert(b"'$$name'", (b"' >> $@ ; \
ls -1 $$folder | sort | awk 'NR > 1 {printf("\\n")} {printf("%s", $$0)}' >> $@ ; \
echo '", true));' >> $@ ; \
done
find initfs -type f -o -type l | cut -d '/' -f2- | sort | awk '{printf(" files.insert(b\"%s\", (include_bytes!(\"../../initfs/%s\"), false));\n", $$0, $$0)}' >> $@
echo ' files' >> $@
echo '}' >> $@
filesystem/bin/%: drivers/%/Cargo.toml drivers/%/src/** $(BUILD)/libstd.rlib
mkdir -p filesystem/bin
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
strip $@
rm $@.d
2016-09-28 05:56:29 +02:00
filesystem/bin/%: programs/%/Cargo.toml programs/%/src/** $(BUILD)/libstd.rlib
mkdir -p filesystem/bin
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
strip $@
rm $@.d
filesystem/bin/%: programs/coreutils/Cargo.toml programs/coreutils/src/bin/%.rs $(BUILD)/libstd.rlib
mkdir -p filesystem/bin
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
strip $@
rm $@.d
2016-09-28 19:07:54 +02:00
filesystem/bin/%: programs/extrautils/Cargo.toml programs/extrautils/src/bin/%.rs $(BUILD)/libstd.rlib
mkdir -p filesystem/bin
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
strip $@
rm $@.d
2016-10-07 18:42:17 +02:00
filesystem/bin/%: programs/userutils/Cargo.toml programs/userutils/src/bin/%.rs $(BUILD)/libstd.rlib
mkdir -p filesystem/bin
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
strip $@
rm $@.d
2016-09-28 17:00:28 +02:00
filesystem/bin/%: schemes/%/Cargo.toml schemes/%/src/** $(BUILD)/libstd.rlib
mkdir -p filesystem/bin
$(CARGO) rustc --manifest-path $< --bin $* $(CARGOFLAGS) -o $@
strip $@
rm $@.d
drivers: \
2016-10-08 04:18:05 +02:00
filesystem/bin/e1000d \
2016-09-28 18:29:47 +02:00
filesystem/bin/ps2d \
filesystem/bin/vesad
2016-09-28 17:00:28 +02:00
2016-09-28 05:56:29 +02:00
coreutils: \
2016-09-28 19:07:54 +02:00
filesystem/bin/basename \
2016-09-28 05:56:29 +02:00
filesystem/bin/cat \
2016-09-28 19:07:54 +02:00
filesystem/bin/clear \
filesystem/bin/cp \
filesystem/bin/cut \
filesystem/bin/date \
2016-10-09 05:36:21 +02:00
filesystem/bin/dd \
2016-09-28 19:07:54 +02:00
filesystem/bin/du \
2016-09-28 05:56:29 +02:00
filesystem/bin/echo \
filesystem/bin/env \
2016-09-28 19:07:54 +02:00
filesystem/bin/false \
filesystem/bin/head \
2016-09-28 05:56:29 +02:00
filesystem/bin/ls \
2016-09-28 19:07:54 +02:00
filesystem/bin/mkdir \
filesystem/bin/mv \
2016-09-28 05:56:29 +02:00
filesystem/bin/printenv \
filesystem/bin/pwd \
2016-09-28 19:07:54 +02:00
filesystem/bin/realpath \
filesystem/bin/reset \
filesystem/bin/rmdir \
filesystem/bin/rm \
filesystem/bin/seq \
filesystem/bin/sleep \
filesystem/bin/tail \
filesystem/bin/time \
filesystem/bin/touch \
filesystem/bin/true \
filesystem/bin/wc \
filesystem/bin/yes
#filesystem/bin/free filesystem/bin/ps filesystem/bin/shutdown filesystem/bin/test
extrautils: \
filesystem/bin/calc \
filesystem/bin/cksum \
filesystem/bin/cur \
filesystem/bin/grep \
filesystem/bin/less \
filesystem/bin/mdless \
filesystem/bin/mtxt \
filesystem/bin/rem \
#filesystem/bin/dmesg filesystem/bin/info filesystem/bin/man filesystem/bin/watch
2016-10-07 18:42:17 +02:00
userutils: \
filesystem/bin/getty \
filesystem/bin/id \
filesystem/bin/login \
filesystem/bin/su \
filesystem/bin/sudo
2016-09-28 05:56:29 +02:00
2016-09-28 17:00:28 +02:00
schemes: \
filesystem/bin/example
2016-09-28 05:56:29 +02:00
$(BUILD)/filesystem.bin: \
2016-09-28 17:00:28 +02:00
drivers \
2016-09-28 05:56:29 +02:00
coreutils \
2016-09-28 19:52:40 +02:00
extrautils \
2016-10-07 18:42:17 +02:00
userutils \
2016-09-28 17:00:28 +02:00
schemes \
2016-09-28 05:56:29 +02:00
filesystem/bin/ion \
2016-10-07 18:42:17 +02:00
filesystem/bin/smith
2016-09-28 05:56:29 +02:00
rm -rf $@ $(BUILD)/filesystem/
echo exit | cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-utility $@ 8
2016-09-28 05:56:29 +02:00
mkdir -p $(BUILD)/filesystem/
cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-fuse $@ $(BUILD)/filesystem/ &
sleep 2
2016-09-28 17:00:28 +02:00
-cp -RL filesystem/* $(BUILD)/filesystem/
-chown -R 0:0 $(BUILD)/filesystem/
-chown -R 1000:1000 $(BUILD)/filesystem/home/user/
2016-10-06 02:01:05 +02:00
-chmod 700 $(BUILD)/filesystem/root/
-chmod 700 $(BUILD)/filesystem/home/user/
2016-10-07 18:42:17 +02:00
-chmod +s $(BUILD)/filesystem/bin/su
-chmod +s $(BUILD)/filesystem/bin/sudo
2016-09-28 05:56:29 +02:00
sync
-fusermount -u $(BUILD)/filesystem/
rm -rf $(BUILD)/filesystem/
2016-09-28 17:00:28 +02:00
mount: FORCE
mkdir -p $(KBUILD)/harddrive/
cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-fuse $(KBUILD)/harddrive.bin $(KBUILD)/harddrive/ &
sleep 2
unmount: FORCE
sync
-fusermount -u $(KBUILD)/harddrive/
rm -rf $(KBUILD)/harddrive/