当我确认重新制作Makefile时,为什么退出?

时间:2019-03-06 03:10:50

标签: makefile

Remaking-Makefiles
在我的理解下,我试图验证这一章,这应该是一个无休止的循环, 但事实并非如此。

$ cat Makefile 
#/tmp/Makefile: ;
-include /tmp/include.mk
/tmp/generate:/tmp/generate_file.c
        gcc $< -o $@

/tmp/include.mk:/tmp/generate
        /tmp/generate $@
        /tmp/touch_file

/tmp/generate是可执行文件,可以创建文件。
/tmp/touch_file是可执行文件,可以更新/tmp/generate的时间戳。
 在第二次检测中,/tmp/generate/tmp/include.mk更新,为什么不 再次更新?

xuwl@xuwl:/tmp$ make
/tmp/generate /tmp/include.mk
/tmp/touch_file 
/tmp/generate last change time Wed Mar  6 10:59:53 2019
/tmp/generate /tmp/include.mk
/tmp/touch_file 
/tmp/generate last change time Wed Mar  6 11:08:48 2019
make: '/tmp/generate' is up to date.
xuwl@xuwl:/tmp$ stat /tmp/include.mk 
  File: '/tmp/include.mk'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 806h/2054d      Inode: 915845      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/    xuwl)   Gid: ( 1000/    xuwl)
Access: 2019-03-06 11:08:48.782753764 +0800
Modify: 2019-03-06 11:08:41.778754001 +0800
Change: 2019-03-06 11:08:41.778754001 +0800
 Birth: -
xuwl@xuwl:/tmp$ stat /tmp/generate
  File: '/tmp/generate'
  Size: 8768            Blocks: 24         IO Block: 4096   regular file
Device: 806h/2054d      Inode: 915856      Links: 1
Access: (0775/-rwxrwxr-x)  Uid: ( 1000/    xuwl)   Gid: ( 1000/    xuwl)
Access: 2019-03-06 11:08:55.782753529 +0800
Modify: 2019-03-06 11:08:55.782753529 +0800
Change: 2019-03-06 11:08:55.782753529 +0800
 Birth: -

touch_file.c/tmp/touch_file

的源代码
#include<stdio.h>
#include<time.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>

#define GENERATEFILE "/tmp/generate"
int main(int argc, char* argv[])
{
        int fd = open(GENERATEFILE, O_RDWR);
        if(fd<0){
                perror("open file failed\n");
                return -1;
        }

        struct stat st;
        stat(GENERATEFILE,&st);
        printf("%s last change time %s",GENERATEFILE,ctime(&st.st_ctime));

        sleep(4);
        futimens(fd,0);

        close(fd);
        return 0;
}

generate_file.c/tmp/generate的来源
/tmp$ cat generate_file.c

#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/stat.h>
#include<errno.h>
#include<string.h>

int main(int argc, char* argv[])
{
        int fd=open(argv[1], O_CREAT|O_RDWR, 0666);
        if(fd<0){
                printf("open file %s error\n", argv[1]);
                return -1;
        }

        sleep(3);
        close(fd);

        return 0;
}

0 个答案:

没有答案