Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails/crashes for makefiles that use a recursive $(MAKE) pattern to rebuild when makefile changes #100

Open
travisdowns opened this issue Jun 19, 2020 · 0 comments

Comments

@travisdowns
Copy link

I have a makefile that uses a specific matter to trigger a full rebuild when the Makefile itself changes, like so

include config.mk

# rebuild when makefile changes
-include dummy.rebuild

EXE := bench

.PHONY: all clean

CXX ?= g++
CC ?= gcc
ASM ?= nasm
ASM_FLAGS ?= -DNASM_ENABLE_DEBUG=$(NASM_DEBUG) -w+all

ARCH_FLAGS := -march=$(CPU_ARCH)


# make submakes use the specified compiler also
export CXX
export CC

INCLUDES += -Ifmt/include

COMMON_FLAGS := -MMD -Wall $(ARCH_FLAGS) -g $(O_LEVEL) $(INCLUDES) $(NDEBUG)

CPPFLAGS +=
CFLAGS += $(COMMON_FLAGS)
CXXFLAGS += $(COMMON_FLAGS) -Wno-unused-variable 

SRC_FILES := $(wildcard *.cpp) $(wildcard *.c) fmt/src/format.cc

# on most compilers we should use no-pie since the nasm stuff isn't position independent
# but since old compilers don't support it, you can override it with PIE= on the command line
PIE ?= -no-pie
LDFLAGS += $(PIE) -lpthread

EXTRA_DEPS :=

OBJECTS := $(SRC_FILES:.cpp=.o) $(ASM_FILES:.asm=.o)
OBJECTS := $(OBJECTS:.cc=.o)
OBJECTS := $(OBJECTS:.c=.o)
DEPFILES = $(OBJECTS:.o=.d)
# $(info OBJECTS=$(OBJECTS))

# VPATH = test:$(PSNIP_DIR)/cpu

###########
# Targets #
###########

all: bench

-include $(DEPFILES)

clean:
	rm -f *.d *.o $(EXE)

$(EXE): $(OBJECTS) $(EXTRA_DEPS)
	$(CXX) $(OBJECTS) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS)  -o $@

%.o : %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

%.o : %.cpp
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<


%.o: %.asm
	$(ASM) $(ASM_FLAGS) -f elf64 $<

# https://stackoverflow.com/a/3892826/149138
dummy.rebuild: Makefile
	touch $@
	$(MAKE) -s clean

Note the dummy.rebuild target. It causes $(MAKE) -s clean to be called up front, cleaning the project so the build rebuilds everything. When running compiledb make on this project it takes almost a minute and errors out like so:

$ compiledb make
## Building [make]...
make: Nothing to be done for 'all'.

make[3593]: Warning: File 'dummy.rebuild' has modification time 1.1 s in the future
make[9854]: fork: Resource temporarily unavailable
make[9854]: fork: Resource temporarily unavailable
/bin/sh: 1: Cannot fork
make[9853]: *** [Makefile:56: clean] Error 2

Looks like an infinite recursion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant