Fix a race condition in the makedirs target

A race condition can happen when running "make all" with parallel jobs.

The issue is that the build directory can be created by another
concurrent job between the moment it was detected as missing and the
moment mkdir is called (which fails if the directory already exists).

This fixes the problem by always using `mkdir -p` which doesn't fail if
the directory already exists.
This commit is contained in:
Mickaël Thomas 2017-10-16 16:44:06 +02:00 committed by Tim Angus
parent 690c5a4dac
commit 7d012f229e

View file

@ -322,7 +322,7 @@ endif
#############################################################################
INSTALL=install
MKDIR=mkdir
MKDIR=mkdir -p
EXTRA_FILES=
CLIENT_EXTRA_FILES=
@ -836,7 +836,6 @@ ifeq ($(PLATFORM),irix64)
ARCH=mips
CC = c99
MKDIR = mkdir -p
BASE_CFLAGS=-Dstricmp=strcasecmp -Xcpluscomm -woff 1185 \
-I. -I$(ROOT)/usr/include
@ -865,7 +864,7 @@ ifeq ($(PLATFORM),sunos)
CC=gcc
INSTALL=ginstall
MKDIR=gmkdir
MKDIR=gmkdir -p
COPYDIR="/usr/local/share/games/quake3"
ifneq ($(ARCH),x86)
@ -1379,34 +1378,28 @@ ifneq ($(PLATFORM),darwin)
endif
makedirs:
@if [ ! -d $(BUILD_DIR) ];then $(MKDIR) $(BUILD_DIR);fi
@if [ ! -d $(B) ];then $(MKDIR) $(B);fi
@if [ ! -d $(B)/autoupdater ];then $(MKDIR) $(B)/autoupdater;fi
@if [ ! -d $(B)/client ];then $(MKDIR) $(B)/client;fi
@if [ ! -d $(B)/client/opus ];then $(MKDIR) $(B)/client/opus;fi
@if [ ! -d $(B)/client/vorbis ];then $(MKDIR) $(B)/client/vorbis;fi
@if [ ! -d $(B)/renderergl1 ];then $(MKDIR) $(B)/renderergl1;fi
@if [ ! -d $(B)/renderergl2 ];then $(MKDIR) $(B)/renderergl2;fi
@if [ ! -d $(B)/renderergl2/glsl ];then $(MKDIR) $(B)/renderergl2/glsl;fi
@if [ ! -d $(B)/ded ];then $(MKDIR) $(B)/ded;fi
@if [ ! -d $(B)/$(BASEGAME) ];then $(MKDIR) $(B)/$(BASEGAME);fi
@if [ ! -d $(B)/$(BASEGAME)/cgame ];then $(MKDIR) $(B)/$(BASEGAME)/cgame;fi
@if [ ! -d $(B)/$(BASEGAME)/game ];then $(MKDIR) $(B)/$(BASEGAME)/game;fi
@if [ ! -d $(B)/$(BASEGAME)/ui ];then $(MKDIR) $(B)/$(BASEGAME)/ui;fi
@if [ ! -d $(B)/$(BASEGAME)/qcommon ];then $(MKDIR) $(B)/$(BASEGAME)/qcommon;fi
@if [ ! -d $(B)/$(BASEGAME)/vm ];then $(MKDIR) $(B)/$(BASEGAME)/vm;fi
@if [ ! -d $(B)/$(MISSIONPACK) ];then $(MKDIR) $(B)/$(MISSIONPACK);fi
@if [ ! -d $(B)/$(MISSIONPACK)/cgame ];then $(MKDIR) $(B)/$(MISSIONPACK)/cgame;fi
@if [ ! -d $(B)/$(MISSIONPACK)/game ];then $(MKDIR) $(B)/$(MISSIONPACK)/game;fi
@if [ ! -d $(B)/$(MISSIONPACK)/ui ];then $(MKDIR) $(B)/$(MISSIONPACK)/ui;fi
@if [ ! -d $(B)/$(MISSIONPACK)/qcommon ];then $(MKDIR) $(B)/$(MISSIONPACK)/qcommon;fi
@if [ ! -d $(B)/$(MISSIONPACK)/vm ];then $(MKDIR) $(B)/$(MISSIONPACK)/vm;fi
@if [ ! -d $(B)/tools ];then $(MKDIR) $(B)/tools;fi
@if [ ! -d $(B)/tools/asm ];then $(MKDIR) $(B)/tools/asm;fi
@if [ ! -d $(B)/tools/etc ];then $(MKDIR) $(B)/tools/etc;fi
@if [ ! -d $(B)/tools/rcc ];then $(MKDIR) $(B)/tools/rcc;fi
@if [ ! -d $(B)/tools/cpp ];then $(MKDIR) $(B)/tools/cpp;fi
@if [ ! -d $(B)/tools/lburg ];then $(MKDIR) $(B)/tools/lburg;fi
@$(MKDIR) $(B)/autoupdater
@$(MKDIR) $(B)/client/opus
@$(MKDIR) $(B)/client/vorbis
@$(MKDIR) $(B)/renderergl1
@$(MKDIR) $(B)/renderergl2
@$(MKDIR) $(B)/renderergl2/glsl
@$(MKDIR) $(B)/ded
@$(MKDIR) $(B)/$(BASEGAME)/cgame
@$(MKDIR) $(B)/$(BASEGAME)/game
@$(MKDIR) $(B)/$(BASEGAME)/ui
@$(MKDIR) $(B)/$(BASEGAME)/qcommon
@$(MKDIR) $(B)/$(BASEGAME)/vm
@$(MKDIR) $(B)/$(MISSIONPACK)/cgame
@$(MKDIR) $(B)/$(MISSIONPACK)/game
@$(MKDIR) $(B)/$(MISSIONPACK)/ui
@$(MKDIR) $(B)/$(MISSIONPACK)/qcommon
@$(MKDIR) $(B)/$(MISSIONPACK)/vm
@$(MKDIR) $(B)/tools/asm
@$(MKDIR) $(B)/tools/etc
@$(MKDIR) $(B)/tools/rcc
@$(MKDIR) $(B)/tools/cpp
@$(MKDIR) $(B)/tools/lburg
#############################################################################
# QVM BUILD TOOLS
@ -2831,10 +2824,10 @@ copyfiles: release
@if [ ! -d $(COPYDIR)/$(BASEGAME) ]; then echo "You need to set COPYDIR to where your Quake3 data is!"; fi
ifneq ($(BUILD_GAME_SO),0)
ifneq ($(BUILD_BASEGAME),0)
-$(MKDIR) -p -m 0755 $(COPYDIR)/$(BASEGAME)
-$(MKDIR) -m 0755 $(COPYDIR)/$(BASEGAME)
endif
ifneq ($(BUILD_MISSIONPACK),0)
-$(MKDIR) -p -m 0755 $(COPYDIR)/$(MISSIONPACK)
-$(MKDIR) -m 0755 $(COPYDIR)/$(MISSIONPACK)
endif
endif