Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ kernel/o/
*.swp
*.d
genInitrd/make_initrd
cross/
43 changes: 43 additions & 0 deletions COMPILING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
To compile Q-OS you need to compile a cross compiler.

Needed packages
---------------

gcc 5.x
g++ 5.x
GNU Make
GNU Bison
Flex
Texinfo
ISL (optional)
CLooG (optional)

For Mac users:
If you use OS X 10.7 or older you need to install gcc and do this:

# This is only necessary for OS X users running 10.7 or below.
export CC=/usr/bin/gcc-5.X
export CXX=/usr/bin/g++-5.X
export CPP=/usr/bin/cpp-5.X
export LD=/usr/bin/gcc-5.X

note: don't make these permanent

Installing
----------
Run build_cross_compiler.sh script.
After it's finished run:

. ./set_path.sh

Note: you need to do that every time you start new console sessioi. Or permanently change your $PATH.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, typo.


Compiling Q-OS
--------------
To compile:

make

To compile and run:

make qemu
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
ASM:=nasm
#ASM flags
ASMFLAGS:=-f elf32
LD:=i686-elf-ld

#C compiler
CC:=gcc
CC:=i686-elf-gcc
#C compiler flags
WARNINGS:=-Wall -Wextra #-pedantic -Wshadow -Wpointer-arith -Wcast-align \
#-Wwrite-strings -Wmissing-prototypes -Wmissing-declarations \
#-Wredundant-decls -Wnested-externs -Winline -Wno-long-long \
#-Wuninitialized -Wconversion -Wstrict-prototypes -Werror
CFLAGS:=-m32 -ffreestanding -std=c99 -Werror -pedantic $(WARNINGS)
CFLAGS:=-ffreestanding -std=c99 -Werror -pedantic $(WARNINGS)
#object file directory

ODIR:=kernel/o
Expand Down Expand Up @@ -54,7 +55,7 @@ $(ISO): $(KERNEL) $(INITRD)

$(KERNEL): $(CSOURCES) $(ASOURCES) $(COBJECTS) $(AOBJECTS)
@mkdir -p $(IMGDIR)/boot/
@ld -m elf_i386 -T $(DIR)/link.ld $(AOBJECTS) $(COBJECTS) -o $(IMGDIR)/boot/$@
@$(LD) -m elf_i386 -T $(DIR)/link.ld $(AOBJECTS) $(COBJECTS) -o $(IMGDIR)/boot/$@

$(INITRD):

Expand Down
47 changes: 47 additions & 0 deletions build-cross-compiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

mkdir cross
cd cross

export PREFIX="$(pwd)"
export TARGET="i686-elf"
export PATH="$PREFIX/bin:$PATH"

echo $PREFIX $TARGET $PATH

BINUTILS_VER="binutils-2.25.1"
wget http://ftp.gnu.org/gnu/binutils/$BINUTILS_VER.tar.bz2
tar -xvf $BINUTILS_VER.tar.bz2
mkdir build-binutils
cd build-binutils
../$BINUTILS_VER/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make -j4
make install
cd ..

GMP_VER="gmp-6.1.0"
MPFR_VER="mpfr-3.1.3"
MPC_VER="mpc-1.0.3"
GCC_VER="gcc-5.3.0"
#prepare GCC for installation
wget https://gmplib.org/download/gmp/$GMP_VER.tar.lz
wget http://www.mpfr.org/mpfr-current/$MPFR_VER.tar.gz
wget ftp://ftp.gnu.org/gnu/mpc/$MPC_VER.tar.gz
tar --lzip -xvf $GMP_VER.tar.lz
tar -xvf $MPFR_VER.tar.gz
tar -xvf $MPC_VER.tar.gz
wget ftp://ftp.gnu.org/gnu/gcc/gcc-5.3.0/$GCC_VER.tar.gz
tar -xvf $GCC_VER.tar.gz
mv $GMP_VER $GCC_VER/gmp
mv $MPFR_VER $GCC_VER/mpfr
mv $MPC_VER $GCC_VER/mpc

which -- $TARGET-as || echo $TARGET-as is not in the PATH

mkdir build-gcc
cd build-gcc
../$GCC_VER/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make -j4 all-gcc
make -j4 all-target-libgcc
make install-gcc
make install-target-libgcc
24 changes: 24 additions & 0 deletions set_path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
contains() {
string="$1"
substring="$2"
if test "${string#*$substring}" != "$string"
then
return 0 # $substring is in $string
else
return 1 # $substring is not in $string
fi
}

cd cross
export PREFIX="$(pwd)"
export TARGET="i686-elf"
export ADD_PATH="$PREFIX/bin"
if ! contains $PATH $ADD_PATH
then
export PATH="$ADD_PATH:$PATH"
echo "PATH set to $PATH"
else
echo "Path already set"
fi
cd ..