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