Bug #20241
closedMakefile rule for BUILTIN_ENCOBJS does not create the directory for its output files
Description
When I build Ruby out-of-source (e.g. in a build/
subdirectory) by running mkdir build && cd build && ../configure <args> && make
, the build fails because GCC tries to write build/enc/ascii.o
but the build/enc
subdirectory does not exist. If I run make --debug
from this point, this is the chain of rules causing this to happen:
kj@kj-thinkpad build % make --debug V=1
GNU Make 4.4.1
Built for x86_64-redhat-linux-gnu
Copyright (C) 1988-2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles....
Updating goal targets....
File 'all' does not exist.
File 'main' does not exist.
File 'exts' does not exist.
File 'build-ext' does not exist.
File 'exts.mk' does not exist.
File 'ext/configure-ext.mk' does not exist.
File 'miniruby' does not exist.
File 'enc/ascii.o' does not exist.
Must remake target 'enc/ascii.o'.
gcc -DVM_CHECK_MODE=1 -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdiv-by-zero -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wmisleading-indentation -Wundef -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard -DRUBY_EXPORT -fPIE -I. -I.ext/include/x86_64-linux -I../include -I.. -I../prism -I../enc/unicode/15.0.0 -o enc/ascii.o -c ../enc/ascii.c
Assembler messages:
Fatal error: can't create enc/ascii.o: No such file or directory
make: *** [Makefile:448: enc/ascii.o] Error 1
I don't know when exactly this started - it could simply be that by random chance my machine did used to run other rules first which did create enc/
, and now doesn't, since make rules are not a total order.
I'm not sure exactly what the right way to fix this. I think in a "standard GNU autotools project", the right way for these subdirs to be created is for each of them to have their own Makefile.in. That way, ./configure would create the subdirectory in the build dir and template out the Makefile.in into e.g. build/enc/Makefile
. However, we don't use recursive make, so we don't call AC_CONFIG_FILES([enc/Makefile])
or anything like that. (There is actually an enc/Makefile.in
, but it's templated by a Ruby script, not by autoconf).
Has anybody else noticed this?
Updated by kjtsanaktsidis (KJ Tsanaktsidis) over 1 year ago
- Subject changed from Makefile rule for BUILTIN_ENCOBJS to Makefile rule for BUILTIN_ENCOBJS does not create the directory for its output files
Updated by kjtsanaktsidis (KJ Tsanaktsidis) over 1 year ago
https://github.com/ruby/ruby/pull/9846 is my best suggestion to fix this but I'm very open to better ideas from people better versed in Make and autotools than me.
Updated by nobu (Nobuyoshi Nakada) over 1 year ago
- Status changed from Open to Feedback
Try removing .ext/.timestamp
directory.
Updated by alanwu (Alan Wu) over 1 year ago
Also note that having an in-place build and an out-of-src build at the same time doesn't work. Maybe that's what you're seeing.
Updated by kjtsanaktsidis (KJ Tsanaktsidis) over 1 year ago
- Status changed from Feedback to Closed
Also note that having an in-place build and an out-of-src build at the same time doesn't work. Maybe that's what you're seeing.
Exactly this - now I feel stupid. I thought i'd make clean
'd my previous in tree build, but .ext/.timestamp
was still there. Of course, then for my out of tree build, make sees that and thinks the target is up to date, so this rule never runs:
$(ENC_TRANS_D):
$(Q) $(MAKEDIRS) enc/trans $(@D)
@$(NULLCMD) > $@
I must have just done something strange. I did an in-tree build just now, followed by make clean
and then an out-of-tree build, and it worked.
Thanks for your help!