Esempio n. 1
0
/*
 * Generate dependencies for one file.
 */
void do_depend(const char * filename, const char * command)
{
    int mapsize;
    int pagesizem1 = getpagesize()-1;
    int fd;
    struct stat st;
    char * map;

    fd = open(filename, O_RDONLY);
    if (fd < 0) {
        fprintf(stderr,"cannot open file: %s\n",filename);
        return;
    }

    fstat(fd, &st);
    if (st.st_size == 0) {
        fprintf(stderr,"%s is empty\n",filename);
        close(fd);
        return;
    }

    mapsize = st.st_size;
    mapsize = (mapsize+pagesizem1) & ~pagesizem1;
    map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
    if ((long) map == -1) {
        fprintf(stderr,"mmap failed\n");
        close(fd);
        return;
    }
    if ((unsigned long) map % sizeof(unsigned long) != 0)
    {
        fprintf(stderr, "do_depend: map not aligned\n");
        exit(1);
    }

    hasdep = 0;
    state_machine(map, map+st.st_size);
    if (hasdep) {
        puts(command);
        if (*command)
            define_precious(filename);
    }
    else
    {
        // Create empty target to avoid "no rule to create ..." when we delete/rename a file:
        printf("%s:\n", filename);
    }

    munmap(map, mapsize);
    close(fd);
}
Esempio n. 2
0
/*
 * Generate dependencies for one file.
 */
void do_depend(const char * filename, const char * command)
{
	int mapsize;
	int pagesizem1 = getpagesize()-1;
	int fd;
	struct stat st;
	char * map;

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		perror(filename);
		return;
	}

	fstat(fd, &st);
	if (st.st_size == 0) {
		fprintf(stderr,"%s is empty\n",filename);
		close(fd);
		return;
	}

	mapsize = st.st_size;
	mapsize = (mapsize+pagesizem1) & ~pagesizem1;
	map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
	if ((long) map == -1) {
		perror("mkdep: mmap");
		close(fd);
		return;
	}
	if ((unsigned long) map % sizeof(unsigned long) != 0)
	{
		fprintf(stderr, "do_depend: map not aligned\n");
		exit(1);
	}

	hasdep = 0;
	clear_config();
	state_machine(map, map+st.st_size);
	if (hasdep) {
		puts(command);
		if (*command)
			define_precious(filename);
	}

	munmap(map, mapsize);
	close(fd);
}