I'm trying to adjust my Makefile
for my GoLang project. I have several rules which should:
- Setup a git pre-commit hook (Don't want to commit the binary files and break copyright law by accident)
- Download an mp3 file via
youtube-dl
- Extract a subsection of that video via
ffmpeg
Previously I was doing this via shellscript and checking for each file manually, but in the act of converting my script to a Makefile I seem to be missing something.
The only rule that doesn't re-run is the pre-hook, but I think that's because I'm not using a variable for my target/rule name?
.default: install
.phony: install generate clean
export bin_directory = bin
export asset_directory = data/assets
export song_url = https://www.youtube.com/watch?v=z8cgNLGnnK4
export song_file = ${bin_directory}/nsp-you-spin-me-cover.mp3
export loop_file = ${asset_directory}/spin-loop.mp3
install:
go install .
generate: $(loop_file)
go generate ./data
$(loop_file): $(song_file)
mkdir -p "${asset_directory}"
ffmpeg -i "${song_file}" -ss 00:01:13.30 -to 00:01:30.38 -c copy "${loop_file}"
$(song_file): .git/hooks/pre-commit
mkdir -p "${bin_directory}"
youtube-dl "${song_url}" --extract-audio --audio-format mp3 --exec "mv {} ${song_file}"
.git/hooks/pre-commit:
cp ./pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
clean:
git clean -xdf
UPDATE: I've found this works correctly if I lump all the dependencies onto the generate
rule like so (which seems like the wrong thing to do)
.default: install
.phony: install generate clean
bin_directory:=bin
asset_directory:=data/assets
song_url:=https://www.youtube.com/watch?v=z8cgNLGnnK4
song_file:=$(bin_directory)/nsp-you-spin-me-cover.mp3
loop_file:=$(asset_directory)/spin-loop.mp3
install:
go install .
.git/hooks/pre-commit:
cp ./pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
$(song_file):
mkdir -p "${bin_directory}"
youtube-dl "${song_url}" --extract-audio --audio-format mp3 --exec "mv {} ${song_file}"
$(loop_file):
mkdir -p "${asset_directory}"
ffmpeg -i "${song_file}" -ss 00:01:13.30 -to 00:01:30.38 -c copy "${loop_file}"
generate: .git/hooks/pre-commit $(song_file) $(loop_file)
go generate ./data
clean:
git clean -xdf