sortix-mirror/libmaxsi/Makefile
Jonas 'Sortie' Termansen fdbd4ca90d Implemented large parts of the stdio(3), including fprintf.
Made FILE an interface to various backends. This allows application writers
to override the standard FILE API functions with their own backends. This
is highly unportable - it'd be nice if a real standard existed for this.
glibc already does something like this internally, but AFAIK you can't hook
into it.

Added fdopen(3), fopen(3), fregister(3), funregister(3), fread(3),
fwrite(3), fseek(3), clearerr(3), ferror(3), feof(3), rewind(3), ftell(3),
fflush(3), fclose(3), fileno(3), fnewline(3), fcloseall(3), memset(3),
stdio(3), vfprintf(3), fprintf(3), and vprintf(3).

Added a file-descriptor backend to the FILE API.

fd's {0, 1, 2} are now initialized as stdin, stdout, and stderr when the
standard library initializes.

fcloseall(3) is now called on exit(3).

decl/intn_t_.h now @include(size_t.h) instead of declaring it itself.

Added <stdint.h>.

The following programs now flush stdout: cat(1), clear(1), editor(1),
init(1), mxsh(1).

printf(3) is now hooked up against vprintf(3), while Maxsi::PrintF
remains using the system call, for now.
2011-12-24 04:28:34 +01:00

203 lines
4 KiB
Makefile

ifndef CPU
CPU=x86
endif
ifeq ($(CPU),x86)
CPUDEFINES=-DPLATFORM_X86
CPUFLAGS=-m32
CPULDFLAGS=-melf_i386
CPUASFLAGS=-32
CPUNASMFLAGS=-felf32
endif
ifeq ($(CPU),x64)
CPU=x64
CPUDEFINES=-DPLATFORM_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 $(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)
LDFLAGS=$(CPULDFLAGS)
ASFLAGS=$(CPUASFLAGS)
NASMFLAGS=$(CPUNASMFLAGS)
COBJS=\
c/file.o \
c/fdio.o \
c/stdio.o \
CHEADERS=\
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/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) \
sortix-keyboard.o \
sortix-sound.o \
process.o \
thread.o \
io.o \
init.o \
signal.o \
$(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 \
keyboard.h \
sortedlist.h \
signal.h \
signalnum.h \
sortix-vga.h \
sortix-keyboard.h \
sortix-sound.h \
OBJS:=$(LIBMAXSIOBJS)
BINS:=
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
endif
ifndef LIBMAXSI_NO_STATIC
BINS:=$(BINS) libc.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../..
all: $(BINS)
libmaxsi.a: $(OBJS)
ar rcs libmaxsi.a $(OBJS)
libmaxsi.so: $(OBJS)
ld $(LDFLAGS) -shared -o $@ $(OBJS)
libmaxsi-sortix.a: $(SORTIXOBJS)
ar rcs libmaxsi-sortix.a $(SORTIXOBJS)
libc.a: libmaxsi.a
ln -sf $< $@
libc.so: libmaxsi.so
ln -sf $< $@
start.o: $(CPU)/start.o
ln -sf $< $@
# libmaxsi
*.cpp: $(HEADERS)
%.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 $@
%.o: %.asm
nasm $(CPUNASMFLAGS) $< -o $@
# libc
c/*.c: $(CHEADERS)
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 $< >> $@
# libmaxsi-sortix
sortix/*.cpp: $(HEADERS)
sortix/%.o: %.cpp $(HEADERS)
g++ -c $< -o $@ $(SORTIXFLAGS)
sortix/%.o: sortix/%.cpp
g++ -c $< -o $@ $(SORTIXFLAGS)
clean:
rm -f *.o sortix/*.o c/*.o x86/*.o x64/*.o *.a *.so $(CHEADERS) $(HEADERS)
# Installation into sysroot
install:
mkdir -p $(SYSROOT)/usr/lib
for F in $(BINS); do cp --preserve=links $$F $(SYSROOT)/usr/lib || 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/crt1.o
touch deleteme.cpp
g++ $(CPUFLAGS) -c deleteme.cpp -o deleteme.o
for F in crt0.o crtn.o crtbegin.o crtend.o crtbeginT.o crti.o; do cp deleteme.o $(SYSROOT)/usr/lib/$$F; done
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