1

I have a list of files such as:

SOURCES = program1.txt \ 
          program2.txt \
          ... \ 
          program_n.txt

from which I want to generate, when specified, handlers in C, Python, etc. These will later be compiled/included by a top makefile.

how can I write my makefile so from each file in SOURCES, it generates its handler by calling a script.

the main targets should be something like:

all: handler_py handler_c ... handler_whatever

handler_py: all_my_possible_python_handlers

handler_c: all_my_possible_c_handlers

handler_whatever: all_my_possible_whatever_handlers

So in the end we get

sources/(name_of_program).txt produces output/handler_type/my_handler_(name_of_program).handler_type 

The idea is that whenever I write a new program I only have to update the SOURCES list

instead of copy-pasting this for example:

handler_py : output/my_handler_program.py output/my_handler_program1.py ... 

output/my_handler_program.py : sources/program.txt
    ./generate_handler.py py sources/program.txt

output/my_handler_program1.py : sources/program1.txt
    ./generate_handler.py py sources/program1.txt
...

picatostas
  • 58
  • 8

1 Answers1

0

Straightforward use of pattern rules:

SOURCES = program1.txt program2.txt

handler_py: $(patsubst %.txt,output/my_handler_%.py,$(SOURCES))

output/my_handler_%.py : sources/%.txt
        ./generate_handler.py py $<
MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • This worked, thank you ! I managed to get to the patsubst before reading this answer, but the rest helped a lot ! – picatostas Apr 23 '20 at 08:59