Portable makefile creation of directories

前端 未结 3 1266
予麋鹿
予麋鹿 2021-01-06 04:17

I\'m looking to save myself some effort further down the line by making a fairly generic makefile that will put together relatively simple C++ projects for me with minimal m

3条回答
  •  猫巷女王i
    2021-01-06 04:54

    Windows mkdir always does what Unix mkdir does with the -p switch on. And you can deal with the backslash problem with $(subst). So, on Windows, you want this:

    $(BIN_DIR) $(OBJ_DIR):
            mkdir $(subst /,\\,$@)
    

    and on Unix you want this:

    $(BIN_DIR) $(OBJ_DIR):
            mkdir -p -- $@
    

    Choosing between these is not practical to do within a makefile. This is what Autoconf is for.

    As a side note, never, ever use the @command feature in your makefiles. There will come a day when you need to debug your build process on a machine you do not have direct access to, and on that day, you will regret it.

提交回复
热议问题