Skip to content

Commit 03e9189

Browse files
committed
fix the fPIC issue in library build
1 parent 4e4bb0a commit 03e9189

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

lib/build_mitgcm_lib.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,24 @@ if ! grep -q '_BYTESWAPIO' "$BUILD_DIR/Makefile" 2>/dev/null; then
132132
make depend 2>&1 | tail -3
133133
fi
134134

135-
echo " Compiling MITgcm..."
136-
make -j$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4) 2>&1 | tail -5
135+
# For shared library mode, compile everything with -fPIC
136+
echo " Compiling MITgcm with -fPIC for shared library..."
137+
138+
# Clean previous builds to force recompilation with new flags
139+
make clean 2>&1 | tail -2
140+
make depend 2>&1 | tail -3
141+
142+
# Build with -fPIC appended to all compiler flags
143+
# Extract existing flags first
144+
EXISTING_FFLAGS=$(grep '^FFLAGS = ' "$BUILD_DIR/Makefile" | sed 's/^FFLAGS = //' | head -1)
145+
EXISTING_FOPTIM=$(grep '^FOPTIM = ' "$BUILD_DIR/Makefile" | sed 's/^FOPTIM = //' | head -1)
146+
EXISTING_CFLAGS=$(grep '^CFLAGS = ' "$BUILD_DIR/Makefile" | sed 's/^CFLAGS = //' | head -1)
147+
148+
make -j$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4) \
149+
FFLAGS="${EXISTING_FFLAGS} -fPIC" \
150+
FOPTIM="${EXISTING_FOPTIM} -fPIC" \
151+
CFLAGS="${EXISTING_CFLAGS} -fPIC" \
152+
2>&1 | tail -5
137153

138154
echo " MITgcm build complete."
139155
echo ""
@@ -216,6 +232,15 @@ else
216232
done
217233
fi
218234

235+
echo ">> $FC"
236+
echo ">> $SHLIB_FLAGS"
237+
echo ">> $OUTPUT_DIR"
238+
echo ">> $OBJ_FILES"
239+
echo ">> $SHLIB_NAME"
240+
echo ">> $LIBS"
241+
242+
#echo "$FC $SHLIB_FLAGS -o $OUTPUT_DIR/$SHLIB_NAME $OBJ_FILES $LIBS"
243+
219244
$FC $SHLIB_FLAGS -o "$OUTPUT_DIR/$SHLIB_NAME" $OBJ_FILES $LIBS
220245

221246
echo " Created: $OUTPUT_DIR/$SHLIB_NAME"

0 commit comments

Comments
 (0)