0

Can anyone help me figure out why am I not be bale to pass different versions of .ll files to LLVM_OPT here? Is there a way in makefile to extract each basename of those $(SRC) to pass to opt?

So the scenario is compiling *.c with clang and then applying opt with $(CCC_OPT) to each individual *.ll to transform them to $file_Opt.ll. At last, clang generate the backend a.out by linking all $file_Opt.ll.

BENCHMARK = $(shell basename `pwd`)
SRC := $(wildcard *.c) 
HEADERS := $(wildcard *.h)

# Actions
.PHONY: all  clean vclean
all: 
    $(ZCC) $(HEADERS) $(INCPATHS) $(SRC)  
    $(foreach var,$(SRC), $(CC_OPTS) $(CCC_OPTS) -S -o $(var)_llvmOpt.ll $(var).ll;)
    $(LCC) -v  *_llvmOpt.ll -lm
clean:
    rm -f a.out *.o *.a *.s *.i *.I

vclean:
    rm -f a.out *.o *.a *.s *.i *.I *.ll

output:

opt: loop-wrap.c.ll: error: Could not open input file: No such file or directory
make: *** [all] Error 1
Amir
  • 1,348
  • 3
  • 21
  • 44
  • What about this isn't working exactly? What is the output from running `make`? What is `$(CC_OPTS)`? What is `$(CCC_OPTS)`? Does `$(CC_OPTS)` contain the actual command to run? – Etan Reisner Nov 10 '15 at 15:50
  • Sorry for the incomplete question. I am updating it. the issue is that from each `file.c`, I should extract the `file` part and then pass it to `opt` – Amir Nov 10 '15 at 15:52
  • 1
    Yeah, so, you do realize that's not *anywhere* in your original question, right? And not even explicitly asked in the updated question, right? – Etan Reisner Nov 10 '15 at 16:02
  • Well, the question is still valid. how to define certain loops in makefiles. Now I need to define another before the `action` section, but how... – Amir Nov 10 '15 at 16:03
  • Your use of `$(foreach)` is perfectly fine and correct. You haven't mentioned anything about another loop. You haven't shown an attempt at one. You haven't provided a failure or error or anything about how your other loop isn't working. So that's not part of the question you asked either. – Etan Reisner Nov 10 '15 at 16:04
  • Ok @EtanReisner. Just a sec – Amir Nov 10 '15 at 16:06

1 Answers1

1

Two choices for removing the .c suffix from the filename.

You can use the Text Function patsubst directly:

$(foreach var,$(patsubst %.c,%,$(SRC)),$(CC_OPTS) $(CCC_OPTS) -S -o $(var)_llvmOpt.ll $(var).ll;)

Or through a Substitution Reference.

$(foreach var,$(SRC:.c=),$(CC_OPTS) $(CCC_OPTS) -S -o $(var)_llvmOpt.ll $(var).ll;)

Or, and this is arguably more correct, you could also use the Functions for File Names function basename for this:

$(foreach var,$(basename $(SRC)),$(CC_OPTS) $(CCC_OPTS) -S -o $(var)_llvmOpt.ll $(var).ll;)
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148