I’m new to makefiles, and I’m stuck in this problem: how to create symbolic links to all the files in a directory found, all this inside a rule:
I want to know if a call to “find” retrieves any result. If I assign the result to a variable with “eval” (what is the only way I know to set a variable inside a rule), “ifdef” evaluation doesn’t work.
I have also tried comparing to “” with “ifneq” But doesn’t work.
Probably I’m following a wrong direction, so if someone has an alternative approach, I’ll be very thankful.
Here the whole Makefile: (interesting line marked with ######)
Thank you a lot!
DEFAULT_YCS_ROOT := /opt/yujin
all:
ifdef YCS_ROOT
@echo Looking for Yujin maps in ${YCS_ROOT}
else
$(eval YCS_ROOT := ${DEFAULT_YCS_ROOT})
@echo WARNING: YCS_ROOT is undefined. Looking for Yujin maps in default path ${YCS_ROOT}
endif
$(eval MAPS_DIR := $(shell find ${YCS_ROOT} -name yujin_maps))
@echo ${MAPS_DIR} "${MAPS_DIR}"
ifdef MAPS_DIR ######
###### misguided alternative.... ifneq (${MAPS_DIR}, " ")
$(eval DEST_DIR := $(shell pwd)/resources/yaml/stage/maps)
@echo Creating symbolic links on ${DEST_DIR} for every PGM map on ${MAPS_DIR}/maps
rm ${DEST_DIR}/*.pgm
for f in ${MAPS_DIR}/maps/*.pgm; do ln -s $$f ${DEST_DIR}/; done
else
@echo ERROR: Yujin maps package not found in ${YCS_ROOT}. Define YCS_ROOT variable properly
endif
First, assuming you are using GNUMake, there is an easier way to handle
YCS_ROOTandDEFAULT_YCS_ROOT:This will assign the value of
DEFAULT_YCS_ROOTtoYCS_ROOTif and only ifYCS_ROOTis undefined.For the variables
MAPS_DIRandDEST_DIR, you are mixing Make syntax with shell syntax. I think the easiest approach is to define both variables outside the rule:You should test all of this to make certain that the variables have the values you expect. It seems that you expect only one directory in
MAPS_DIR; I will follow that convention, but it is unsafe. Once the makefile so far is working, you can add the rule. You can use a shell loop:or use Make syntax (which gives some advantages):