简体   繁体   中英

How to split $(MAKECMDGOALS) by whitespace

There is probably a better way to do this (and if there is please let me know), but I'm trying make it so that I don't have to type so much every time I want to compile and run my programs. I'll probably receive some comments about using a Makefile to compile and run my Java programs and that's fine. If I was actually developing Java applications, I would use an IDE. This is just for a class assignment.

I'm trying to pass my arguments from the command line to my Makefile.
Say I want to run this command:

java Driver -n $(arg1) -h $(arg2)

Here is what I have so far, but it doesn't work

arg1 = `echo $(MAKECMDGOALS) | awk {$$1}`

Ideally, all I would have to type is make 1 2 and this would run java Driver -n 1 -h 2

This is really contrary to how Make is supposed to work. But if you insist, here it is:

arg1 := $(word 1,$(MAKECMDGOALS))
arg2 := $(word 2,$(MAKECMDGOALS))

null:
    java Driver -n $(arg1) -h $(arg2)

%:null
    @:

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