I want to do following "stuff" using make:
- Convert .pdf files within a folder to .txt files but rename their extension
from .txt to
.textfile. - Delete their page numbers and save them as
.nopagefiles. - Save all .nopage files into an archive. The archive's name should be
archive.tgz.
My targets are: textfile, nopage and archive. all is supposed to do the same as archive.
Here is my code:
SRC=$(wildcard *.pdf)
OBJ=$(SRC:.pdf=.converted)
.PHONY: all archive trimmed converted search-% help clean
.SECONDARY:
help:
@echo "$$helptext"
textfile: $(OBJ)
%.textfile: %.pdf
pdftotext $< $@
nopage: textfile
%.nopage: %.textfile
@cat $< | sed 's/Page [0-9]*//g' > $@
archive: nopage
archive.tgz: %nopage
tar -c --gzip $@ $<
all: archive
Using the variables SRC and OBJ, I collect all the .pdf filenames so that textfile can start with the "first operation", on which the following targets are all depending on.
However, my Makefile stops after doing textfile. So if I'd call "make nopage", it would only create the .textfile files and stops there. Same for the targets that follow.
Any ideas on how I can solve that?
Look at these two rules:
Yes, those are two rules. The first is the one you call; its target is
nopagee, it hastextfileas a prerequisite, and it has no commands. So after make executes thetextfilerule, is does no more. The pattern rule (%.nopage: ...) is never executed at all.Here's a good way to do it:
And be sure to change the archive rule as well:
Note the use of
$^rather than$<in that last command. Also note that I copied thetarsyntax from your makefile; my version of tar won't accept that command, it requires "-f" before "$@".