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

Disable GNU make implicit variables and Quiet ar with ARFLAGS rather than > null #2711

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CPPFLAGS := -Iinclude $(CPPFLAGS)
CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden $(CFLAGS)
CC ?= cc
AR ?= ar
ARFLAGS ?= -r$(V0:1=v)
WASI_SDK_PATH := /opt/wasi-sdk

MAKEDIRS ?= mkdir -p
Expand All @@ -37,7 +38,7 @@ build/libprism.$(SOEXT): $(SHARED_OBJECTS)

build/libprism.a: $(STATIC_OBJECTS)
$(ECHO) "building $@ with $(AR)"
$(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)
$(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS)
Copy link
Contributor Author

@ParadoxV5 ParadoxV5 Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick text find shows that this was the only recipe where Q1 is used, and the only other use of Q1 is

Q = $(Q1:0=@)
, which may now be flattenend.
(I’m a novice in C-land; if the entire set of Vs and Qs is a convention, introduce them to me.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this matter, ba82ce9 introduces an acutal use for V0:

prism/Makefile

Line 17 in ba82ce9

ARFLAGS ?= -r$(V0:1=v)


javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
$(ECHO) "building $@"
Expand Down
9 changes: 5 additions & 4 deletions ext/prism/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def make(env, target)
system(
env,
RUBY_PLATFORM.match?(/openbsd|freebsd/) ? "gmake" : "make",
"--no-builtin-variables", # don't let GNU make implicit variables override variable fallbacks in the Makefile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what this is doing. Could you explain why we need this?

Copy link
Contributor Author

@ParadoxV5 ParadoxV5 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted on the previous posts, this flag disables implicit variables for GNU make (updated top post).
GNU make takes those implicit variables precedence over our ?=s, especially the new ARFLAGS ?= -r$(V0:1=v) (PR thread), meaning they aren’t applied without this flag.

prism/Makefile

Lines 15 to 17 in 9bb8710

CC ?= cc
AR ?= ar
ARFLAGS ?= -r$(V0:1=v)

target,
exception: true
)
Expand All @@ -76,22 +77,22 @@ def make(env, target)
# The C extension uses RbConfig, which contains values from the toolchain that built the running Ruby.
env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")

require "mkmf"

# It's possible that the Ruby that is being run wasn't actually compiled on this
# machine, in which case parts of RbConfig might be incorrect. In this case
# we'll need to do some additional checks and potentially fall back to defaults.
if env.key?("CC") && !File.exist?(env["CC"])
if env.key?("CC") && !find_executable(env["CC"])
env.delete("CC")
env.delete("CFLAGS")
env.delete("CPPFLAGS")
end

if env.key?("AR") && !File.exist?(env["AR"])
if env.key?("AR") && !find_executable(env["AR"])
env.delete("AR")
env.delete("ARFLAGS")
end

require "mkmf"

# First, ensure that we can find the header for the prism library.
generate_templates # Templates should be generated before find_header.
unless find_header("prism.h", File.expand_path("../../include", __dir__))
Expand Down
Loading