Create directories using make file

前端 未结 9 2074
情深已故
情深已故 2020-11-28 21:27

I\'m a very new to makefiles and i want to create directories using makefile. My project directory is like this

+--Project  
   +--output  
   +--source  
           


        
9条回答
  •  忘掉有多难
    2020-11-28 22:08

    All solutions including the accepted one have some issues as stated in their respective comments. The accepted answer by @jonathan-leffler is already quite good but does not take into effect that prerequisites are not necessarily to be built in order (during make -j for example). However simply moving the directories prerequisite from all to program provokes rebuilds on every run AFAICT. The following solution does not have that problem and AFAICS works as intended.

    MKDIR_P := mkdir -p
    OUT_DIR := build
    
    .PHONY: directories all clean
    
    all: $(OUT_DIR)/program
    
    directories: $(OUT_DIR)
    
    $(OUT_DIR):
        ${MKDIR_P} $(OUT_DIR)
    
    $(OUT_DIR)/program: | directories
        touch $(OUT_DIR)/program
    
    clean:
        rm -rf $(OUT_DIR)
    

提交回复
热议问题