Home > Net >  with Makefile create folders from specific filenames
with Makefile create folders from specific filenames

Time:04-11

I need a Makefile that create for every <file.rst> a <file> folder to then execute
hovercraft on the <file.rst> which need a folder as second argument


    $ tree                                                                                          
    .                                                                                               
    ├── a.rst                                                                                       
    ├── b.rst                                                                                       
    └── Makefile                                                                                    

With this Makefile

    $ cat Makefile                                                                                  
    .PHONY: html   
                                                                               
    HTML_TARGETS:= $(patsubst %.rst,%.html,$(wildcard *.rst))                                       
                                                                                                    
    html: $(HTML_TARGETS)                                                                           
                                                                                                    
    %.html: %.rst                                                                                   
        @rm -fr $(basename $@ .html)                                                                
        @mkdir -p $(basename $@ .html)                                                              
        @hovercraft -Ns $< $(basename $@ .html)                                                     
    $                                                                                               

I kind of work

.
├── a
│   └── index.html
├── a.rst
├── b
│   └── index.html
├── b.rst
└── Makefile

I fell how baroquish this Makefile is, what could be a better way to write it ?

BTW I fail to add in the Makefile this echo:

@echo output done in $(basename $@ .html)/index.html                                            

I get:

 output done in a /index.html                                                                   
 output done in b /index.html                                                                   
                 ^                                                                              
                 └─ with an unwanted space                                                      
                                                                                                

I whould like to print:

 output done in a/index.html                                                                    
 output done in b/index.html     

CodePudding user response:

If I understand correctly that you want to make a directory "x", then execute hovercraft x.rst x/index.html for every file "x.rst", then this should be a succinct way to do so.

SOURCES := $(wildcard *.rst)
TARGETS := $(SOURCES:.rst=/index.html)

%/index.html: %.rst
    mkdir -p $*
    hovercraft $< $@

.PHONY: all
all: $(TARGETS)
  • Related