Hello,

How are default LDFLAGS for Go ports applied considering they are set
after they're included into the build command? I don't see those options
in the output when running make and the resulting binary is in its
standard size. However when I relocate the flag settings into the upper
part of the script as in the provided diff, it works as expected and I
get greeted with a shrunk binary. I think the default settings are
skipped on the official build server too, because Go binaries on mirrors
are similarly large.

Could anyone clue me in if this behavior is still correct and I'm just
misunderstanding something?

Index: go.port.mk
===================================================================
RCS file: /cvs/ports/lang/go/go.port.mk,v
retrieving revision 1.66
diff -u -p -r1.66 go.port.mk
--- go.port.mk  21 Feb 2024 12:28:57 -0000      1.66
+++ go.port.mk  27 Feb 2024 15:23:27 -0000
@@ -58,6 +58,11 @@ MODGO_LIST_CMD =     ${MODGO_CMD} list ${MOD
 MODGO_TEST_CMD =       ${MODGO_CMD} test ${MODGO_FLAGS} ${MODGO_TEST_FLAGS}
 MODGO_BINDIR ?=                bin
+.if empty(DEBUG)
+# by default omit symbol table, debug information and DWARF symbol table
+MODGO_LDFLAGS +=       -s -w
+.endif
+
 .if ! empty(MODGO_LDFLAGS)
 MODGO_BUILD_CMD +=     -ldflags="${MODGO_LDFLAGS}"
 MODGO_LIST_CMD +=      -ldflags="${MODGO_LDFLAGS}"
@@ -111,10 +116,7 @@ CATEGORIES +=              lang/go
 MODGO_BUILD_TARGET =   ${MODGO_BUILD_CMD} ${ALL_TARGET}
 MODGO_FLAGS +=         -v -buildvcs=false -p=${MAKE_JOBS}
-.if empty(DEBUG)
-# by default omit symbol table, debug information and DWARF symbol table
-MODGO_LDFLAGS +=       -s -w
-.else
+.if ! empty(DEBUG)
 MODGO_FLAGS +=         -x
 .endif

Reply via email to