1
votes

I need to write a simple makefile to launch a program. This program need two input parameter and An output which depend on input file I have all the inputs on RAW/ directory. The basename of the file are the same but I need two files R1 and R2.


    RDIR=RAW
    OUTDIR=FINAL
    RFILES:=$(wildcard $(RDIR)/*_R1_001.fastq.gz)

    OUTFILE=$(patsubst %_R1_001.fastq.gz,%_R2_001.fastq.gz,$(RFILES))
    OUTKAL=$(patsubst $(RDIR)/%_R1_001.fastq.gz,$(OUTDIR)/%,$(RFILES))
    .PHONY: clean all

    all: $(OUTFILE) $(RFILES) $(OUTDIR) $(OUTKAL)
    $(OUTFILE): $(RFILES)
        -echo $ FINAL/A
       -echo  "tools -i " $"  $@



    $(OUTDIR):
        mkdir -p $(OUTDIR)


    clean::
        $(RM) -rf $(OUTDIR)

What is the simple way to do a comand like this

`tools  A_R1_001.fastq.gz -b "A_R2_001.fastq.gz" > FINAL/A`

So how can combine this patsubst?

1

1 Answers

1
votes

This:

$(OUTFILE): $(RFILES)
    ...

is the wrong construction. It makes all input files prerequisites of each output file. Also, you seem to intend to build FINAL/A, but this rule tells Make that its purpose is to build RAW/A_R2_001.fastq.gz, which will cause problems.

What we need is something like:

FINAL/A: RAW/A_R1_001.fastq.gz $(OUTDIR)
    tools A_R1_001.fastq.gz -b "A_R2_001.fastq.gz" > FINAL/A

but for all input files. So we write a pattern rule which uses automatic variables:

FINAL/%: RAW/%_R1_001.fastq.gz $(OUTDIR)
    tools $*_R1_001.fastq.gz -b "$*_R2_001.fastq.gz" > $@

Then we simplify the all rule:

all: $(OUTKAL)

and we're done.