say I type this in the terminal: “make a_target”
my desired outcome is to have makefile with the following functionality:
TARGET = $(1)
// a varible set to user input, where $(1) is the first argument after the make command I typed in the terminal.
// and of course I want to be able to use the TARGET variable later in my makefile
I saw some solutions to this. one was to type in terminal: “make TARGET=a_target” and have makefile like this:
TARGET=
but I dont want to type TARGET= in the terminal, I only want to write make a_target.
chatgpt gave me this code:
.PHONY: all
# Default target that does nothing
all:
@echo "Specify a target as 'make <your_input>'"
# Generic rule to handle any target and set the variable
%:
@$(eval name := $@)
@echo "Target name is: $(name)"
@echo "Variable 'name' is set to: $(name)"
$(MAKE) use_name
.PHONY: use_name
use_name:
@echo "Using the variable 'name': $(name)"
but i cannot use name as a variable later in the make file.
I seems that what you want is the predefined MAKECMDGOALS
variable