Why the next makefile restores the target build every time

I have the following code to unzip all files in a directory and move it to a directory. If I call make several times, it tries to execute the build target every time, even if the build directory already exists. Has anyone come across this?

I found this question, but it is not the same. Makefile always runs target file

OS: Ubuntu 12.04 Program: GNU Make 3.81

build: mkBuildDir untar chmod 700 build .PHONY: mkBuildDir untar mkBuildDir: mkdir build untar: *.tar.gz for prefix in *.tar.gz; do \ tar xvf $$prefix --directory=build; \ done clean: rm -Rf build 
+4
source share
1 answer

This is almost the same as the question related to you. You never create a file called mkBuildDir , therefore it is always deprecated, therefore build always deprecated.

Your mkBuildDir target does nothing useful (although I assume it is a shorthand make file). If you did

 # it'd be better to list the TARFILES explicitly, though this will probably work TARFILES=`ls *.tar.gz` all: build untar build: $(TARFILES) test -d build || mkdir build chmod 700 build for prefix in $(TARFILES); do \ tar xvf $$prefix --directory=build; \ done clean: rm -Rf build 

which is likely to accomplish what you are looking for.

Too many fake targets in a Makefile is usually the "code smell" of a makefile. They are rarely the best / idiomatic way to do something.

+7
source

All Articles