Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altering Makefile variable with sed

Tags:

makefile

sed

I am trying to alter a Makefile variable with sed. I wrote a small Makefile to illustrate what I am trying to do. The CINCS variable is eventually going to be appended to the CFLAGS variable. The CSINCS variable is supposed to hold the paths of all include files, without "-I" in front.

#
SHELL = /bin/sh

SRCS = /usr/local/src/jpeg/jpeg-9b
CINCS = -I/usr/local/src/jpeg/jpeg-9b
CSINCS = $(CINCS) | sed -e "s/-I//g"

check:
@echo 1. $(SRCS)
find $(SRCS) -name "*.c" -print > cscope.files
@echo 2. $(CSINCS)
find '$(CSINCS) -name" "*.h' -print >> cscope.files
cscope -k -b
cat cscope.files | xargs ctags -u
#

I am trying to remove the "-I" in front of all the include paths. Upon exec:

$ make -f test check
1. /usr/local/src/jpeg/jpeg-9b
find /usr/local/src/jpeg/jpeg-9b -name "*.c" -print > cscope.files
2. /usr/local/src/jpeg/jpeg-9b
find '-I/usr/local/src/jpeg/jpeg-9b | sed -e "s/-I//g" -name" "*.h'   -print >> cscope.files
find: unknown predicate `-I/usr/local/src/jpeg/jpeg-9b | sed -e "s/-I//g" -name" "*.h'
test:8: recipe for target 'check' failed
make: *** [check] Error 1

At postion "2" the CSINCS variable looks correct. But there is an expansion with the "find command. That's the problem.

I know I could use the CINCS variable with the cscope command:

cscope -I $(CINCS)

but I want to use cscope.files for the ctags file as well. I could just generate a separate CSINCS variable and keep CINCS and CSINCS in sync all the time. Just curious as to what is going on.

like image 818
rsun Avatar asked Sep 03 '25 16:09

rsun


1 Answers

You haven't told make to execute the value of CSINCS as a shell script, you need something like

CSINCS := $(shell echo $(CINCS) | sed -e "s/-I//g")

Or if you have make 4.0 or more recent

CSINCS != echo $(CINCS) | sed -e "s/-I//g"

although for something this simple you don't need to use sed or the shell

CSINCS := $(subst -I,,$(CINCS))
like image 95
user657267 Avatar answered Sep 05 '25 14:09

user657267