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

Makefile overrides local CFLAGS and LDFLAGS #315

Open
lquidfire opened this issue Jan 19, 2024 · 0 comments
Open

Makefile overrides local CFLAGS and LDFLAGS #315

lquidfire opened this issue Jan 19, 2024 · 0 comments

Comments

@lquidfire
Copy link

lquidfire commented Jan 19, 2024

Not sure where else to ask this question. This is about the manual building of libcs50 on Linux:

The Makefile for libcs50 overrides the local CFLAGS and LDFLAGS. Is this desired behaviour?

The standard flags on Archlinux are currently:

CFLAGS="-march=x86-64 -O2 -pipe -fno-plt -fexceptions \ -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ -fstack-clash-protection -fcf-protection"

LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"

By overriding the local flags, libcs50 gets compiled withour RELRO for Archlinux.

Would RELRO (or other local flags) inhibit the functionality of libcs50? If not, would it be an option to not override local flags, but simply add the desired flags from the Makefile to the local flags?

I have applied the following patch to the Makefile to add the flags from Makefile to the local CFLAGS and LDFLAGS, instead of overriding the local flags (Linux only):

--- Makefile    2024-01-17 16:45:50.820032476 +0200
+++ Makefile.old        2024-01-17 16:50:35.989535760 +0200
@@ -9,7 +9,7 @@
 INCLUDE := src/cs50.h
 MANS := $(wildcard docs/*.3.gz)
 
-CFLAGS=-Wall -Wextra -Werror -pedantic -std=c11
+CFLAGS+=-Wall -Wextra -Werror -pedantic -std=c11
 BASENAME=libcs50
 LIB_STATIC=$(BASENAME).a
 LIB_OBJ=$(BASENAME).o
@@ -36,8 +36,8 @@
 all: $(LIBS) $(MANS)
 
 $(LIBS): $(SRC) $(INCLUDE) Makefile
-       $(CC) $(CFLAGS) -fPIC -shared $(LINKER_FLAGS) -o $(LIB_VERSION) $(SRC)
-       $(CC) $(CFLAGS) -c -o $(LIB_OBJ) $(SRC)
+       $(CC) $(CFLAGS) -fPIC -shared $(LINKER_FLAGS) -o $(LIB_VERSION) $(SRC) ${LDFLAGS}
+       $(CC) $(CFLAGS) -c -o $(LIB_OBJ) $(SRC) $(LDFLAGS)
        ar rcs $(LIB_STATIC) $(LIB_OBJ)
        chmod 644 $(LIB_STATIC)
        rm -f $(LIB_OBJ)
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