switch build system to Tup
git-svn-id: svn://kolibrios.org@5098 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
85
programs/develop/libraries/menuetlibc/src/libc/Tupfile.lua
Normal file
85
programs/develop/libraries/menuetlibc/src/libc/Tupfile.lua
Normal file
@@ -0,0 +1,85 @@
|
||||
if tup.getconfig("NO_GCC") ~= "" then return end
|
||||
FOLDERS = {
|
||||
"ansi/assert",
|
||||
"ansi/ctype",
|
||||
"ansi/errno",
|
||||
"ansi/locale",
|
||||
"ansi/math",
|
||||
"ansi/setjmp",
|
||||
"ansi/stdio",
|
||||
"ansi/stdlib",
|
||||
"ansi/string",
|
||||
"ansi/time",
|
||||
"ansif",
|
||||
"compat/bsd",
|
||||
"compat/io",
|
||||
"compat/math",
|
||||
"compat/mman",
|
||||
"compat/mntent",
|
||||
"compat/search",
|
||||
"compat/signal",
|
||||
"compat/stdio",
|
||||
"compat/stdlib",
|
||||
"compat/string",
|
||||
"compat/sys/resource",
|
||||
"compat/sys/stat",
|
||||
"compat/sys/vfs",
|
||||
"compat/termios",
|
||||
"compat/time",
|
||||
"compat/unistd",
|
||||
"compat/v1",
|
||||
"crt0",
|
||||
"dos/compat",
|
||||
"dos/dir",
|
||||
"dos/dos",
|
||||
"dos/dos_emu",
|
||||
"dos/errno",
|
||||
"dos/io",
|
||||
"dos/process",
|
||||
"dos/sys/timeb",
|
||||
"fsext",
|
||||
"menuetos",
|
||||
"net",
|
||||
"pc_hw/cpu",
|
||||
"pc_hw/endian",
|
||||
"pc_hw/farptr",
|
||||
"pc_hw/fpu",
|
||||
"pc_hw/hwint",
|
||||
"pc_hw/kb",
|
||||
"pc_hw/mem",
|
||||
"pc_hw/sound",
|
||||
"pc_hw/timer",
|
||||
"posix/dirent",
|
||||
"posix/fcntl",
|
||||
"posix/fnmatch",
|
||||
"posix/glob",
|
||||
"posix/grp",
|
||||
-- "posix/regex", -- not compilable
|
||||
"posix/pwd",
|
||||
"posix/setjmp",
|
||||
"posix/signal",
|
||||
"posix/stdio",
|
||||
"posix/sys/stat",
|
||||
"posix/sys/times",
|
||||
"posix/sys/wait",
|
||||
"posix/unistd",
|
||||
"posix/utime",
|
||||
"posix/utsname",
|
||||
"termios",
|
||||
}
|
||||
|
||||
CFLAGS="-Os -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -fno-ident -fomit-frame-pointer -fno-asynchronous-unwind-tables -mpreferred-stack-boundary=2"
|
||||
OBJS={}
|
||||
for i,v in ipairs(FOLDERS) do
|
||||
tup.append_table(OBJS,
|
||||
tup.foreach_rule({v .. "/*.c", extra_inputs = {"../../config.h"}},
|
||||
'kos32-gcc -c -I../../include -D__DEV_CONFIG_H=\\"../../config.h\\" ' .. CFLAGS .. " -o %o %f",
|
||||
v .. "/%B.o")
|
||||
)
|
||||
tup.append_table(OBJS,
|
||||
tup.foreach_rule({v .. "/*.s", extra_inputs = {"../../config.h"}},
|
||||
'kos32-cpp -I../../include -D__DEV_CONFIG_H=\\"../../config.h\\" %f | kos32-as -o %o',
|
||||
v .. "/%B.o")
|
||||
)
|
||||
end
|
||||
tup.rule(OBJS, "kos32-ar rcs %o %f", {"../../lib/libc.a", "../../<libc>"})
|
@@ -1,5 +1,6 @@
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <libc/file.h>
|
||||
|
||||
int
|
||||
|
@@ -3,8 +3,8 @@
|
||||
|
||||
#undef bcopy
|
||||
|
||||
void *
|
||||
void
|
||||
bcopy(const void *a, void *b, size_t len)
|
||||
{
|
||||
return memmove(b, a, len);
|
||||
memmove(b, a, len);
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@
|
||||
|
||||
#undef bzero
|
||||
|
||||
void *
|
||||
void
|
||||
bzero(void *a, size_t b)
|
||||
{
|
||||
return memset(a,0,b);
|
||||
memset(a,0,b);
|
||||
}
|
||||
|
@@ -6,18 +6,18 @@ NaN:
|
||||
|
||||
MK_C_SYM(sincos)
|
||||
|
||||
/* void sincos(double *cosine, double *sine, double x); */
|
||||
/* void sincos(double x, double *sine, double *cosine); */
|
||||
|
||||
movl 16(%esp), %ecx
|
||||
movl 8(%esp), %ecx
|
||||
|
||||
movl 4(%esp), %eax /* Point to cosine. */
|
||||
movl 8(%esp), %edx /* Point to sine. */
|
||||
movl 16(%esp), %eax /* Point to cosine. */
|
||||
movl 12(%esp), %edx /* Point to sine. */
|
||||
|
||||
andl $0x7FF00000, %ecx /* Examine exponent of x. */
|
||||
cmpl $0x43E00000, %ecx /* |x| >= 2^63 */
|
||||
jae bigarg
|
||||
|
||||
fldl 12(%esp)
|
||||
fldl 4(%esp)
|
||||
fsincos
|
||||
fstpl (%eax) /* cos */
|
||||
fstpl (%edx) /* sin */
|
||||
|
@@ -1,287 +0,0 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#include<errno.h>
|
||||
#include<fcntl.h>
|
||||
#include<menuet/os.h>
|
||||
|
||||
struct systree_blk
|
||||
{
|
||||
unsigned long cmd,pos,blks;
|
||||
void * data,* work;
|
||||
char name[256];
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct EMU_FILE
|
||||
{
|
||||
int handle;
|
||||
unsigned long size;
|
||||
unsigned long pos;
|
||||
unsigned long mode;
|
||||
unsigned long current_sector;
|
||||
unsigned long size_sectors;
|
||||
char * write_buf;
|
||||
unsigned long write_bufsize;
|
||||
char rd_buffer[512];
|
||||
char name[256];
|
||||
unsigned char dirty;
|
||||
} EMU_FILE;
|
||||
|
||||
#define _MAX_HANDLES 64
|
||||
|
||||
static EMU_FILE * EMU_file_table[_MAX_HANDLES];
|
||||
static char systree_work_area[16384+512];
|
||||
static volatile struct systree_blk sblk;
|
||||
static volatile int S_eax,S_ebx;
|
||||
|
||||
static inline int EMU_alloc_handle(void)
|
||||
{
|
||||
register int i;
|
||||
for(i=0;i<_MAX_HANDLES;i++)
|
||||
if(!EMU_file_table[i])
|
||||
{
|
||||
EMU_file_table[i]=(EMU_FILE *)malloc(sizeof(EMU_FILE));
|
||||
if(!EMU_file_table[i]) return -ENOMEM;
|
||||
return i;
|
||||
}
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
static inline int EMU_systree_cmd(void)
|
||||
{
|
||||
__asm__ __volatile__("int $0x40"
|
||||
:"=a"(S_eax),"=b"(S_ebx)
|
||||
:"0"(58),"1"((void *)&sblk));
|
||||
return S_eax;
|
||||
}
|
||||
|
||||
static int EMU_loadsector(EMU_FILE * filp)
|
||||
{
|
||||
sblk.cmd=0;
|
||||
sblk.pos=filp->current_sector;
|
||||
sblk.blks=1;
|
||||
sblk.data=filp->rd_buffer;
|
||||
sblk.work=systree_work_area;
|
||||
memcpy((void *)&sblk.name,(const void *)filp->name,strlen(filp->name)+1);
|
||||
return EMU_systree_cmd();
|
||||
}
|
||||
|
||||
static int EMU_fsync(EMU_FILE * filp)
|
||||
{
|
||||
if(filp->mode==O_RDONLY) return 0;
|
||||
if(!filp->dirty) return 0;
|
||||
filp->dirty=0;
|
||||
sblk.cmd=1;
|
||||
sblk.pos=0;
|
||||
sblk.blks=filp->size;
|
||||
sblk.data=filp->write_buf;
|
||||
sblk.work=systree_work_area;
|
||||
memcpy((void *)sblk.name,(const void *)filp->name,strlen(filp->name)+1);
|
||||
return EMU_systree_cmd();
|
||||
}
|
||||
|
||||
static inline int EMU_realloc_buf(EMU_FILE * filp,unsigned long newsize)
|
||||
{
|
||||
char * n;
|
||||
newsize=(newsize+511)&~511;
|
||||
if(filp->write_bufsize==newsize) return 0;
|
||||
n=(char *)realloc(filp->write_buf,newsize);
|
||||
if(!n) return -ENOSPC;
|
||||
filp->write_buf=n;
|
||||
filp->write_bufsize=newsize;
|
||||
filp->dirty=1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int EMU_createtrunc(char * fname)
|
||||
{
|
||||
sblk.cmd=1;
|
||||
sblk.pos=0;
|
||||
sblk.blks=0;
|
||||
sblk.data=sblk.work=systree_work_area;
|
||||
memcpy((void *)sblk.name,(const void *)fname,strlen(fname)+1);
|
||||
return EMU_systree_cmd();
|
||||
}
|
||||
|
||||
static int EMU_getfsize(char * fname,unsigned long * sizep)
|
||||
{
|
||||
sblk.cmd=0;
|
||||
sblk.pos=0;
|
||||
sblk.blks=1;
|
||||
sblk.data=systree_work_area+16384;
|
||||
sblk.work=systree_work_area;
|
||||
memcpy((void *)sblk.name,(const void *)fname,strlen(fname)+1);
|
||||
if(EMU_systree_cmd()!=0) return -EINVAL;
|
||||
if(sizep) *sizep=(unsigned long)S_ebx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int EMU_open(char * fname,int mode)
|
||||
{
|
||||
EMU_FILE * filp;
|
||||
register int hid;
|
||||
unsigned long iomode;
|
||||
hid=EMU_alloc_handle();
|
||||
if(hid<0) return hid;
|
||||
filp=EMU_file_table[hid];
|
||||
filp->handle=hid;
|
||||
iomode=mode&(O_RDONLY|O_WRONLY|O_RDWR);
|
||||
memcpy((void *)filp->name,(const void *)fname,strlen(fname)+1);
|
||||
strupr(filp->name);
|
||||
filp->mode=iomode;
|
||||
if(mode&O_CREAT)
|
||||
{
|
||||
int createflags=mode&(O_TRUNC|O_EXCL);
|
||||
if(createflags&O_EXCL)
|
||||
{
|
||||
unsigned long psz=0;
|
||||
if(EMU_getfsize(filp->name,&psz)==0)
|
||||
{
|
||||
free(EMU_file_table[hid=filp->handle]);
|
||||
EMU_file_table[hid]=NULL;
|
||||
return -EEXIST;
|
||||
}
|
||||
}
|
||||
if(createflags&O_TRUNC)
|
||||
{
|
||||
EMU_createtrunc(filp->name);
|
||||
}
|
||||
}
|
||||
if(iomode==O_RDONLY)
|
||||
{
|
||||
hid=EMU_getfsize(filp->name,&filp->size);
|
||||
if(hid<0)
|
||||
{
|
||||
free(EMU_file_table[hid=filp->handle]);
|
||||
EMU_file_table[hid]=NULL;
|
||||
return -ENOENT;
|
||||
}
|
||||
filp->current_sector=0;
|
||||
if(EMU_loadsector(filp)<0) filp->current_sector=-1UL;
|
||||
filp->mode=O_RDONLY;
|
||||
filp->size_sectors=(filp->size+511)/512;
|
||||
filp->write_bufsize=0;
|
||||
filp->dirty=0;
|
||||
return filp->handle;
|
||||
}
|
||||
if(iomode==O_WRONLY)
|
||||
{
|
||||
hid=EMU_getfsize(filp->name,&filp->size);
|
||||
if(hid<0)
|
||||
{
|
||||
BAD_WRO:
|
||||
free(EMU_file_table[hid=filp->handle]);
|
||||
EMU_file_table[hid]=NULL;
|
||||
return -ENOENT;
|
||||
}
|
||||
filp->current_sector=-1UL;
|
||||
filp->mode=O_WRONLY;
|
||||
filp->size_sectors=0;
|
||||
filp->write_bufsize=(filp->size+511)&~511;
|
||||
filp->write_buf=(char *)malloc(filp->write_bufsize);
|
||||
if(!filp->write_buf)
|
||||
{
|
||||
free(filp->write_buf);
|
||||
goto BAD_WRO;
|
||||
}
|
||||
sblk.cmd=0;
|
||||
sblk.pos=0;
|
||||
sblk.blks=filp->write_bufsize/512;
|
||||
sblk.data=filp->write_buf;
|
||||
sblk.work=systree_work_area;
|
||||
if(EMU_systree_cmd()!=0) goto BAD_WRO1;
|
||||
return filp->handle;
|
||||
}
|
||||
hid=EMU_getfsize(filp->name,&filp->size);
|
||||
if(hid<0)
|
||||
{
|
||||
BAD_WRO1:
|
||||
free(EMU_file_table[hid=filp->handle]);
|
||||
EMU_file_table[hid]=NULL;
|
||||
return -ENOENT;
|
||||
}
|
||||
filp->current_sector=-1UL;
|
||||
filp->mode=O_RDWR;
|
||||
filp->size_sectors=0;
|
||||
filp->write_bufsize=(filp->size+511)&~511;
|
||||
filp->write_buf=(char *)malloc(filp->write_bufsize);
|
||||
if(!filp->write_buf)
|
||||
{
|
||||
free(filp->write_buf);
|
||||
goto BAD_WRO1;
|
||||
}
|
||||
sblk.cmd=0;
|
||||
sblk.pos=0;
|
||||
sblk.blks=filp->write_bufsize/512;
|
||||
sblk.data=filp->write_buf;
|
||||
sblk.work=systree_work_area;
|
||||
if(EMU_systree_cmd()!=0) goto BAD_WRO1;
|
||||
return filp->handle;
|
||||
}
|
||||
|
||||
static int EMU_close(EMU_FILE * filp)
|
||||
{
|
||||
int hid;
|
||||
if(!filp) return -ENOENT;
|
||||
if(EMU_file_table[hid=filp->handle]!=filp) return -EBADF;
|
||||
if(filp->write_buf) free(filp->write_buf);
|
||||
free(filp);
|
||||
EMU_file_table[hid]=NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int EMU_lseek(EMU_FILE * filp,unsigned long off,int whence)
|
||||
{
|
||||
unsigned long newpos;
|
||||
switch(whence)
|
||||
{
|
||||
case SEEK_SET:
|
||||
newpos=off;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
newpos=filp->pos+off;
|
||||
break;
|
||||
case SEEK_END:
|
||||
newpos=filp->size+off-1;
|
||||
break;
|
||||
}
|
||||
if(newpos>=filp->size) return -1;
|
||||
filp->pos=newpos;
|
||||
return filp->pos;
|
||||
}
|
||||
|
||||
static int EMU_read(EMU_FILE * filp,unsigned long size,void * buf)
|
||||
{
|
||||
int icount,curr_sector,curr_sector_ofs,n;
|
||||
int nbufbytes,totalremaining;
|
||||
if(filp->pos+count>filp->size)
|
||||
count=filp->size-filp->pos;
|
||||
if(filp->mode==O_RDWR)
|
||||
{
|
||||
memcpy(buffer,filp->write_buf+filp->pos,count);
|
||||
filp->pos+=count;
|
||||
return count;
|
||||
}
|
||||
icount=count;
|
||||
while(count>0)
|
||||
{
|
||||
if(filp->pos>=filp->size) return icount=count;
|
||||
curr_sector=sh->pointer>>9;
|
||||
curr_sector_ofs=sh->pointer&511;
|
||||
n=count;
|
||||
if(sh->bufsector==-1 || curr_sector!=sh->bufsector)
|
||||
{
|
||||
if(dosemu_loadcurrsector(sh)==-1) return -1;
|
||||
}
|
||||
nbufbytes=512-curr_sector_ofs;
|
||||
totalremaining=sh->size-sh->pointer;
|
||||
if(nbufbytes>totalremaining) nbufbytes=totalremaining;
|
||||
if(n>nbufbytes) n=nbufbytes;
|
||||
memcpy(buffer,&sh->buf[curr_sector_ofs],n);
|
||||
buffer+=n;
|
||||
count-=n;
|
||||
sh->pointer+=n;
|
||||
}
|
||||
return icount;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user