This question already has answers here:
What do $< and $# represent in a Makefile?
(2 answers)
Closed 7 years ago.
I am trying to understand a simple command-line string that executes Javac and passes it some simple arguments. The complete command line is:
javac -d $(OUTPATH) -sourcepath $(SOURCEPATH) $<
Everything in this line is straightforward and understandable to me except for the final tokens: $<.
What do these tokens mean?
ADDENDUM: Indeed, the commenters are correct. This line occurs within a makefile. It is obvious to me now, but not when I wrote this question, that a makefile is passed to make and is not a shell script.
Please note: What do $< and $# represent in a Makefile? also discusses this (I did not see it when I looked for previous questions about this).
This looks like something from a makefile, not a command line. In that case, $< expands to the first prerequisite of the current target. That is, the .java file that the .class target depends on.
Related
This question already has an answer here:
Trying to implement a loop in Makefile target
(1 answer)
Closed 1 year ago.
I am writing a Makefile for a simple projects. The Makefile should produce the README.md of the project which should include a time & date make was run.
Here's what I've got so far:
README.md:dependent_file.sh
now=$(date)
echo "Generated on $now"
clean:
rm *.md
For now, all I want my Makefile to do is append the current date to the README.md
My problem is that I cannot get the actual date-it coms up as blank.
Any help would be appreciated.
Thanks.
Each line of a recipe is executed in a separate shell, so now is not defined in the shell that executes the echo statement. You can use line continuations to join multiple physical lines into a single logical line.
README.md: dependent_file.sh
now=$$(date) \
echo "Generated on $$now"
or use a semicolon to combine both commands on a single line.
README.md: dependent_file.sh
now=$$(date); echo "Generated on $$now"
In both cases, you'll have to use $$ to prevent any expansions from happening in the Makefile before the recipes are executed.
This question already has an answer here:
Is there any established order for 'ls' arguments?
(1 answer)
Closed 5 years ago.
I am testing Hugo static blog generator which comes with themes and example sites within them.
In order to easily use exampleSite, I just copy the content it's content to Hugo project root. While I did this, I noticed that where, I put the -flag args seems to be important.
Is this is a normal bash behavior or something introduced by zsh?
This command didn't work
cp themes/hugo-theme-bootstrap4-blog/exampleSite/* . -R
This command worked!
cp -R themes/hugo-theme-bootstrap4-blog/exampleSite/* .
cp is its own command, provided by your OS vendor. Neither bash nor zsh controls the behavior of cp.
The POSIX standard only requires cp to accept options before arguments. This is given in POSIX utility syntax guidelines, entry #9:
All options should precede operands on the command line.
GNU tools go beyond this requirement, accepting options after arguments unless -- is given prior (as described in guideline #10).
This question already has answers here:
Bash mkdir and subfolders [duplicate]
(3 answers)
Closed 6 years ago.
I'm sure this question has been asked elsewhere but I can't seem to phrase it in a way that returns a useful Google result.
I am creating a dozen directories that all have the same root path and I don't want to have to cd into it to be able to make these directories. The current command looks like something like, which is awful and repetitive:
$ mkdir frontend/app/components/Home frontend/app/components/Profile \
frontend/app/components/Post frontend/app/components/Comment
An ideal syntax would be something along the lines of:
$ mkdir frontend/app/components/{Home, Profile, Post, Comment}
Is there something like this already that I just haven't found? I don't want to have to run a for loop just to make a few directories.
Your wish is granted :-).
mkdir doesn't know and doesn't have to, but shells like bash or zsh understand the syntax {...,...,...}.
Just remove the spaces from your "along the lines of" and it works:
mkdir frontend/app/components/{Home,Profile,Post,Comment}
The shell will expand it to
mkdir frontend/app/components/Home frontend/app/components/Profile frontend/app/components/Post frontend/app/components/Comment
Since it is done by the shell, it works with any command.
Remove spaces around comma and use -p option:
mkdir -p frontend/app/components/{Home,Profile,Post,Comment}
This question already has answers here:
What is the purpose of .PHONY in a Makefile?
(9 answers)
Closed 7 years ago.
I am using a makefile to run tests. I am not sure about the use of .PHONY. I've read this post: What is the purpose of .PHONY in a makefile?, but still I'm not sure.
I have the following makefile:
```
test:
## Clear console log before we start.
#clear
# Make sure we are not having too much modules.
#npm prune
# Make sure we have the required modules.
#npm install
## Clear the console, so we only see the test results.
#clear
# Run the test.
#./node_modules/.bin/mocha-casperjs test.js --reporter=spec
```
My make test command isn't making any new files. Should I be using the .PHONY: test or not? But even more important, why? (or why not?)
Thank you!
Malcolm Kindermans
Thanks to #Wintermute I got the answer to my question. He commented:
If you removed the tab before them, they'd not show up either -- then they'd be make comments instead of shell comments. Anyway, this question seems to be answered quite extensively behind the link you posted. test should be phony so that touch test; make test doesn't claim that test is up to date. What exactly is still unclear?
So the answer is: "Yes, I need to add test to the .PHONY, because executing the command touch test would break this make command.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Should I name “makefile” or “Makefile”?
What's the standard convention for make files as far as its capitalization. I've seen both Makefile and makefile. Does it depend on language? Project?
You can use either of them, but conventionally Makefile is preferred over makefile. If you have both Makefile and makefile in the same directory and you just type make then makefile is executed and Makefile is ignored.
It doesn't matter. The make program looks for either one. I personally prefer Makefile since I'm always on Linux and it shows up first in the directory listing since I use lower case on all of my .ccp and .h files.
I believe it is usually capitalized. At least on *nix systems.
Makefile (capitalized) is a standard in Unix world, where file system is case sensitive (i.e. makefile, MAKEFILE and Makefile are all different files). On Windows, it doesn't matter.