I'm trying to convert all .txt with a script to a different format.
I'm allowed to use shell commands just for the targets, but I'm not allowed to use loops...
BTW I have to use the dash interpreter.
The script is called txtConverter. It reads txt from stdin and puts the converted text (maybe markdown or other format) to stdout. So I have to read all .txt files in the current directory and comverting each by using the script to a explicit format with a different file name.
For Example if there is just 1 .txt file in the current directory, there should be 2 files after using the makefile:
1. Directory: Hallo.txt
2. using make
3. Directory: Hallo.txt
Hallo.sh
I found something like this:
OBJ=$(patsubst %.txt, %.sh, $(wildcard *.txt))
This should look for .txt files and convert it to .sh files right?
convertToSh : $(OBJ)
What kind of Code?
But I need a rule to convert right?
%.txt : %.sh
The problem is I dont know how to use shell code to fill the .sh file like:
cat $< | ./txtConverter > $@
If I use $() to execute shell code it doens't work as well like:
@echo $(ls -1)
I'm new to Makefiles and I was looking in a documentary but I don't really understood how it works. I am not sure how it looks like if u put all this together in one Makefile. Thx for help!
SOLUTION FOUND:
Thx to @MadScientist and thx to A Makefile to Convert All Markdown Files to PDFs Using Pandoc
.RECIPEPREFIX = ~
OBJS=$(patsubst %.txt, %.sh, $(wildcard *.txt))
convertToSh : $(OBJS)
%.sh : %.txt
~ ./convertTxtToSh > $@ < $<
Works fine! Found .RECIPEPREFIX = ~
in the GNU Manual from @MadScientist