I have a makefile with separate rules that set a variable of the same name. How do I set this variable to become global from within the rule so that I can use it later.
rule1: test_var=/path/to/folder/
rule2: test_var=/path/to/another/folder/
$(info test_var is $(test_var))
When I call "make rule2" it says "test var is "
But I want "test var is /path/to/another/folder"
Thanks!
EDIT I may have simplified my approach too much, I thought I had it with the global variable idea but make maybe shouldn't be used that way. Here is the problem below.
When I run this code I get the error *** No rule to make target '/file_i_want_compiled.c', needed by 'out/IceCream'. Stop
LINK:= -lpthread
C_SRCS =
C_SRCS += folder1/file1.c
C_FLAGS:= -stf=gnu11
OBJ_PATH= out/objects/
rule1: path = /path/to/rule1folder
.PHONY : rule1
rule2: path = /path/to/rule2folder
.PHONY : rule2
C_SRCS_NO_DIR := $(notdir $(C_SRCS))
C_OBJS := $(C_SRCS_NO_DIR:%.c=$(OBJ_PATH)%.o
C_OBJS += $(path)/file_i_want_compiled.o
out/IceCream: GEN_ICECREAM $(C_OBJS) $(OBJ_PATH)IceCream.o
$(CC) $(C_FLAGS) $(C_OBJS) %(OBJ_PATH)IceCream.o -o $@ $(LINK)
/path/to/rule1folder & /path/to/rule2folder both have their own unique file_i_want_compiled.c
I call make with make rule1 for example
make rule1
will do is set the path variable (if that). How is the out/IceCream target reached? – Shawn