OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [scripts/] [mkdep.c] - Diff between revs 1629 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 1629 Rev 1765
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
 
 
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <sys/mman.h>
 
 
char *filename, *command, __depname[256] = "\n\t@touch ";
char *filename, *command, __depname[256] = "\n\t@touch ";
int needsconfig, hasconfig, hasdep;
int needsconfig, hasconfig, hasdep;
int filelen;
int filelen;
 
 
#define depname (__depname+9)
#define depname (__depname+9)
 
 
struct path_struct {
struct path_struct {
        int len;
        int len;
        char buffer[256-sizeof(int)];
        char buffer[256-sizeof(int)];
} path_array[2] = {
} path_array[2] = {
/*      { 23, "/usr/src/linux/include/" },
/*      { 23, "/usr/src/linux/include/" },
*/
*/
        { 35, "/home/simons/uClinux/linux/include/" },
        { 35, "/home/simons/uClinux/linux/include/" },
        {  0, "" }
        {  0, "" }
};
};
 
 
static void handle_include(int type, char *name, int len)
static void handle_include(int type, char *name, int len)
{
{
        int plen;
        int plen;
        struct path_struct *path = path_array+type;
        struct path_struct *path = path_array+type;
 
 
        if (len == 14 && !memcmp(name, "linux/config.h", len))
        if (len == 14 && !memcmp(name, "linux/config.h", len))
                hasconfig = 1;
                hasconfig = 1;
 
 
        plen = path->len;
        plen = path->len;
        memcpy(path->buffer+plen, name, len);
        memcpy(path->buffer+plen, name, len);
        len += plen;
        len += plen;
        path->buffer[len] = '\0';
        path->buffer[len] = '\0';
        if (access(path->buffer, F_OK))
        if (access(path->buffer, F_OK))
                return;
                return;
 
 
        if (!hasdep) {
        if (!hasdep) {
                hasdep = 1;
                hasdep = 1;
                printf("%s:", depname);
                printf("%s:", depname);
        }
        }
        printf(" \\\n   %s", path->buffer);
        printf(" \\\n   %s", path->buffer);
}
}
 
 
static void handle_config(void)
static void handle_config(void)
{
{
        needsconfig = 1;
        needsconfig = 1;
        if (!hasconfig)
        if (!hasconfig)
                fprintf(stderr,
                fprintf(stderr,
                        "%s needs config but has not included config file\n",
                        "%s needs config but has not included config file\n",
                        filename);
                        filename);
}
}
 
 
#if defined(__alpha__) || defined(__i386__) || defined(__arm__)
#if defined(__alpha__) || defined(__i386__) || defined(__arm__)
#define LE_MACHINE
#define LE_MACHINE
#endif
#endif
 
 
#ifdef LE_MACHINE
#ifdef LE_MACHINE
#define next_byte(x) (x >>= 8)
#define next_byte(x) (x >>= 8)
#define current ((unsigned char) __buf)
#define current ((unsigned char) __buf)
#else
#else
#define next_byte(x) (x <<= 8)
#define next_byte(x) (x <<= 8)
#define current (__buf >> 8*(sizeof(unsigned long)-1))
#define current (__buf >> 8*(sizeof(unsigned long)-1))
#endif
#endif
 
 
#define GETNEXT { \
#define GETNEXT { \
next_byte(__buf); \
next_byte(__buf); \
if (!__nrbuf) { \
if (!__nrbuf) { \
        __buf = *(unsigned long *) next; \
        __buf = *(unsigned long *) next; \
        __nrbuf = sizeof(unsigned long); \
        __nrbuf = sizeof(unsigned long); \
        if (!__buf) \
        if (!__buf) \
                break; \
                break; \
} if(!(--filelen))break;next++; __nrbuf--; }
} if(!(--filelen))break;next++; __nrbuf--; }
 
 
#define CASE(c,label) if (current == c) goto label
#define CASE(c,label) if (current == c) goto label
#define NOTCASE(c,label) if (current != c) goto label
#define NOTCASE(c,label) if (current != c) goto label
 
 
static void state_machine(register char *next)
static void state_machine(register char *next)
{
{
        for(;;) {
        for(;;) {
 
 
        register unsigned long __buf = 0;
        register unsigned long __buf = 0;
        register unsigned long __nrbuf = 0;
        register unsigned long __nrbuf = 0;
 
 
normal:
normal:
        GETNEXT
        GETNEXT
__normal:
__normal:
        CASE('/',slash);
        CASE('/',slash);
        CASE('"',string);
        CASE('"',string);
        CASE('\'',char_const);
        CASE('\'',char_const);
        CASE('#',preproc);
        CASE('#',preproc);
        goto normal;
        goto normal;
 
 
slash:
slash:
        GETNEXT
        GETNEXT
        CASE('*',comment);
        CASE('*',comment);
        goto __normal;
        goto __normal;
 
 
string:
string:
        GETNEXT
        GETNEXT
        CASE('"',normal);
        CASE('"',normal);
        NOTCASE('\\',string);
        NOTCASE('\\',string);
        GETNEXT
        GETNEXT
        goto string;
        goto string;
 
 
char_const:
char_const:
        GETNEXT
        GETNEXT
        CASE('\'',normal);
        CASE('\'',normal);
        NOTCASE('\\',char_const);
        NOTCASE('\\',char_const);
        GETNEXT
        GETNEXT
        goto char_const;
        goto char_const;
 
 
comment:
comment:
        GETNEXT
        GETNEXT
__comment:
__comment:
        NOTCASE('*',comment);
        NOTCASE('*',comment);
        GETNEXT
        GETNEXT
        CASE('/',normal);
        CASE('/',normal);
        goto __comment;
        goto __comment;
 
 
preproc:
preproc:
        GETNEXT
        GETNEXT
        CASE('\n',normal);
        CASE('\n',normal);
        CASE(' ',preproc);
        CASE(' ',preproc);
        CASE('\t',preproc);
        CASE('\t',preproc);
        CASE('i',i_preproc);
        CASE('i',i_preproc);
        GETNEXT
        GETNEXT
 
 
skippreproc:
skippreproc:
        CASE('\n',normal);
        CASE('\n',normal);
        CASE('\\',skippreprocslash);
        CASE('\\',skippreprocslash);
        GETNEXT
        GETNEXT
        goto skippreproc;
        goto skippreproc;
 
 
skippreprocslash:
skippreprocslash:
        GETNEXT;
        GETNEXT;
        GETNEXT;
        GETNEXT;
        goto skippreproc;
        goto skippreproc;
 
 
i_preproc:
i_preproc:
        GETNEXT
        GETNEXT
        CASE('f',if_line);
        CASE('f',if_line);
        NOTCASE('n',skippreproc);
        NOTCASE('n',skippreproc);
        GETNEXT
        GETNEXT
        NOTCASE('c',skippreproc);
        NOTCASE('c',skippreproc);
        GETNEXT
        GETNEXT
        NOTCASE('l',skippreproc);
        NOTCASE('l',skippreproc);
        GETNEXT
        GETNEXT
        NOTCASE('u',skippreproc);
        NOTCASE('u',skippreproc);
        GETNEXT
        GETNEXT
        NOTCASE('d',skippreproc);
        NOTCASE('d',skippreproc);
        GETNEXT
        GETNEXT
        NOTCASE('e',skippreproc);
        NOTCASE('e',skippreproc);
 
 
/* "# include" found */
/* "# include" found */
include_line:
include_line:
        GETNEXT
        GETNEXT
        CASE('\n',normal);
        CASE('\n',normal);
        CASE('<', std_include_file);
        CASE('<', std_include_file);
        NOTCASE('"', include_line);
        NOTCASE('"', include_line);
 
 
/* "local" include file */
/* "local" include file */
{
{
        char *incname = next;
        char *incname = next;
local_include_name:
local_include_name:
        GETNEXT
        GETNEXT
        CASE('\n',normal);
        CASE('\n',normal);
        NOTCASE('"', local_include_name);
        NOTCASE('"', local_include_name);
        handle_include(1, incname, next-incname-1);
        handle_include(1, incname, next-incname-1);
        goto skippreproc;
        goto skippreproc;
}
}
 
 
/* <std> include file */
/* <std> include file */
std_include_file:
std_include_file:
{
{
        char *incname = next;
        char *incname = next;
std_include_name:
std_include_name:
        GETNEXT
        GETNEXT
        CASE('\n',normal);
        CASE('\n',normal);
        NOTCASE('>', std_include_name);
        NOTCASE('>', std_include_name);
        handle_include(0, incname, next-incname-1);
        handle_include(0, incname, next-incname-1);
        goto skippreproc;
        goto skippreproc;
}
}
 
 
if_line:
if_line:
        if (needsconfig)
        if (needsconfig)
                goto skippreproc;
                goto skippreproc;
if_start:
if_start:
        GETNEXT
        GETNEXT
        CASE('C', config);
        CASE('C', config);
        CASE('\n', normal);
        CASE('\n', normal);
        CASE('_', if_middle);
        CASE('_', if_middle);
        if (current >= 'a' && current <= 'z')
        if (current >= 'a' && current <= 'z')
                goto if_middle;
                goto if_middle;
        if (current < 'A' || current > 'Z')
        if (current < 'A' || current > 'Z')
                goto if_start;
                goto if_start;
config:
config:
        GETNEXT
        GETNEXT
        NOTCASE('O', __if_middle);
        NOTCASE('O', __if_middle);
        GETNEXT
        GETNEXT
        NOTCASE('N', __if_middle);
        NOTCASE('N', __if_middle);
        GETNEXT
        GETNEXT
        NOTCASE('F', __if_middle);
        NOTCASE('F', __if_middle);
        GETNEXT
        GETNEXT
        NOTCASE('I', __if_middle);
        NOTCASE('I', __if_middle);
        GETNEXT
        GETNEXT
        NOTCASE('G', __if_middle);
        NOTCASE('G', __if_middle);
        GETNEXT
        GETNEXT
        NOTCASE('_', __if_middle);
        NOTCASE('_', __if_middle);
        handle_config();
        handle_config();
        goto skippreproc;
        goto skippreproc;
 
 
if_middle:
if_middle:
        GETNEXT
        GETNEXT
__if_middle:
__if_middle:
        CASE('\n', normal);
        CASE('\n', normal);
        CASE('_', if_middle);
        CASE('_', if_middle);
        if (current >= 'a' && current <= 'z')
        if (current >= 'a' && current <= 'z')
                goto if_middle;
                goto if_middle;
        if (current < 'A' || current > 'Z')
        if (current < 'A' || current > 'Z')
                goto if_start;
                goto if_start;
        goto if_middle;
        goto if_middle;
        }
        }
}
}
 
 
static void do_depend(void)
static void do_depend(void)
{
{
        char *map;
        char *map;
        int mapsize;
        int mapsize;
        int pagesizem1 = getpagesize()-1;
        int pagesizem1 = getpagesize()-1;
        int fd = open(filename, O_RDONLY);
        int fd = open(filename, O_RDONLY);
        struct stat st;
        struct stat st;
 
 
        if (fd < 0) {
        if (fd < 0) {
                perror("mkdep: open");
                perror("mkdep: open");
                return;
                return;
        }
        }
        fstat(fd, &st);
        fstat(fd, &st);
/* SIMON */
/* SIMON */
        filelen = st.st_size;
        filelen = st.st_size;
        if (0 == (long)st.st_size) {
        if (0 == (long)st.st_size) {
                perror("mkdep: file empty");
                perror("mkdep: file empty");
                close(fd);
                close(fd);
                return;
                return;
        }
        }
        mapsize = st.st_size + 2*sizeof(unsigned long);
        mapsize = st.st_size + 2*sizeof(unsigned long);
        mapsize = (mapsize+pagesizem1) & ~pagesizem1;
        mapsize = (mapsize+pagesizem1) & ~pagesizem1;
        map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
        map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
        if (-1 == (long)map) {
        if (-1 == (long)map) {
                perror("mkdep: mmap");
                perror("mkdep: mmap");
                close(fd);
                close(fd);
                return;
                return;
        }
        }
        close(fd);
        close(fd);
        state_machine(map);
        state_machine(map);
        munmap(map, mapsize);
        munmap(map, mapsize);
        if (hasdep)
        if (hasdep)
                puts(command);
                puts(command);
}
}
 
 
int main(int argc, char **argv)
int main(int argc, char **argv)
{
{
        int len;
        int len;
        char * hpath;
        char * hpath;
 
 
        hpath = getenv("HPATH");
        hpath = getenv("HPATH");
        if (!hpath)
        if (!hpath)
                hpath = "/home/simons/uClinux/linux/include/";
                hpath = "/home/simons/uClinux/linux/include/";
        len = strlen(hpath);
        len = strlen(hpath);
        memcpy(path_array[0].buffer, hpath, len);
        memcpy(path_array[0].buffer, hpath, len);
        if (len && hpath[len-1] != '/') {
        if (len && hpath[len-1] != '/') {
                path_array[0].buffer[len] = '/';
                path_array[0].buffer[len] = '/';
                len++;
                len++;
        }
        }
        path_array[0].buffer[len] = '\0';
        path_array[0].buffer[len] = '\0';
        path_array[0].len = len;
        path_array[0].len = len;
 
 
        while (--argc > 0) {
        while (--argc > 0) {
                int len;
                int len;
                char *name = *++argv;
                char *name = *++argv;
                filename = name;
                filename = name;
                len = strlen(name);
                len = strlen(name);
                memcpy(depname, name, len+1);
                memcpy(depname, name, len+1);
                command = __depname;
                command = __depname;
                if (len > 2 && name[len-2] == '.') {
                if (len > 2 && name[len-2] == '.') {
                        switch (name[len-1]) {
                        switch (name[len-1]) {
                                case 'c':
                                case 'c':
                                case 'S':
                                case 'S':
                                        depname[len-1] = 'o';
                                        depname[len-1] = 'o';
                                        command = "";
                                        command = "";
                        }
                        }
                }
                }
                needsconfig = hasconfig = hasdep = 0;
                needsconfig = hasconfig = hasdep = 0;
                do_depend();
                do_depend();
                if (hasconfig && !needsconfig)
                if (hasconfig && !needsconfig)
                        fprintf(stderr, "%s doesn't need config\n", filename);
                        fprintf(stderr, "%s doesn't need config\n", filename);
        }
        }
        return 0;
        return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.