Update markdown and tabs and stuff
This commit is contained in:
@@ -40,19 +40,19 @@ compiling newlib with that setup is rather annoying.
|
||||
|
||||
I'm also a fan of clean makefiles. Take a look at this:
|
||||
|
||||
VPATH := ../src
|
||||
|
||||
CC := i586-pc-myos-gcc
|
||||
|
||||
TARGETS := $(shell find ../src -name "*.c")
|
||||
TARGETS := $(notdir $(TARGETS))
|
||||
TARGETS := $(patsubst %.c, %, $(TARGETS))
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
clean:
|
||||
-rm $(TARGETS) 2>/dev/null
|
||||
{: .lang-make}
|
||||
:::make
|
||||
VPATH := ../src
|
||||
|
||||
CC := i586-pc-myos-gcc
|
||||
|
||||
TARGETS := $(shell find ../src -name "*.c")
|
||||
TARGETS := $(notdir $(TARGETS))
|
||||
TARGETS := $(patsubst %.c, %, $(TARGETS))
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
clean:
|
||||
-rm $(TARGETS) 2>/dev/null
|
||||
|
||||
That's the makefile for the entire `/bin` directory in my os.
|
||||
|
||||
@@ -67,13 +67,14 @@ make a formula for it. So after applying the patches described in the
|
||||
post (I even kept the name `i586-pc-myos` since I don't have a working
|
||||
name for my kernel besides an iteration number...) I did
|
||||
|
||||
export TARGET=i586-pc-myos
|
||||
export PREFIX=/usr/local/Cellar/osdev/1.0
|
||||
# Configure, build and install binutils
|
||||
brew link osdev
|
||||
# Configure, build and install gcc and libgcc
|
||||
brew unlink osdev
|
||||
brew link osdev
|
||||
:::bash
|
||||
$ export TARGET=i586-pc-myos
|
||||
$ export PREFIX=/usr/local/Cellar/osdev/1.0
|
||||
# Configure, build and install binutils
|
||||
$ brew link osdev
|
||||
# Configure, build and install gcc and libgcc
|
||||
$ brew unlink osdev
|
||||
$ brew link osdev
|
||||
|
||||
And that prepared me for building newlib.
|
||||
|
||||
@@ -85,50 +86,52 @@ automake and autoconf since a couple of versions. More specifically,
|
||||
you need automake version 1.12 or earlier and autoconf version 2.64.
|
||||
Unfortunately, those versions are not available through Homebrew, so ...
|
||||
|
||||
curl -O http://ftp.gnu.org/gnu/automake/automake-1.12.tar.gz
|
||||
tar -zxf automake-1.12.tar.gz
|
||||
mkdir -p build-automake
|
||||
pushd build-automake
|
||||
../automake-1.12/configure --prefix=/usr/local/Cellar/automake/1.12
|
||||
make all -j
|
||||
make install
|
||||
popd
|
||||
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.64.tar.gz
|
||||
tar -zxf autoconf-2.64.tar.gz
|
||||
pushd build-autoconf
|
||||
../autoconf-2.64/configure --prefix=/usr/local/Cellar/autoconf/2.64
|
||||
make all -j
|
||||
make install
|
||||
popd
|
||||
|
||||
brew switch automake 1.12
|
||||
brew switch autoconf 2.64
|
||||
:::bash
|
||||
$ curl -O http://ftp.gnu.org/gnu/automake/automake-1.12.tar.gz
|
||||
$ tar -zxf automake-1.12.tar.gz
|
||||
$ mkdir -p build-automake
|
||||
$ pushd build-automake
|
||||
$ ../automake-1.12/configure --prefix=/usr/local/Cellar/automake/1.12
|
||||
$ make all -j
|
||||
$ make install
|
||||
$ popd
|
||||
$ curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.64.tar.gz
|
||||
$ tar -zxf autoconf-2.64.tar.gz
|
||||
$ pushd build-autoconf
|
||||
$ ../autoconf-2.64/configure --prefix=/usr/local/Cellar/autoconf/2.64
|
||||
$ make all -j
|
||||
$ make install
|
||||
$ popd
|
||||
$ brew switch automake 1.12
|
||||
$ brew switch autoconf 2.64
|
||||
|
||||
Those last two lines tells Homebrew that you want to use those specific
|
||||
versions for now.
|
||||
|
||||
Now for the neat part. I followed the wiki post and used the
|
||||
Now for the neat part. I followed the wiki post and used the
|
||||
[syscall interface](/blog/2013/06/System-Calls) i've described earlier
|
||||
but I also wrapped `crt0.S` and `syscalls.c` in
|
||||
|
||||
#ifndef KERNEL_MODE
|
||||
...
|
||||
#endif
|
||||
:::c
|
||||
#ifndef KERNEL_MODE
|
||||
...
|
||||
#endif
|
||||
|
||||
Then I built it all through
|
||||
|
||||
pushd build-newlib
|
||||
../newlib/configure --target=$TARGET --prefix=$PREFIX
|
||||
export CPPFLAGS_FOR_TARGET=-DKERNEL_MODE
|
||||
make -j
|
||||
make install
|
||||
mv $PREFIX/$TARGET/lib/libc.a $PREFIX/$TARGET/lib/libkernel.a
|
||||
rm -rf *
|
||||
../newlib/configure --target=$TARGET --prefix=$PREFIX
|
||||
export CPPFLAGS_FOR_TARGET=
|
||||
make -j
|
||||
make install
|
||||
popd
|
||||
:::bash
|
||||
$ pushd build-newlib
|
||||
$ ../newlib/configure --target=$TARGET --prefix=$PREFIX
|
||||
$ export CPPFLAGS_FOR_TARGET=-DKERNEL_MODE
|
||||
$ make -j
|
||||
$ make install
|
||||
$ mv $PREFIX/$TARGET/lib/libc.a $PREFIX/$TARGET/lib/libkernel.a
|
||||
$ rm -rf *
|
||||
$ ../newlib/configure --target=$TARGET --prefix=$PREFIX
|
||||
$ export CPPFLAGS_FOR_TARGET=
|
||||
$ make -j
|
||||
$ make install
|
||||
$ popd
|
||||
|
||||
This gives me two versions of the newlib c library. One with all syscalls
|
||||
defined and one without. The latter is suitable for linking into the
|
||||
@@ -160,24 +163,26 @@ compile the kernel using a very simple makefile.
|
||||
|
||||
Somewhat simplified:
|
||||
|
||||
OBJECTS := $(shell find . -name "*.S")
|
||||
OBJECTS += $(shell find . -name "*.c")
|
||||
OBJECTS := $(OBJECTS:%.S=%.o)
|
||||
OBJECTS := $(OBJECTS:%.c=%.o)
|
||||
:::make
|
||||
OBJECTS := $(shell find . -name "*.S")
|
||||
OBJECTS += $(shell find . -name "*.c")
|
||||
OBJECTS := $(OBJECTS:%.S=%.o)
|
||||
OBJECTS := $(OBJECTS:%.c=%.o)
|
||||
|
||||
CC := i586-pc-myos-gcc
|
||||
LDFLAGS := -nostdlib -T linkfile.ld
|
||||
LDLIBS := -lkernel
|
||||
CC := i586-pc-myos-gcc
|
||||
LDFLAGS := -nostdlib -T linkfile.ld
|
||||
LDLIBS := -lkernel
|
||||
|
||||
kernel: $(OBJECTS)
|
||||
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
|
||||
kernel: $(OBJECTS)
|
||||
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
|
||||
|
||||
and everything else is taken care of by the default rules of gnu make,
|
||||
including preprocessing and assembling .S files.
|
||||
|
||||
For executables running under my operating system it's even easier
|
||||
|
||||
CC := i586-pc-myos-gcc
|
||||
:::make
|
||||
CC := i586-pc-myos-gcc
|
||||
|
||||
That's all.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user