Commit fec176fa authored by Jonas Termansen's avatar Jonas Termansen

Refactored the libmaxsi/ directory.

C and C++ files are now kept together and so are the mxmpp declarations.

Header files are now stored in include/ and mxmpp'd into preproc/.

All other code now -I ../libmaxsi/preproc.

And other stuff to make this happen, including refactoring Makefile.
parent 4e29f2b9
......@@ -23,7 +23,7 @@ LIBS=$(LIBC)
CPPFLAGS=$(CPUDEFINES) -U_GNU_SOURCE
FLAGS=-nostdinc -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
INCLUDES=-I $(LIBMAXSIROOT)/c/h/ -I $(OSROOT)/
INCLUDES=-I $(LIBMAXSIROOT)/preproc -I $(OSROOT)/
LD=ld
LDFLAGS=$(CPULDFLAGS)
......
......@@ -5,6 +5,4 @@
*.so
*.a
# Ignore dynamically generated headers.
/*.h
c/h/*.h
c/h/sys/*.h
preproc
......@@ -2,12 +2,13 @@ ifndef CPU
CPU=x86
endif
BINS=libc.a libg.a libmaxsi.a libmaxsi-sortix.a
ifeq ($(CPU),x86)
CPUDEFINES=-DPLATFORM_X86
CPUFLAGS=-m32
CPULDFLAGS=-melf_i386
CPUASFLAGS=-32
CPUNASMFLAGS=-felf32
endif
ifeq ($(CPU),x64)
......@@ -16,53 +17,24 @@ ifeq ($(CPU),x64)
CPUFLAGS=-fPIC -m64
CPULDFLAGS=-melf_x86_64
CPUASFLAGS=-64
CPUNASMFLAGS=-felf64
LIBMAXSI_NO_SHARED=1 # This doesn't work yet
endif
DEFINES=-DLIBMAXSI_LIBRARY -DSORTIX -U_GNU_SOURCE $(CPUDEFINES)
FLAGSRELEASE=-O2
FLAGSDEBUG=-O2
FLAGS=$(CPUFLAGS) -std=gnu++0x -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-stack-protector -nostdinc $(FLAGSRELEASE) $(DEFINES)
CPPINCLUDES=-I preproc -I ..
CPPFLAGS=-DLIBMAXSI_LIBRARY -DSORTIX -U_GNU_SOURCE $(CPUDEFINES) $(CPPINCLUDES)
FLAGS=$(CPUFLAGS) -Wall -Wextra -nostdlib -fno-builtin -nostartfiles \
-nodefaultlibs -fno-stack-protector -nostdinc
CFLAGS=$(FLAGS) -std=c99
CXXFLAGS=$(FLAGS) -std=gnu++0x -fno-exceptions -nostdinc++ -fno-rtti
LDFLAGS=$(CPULDFLAGS)
ASFLAGS=$(CPUASFLAGS)
NASMFLAGS=$(CPUNASMFLAGS)
COBJS=\
c/ctype.o \
c/file.o \
c/fdio.o \
c/stdio.o \
c/dir.o \
c/fddir-sortix.o \
CHEADERS=\
c/h/ctype.h \
c/h/unistd.h \
c/h/stdlib.h \
c/h/wchar.h \
c/h/stddef.h \
c/h/fcntl.h \
c/h/stdarg.h \
c/h/wctype.h \
c/h/features.h \
c/h/string.h \
c/h/errno.h \
c/h/error.h \
c/h/dirent.h \
c/h/sys/keycodes.h \
c/h/sys/termmode.h \
c/h/sys/readdirents.h \
c/h/sys/stat.h \
c/h/sys/types.h \
c/h/sys/wait.h \
c/h/stdio.h \
c/h/signal.h \
c/h/stdint.h \
COMMONOBJS=c++.o memory.o heap.o string.o error.o format.o
SORTIXOBJS:=$(addprefix sortix/,$(COMMONOBJS))
LIBMAXSIOBJS:=$(COMMONOBJS) \
OBJS=\
ctype.o \
file.o \
fdio.o \
stdio.o \
dir.o \
fddir-sortix.o \
sortix-sound.o \
process.o \
thread.o \
......@@ -74,62 +46,29 @@ $(CPU)/signal.o \
start.o \
time.o \
random.o \
integer.o
MAXSIHEADERS=\
error.h \
io.h \
memory.h \
platform.h \
string.h \
syscall.h \
thread.h \
process.h \
types.h \
format.h \
sortedlist.h \
signal.h \
signalnum.h \
sortix-vga.h \
sortix-sound.h \
OBJS:=$(LIBMAXSIOBJS)
BINS:=
ifndef LIBMAXSI_SHARED
LIBMAXSI_NO_SHARED=1
endif
ifndef LIBMAXSI_NO_SHARED
BINS:=$(BINS) libmaxsi.so
endif
ifndef LIBMAXSI_NO_STATIC
BINS:=$(BINS) libmaxsi.a
endif
ifndef LIBMAXSI_NO_SORTIX
BINS:=$(BINS) libmaxsi-sortix.a
endif
ifndef LIBMAXSI_NO_LIBC
OBJS:=$(OBJS) $(COBJS)
ifndef LIBMAXSI_NO_SHARED
BINS:=$(BINS) libc.so libg.so
endif
ifndef LIBMAXSI_NO_STATIC
BINS:=$(BINS) libc.a libg.a
endif
HEADERS:=$(MAXSIHEADERS) $(CHEADERS)
else
DEFINES:=$(DEFINES) -DLIBMAXSI_NO_LIBC
endif
CFLAGS:=$(FLAGS) -std=c99 -Ic/h -I..
CXXFLAGS:=$(FLAGS) -nostdinc++ -fno-rtti -I.. -Ic/h
SORTIXFLAGS:=$(CXXFLAGS) -DSORTIX_KERNEL -I.. -I../..
integer.o \
c++.o \
memory.o \
heap.o \
string.o \
error.o \
format.o \
UNPROCHEADERDIRS:=$(shell find include -type d)
UNPROCHEADERS:=$(shell find include -type f)
HEADERDIRS:=$(patsubst include%,preproc%,$(UNPROCHEADERDIRS))
HEADERS:=$(patsubst include%,preproc%,$(UNPROCHEADERS))
SORTIXOBJS=\
c++.o \
memory.o \
heap.o \
string.o \
error.o \
format.o \
SORTIXOBJS:=$(addprefix sortix/,$(SORTIXOBJS))
SORTIXCPPFLAGS:=-DSORTIX_KERNEL
all: $(BINS)
......@@ -157,57 +96,44 @@ libg.so: libc.so
start.o: $(CPU)/start.o
ln -sf $< $@
# libmaxsi
*.cpp: $(HEADERS)
# header preprocessing
$(HEADERDIRS):
mkdir -p $@
%.o: %.cpp
g++ -c $< -o $@ $(CXXFLAGS)
%.h: hsrc/%.h
echo "/* WARNING: This header is generated - edits will be lost! */" > $@
mxmpp -I decl $< >> $@
%.o: %.s
as $(ASFLAGS) $< -o $@
preproc/%: include/%
mxmpp -I decl $< -o $@
%.o: %.asm
nasm $(CPUNASMFLAGS) $< -o $@
headers: $(HEADERDIRS) $(HEADERS)
# libc
# standard library
%.o: %.c headers
gcc -c $< -o $@ $(CPPFLAGS) $(CFLAGS)
c/*.c: $(CHEADERS)
%.o: %.cpp headers
g++ -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS)
c/%.o: c/%.c
gcc -c $< -o $@ $(CFLAGS)
c/h/%.h: c/hsrc/%.h
mkdir -p c/h
mkdir -p c/h/sys
echo "/* WARNING: This header is generated - edits will be lost! */" > $@
mxmpp -I decl -I c/decl $< >> $@
%.o: %.s
as $(ASFLAGS) $< -o $@
# libmaxsi-sortix
sortix:
mkdir -p sortix
sortix/*.cpp: $(HEADERS)
sortix/%.o: %.cpp $(HEADERS)
g++ -c $< -o $@ $(SORTIXFLAGS)
sortix/%.o: sortix/%.cpp
g++ -c $< -o $@ $(SORTIXFLAGS)
sortix/%.o: %.cpp $(HEADERS) sortix
g++ -c $< -o $@ $(CPPFLAGS) $(SORTIXCPPFLAGS) $(CXXFLAGS)
clean:
rm -f *.o sortix/*.o c/*.o x86/*.o x64/*.o *.a *.so $(CHEADERS) $(HEADERS)
rm -f *.o sortix/*.o c/*.o x86/*.o x64/*.o *.a *.so
rm -f $(OBJS)
rm -rf sortix $(HEADERDIRS)
# Installation into sysroot
install:
mkdir -p $(SYSROOT)/usr/lib
for F in $(BINS); do cp -P $$F $(SYSROOT)/usr/lib || exit $?; done
for D in $(UNPROCHEADERDIRS); do mkdir -p $(SYSROOT)/usr/$$D || exit $?; done
for SRC in $(HEADERS); do DEST=`echo $$SRC | sed 's/preproc/include/'`; cp $$SRC $(SYSROOT)/usr/$$DEST || exit $?; done
mkdir -p $(SYSROOT)/usr/include
for F in $(CHEADERS); do F=`echo $$F | sed 's/c\/h\///g'`; mkdir -p $(SYSROOT)/usr/include/`dirname $$F`; cp c/h/$$F $(SYSROOT)/usr/include/$$F || exit $?; done
mkdir -p $(SYSROOT)/usr/include/libmaxsi
for F in $(MAXSIHEADERS); do cp $$F $(SYSROOT)/usr/include/libmaxsi || exit $?; done
cp start.o $(SYSROOT)/usr/lib/crtbegin.o
touch deleteme.cpp
g++ $(CPUFLAGS) -c deleteme.cpp -o deleteme.o
......
......@@ -22,7 +22,7 @@
******************************************************************************/
#include "platform.h"
#include <libmaxsi/platform.h>
extern "C" void __cxa_pure_virtual()
{
......
/******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
This file is part of LibMaxsi.
LibMaxsi is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
string.c
Implements things from <string.h> that is slightly incompatible with
how libmaxsi does stuff.
******************************************************************************/
#include <stdlib.h>
char* strdup(const char* input)
{
size_t inputsize = strlen(input);
char* result = (char*) malloc(inputsize + 1);
if ( result == NULL ) { return NULL; }
memcpy(result, input, inputsize + 1);
return result;
}
......@@ -22,10 +22,10 @@
******************************************************************************/
#include "platform.h"
#include "error.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/error.h>
#ifndef SORTIX_KERNEL
#include "syscall.h"
#include <libmaxsi/syscall.h>
#include <stdio.h>
#endif
......
......@@ -22,9 +22,9 @@
******************************************************************************/
#include "platform.h"
#include "string.h"
#include "format.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/string.h>
#include <libmaxsi/format.h>
namespace Maxsi
{
......
......@@ -22,9 +22,9 @@
******************************************************************************/
#include "platform.h"
#include "memory.h"
#include "error.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/memory.h>
#include <libmaxsi/error.h>
#ifdef SORTIX_KERNEL
#define HEAP_GROWS_DOWNWARDS
......
......@@ -41,7 +41,7 @@
!defined(_SVID_SOURCE) && \
!defined(_XOPEN_SOURCE) && !defined(_XOPEN_SOURCE_EXTENDED) && \
!defined(_GNU_SOURCE) && \
true
1
#define _SORTIX_SOURCE 1
#endif
......
......@@ -23,11 +23,11 @@
******************************************************************************/
#include "platform.h"
#include "signal.h"
#include "string.h"
#include "io.h"
#include "memory.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/signal.h>
#include <libmaxsi/string.h>
#include <libmaxsi/io.h>
#include <libmaxsi/memory.h>
namespace Maxsi
{
......
......@@ -23,7 +23,7 @@
******************************************************************************/
#include "platform.h"
#include <libmaxsi/platform.h>
namespace Maxsi
{
......
......@@ -22,12 +22,12 @@
******************************************************************************/
#include "platform.h"
#include "syscall.h"
#include "io.h"
#include "format.h"
#include "string.h"
#include "memory.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <libmaxsi/io.h>
#include <libmaxsi/format.h>
#include <libmaxsi/string.h>
#include <libmaxsi/memory.h>
#include <sys/readdirents.h>
#include <unistd.h>
#include <errno.h>
......
......@@ -22,11 +22,11 @@
******************************************************************************/
#include "platform.h"
#include "memory.h"
#include "error.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/memory.h>
#include <libmaxsi/error.h>
#ifndef SORTIX_KERNEL
#include "syscall.h"
#include <libmaxsi/syscall.h>
#endif
namespace Maxsi
......
......@@ -22,9 +22,9 @@
******************************************************************************/
#include "platform.h"
#include "syscall.h"
#include "process.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <libmaxsi/process.h>
#include <stdio.h>
#include <dirent.h>
......
......@@ -22,7 +22,7 @@
******************************************************************************/
#include "platform.h"
#include <libmaxsi/platform.h>
namespace Maxsi
{
......
......@@ -22,12 +22,12 @@
******************************************************************************/
#include "platform.h"
#include "string.h"
#include "memory.h"
#include "syscall.h"
#include "process.h"
#include "signal.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/string.h>
#include <libmaxsi/memory.h>
#include <libmaxsi/syscall.h>
#include <libmaxsi/process.h>
#include <libmaxsi/signal.h>
#include <signal.h>
namespace Maxsi
......
......@@ -23,9 +23,9 @@
******************************************************************************/
#include "platform.h"
#include "syscall.h"
#include "sortix-sound.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <libmaxsi/sortix-sound.h>
namespace System
{
......
......@@ -22,9 +22,11 @@
******************************************************************************/
#include "platform.h"
#include "string.h"
#include "memory.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/string.h>
#include <libmaxsi/memory.h>
#include <stdlib.h>
#include <string.h>
namespace Maxsi
{
......@@ -224,6 +226,17 @@ namespace Maxsi
return result;
}
#ifndef SORTIX_KERNEL
extern "C" char* strdup(const char* input)
{
size_t inputsize = strlen(input);
char* result = (char*) malloc(inputsize + 1);
if ( result == NULL ) { return NULL; }
memcpy(result, input, inputsize + 1);
return result;
}
#endif
#if 0
char* Combine(size_t NumParameters, ...)
{
......
......@@ -22,8 +22,8 @@
******************************************************************************/
#include "platform.h"
#include "syscall.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/termmode.h>
#include <unistd.h>
......
......@@ -22,12 +22,12 @@
******************************************************************************/
#include "platform.h"
#include <libmaxsi/platform.h>
#ifdef LIBMAXSI_LIBC
#include <sys/types.h>
#endif
#include "syscall.h"
#include "thread.h"
#include <libmaxsi/syscall.h>
#include <libmaxsi/thread.h>
#ifdef SORTIX_KERNEL
extern "C" void PanicF(const char* Format, ...);
......
......@@ -22,10 +22,10 @@
******************************************************************************/
#include "platform.h"
#include "string.h"
#include "memory.h"
#include "syscall.h"
#include <libmaxsi/platform.h>
#include <libmaxsi/string.h>
#include <libmaxsi/memory.h>
#include <libmaxsi/syscall.h>
namespace Maxsi
{
......
......@@ -59,7 +59,7 @@ else
endif
CPPFLAGSRELEASE=-s $(O)
CPPFLAGSDEBUG=
CPPFLAGS=-I.. -I. $(CPUDEFINES) $(CPUFLAGS) -std=gnu++0x -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector $(DEFINES) $(CPPFLAGSRELEASE)
CPPFLAGS=-I ../libmaxsi/preproc -I.. -I. $(CPUDEFINES) $(CPUFLAGS) -std=gnu++0x -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector $(DEFINES) $(CPPFLAGSRELEASE)
OBJS=$(CPUOBJS) \
kernel.o \
descriptor_tables.o \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment