aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml6
-rw-r--r--CMakeLists.txt40
-rw-r--r--Makefile123
-rw-r--r--README.md14
-rw-r--r--cross.sh47
5 files changed, 81 insertions, 149 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 0a731e8..6c129cf 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -13,14 +13,14 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Install
- run: sudo apt-get update && sudo apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libcloog-isl-dev libisl-0.18-dev curl nasm genisoimage qemu qemu-kvm mtools
+ run: sudo apt-get update && sudo apt-get install -y build-essential cmake bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libcloog-isl-dev libisl-0.18-dev curl nasm genisoimage qemu qemu-kvm mtools
- name: Build
- run: make cross build
+ run: sh cross.sh && mkdir build && cd build && cmake .. && make && cd ..
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
- files: build/melvix.iso
+ files: iso/melvix.iso
name: Melvix Weekly Release
prerelease: 1
env:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7a074d3..2942c02 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,8 +27,9 @@ add_executable(resources ${resources_sources})
set_target_properties(resources PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/iso/font.o")
add_custom_command(
TARGET resources POST_BUILD
- COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cross/opt/bin/i686-elf-objcopy -O binary ${CMAKE_CURRENT_SOURCE_DIR}/iso/font.o ${CMAKE_CURRENT_SOURCE_DIR}/iso/font.bin
- COMMAND rm ${CMAKE_CURRENT_SOURCE_DIR}/iso/font.o
+ COMMAND cross/opt/bin/i686-elf-objcopy -O binary iso/font.o iso/font.bin
+ COMMAND rm iso/font.o
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# USERSPACE
@@ -37,27 +38,30 @@ add_executable(user ${user_sources})
set_target_properties(user PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/iso/user.o")
add_custom_command(
TARGET user POST_BUILD
- COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cross/opt/bin/i686-elf-objcopy -O binary ${CMAKE_CURRENT_SOURCE_DIR}/iso/user.o ${CMAKE_CURRENT_SOURCE_DIR}/iso/user.bin
- COMMAND rm ${CMAKE_CURRENT_SOURCE_DIR}/iso/user.o
+ COMMAND cross/opt/bin/i686-elf-objcopy -O binary iso/user.o iso/user.bin
+ COMMAND rm iso/user.o
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# ISO
-add_custom_target(
- iso
- COMMAND nasm ${CMAKE_CURRENT_SOURCE_DIR}/src/bootloader/cd.asm -o ${CMAKE_CURRENT_SOURCE_DIR}/iso/boot/cd.bin -f bin
- COMMAND nasm ${CMAKE_CURRENT_SOURCE_DIR}/src/bootloader/hdd1.asm -o ${CMAKE_CURRENT_SOURCE_DIR}/iso/boot/hdd1.bin -f bin
- COMMAND nasm ${CMAKE_CURRENT_SOURCE_DIR}/src/bootloader/hdd2.asm -o ${CMAKE_CURRENT_SOURCE_DIR}/iso/boot/hdd2.bin -f bin
- COMMAND genisoimage -input-charset utf-8 -no-emul-boot -b boot/cd.bin -o ${CMAKE_CURRENT_SOURCE_DIR}/iso/melvix.iso ${CMAKE_CURRENT_SOURCE_DIR}/iso
+add_custom_command(
+ TARGET kernel POST_BUILD
+ COMMAND nasm src/bootloader/cd.asm -o iso/boot/cd.bin -f bin
+ COMMAND nasm src/bootloader/hdd1.asm -o iso/boot/hdd1.bin -f bin
+ COMMAND nasm src/bootloader/hdd2.asm -o iso/boot/hdd2.bin -f bin
+ COMMAND genisoimage -input-charset utf-8 -no-emul-boot -b boot/cd.bin -o iso/melvix.iso iso
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# TEST
-add_custom_target(
- test
- COMMAND head -c 10485760 /dev/zero > ${CMAKE_CURRENT_SOURCE_DIR}/iso/hdd10M.img
- COMMAND qemu-system-i386 -no-reboot -vga std -smp $$(nproc) -serial stdio -rtc base=localtime -m 256M -net nic,model=rtl8139,macaddr=42:42:42:42:42:42 -net user -cdrom ${CMAKE_CURRENT_SOURCE_DIR}/melvix.iso -drive file=${CMAKE_CURRENT_SOURCE_DIR}/iso/hdd10M.img,format=raw
-)
+if (DEFINED ENV{DISPLAY})
+ add_custom_command(
+ TARGET kernel POST_BUILD
+ COMMAND head -c 10485760 /dev/zero > iso/hdd10M.img
+ COMMAND qemu-system-i386 -no-reboot -vga std -smp $$(nproc) -serial stdio -rtc base=localtime -m 256M -net nic,model=rtl8139,macaddr=42:42:42:42:42:42 -net user -cdrom iso/melvix.iso -drive file=iso/hdd10M.img,format=raw
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+endif ()
add_custom_target(clean_iso COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/iso && mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/iso/boot)
-add_dependencies(kernel clean_iso resources user)
-add_dependencies(iso kernel)
-add_dependencies(test iso)
+add_dependencies(kernel clean_iso resources user) \ No newline at end of file
diff --git a/Makefile b/Makefile
deleted file mode 100644
index a51af76..0000000
--- a/Makefile
+++ /dev/null
@@ -1,123 +0,0 @@
-.DEFAULT_GOAL := build
-.SILENT: cross build test
-
-DIR := $(shell pwd)/cross
-export PREFIX := $(DIR)/opt
-export TARGET := i686-elf
-export PATH := $(PREFIX)/bin:$(PATH)
-export NETWORK := rtl8139
-
-clean:
- @-rm -rf ./build ./iso
- @echo "Cleaned build directory"
-
-build: clean
- @set -e; \
- echo "Building..."; \
- mkdir -p ./build/kernel && mkdir -p ./build/userspace; \
-
- # Assemble ASM files
- nasm -f elf ./src/kernel/boot.asm -o ./build/kernel/boot.o || exit; \
-
- # Make all kernel C files
- find ./src/kernel/ -name \*.c >./build/tmp; \
- while read -r line; do \
- stripped=$$(echo "$${line}" | sed -r 's/\//_/g'); \
- stripped=$${stripped#??????}; \
- stripped=$${stripped%%?}o; \
- i686-elf-gcc -c ./"$${line}" -o ./build/kernel/"$${stripped}" -I ./src -std=gnu99 -ffreestanding -O3 -Wall -Wextra -Wno-unused-parameter -D ${NETWORK} || exit; \
- done <./build/tmp; \
- rm ./build/tmp; \
- i686-elf-gcc -T ./src/kernel/linker.ld -I ./src -o ./build/melvix.bin -std=gnu99 -ffreestanding -O2 -nostdlib ./build/kernel/*.o || exit; \
-
- # Modules
- i686-elf-gcc -c ./src/resources/font.c -o ./build/font.o -I ./src -std=gnu99 -ffreestanding -O2 -nostdlib; \
- i686-elf-objcopy -O binary ./build/font.o ./build/font.bin; \
- rm ./build/font.o; \
-
- # Userspace
- nasm -f elf ./src/userspace/start.asm -o ./build/userspace/start.o || exit; \
- find ./src/userspace/ -name \*.c >./build/tmp; \
- while read -r line; do \
- stripped=$$(echo "$${line}" | sed -r 's/\//_/g'); \
- stripped=$${stripped#??????}; \
- stripped=$${stripped%%?}o; \
- i686-elf-gcc -c ./"$${line}" -o ./build/userspace/"$${stripped}" -I ./src/userspace -std=gnu99 -ffreestanding -O3 -Wall -Wextra -Wno-unused-parameter || exit; \
- done <./build/tmp; \
- rm ./build/tmp; \
- i686-elf-gcc -I ./src/userspace -o ./build/user.o -std=gnu99 -ffreestanding -O2 -nostdlib ./build/userspace/*.o || exit; \
- i686-elf-objcopy -O binary ./build/user.o ./build/user.bin; \
-
- # Create ISO
- mkdir -p ./iso/boot/; \
- mv ./build/melvix.bin ./iso/boot/kernel.bin; \
- nasm ./src/bootloader/cd.asm -f bin -o ./iso/boot/cd.bin || exit; \
- nasm ./src/bootloader/hdd1.asm -f bin -o ./iso/boot/hdd1.bin || exit; \
- nasm ./src/bootloader/hdd2.asm -f bin -o ./iso/boot/hdd2.bin || exit; \
- cp ./build/user.bin ./iso/user.bin || exit; \
- cp ./build/font.bin ./iso/font.bin || exit; \
- genisoimage -quiet -input-charset utf-8 -no-emul-boot -b boot/cd.bin -o ./build/melvix.iso ./iso;
-
-cross:
- @set -e; \
- [ -d "./cross/" ] && echo "Please remove ./cross/ and try again" && exit; \
- mkdir cross || exit; \
- cd cross || exit; \
- DIR=$$(pwd); \
- mkdir "$${DIR}/src" && cd "$${DIR}/src" || exit; \
- echo "Downloading..."; \
- curl -sSL "https://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.xz" | tar xJ; \
- curl -sSL "https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz" | tar xJ; \
- mkdir -p "$${DIR}/opt/bin"; \
- export PREFIX="$${DIR}/opt"; \
- export TARGET=i686-elf; \
- export PATH="$$PREFIX/bin:$$PATH"; \
- mkdir "$${DIR}/src/build-binutils" && cd "$${DIR}/src/build-binutils" || exit; \
- ../binutils-2.32/configure --target="$$TARGET" --prefix="$$PREFIX" --with-sysroot --disable-nls --disable-werror; \
- make; \
- make install; \
- mkdir "$${DIR}/src/build-gcc" && cd "$${DIR}/src/build-gcc" || exit; \
- ../gcc-9.2.0/configure --target="$$TARGET" --prefix="$$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers; \
- make all-gcc; \
- make all-target-libgcc; \
- make install-gcc; \
- make install-target-libgcc; \
- cd "$${DIR}/.." || exit;
-
-test: build debug
-
-QEMU_OPTIONS := -no-reboot -vga std -smp $$(nproc) -serial stdio -rtc base=localtime -m 256M -net nic,model=rtl8139,macaddr=42:42:42:42:42:42 -net user
-
-debug:
- @echo "Starting simulation..."
- @head -c 10485760 /dev/zero > ./build/hdd10M.img
- @echo "[SERIAL OUTPUT]"
- @qemu-system-i386 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
- @echo "[END OF CONNECTION]"
-
-image: build
- @echo "Starting simulation..."
- @head -c 10485760 /dev/zero > ./build/hdd10M.img
- @echo "[SERIAL OUTPUT]"
- @qemu-system-i386 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
- @echo "[END OF CONNECTION]"
- @printf "\n"
- @echo "[SERIAL OUTPUT]"
- @qemu-system-i386 ${QEMU_OPTIONS} -drive file=./build/hdd10M.img,format=raw
- @echo "[END OF CONNECTION]"
-
-debugHDD:
- @echo "Starting simulation..."
- @echo "[SERIAL OUTPUT]"
- @qemu-system-i386 ${QEMU_OPTIONS} -drive file=./build/hdd10M.img,format=raw
- @echo "[END OF CONNECTION]"
-
-bochs: build
- @head -c 10485760 /dev/zero > ./build/hdd10M.img
- @qemu-system-i386 ${QEMU_OPTIONS} -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
- @bochs -f bochs.txt
-
-bochsHDD:
- @bochs -f bochs.txt
-
-.PHONY: build clean cross test debug image debugHDD bochs bochsHDD \ No newline at end of file
diff --git a/README.md b/README.md
index 833579d..256a60d 100644
--- a/README.md
+++ b/README.md
@@ -17,9 +17,11 @@
* Use any system running GNU/Linux (Successfully tried building on Debian, Arch Linux and even OpenBSD)
* Install build dependencies (package names may vary depending on your operating system)
+ * Ubuntu/Debian _"instructions"_ can be found here: [GitHub Workflow](https://raw.githubusercontent.com/marvinborner/Melvix/master/.github/workflows/build.yml)
* binutils
* gcc
* make
+ * cmake
* bison
* flex
* gmp
@@ -31,13 +33,15 @@
* genisoimage
* qemu
-* Build a cross compiler using `make cross`
+* Build a cross compiler using `sh cross.sh`
-* Run `make build`
+* Run
+ * `mkdir build && cd build`
+ * `cmake .. && make`
+ * `cd .. && rm -rf build`
+ * The relevant files are in iso/
-* Test Melvix in QEMU (opens after `make test`)
-
-* Optional: Flash the built ISO to a USB/Floppy/CD drive using `sudo dd if=./build/melvix.iso of=/dev/sdX bs=4M oflag=sync`
+* Optional: Flash the built ISO to a CD drive using `sudo dd if=./iso/melvix.iso of=/dev/sdX bs=4M oflag=sync`
## Licenses
Melvix is released under the MIT License and uses the following 3rd party applications (as stated in the regarding files):
diff --git a/cross.sh b/cross.sh
new file mode 100644
index 0000000..6a4c21c
--- /dev/null
+++ b/cross.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env sh
+# Sets up a cross compiler
+
+if [ ! -d "./cross/" ]; then
+ # Create directory
+ mkdir -p cross
+ cd cross || exit
+ DIR=$(pwd)
+
+ # Get sources
+ mkdir "${DIR}/src" && cd "${DIR}/src" || exit
+ echo "Downloading..."
+ curl -sSL "https://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.xz" | tar xJ
+ curl -sSL "https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz" | tar xJ
+
+ # Prepare compiling
+ mkdir -p "${DIR}/opt/bin"
+ export PREFIX="${DIR}/opt"
+ export TARGET=i686-elf
+ export PATH="$PREFIX/bin:$PATH"
+
+ # Compile binutilsq
+ mkdir "${DIR}/src/build-binutils" && cd "${DIR}/src/build-binutils" || exit
+ ../binutils-2.32/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
+ make
+ make install
+
+ # Compile GCC
+ mkdir "${DIR}/src/build-gcc" && cd "${DIR}/src/build-gcc" || exit
+ ../gcc-9.2.0/configure --target="$TARGET" --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
+ make all-gcc
+ make all-target-libgcc
+ make install-gcc
+ make install-target-libgcc
+
+ # Source exported variables
+ cd "${DIR}/.." || exit
+ . cross.sh
+else
+ # Should be sourced to take effect
+ cd cross || exit
+ DIR=$(pwd)
+ export PREFIX="${DIR}/opt"
+ export TARGET=i686-elf
+ export PATH="$PREFIX/bin:$PATH"
+ cd ..
+fi \ No newline at end of file