I’m writting a Makefile in order to compile Java programs. It looks like this:
#!/bin/bash
LANG=en
CURRENT_EX = hello.java
RUN_CURRENT_EX = for i in `ls *.class`; do java *$\.class ; done
RM = rm -f
TRASH = *~ *.class
ALL = $(RM) $(THRASH) && \
javac $(CURRENT_EX)
all:
$(ALL) && \
$(RUN_CURRENT_EX)
When I compile a Java Program (let’s say its name is “hello.java”) it works like this. At first, I put in the Linux terminal:
$ javac hello.java
It yelds a file named “Hello.class”, and for executing it I put
$ java Hello
The issue is that I want to automate this task through a Makefile, and I have a trouble with this line:
RUN_CURRENT_EX = for i in `ls *.class`; do java *$\.class ; done
where it says “java *$.class”. What I want do is to take only the string “Hello” from “Hello.class” filename, but my regex doesn’t work:
$ make all
Error: Could not find or load main class Hello.class
make: *** [all] Error 1
How could I take away the string “.class” from “Hello.class”?
Thanks in advance 🙂
You should really learn about Makefile syntax. Instead of doing things yourself,
makeactually has a lot of functionality to help you.As a starter, also remove the incorrect
#!/bin/bashfrom your Makefile…Then learn about
$(wildcard)for matching files,Pattern substitution
$(patsubst %.class,%,$(CLASSES))to strip the.classpostfix,and pattern rules, such as