2011-08-05 08:25:00 -04:00
i f n d e f C P U
CPU = x86
e n d i f
i f e q ( $( CPU ) , x 8 6 )
CPUDEFINES = -DPLATFORM_X86
CPUFLAGS = -m32
CPULDFLAGS = -melf_i386
CPUASFLAGS = -32
CPUNASMFLAGS = -felf32
e n d i f
i f e q ( $( CPU ) , x 6 4 )
CPU = x64
CPUDEFINES = -DPLATFORM_X64
CPUFLAGS = -fPIC -m64
CPULDFLAGS = -melf_x86_64
CPUASFLAGS = -64
CPUNASMFLAGS = -felf64
2011-09-15 16:19:04 -04:00
LIBMAXSI_NO_SHARED = 1 # This doesn't work yet
2011-08-05 08:25:00 -04:00
e n d i f
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
CHEADERS = \
c / h / u n i s t d . h \
c / h / s t d l i b . h \
c / h / w c h a r . h \
c / h / s t d d e f . h \
c / h / f c n t l . h \
c / h / s t d a r g . h \
c / h / w c t y p e . h \
c / h / f e a t u r e s . h \
c / h / s t r i n g . h \
2011-11-22 11:26:47 -05:00
c / h / e r r n o . h \
2011-11-26 05:00:45 -05:00
c / h / e r r o r . h \
2011-11-20 18:02:53 -05:00
c / h / s y s / r e a d d i r e n t s . h \
2011-08-05 08:25:00 -04:00
c / h / s y s / s t a t . h \
c / h / s y s / t y p e s . h \
2011-11-06 16:00:29 -05:00
c / h / s y s / w a i t . h \
2011-09-14 12:11:52 -04:00
c / h / s t d i o . h \
2011-09-15 16:38:40 -04:00
c / h / s i g n a l . h \
2011-08-05 08:25:00 -04:00
2011-11-27 10:55:44 -05:00
COMMONOBJS = c++.o memory.o heap.o string.o error.o format.o
2011-08-05 08:25:00 -04:00
SORTIXOBJS := $( addprefix sortix/,$( COMMONOBJS) )
2011-09-14 12:11:52 -04:00
LIBMAXSIOBJS := $( COMMONOBJS) \
s o r t i x - k e y b o a r d . o \
s o r t i x - s o u n d . o \
p r o c e s s . o \
t h r e a d . o \
i o . o \
i n i t . o \
2011-09-15 16:38:40 -04:00
s i g n a l . o \
$( CPU ) / s i g n a l . o \
2011-09-15 16:19:04 -04:00
s t a r t . o \
2011-11-10 06:27:31 -05:00
r a n d o m . o \
2011-09-14 12:11:52 -04:00
2011-09-15 16:38:40 -04:00
MAXSIHEADERS = \
2011-08-21 06:47:59 -04:00
e r r o r . h \
i o . h \
m e m o r y . h \
p l a t f o r m . h \
s t r i n g . h \
s y s c a l l . h \
t h r e a d . h \
2011-08-27 14:57:39 -04:00
p r o c e s s . h \
2011-08-21 06:47:59 -04:00
t y p e s . h \
f o r m a t . h \
k e y b o a r d . h \
2011-10-25 12:21:06 -04:00
s o r t e d l i s t . h \
2011-09-15 16:38:40 -04:00
s i g n a l . h \
s i g n a l n u m . h \
2011-08-21 06:47:59 -04:00
s o r t i x - v g a . h \
2011-08-21 18:25:28 -04:00
s o r t i x - k e y b o a r d . h \
s o r t i x - s o u n d . h \
2011-08-05 08:25:00 -04:00
OBJS := $( LIBMAXSIOBJS)
2011-09-15 16:19:04 -04:00
BINS :=
i f n d e f L I B M A X S I _ N O _ S H A R E D
BINS:= $( BINS) libmaxsi.so
e n d i f
2011-08-05 08:25:00 -04:00
i f n d e f L I B M A X S I _ N O _ S T A T I C
BINS:= $( BINS) libmaxsi.a
e n d i f
i f n d e f L I B M A X S I _ N O _ S O R T I X
2011-09-15 16:19:04 -04:00
BINS:= $( BINS) libmaxsi-sortix.a
2011-08-05 08:25:00 -04:00
e n d i f
i f n d e f L I B M A X S I _ N O _ L I B C
OBJS:= $( OBJS) $( COBJS)
2011-09-15 16:19:04 -04:00
ifndef LIBMAXSI_NO_SHARED
BINS:= $( BINS) libc.so
endif
2011-08-05 08:25:00 -04:00
ifndef LIBMAXSI_NO_STATIC
BINS:= $( BINS) libc.a
endif
2011-09-15 16:38:40 -04:00
HEADERS:= $( MAXSIHEADERS) $( CHEADERS)
2011-08-05 08:25:00 -04:00
e l s e
DEFINES:= $( DEFINES) -DLIBMAXSI_NO_LIBC
e n d i f
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 $< $@
2011-09-15 16:19:04 -04:00
start.o : $( CPU ) /start .o
ln -sf $< $@
2011-08-05 08:25:00 -04:00
# 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
2011-08-06 19:36:27 -04:00
mkdir -p c/h
2011-08-06 19:37:43 -04:00
mkdir -p c/h/sys
2011-08-05 08:25:00 -04:00
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 :
2011-09-15 16:19:04 -04:00
rm -f *.o sortix/*.o c/*.o x86/*.o x64/*.o *.a *.so $( CHEADERS) $( HEADERS)
2011-08-05 08:25:00 -04:00
2011-09-15 16:38:40 -04:00
# 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