1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Use cross compiler in build system.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-10 23:36:15 +02:00
parent 81530bc58c
commit 9cf092d32e
13 changed files with 469 additions and 235 deletions

136
Makefile
View file

@ -1,36 +1,48 @@
BITS:=$(shell getconf LONG_BIT)
ifndef CPU
ifeq ($(BITS),64)
CPU:=x64
else
CPU:=x86
endif
MFLAGS:=$(MFLAGS) CPU=$(CPU)
endif
include compiler.mak
include version.mak
ifndef O
O=-O2
MFLAGS:=$(MFLAGS) 0=$(O)
ifneq ($(BUILD_LIBC),0)
MODULES:=$(MODULES) libmaxsi
endif
ifndef BENCH
BENCH:=1
ALLMODULES:=$(ALLMODULES) libmaxsi
ifneq ($(BUILD_GAMES),0)
MODULES:=$(MODULES) games
endif
ifeq ($(BENCH),1)
EXTRAMODULES:=$(EXTRAMODULES) bench
ALLMODULES:=$(ALLMODULES) games
ifneq ($(BUILD_MKINITRD),0)
MODULES:=$(MODULES) mkinitrd
endif
ALLMODULES:=$(ALLMODULES) mkinitrd
ifneq ($(BUILD_UTILS),0)
MODULES:=$(MODULES) utils
endif
ALLMODULES:=$(ALLMODULES) utils
ifneq ($(BUILD_BENCH),0)
MODULES:=$(MODULES) bench
endif
ALLMODULES:=$(ALLMODULES) bench
ifneq ($(BUILD_KERNEL),0)
MODULES:=$(MODULES) sortix
endif
ALLMODULES:=$(ALLMODULES) sortix
ifndef SYSROOT
SYSROOT:=$(shell pwd)/sysroot
MFLAGS:=$(MFLAGS) SYSROOT=$(SYSROOT)
SYSROOT:=$(shell pwd)/sysroot
MFLAGS:=$(MFLAGS) SYSROOT=$(SYSROOT)
endif
REMOTE=192.168.2.6
REMOTEUSER=sortie
REMOTECOPYDIR:=/home/$(REMOTEUSER)/Desktop/MaxsiOS
MODULES=libmaxsi games mkinitrd utils $(EXTRAMODULES) sortix
ALLMODULES=libmaxsi games mkinitrd utils bench sortix
ifndef PREFIXNAME
PREFIXNAME:=/
MFLAGS:=$(MFLAGS) PREFIXNAME=$(PREFIXNAME)
endif
include dirs.mak
VERSION=0.8dev
DEBNAME:=sortix_$(VERSION)_$(CPU)
DEBSRCNAME:=sortix_$(VERSION)
DEBDIR:=builds/$(DEBNAME)
@ -39,42 +51,63 @@ DEBFILE:=builds/$(DEBNAME).deb
PACKAGENAME:=sortix
ISODIR:=builds/$(DEBNAME)-iso
ISOFILE:=builds/$(DEBNAME).iso
INITRDDIR:=initrd
INITRD=sortix/sortix.initrd
INITRD=$(INSTALLBOOTDIR)/$(HOST)/sortix.initrd
MFLAGS:=$(MFLAGS) VERSION=$(VERSION)
all: $(INITRD)
suball:
(for D in $(MODULES); do ($(MAKE) all $(MFLAGS) --directory $$D && $(MAKE) install $(MFLAGS) --directory $$D) || exit $?; done)
.PHONY: all suball sysroot-base-headers sysroot-fsh clean distclean \
everything everything-all-archs all-archs linecount install uninstall \
deb debfile debsource iso run-virtualbox run-virtualbox-debug \
clean-builds clean-sysroot
sysroot-base-headers:
(for D in libmaxsi sortix; do ($(MAKE) install-headers $(MFLAGS) --directory $$D) || exit $?; done)
suball: sysroot-base-headers
(for D in $(MODULES); do ($(MAKE) all $(MFLAGS) --directory $$D && $(MAKE) install $(MFLAGS) --directory $$D) || exit $$?; done)
sysroot-base-headers: sysroot-fsh
(for D in libmaxsi sortix; do ($(MAKE) install-headers $(MFLAGS) --directory $$D) || exit $$?; done)
sysroot-fsh:
mkdir -p "$(SYSROOT)"
for DIRNAME in bin boot lib include; do (\
mkdir -p "$(SYSROOT)/$$DIRNAME" &&\
mkdir -p "$(SYSROOT)/$$DIRNAME/$(HOST)" \
) || exit $$?; done;
if [ ! -e "$(SYSROOT)/usr" ]; then ln -s . "$(SYSROOT)/usr"; fi
clean:
rm -rf $(SYSROOT)
rm -f $(INITRD)
rm -f initrd/*
(for D in $(ALLMODULES); do $(MAKE) clean $(MFLAGS) --directory $$D || exit $?; done)
rm -f "$(INITRD)"
rm -f sortix/sortix.initrd # Backwards compatibility, not needed for newer builds.
rm -f initrd/* # Backwards compatibility, not needed for newer builds.
(for D in $(ALLMODULES); do $(MAKE) clean $(MFLAGS) --directory $$D || exit $$?; done)
distclean: clean cleanbuilds
cleanbuilds:
clean-builds:
rm -rf builds/
rm -f sortix.iso
clean-sysroot:
rm -rf "$(SYSROOT)"
distclean: clean clean-builds clean-sysroot
everything: all deb iso
everything-all-archs:
$(MAKE) clean $(MFLAGS)
$(MAKE) everything $(MFLAGS) CPU=x86
$(MAKE) everything $(MFLAGS) HOST=i486-sortix
$(MAKE) clean $(MFLAGS)
$(MAKE) everything $(MFLAGS) CPU=x64
$(MAKE) everything $(MFLAGS) HOST=x86_64-sortix
all-archs:
$(MAKE) clean $(MFLAGS)
$(MAKE) all $(MFLAGS) HOST=i486-sortix
$(MAKE) clean $(MFLAGS)
$(MAKE) all $(MFLAGS) HOST=x86_64-sortix
# Initializing RamDisk
$(INITRD): suball
mkinitrd/mkinitrd initrd -o $(INITRD)
mkinitrd/mkinitrd $(SYSROOT)/bin/$(HOST) -o $(INITRD)
# Statistics
linecount:
@ -92,18 +125,6 @@ install: all
uninstall:
rm -f /boot/sortix.bin
rm -f /etc/grub.d/42_sortix
update-grub
# Remote machine
install-remote: all
scp -r ./ $(REMOTE):$(REMOTECOPYDIR)
scp sortix/sortix.bin root@$(REMOTE):/boot
scp $(INITRD) root@$(REMOTE):/boot
ssh root@$(REMOTE) "init 6"
uninstall-remote:
ssh root@$(REMOTE) "rm /boot/sortix.bin"
# Packaging
@ -114,7 +135,7 @@ debfile: all
mkdir -p $(DEBDIR)
mkdir -p $(DEBDIR)/boot
cp sortix/sortix.bin $(DEBDIR)/boot
cp sortix/sortix.initrd $(DEBDIR)/boot
cp $(INITRD) $(DEBDIR)/boot
expr \( `stat --printf="%s" $(DEBDIR)/boot/sortix.bin` \
+ `stat --printf="%s" $(DEBDIR)/boot/sortix.initrd` \
+ 1023 \) / 1024 > $(DEBDIR)/boot/deb.size
@ -137,14 +158,14 @@ debsource: all
rm -rf $(DEBSRCDIR)
mkdir -p $(DEBSRCDIR)
for D in `ls | grep -v builds | grep -v sysroot`; do cp -r $$D $(DEBSRCDIR); done
(cd $(DEBSRCDIR) && make distclean)
(cd $(DEBSRCDIR) && make distclean SYSROOT=$(shell pwd)/$(DEBSRCDIR)/sysroot)
rm -rf $(DEBSRCDIR)/sysroot
(cd builds && tar cfz $(DEBSRCNAME)-src.tar.gz $(DEBSRCNAME)-src)
rm -rf $(DEBSRCDIR)
# Bootable images
iso: all debsource
$(ISOFILE): all debsource
rm -rf $(ISODIR)
mkdir -p builds
mkdir -p $(ISODIR)
@ -155,8 +176,10 @@ iso: all debsource
grub-mkrescue -o $(ISOFILE) $(ISODIR)
rm -rf $(ISODIR)
iso: $(ISOFILE)
sortix.iso: iso
cp $(ISOFILE) sortix.iso
cp $(ISOFILE) $@
# Virtualization
run-virtualbox: sortix.iso
@ -165,4 +188,3 @@ run-virtualbox: sortix.iso
run-virtualbox-debug: sortix.iso
virtualbox --debug --start-running --startvm sortix

2
bench/.gitignore vendored
View file

@ -1 +1,3 @@
*.o
benchctxswitch
benchsyscall

View file

@ -1,29 +1,40 @@
# Set up variables such that we can easily cross-compile.
OSROOT=..
include ../crosscompilemakefile.mak
include ../compiler.mak
include ../version.mak
include ../dirs.mak
CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra
ifndef OPTLEVEL
OPTLEVEL=-O2
endif
INITRDDIR:=../initrd
LOCALBINARIES:=\
ifndef CXXFLAGS
CXXFLAGS:=$(OPTLEVEL)
endif
CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti
BINARIES:=\
benchsyscall \
benchctxswitch \
BINARIES:=$(addprefix $(INITRDDIR)/,$(LOCALBINARIES))
all: $(BINARIES)
all: install
.PHONY: all install uninstall clean
install: $(LOCALBINARIES)
cp $(LOCALBINARIES) $(INITRDDIR)
rm -f $(LOCALBINARIES)
install: all
mkdir -p $(INSTALLBINDIR)/$(HOST)
install $(BINARIES) $(INSTALLBINDIR)/$(HOST)
uninstall:
for FILE in $(INSTALLBINDIR); do \
rm -f $(INSTALLBINDIR)/$(HOST)/$$FILE; \
done
%: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -O2 -c $< -o $@.o
$(LD) $(LDFLAGS) $@.o -o $@ $(LIBS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $< -o $@
sh: mxsh
cp $< $@
clean:
rm -f $(BINARIES) $(LOCALBINARIES) *.o
rm -f $(BINARIES) *.o

65
compiler.mak Normal file
View file

@ -0,0 +1,65 @@
ifndef BITS
BITS:=$(shell getconf LONG_BIT)
endif
ifndef HOST
ifeq ($(BITS),64)
HOST:=x86_64-sortix
else
HOST:=i486-sortix
endif
MFLAGS:=$(MFLAGS) HOST=$(HOST)
endif
ifeq ($(HOST),i486-sortix)
CPU:=x86
endif
ifeq ($(HOST),x86_64-sortix)
CPU:=x64
endif
ifndef BUILDCC
BUILDCC:=gcc
endif
ifndef BUILDCXX
BUILDCXX:=g++
endif
ifndef BUILDAR
BUILDAR:=ar
endif
ifndef BUILDAS
BUILDAS:=as
endif
ifndef BUILDLD
BUILDAS:=ld
endif
ifndef BUILDOBJCOPY
BUILDOBJCOPY:=objcopy
endif
ifndef HOSTCC
HOSTCC:=$(HOST)-gcc
endif
ifndef HOSTCXX
HOSTCXX:=$(HOST)-g++
endif
ifndef HOSTAR
HOSTAR:=$(HOST)-ar
endif
ifndef HOSTAS
HOSTAS:=$(HOST)-as
endif
ifndef HOSTLD
HOSTLD:=$(HOST)-ld
endif
ifndef HOSTOBJCOPY
HOSTOBJCOPY:=$(HOST)-objcopy
endif
CC:=$(HOSTCC)
CXX:=$(HOSTCXX)
AR=:$(HOSTAR)
AS:=$(HOSTAS)
LD:=$(HOSTLD)
OBJCOPY:=$(HOSTOBJCOPY)

View file

@ -1,36 +0,0 @@
ifndef CPU
CPU=x86
endif
ifeq ($(CPU),x86)
X86FAMILY=1
CPUDEFINES=-DPLATFORM_X86
CPUFLAGS=-m32
CPULDFLAGS=-melf_i386
endif
ifeq ($(CPU),x64)
X86FAMILY=1
CPUDEFINES=-DPLATFORM_X64
CPUFLAGS=-m64
CPULDFLAGS=-melf_x86_64
endif
LIBMAXSIROOT:=$(OSROOT)/libmaxsi
SORTIXROOT:=$(OSROOT)/sortix
LIBC:=$(LIBMAXSIROOT)/start.o $(LIBMAXSIROOT)/libc.a
LIBS:=$(LIBC)
CPPFLAGS:=$(CPUDEFINES) -U_GNU_SOURCE -Ulinux -Dsortix
FLAGS:=-nostdinc -nostdlib -nostartfiles -nodefaultlibs
INCLUDES:=-I $(LIBMAXSIROOT)/preproc -I $(SORTIXROOT)/include
LD:=ld
LDFLAGS:=$(CPULDFLAGS)
CC:=gcc
CFLAGS:=$(CPUFLAGS) $(FLAGS) $(INCLUDES)
CXX:=g++
CXXFLAGS:=$(CPUFLAGS) $(FLAGS) $(INCLUDES) -fno-exceptions -fno-rtti

119
dirs.mak Normal file
View file

@ -0,0 +1,119 @@
ifndef SYSROOT
SYSROOT:=/
endif
# The locations from where the program will be invoked/run on the host machine.
# For instance, on Sortix programs are normally run from the /bin union
# directory, even though they are actually installed somewhere else.
ifndef RUNPREFIXNAME
RUNPREFIXNAME:=/
endif
RUNPREFIXNAME:=$(shell echo "$(RUNPREFIXNAME)" | sed 's/\/\/*/\//g')
ifndef RUNPREFIX
RUNPREFIX:=/$(RUNPREFIXNAME)
endif
RUNPREFIX:=$(shell echo "$(RUNPREFIX)" | sed 's/\/\/*/\//g')
ifndef RUNBINDIR
RUNBINDIR:=$(RUNPREFIX)/bin
endif
RUNBINDIR:=$(shell echo "$(RUNBINDIR)" | sed 's/\/\/*/\//g')
ifndef RUNLIBDIR
RUNLIBDIR:=$(RUNPREFIX)/lib
endif
RUNLIBDIR:=$(shell echo "$(RUNLIBDIR)" | sed 's/\/\/*/\//g')
ifndef RUNINCLUDEDIR
RUNINCLUDEDIR:=$(RUNPREFIX)/include
endif
RUNINCLUDEDIR:=$(shell echo "$(RUNINCLUDEDIR)" | sed 's/\/\/*/\//g')
ifndef RUNBOOTDIR
RUNBOOTDIR:=$(RUNPREFIX)/boot
endif
RUNBOOTDIR:=$(shell echo "$(RUNBOOTDIR)" | sed 's/\/\/*/\//g')
# Where the program will be really installed on the host machine. For instance,
# on Sortix programs are run from the /bin union directory, but they are
# installed somewhere else, these variables tells where. Note that programs must
# not depend on being installed here, they should detect the proper directories
# at (preferably) runtime, or during the install configuration step when
# installed through package management.
ifndef PREFIXNAME
PREFIXNAME:=/data/local
endif
PREFIXNAME:=$(shell echo "$(PREFIXNAME)" | sed 's/\/\/*/\//g')
ifndef PREFIX
PREFIX:=$(SYSROOT)/$(PREFIXNAME)
endif
PREFIX:=$(shell echo "$(PREFIX)" | sed 's/\/\/*/\//g')
ifndef BINDIR
BINDIR:=$(PREFIX)/bin
endif
BINDIR:=$(shell echo "$(BINDIR)" | sed 's/\/\/*/\//g')
ifndef LIBDIR
LIBDIR:=$(PREFIX)/lib
endif
LIBDIR:=$(shell echo "$(LIBDIR)" | sed 's/\/\/*/\//g')
ifndef INCLUDEDIR
INCLUDEDIR:=$(PREFIX)/include
endif
INCLUDEDIR:=$(shell echo "$(INCLUDEDIR)" | sed 's/\/\/*/\//g')
ifndef BOOTDIR
BOOTDIR:=$(PREFIX)/boot
endif
BOOTDIR:=$(shell echo "$(BOOTDIR)" | sed 's/\/\/*/\//g')
# Where the program will be installed on the build machine. This is mostly
# useful if cross compiling or producing a software distribution image. By
# default programs will be installed in the same location as the host machine.
ifdef INSTALLPREFIX
INSTALLPREFIX_WAS_SPECIFIED=1
endif
ifndef INSTALLPREFIX
INSTALLPREFIX:=$(PREFIX)
endif
INSTALLPREFIX:=$(shell echo "$(INSTALLPREFIX)" | sed 's/\/\/*/\//g')
ifndef INSTALLBINDIR
ifdef INSTALLPREFIX_WAS_SPECIFIED
INSTALLBINDIR:=$(INSTALLPREFIX)/bin
else
INSTALLBINDIR:=$(BINDIR)
endif
endif
INSTALLBINDIR:=$(shell echo "$(INSTALLBINDIR)" | sed 's/\/\/*/\//g')
ifndef INSTALLLIBDIR
ifdef INSTALLPREFIX_WAS_SPECIFIED
INSTALLLIBDIR:=$(INSTALLPREFIX)/lib
else
INSTALLLIBDIR:=$(LIBDIR)
endif
endif
INSTALLLIBDIR:=$(shell echo "$(INSTALLLIBDIR)" | sed 's/\/\/*/\//g')
ifndef INSTALLINCLUDEDIR
ifdef INSTALLPREFIX_WAS_SPECIFIED
INSTALLINCLUDEDIR:=$(INSTALLPREFIX)/include
else
INSTALLINCLUDEDIR:=$(INCLUDEDIR)
endif
endif
INSTALLINCLUDEDIR:=$(shell echo "$(INSTALLINCLUDEDIR)" | sed 's/\/\/*/\//g')
ifndef INSTALLBOOTDIR
ifdef INSTALLPREFIX_WAS_SPECIFIED
INSTALLBOOTDIR:=$(INSTALLPREFIX)/boot
else
INSTALLBOOTDIR:=$(BOOTDIR)
endif
endif
INSTALLBOOTDIR:=$(shell echo "$(INSTALLBOOTDIR)" | sed 's/\/\/*/\//g')

2
games/.gitignore vendored
View file

@ -6,3 +6,5 @@
*.a
pong
conway
snake
asteroids

View file

@ -1,31 +1,42 @@
# Set up variables such that we can easily cross-compile.
OSROOT=..
include ../crosscompilemakefile.mak
include ../compiler.mak
include ../version.mak
include ../dirs.mak
CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra
ifndef OPTLEVEL
OPTLEVEL=-O2
endif
INITRDDIR:=../initrd
LOCALBINARIES:=\
ifndef CXXFLAGS
CXXFLAGS:=$(OPTLEVEL)
endif
CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti
BINARIES:=\
pong \
conway \
snake \
asteroids \
BINARIES:=$(addprefix $(INITRDDIR)/,$(LOCALBINARIES))
all: $(BINARIES)
all: install
.PHONY: all install uninstall clean
install: $(LOCALBINARIES)
cp $(LOCALBINARIES) $(INITRDDIR)
rm -f $(LOCALBINARIES)
install: all
mkdir -p $(INSTALLBINDIR)/$(HOST)
install $(BINARIES) $(INSTALLBINDIR)/$(HOST)
uninstall:
for FILE in $(INSTALLBINDIR); do \
rm -f $(INSTALLBINDIR)/$(HOST)/$$FILE; \
done
%: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -O2 -c $< -o $@.o
$(LD) $(LDFLAGS) $@.o -o $@ $(LIBS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $< -o $@
sh: mxsh
cp $< $@
clean:
rm -f $(BINARIES) $(LOCALBINARIES) *.o
rm -f $(BINARIES) *.o

View file

@ -1,29 +1,32 @@
ifndef CPU
CPU=x86
include ../compiler.mak
include ../version.mak
include ../dirs.mak
ifndef OPTLEVEL
OPTLEVEL:=-O2
endif
ifeq ($(CPU),x86)
CPUDEFINES=-DPLATFORM_X86
CPUFLAGS=-m32
CPULDFLAGS=-melf_i386
CPUASFLAGS=-32
ifeq ($(DEBUG_LIBC),1)
FLAGSDEBUG=-g3
else
FLAGSDEBUG=$(OPTLEVEL)
endif
ifeq ($(CPU),x64)
CPU=x64
CPUDEFINES=-DPLATFORM_X64
CPUFLAGS=-fPIC -m64 -mno-red-zone
CPULDFLAGS=-melf_x86_64
CPUASFLAGS=-64
CPUDIR:=$(CPU)
ifeq ($(HOST),i486-sortix)
CPUFLAGS=
endif
CPPINCLUDES=-I preproc -I ../sortix/include
CPPFLAGS=-DLIBMAXSI_LIBRARY -DSORTIX -U_GNU_SOURCE $(CPUDEFINES) $(CPPINCLUDES)
FLAGS=$(CPUFLAGS) -Wall -Wextra -nostdlib -fno-builtin -nostartfiles \
-nodefaultlibs -fno-stack-protector -nostdinc
ifeq ($(HOST),x86_64-sortix)
CPUFLAGS=-fPIC -mno-red-zone
endif
CPPINCLUDES=-I preproc
CPPFLAGS=-DLIBMAXSI_LIBRARY -U_GNU_SOURCE $(CPUDEFINES) $(CPPINCLUDES)
FLAGS=$(CPUFLAGS) -Wall -Wextra -fno-stack-protector $(FLAGSDEBUG)
CFLAGS=$(FLAGS) -std=c99
CXXFLAGS=$(FLAGS) -std=gnu++0x -fno-exceptions -nostdinc++ -fno-rtti
LDFLAGS=$(CPULDFLAGS)
CXXFLAGS=$(FLAGS) -std=gnu++0x -fno-exceptions -fno-rtti
ASFLAGS=$(CPUASFLAGS)
OBJS=\
@ -48,8 +51,8 @@ isatty.o \
kernelinfo.o \
init.o \
signal.o \
$(CPU)/signal.o \
$(CPU)/fork.o \
$(CPUDIR)/signal.o \
$(CPUDIR)/fork.o \
time.o \
random.o \
abs.o \
@ -188,7 +191,7 @@ crc32.o \
SORTIXOBJS:=$(addprefix sortix/,$(SORTIXOBJS))
SORTIXCPPFLAGS:=-DSORTIX_KERNEL
BINS=libc.a libg.a libmaxsi.a libmaxsi-sortix.a $(CRTOBJ)
BINS=libc.a libg.a libm.a libstdc++.a libmaxsi.a libmaxsi-sortix.a $(CRTOBJ)
all: $(BINS)
@ -196,36 +199,33 @@ all: $(BINS)
install-lib-dirs install-libs
libmaxsi.a: $(OBJS)
ar rcs libmaxsi.a $(OBJS)
libmaxsi.so: $(OBJS)
ld $(LDFLAGS) -shared -o $@ $(OBJS)
$(HOSTAR) rcs libmaxsi.a $(OBJS)
libmaxsi-sortix.a: $(SORTIXOBJS)
ar rcs libmaxsi-sortix.a $(SORTIXOBJS)
$(HOSTAR) rcs libmaxsi-sortix.a $(SORTIXOBJS)
libc.a: libmaxsi.a
ln -sf $< $@
libc.so: libmaxsi.so
ln -sf $< $@
libg.a: libc.a
ln -sf $< $@
libg.so: libc.so
ln -sf $< $@
libm.a:
$(HOSTAR) rcs $@
start.o: $(CPU)/start.o
libstdc++.a:
$(HOSTAR) rcs $@
start.o: $(CPUDIR)/start.o
ln -f $< $@
crt1.o: $(CPU)/crt1.o
crt1.o: $(CPUDIR)/crt1.o
ln -f $< $@
crti.o: $(CPU)/crti.o
crti.o: $(CPUDIR)/crti.o
ln -f $< $@
crtn.o: $(CPU)/crtn.o
crtn.o: $(CPUDIR)/crtn.o
ln -f $< $@
# header preprocessing
@ -239,20 +239,20 @@ headers: $(HEADERDIRS) $(HEADERS)
# standard library
%.o: %.c headers
gcc -c $< -o $@ $(CPPFLAGS) $(CFLAGS)
$(HOSTCC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS)
%.o: %.cpp headers
g++ -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS)
$(HOSTCXX) -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS)
%.o: %.s
as $(ASFLAGS) $< -o $@
$(HOSTAS) $(ASFLAGS) $< -o $@
# libmaxsi-sortix
sortix:
mkdir -p sortix
sortix/%.o: %.cpp $(HEADERS) sortix
g++ -c $< -o $@ $(CPPFLAGS) $(SORTIXCPPFLAGS) $(CXXFLAGS)
$(HOSTCXX) -c $< -o $@ $(CPPFLAGS) $(SORTIXCPPFLAGS) $(CXXFLAGS)
clean:
rm -f *.o sortix/*.o c/*.o x86/*.o x64/*.o *.a *.so
@ -263,19 +263,26 @@ clean:
install: install-headers install-libs
install-include-dirs: headers
mkdir -p $(SYSROOT)/usr/include
for D in $(UNPROCHEADERDIRS); do mkdir -p $(SYSROOT)/usr/$$D || exit $?; done
mkdir -p $(INSTALLINCLUDEDIR)
DIRS=$$(echo $(UNPROCHEADERDIRS) | \
tr ' ' '\n' | \
sed 's/include\/*//'); \
for D in $$DIRS; do \
mkdir -p $(INSTALLINCLUDEDIR)/$$D || exit $?; \
done
install-headers: install-include-dirs headers
for SRC in $(HEADERS); do DEST=`echo $$SRC | sed 's/preproc/include/'`; cp $$SRC $(SYSROOT)/usr/$$DEST || exit $?; done
for SRC in $(HEADERS); do \
DEST=`echo $$SRC | sed 's/preproc\///'`; \
cp -P $$SRC $(INSTALLINCLUDEDIR)/$$DEST || exit $?; \
done
install-lib-dirs: all
mkdir -p $(SYSROOT)/usr/lib
install-lib-dirs:
mkdir -p $(INSTALLLIBDIR)
mkdir -p $(INSTALLLIBDIR)/$(HOST)
install-libs: install-lib-dirs all
for F in $(BINS); do cp -P $$F $(SYSROOT)/usr/lib || exit $?; done
touch deleteme.cpp
g++ $(CPUFLAGS) -c deleteme.cpp -o deleteme.o
for F in libgcc.so libm.so libstdc++.so; do ld $(CPULDFLAGS) -shared deleteme.o -o $(SYSROOT)/usr/lib/$$F; done
rm -f deleteme.o deleteme.cpp
install-libs: install-lib-dirs
for F in $(BINS); do \
cp -P $$F $(INSTALLLIBDIR)/$(HOST) || exit $?; \
done

View file

@ -1,31 +1,27 @@
ifndef O
O:=-O3
endif
include ../compiler.mak
include ../version.mak
include ../dirs.mak
ifndef CPU
CPU=x86
ifndef OPTLEVEL
OPTLEVEL:=-O2
endif
ifeq ($(CPU),x86)
BUILDID=x86
X86FAMILY=1
CPUDEFINES=-DPLATFORM_X86
CPUFLAGS=-m32
CPULDFLAGS=-melf_i386
CPUASFLAGS=-32
CPUFLAGS=
CPULDFLAGS=
CPUNASMFLAGS=-felf32
CPUOBJS=$(CPU)/boot.o $(CPU)/base.o $(CPU)/x86.o
CPUOBJS:=$(CPU)/boot.o $(CPU)/base.o $(CPU)/x86.o
endif
ifeq ($(CPU),x64)
BUILDID=x64
X86FAMILY=1
CPUDEFINES=-DPLATFORM_X64
CPUFLAGS=-m64 -ffreestanding -mno-red-zone
CPULDFLAGS=-melf64-little -z max-page-size=0x1000
CPUASFLAGS=-64
CPUFLAGS=-ffreestanding -mno-red-zone
CPULDFLAGS=-z max-page-size=0x1000
CPUNASMFLAGS=-felf64
CPUOBJS=$(CPU)/base.o $(CPU)/x64.o
CPUOBJS:=$(CPU)/base.o $(CPU)/x64.o
endif
ifdef X86FAMILY
@ -49,11 +45,7 @@ endif
DIRS=. x64 x86 x86-family fs kb kb/layout
DEFINES:=-DSORTIX_KERNEL -U_GNU_SOURCE $(CPUDEFINES)
ifeq ($(JSSORTIX),1)
DEFINES:=$(DEFINES) -DPLATFORM_SERIAL -DJSSORTIX
BUILDID:=$(BUILDID)-js
endif
DEFINES:=-DSORTIX_KERNEL -U_GNU_SOURCE
ifeq ($(PANIC_SHORT),1)
DEFINES:=$(DEFINES) -DPANIC_SHORT
endif
@ -71,22 +63,22 @@ ifdef VERSION
DEFINES:=$(DEFINES) -DVERSIONSTR=\"$(VERSION)\"
endif
INCLUDES=-I. -Iinclude -I../libmaxsi/preproc
INCLUDES=-I. -Iinclude
CPPFLAGS=$(INCLUDES) $(DEFINES)
ifeq ($(DEBUG_KERNEL),1)
FLAGSDEBUG=-g3
else
FLAGSDEBUG=-s $(O)
FLAGSDEBUG=$(OPTLEVEL)
endif
FLAGS=$(CPUFLAGS) -Wall -Wall -Wextra -nostdlib -fno-builtin -nostartfiles \
FLAGS=$(CPUFLAGS) -Wall -Wall -Wextra -nostdlib -nostartfiles \
-nodefaultlibs -fno-stack-protector $(FLAGSDEBUG)
CFLAGS=$(FLAGS)
CXXFLAGS=$(FLAGS) -std=gnu++0x -fno-exceptions -fno-rtti
ASFLAGS=$(CPUASFLAGS)
ASFLAGS=
NASMFLAGS=$(CPUNASMFLAGS)
STATICLIBS=\
../libmaxsi/libmaxsi-sortix.a \
-lmaxsi-sortix \
HEADERDIRS:=$(shell find include -type d)
HEADERS:=$(shell find include -type f)
@ -146,10 +138,10 @@ fs/initfs.o \
fs/ramfs.o \
fs/videofs.o \
ata.o \
$(STATICLIBS) \
end.o # Must be last, determines kernel size.
JSOBJS:=$(subst .o,-js.o,$(OBJS))
ALLOBJS=\
$(OBJS) \
end.o
all: sortix.bin
@ -157,26 +149,18 @@ all: sortix.bin
headers:
# jssortix compilation
jssortix: jssortix.bin
sortix-x86-js.tmp: $(OBJS)
ld -melf_i386 -Ttext 100000 -o sortix-x86-js-internal.out $(OBJS)
objcopy -O binary sortix-x86-js-internal.out $@
# x64 compilation
x64/boot.o: x64/boot.s
as -64 $< -o $@
$(HOSTAS) -64 $< -o $@
sortix-x64.tmp: $(OBJS) x64/boot.o
ld -N -melf_x86_64 -Ttext 100000 -o sortix-x64-internal.out x64/boot.o $(OBJS)
objcopy sortix-x64-internal.out -O elf32-i386 sortix-x64.tmp
sortix-x64.tmp: $(ALLOBJS) x64/boot.o
$(HOSTLD) -N -melf_x86_64_sortix -Ttext 100000 -o sortix-x64-internal.out x64/boot.o $(OBJS) $(STATICLIBS) end.o
$(HOSTOBJCOPY) sortix-x64-internal.out -O elf32-i386 sortix-x64.tmp
# x86 compilation
sortix-x86.tmp: $(OBJS)
ld -melf_i386 -Ttext 100000 -o $@ $(OBJS)
sortix-x86.tmp: $(ALLOBJS)
$(HOSTLD) -melf_i386_sortix -Ttext 100000 -o $@ $(OBJS) $(STATICLIBS) end.o
# general rules
@ -184,10 +168,10 @@ sortix.bin: sortix-$(BUILDID).tmp
cp -vu $< $@
%.o: %.cpp
g++ -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS)
$(HOSTCXX) -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS)
%.o: %.s
as $(ASFLAGS) $< -o $@
$(HOSTAS) $< -o $@ $(ASFLAGS)
%.o: %.asm
nasm $(NASMFLAGS) $< -o $@
@ -196,15 +180,26 @@ clean:
for D in $(DIRS); do rm -f $$D/*.o $$D/*.bin $$D/*.out $$D/*.tmp; done
# Installation into sysroot
install: install-headers
install: install-headers install-kernel
install-include-dirs: headers
for DIR in $(HEADERDIRS); do \
mkdir -p $(SYSROOT)/usr/$$DIR; \
mkdir -p $(INSTALLINCLUDEDIR)
DIRS=$$(echo $(HEADERDIRS) | \
tr ' ' '\n' | \
sed 's/include\/*//'); \
for D in $$DIRS; do \
mkdir -p $(INSTALLINCLUDEDIR)/$$D || exit $?; \
done
install-headers: install-include-dirs headers
for FILE in $(HEADERS); do \
cp $$FILE $(SYSROOT)/usr/$$FILE; \
for SRC in $(HEADERS); do \
DEST=`echo $$SRC | sed 's/include\///'`; \
cp -P $$SRC $(INSTALLINCLUDEDIR)/$$DEST || exit $?; \
done
install-kernel: install-kernel-binary
install-kernel-binary:
mkdir -p $(INSTALLBOOTDIR)/$(HOST)
cp -P sortix.bin $(INSTALLBOOTDIR)/$(HOST)

24
utils/.gitignore vendored
View file

@ -1 +1,25 @@
*.o
init
calc
cat
cp
echo
rm
sh
mxsh
clear
ls
pwd
help
uptime
memstat
chvideomode
uname
kernelinfo
editor
kill
column
pager
head
tail
type

View file

@ -1,11 +1,18 @@
# Set up variables such that we can easily cross-compile.
OSROOT=..
include ../crosscompilemakefile.mak
include ../compiler.mak
include ../version.mak
include ../dirs.mak
CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra
ifndef OPTLEVEL
OPTLEVEL=-O2
endif
INITRDDIR:=../initrd
LOCALBINARIES:=\
ifndef CXXFLAGS
CXXFLAGS:=$(OPTLEVEL)
endif
CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti
BINARIES:=\
init \
calc \
cat \
@ -31,21 +38,25 @@ head \
tail \
type \
BINARIES:=$(addprefix $(INITRDDIR)/,$(LOCALBINARIES))
all: $(BINARIES)
all: install
.PHONY: all install uninstall clean
install: $(LOCALBINARIES)
cp $(LOCALBINARIES) $(INITRDDIR)
rm -f $(LOCALBINARIES)
install: all
mkdir -p $(INSTALLBINDIR)/$(HOST)
install $(BINARIES) $(INSTALLBINDIR)/$(HOST)
uninstall:
for FILE in $(INSTALLBINDIR); do \
rm -f $(INSTALLBINDIR)/$(HOST)/$$FILE; \
done
%: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -O2 -c $< -o $@.o
$(LD) $(LDFLAGS) $@.o -o $@ $(LIBS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $< -o $@
sh: mxsh
cp $< $@
clean:
rm -f $(BINARIES) $(LOCALBINARIES) *.o
rm -f $(BINARIES) *.o

1
version.mak Normal file
View file

@ -0,0 +1 @@
VERSION=0.8dev