Skip to content

Fix build_c: ARCH test compares a literal, and CFLAGS is empty for both shared libraries - #48

Open
richard-burhans wants to merge 1 commit into
hillerlab:mainfrom
richard-burhans:fix-build-c-cflags
Open

richard-burhans wants to merge 1 commit into
hillerlab:mainfrom
richard-burhans:fix-build-c-cflags

Conversation

@richard-burhans

Copy link
Copy Markdown

Two make/shell variable bugs in build_c, the same class as #46 — an expression that looks like shell but is resolved (or not resolved) by make.

1. The arm64 branch is unreachable

if [ ARCH = "arm64" ]; then \
	CFLAGS="... -arch arm64"; \

ARCH here is a bare word, not $(ARCH) or $$ARCH, so [ compares the literal string ARCH against arm64. That is always false, the else branch always runs, and -arch arm64 is never passed — including on Apple Silicon, where ARCH=$(shell uname -m) really does evaluate to arm64.

2. CFLAGS is empty for both shared libraries

CFLAGS is assigned in the first recipe line. The two gcc calls for chain_coords_converter_slib.so and chain_bst_lib.so are separate recipe lines, and make runs each recipe line in its own shell, so $$CFLAGS is unset there. Both shared libraries are compiled with no -O2, no -std=c99, no warnings — silently, since gcc is happy to compile without them.

Only chain_filter_by_id gets the flags, because it is on the same continued line as the assignment.

Measured

With a stub gcc that echoes its arguments:

# before — identical for ARCH=x86_64 and ARCH=arm64
GCC-ARGS: -Wall -Wextra -O2 -g -std=c99 -o bin/chain_filter_by_id src/c/chain_filter_by_id.c
GCC-ARGS: -fPIC -shared -o src/python/modules/chain_coords_converter_slib.so ...
GCC-ARGS: -fPIC -shared -o src/python/modules/chain_bst_lib.so ...

# after, ARCH=arm64
GCC-ARGS: -Wall -Wextra -O2 -g -std=c99 -arch arm64 -o bin/chain_filter_by_id ...
GCC-ARGS: -Wall -Wextra -O2 -g -std=c99 -arch arm64 -fPIC -shared -o .../chain_coords_converter_slib.so ...
GCC-ARGS: -Wall -Wextra -O2 -g -std=c99 -arch arm64 -fPIC -shared -o .../chain_bst_lib.so ...

The fix

Hoist the flags into a make variable with an ifeq on $(ARCH). That fixes both problems at once and removes the shell conditional entirely. The variable is named TOGA_CFLAGS rather than CFLAGS so it is not exported into the CESAR2.0 sub-make, which has its own build.

make build_c compiles cleanly and produces all three artifacts.

…th shared libraries

Two make/shell variable bugs in build_c:

1. `if [ ARCH = "arm64" ]` compares the literal string "ARCH" against "arm64",
   so the condition is always false and the arm64 branch is unreachable.
   `-arch arm64` is never passed, even when uname -m reports arm64.

2. CFLAGS is assigned in the first recipe line, but the two gcc calls for
   chain_coords_converter_slib.so and chain_bst_lib.so are separate recipe
   lines, and make runs each in its own shell. $$CFLAGS is empty there, so both
   shared libraries are compiled with no -O2, no -std=c99 and no warnings.

Measured with a stub gcc that echoes its arguments:

  before, ARCH=x86_64 and ARCH=arm64 alike:
    -Wall -Wextra -O2 -g -std=c99 -o bin/chain_filter_by_id ...
    -fPIC -shared -o .../chain_coords_converter_slib.so ...      <- no flags
    -fPIC -shared -o .../chain_bst_lib.so ...                    <- no flags

  after, ARCH=arm64:
    -Wall -Wextra -O2 -g -std=c99 -arch arm64 -o bin/chain_filter_by_id ...
    -Wall -Wextra -O2 -g -std=c99 -arch arm64 -fPIC -shared -o .../chain_coords_converter_slib.so ...
    -Wall -Wextra -O2 -g -std=c99 -arch arm64 -fPIC -shared -o .../chain_bst_lib.so ...

Hoisting the flags to a make variable fixes both at once and removes the
shell conditional. The name is TOGA_CFLAGS rather than CFLAGS so it is not
exported into the CESAR2.0 sub-make.
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

Successfully merging this pull request may close these issues.

1 participant