简体   繁体   中英

How do I execute a shell command path after creating a new directory in Makefile?

I'm trying to get an updated path of my variable service_SOURCES, after I have generated some files from jaxb with my makefile:

service.jar$(EXEEXT): $(service_SOURCES)
    mkdir -p bin
    xjc -d src -p gen.files ./src/resources/info.xsd
    javac -cp service_SOURCES

service_SOURCES := $(shell find ./src -name "*.java")

I am trying to compile my existing java code with my generated java code Currently, my service_SOURCES variable finds my folder containing my java files, and compiles them all together. I need it to update to include the newly generated java folder, so it compiles my new java files along with my old java files.

I've tried linking the above commands together using && but the shell command still doesn't update. If I run the above commands in terminal it works, but when I run it in my Makefile the path won't update properly.

(moving to answer as this doesn't fit in comment)

You should understand that Make runs in two phases -- The dependency tree is built in the first phase, and the rules are run in the second. This means that the dependency tree cannot be updated by a shell command run after files are generated by a recipe. If you want to do something like this (and I agree with @JohnBollinger, this might not be the best idea), you might need to split your logic between two makefiles, or have a self-recursive makefile. Either way you need to generate the files, then call the second makefile, which can then build a new dependency tree based on a timely shell command.

Alternative:

service.jar$(EXEEXT): _target_to_generate_java_files_
    mkdir -p bin
    xjc -d src -p gen.files ./src/resources/info.xsd
    javac -cp $$(find ./src -name "*.java")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM