Use NMAKE to make all source in a directory?

后端 未结 6 1503
盖世英雄少女心
盖世英雄少女心 2021-01-21 15:57

Using nmake, is it possible to have the makefile build all the .cpp files in the current directory automatically, without having to specify them individually?

So, instea

6条回答
  •  耶瑟儿~
    2021-01-21 16:45

    Just

    main.exe: *.c resource.RES
        @$(MAKE) $(**:.c=.obj)
        link $(**:.c=.obj) /OUT:$@
    

    and you don't need to add anything else! Every time you nmake, all *.c will be checked if it is compiled or not.

    Where $** for the dependencies, $@ for the target.

    $(**:.c=.obj) is a string substitute, replacing the .c suffix with .obj. And when it comes to resource.RES, it will not replace anything.

    Note that there is a recursive call. This is the most elegant approach, otherwise you can call cmd to print all *.c filenames to a text and load from it.

提交回复
热议问题