0

I have a makefile. I want to ask for the name of the file that will be compiled in specific targets. When I wrote make to the bash and press the tab it suggests the targets in makefile. However, it doesn't suggest when I uncomment the line that commented below.

temp_file_path = ./TestCode/temporary_files/
c_code_file := ./TestCode/$(name)
temp_file := $(temp_file_path)$(name)
#it doesn't autocomplete when I uncomment the line below.
#name := $(shell bash -c 'read -p "Type the c file that you want to compile (without extension): " pwd; echo $$pwd')

executable: 
    @echo temp_file as      $(temp_file)    › will be used
    @echo c_code_file as    $(c_code_file)  › will be used > temp.log

temp.log:
    touch temp.log

Could you explain why it happens and the solution? I want both to solve and to understand the make syntax (and rules).

The answer here suggests to away -c as I understand. (I used it in my makefile.) However, I couldn't understand if it is really the reason and how to solve it.

1 Answers1

0

The completion function can't run your makefile noninteractively to obtain the names of the available targets because you wrote it so that it requires interactive input.

This seems like an absolutely atrociously horrible idea for other reasons as well. Just abandon this idea. Create a wrapper which requests the input and then runs make with it if you insist on making your computing experience worse.

#!/bin/bash
read -p "Type the c file that you want to compile (without extension): " pwd
echo "$pwd"
make "$pwd.c"

There will be a competition for who can guess how long you will use this before you abandon it and just type the target name with completion like the system already beautifully does out of the box.

tripleee
  • 175,061
  • 34
  • 275
  • 318