xiaohongshu
xiaohongshu
build-pmars
Guide for building pMARS (Portable Memory Array Redcode Simulator) and similar software from Debian/Ubuntu source packages. Use this skill when tasks involve enabling source repositories, downloading distribution source packages, removing X11/GUI dependencies, modifying Makefiles, diagnosing segm...
Full skill instructions
This skill provides a systematic approach for building pMARS (and similar software) from Debian/Ubuntu source packages with modifications such as removing X11 dependencies. It emphasizes proper diagnosis of build and runtime issues, verification at each step, and understanding root causes before applying fixes.
Apply this skill when tasks require:
Modern Debian/Ubuntu systems use DEB822 format for apt sources. Enable source packages correctly:
Check current apt sources format:
# Look for .sources files (DEB822 format) vs sources.list (traditional)
ls /etc/apt/sources.list.d/*.sources
cat /etc/apt/sources.list.d/debian.sources
Enable sources in DEB822 format:
# Check current Types field
grep "^Types:" /etc/apt/sources.list.d/debian.sources
# Add deb-src to Types line
sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/debian.sources
Enable sources in traditional format:
# Uncomment or add deb-src lines
sed -i 's/^#deb-src/deb-src/' /etc/apt/sources.list
Update package cache:
apt-get update
Verification - critical step:
# Read back the modified file to verify edit was correct
cat /etc/apt/sources.list.d/debian.sources
# Verify sources are enabled (should show deb-src entries)
apt-cache policy
Common pitfall: File edits may be truncated or malformed. Always read back the modified file to verify correctness before proceeding.
Install required tools and download the source:
# Install dpkg-dev for apt-get source functionality
apt-get install -y dpkg-dev
# Navigate to extraction directory
cd /app
# Download source package (automatically extracts)
apt-get source pmars
What gets created:
pmars_<version>.orig.tar.xz - Original upstream sourcepmars_<version>.debian.tar.xz - Debian patches and metadatapmars_<version>.dsc - Package description filepmars-<version>/ - Extracted and patched source directoryVerification:
# Verify extraction succeeded
ls -la /app/pmars-*/
# Check source directory structure
ls /app/pmars-*/src/
Before making modifications, examine existing Debian patches:
cd /app/pmars-*/
# List available patches
ls debian/patches/
# Read patch series (order of application)
cat debian/patches/series
# Read individual patches to understand known issues
cat debian/patches/*.patch
Why this matters:
Locate and understand the build configuration:
cd /app/pmars-*/src/
# Read Makefile header comments (often document options)
head -100 Makefile | grep "^#"
# Identify key variables
grep -E "^CFLAGS|^LIBS|^LIB|^CC" Makefile
# Look for X11-related flags
grep -i "x11\|xwin\|graphx" Makefile
Common pMARS Makefile structure:
# Comments document available defines:
# -DEXT94 Enables ICWS'94 extensions
# -DXWINGRAPHX Enables X Window graphics
# -DGRAPHX Enables general graphics support
CFLAGS += -O -DEXT94 -DXWINGRAPHX
LIB = -L/usr/X11R6/lib -lX11
Modify CFLAGS to remove graphics defines:
# Remove -DXWINGRAPHX from CFLAGS
# Original: CFLAGS += -O -DEXT94 -DXWINGRAPHX
# Modified: CFLAGS += -O -DEXT94
Remove or comment out library linkage:
# Original: LIB = -L/usr/X11R6/lib -lX11
# Modified: LIB =
# OR comment out entirely: # LIB = -L/usr/X11R6/lib -lX11
Verification after edit:
# CRITICAL: Read back modified Makefile section
grep -E "^CFLAGS|^LIB" Makefile
# Verify X11 references removed
grep -i "x11\|xwin" Makefile
Common pitfall: Edits may not apply correctly or may be truncated. Always verify the modified section by reading it back.
cd /app/pmars-*/src/
make clean
make
Handle compiler warnings appropriately:
Verification:
# Verify binary was created
ls -lh pmars
# Check it's not linked to X11
ldd pmars | grep -i x11
# Expected: no output (no X11 linkage)
# Verify basic functionality
./pmars --help 2>&1 || ./pmars 2>&1 | head -5
Install to target location:
cp /app/pmars-*/src/pmars /usr/local/bin/pmars
chmod +x /usr/local/bin/pmars
# Verify installation
ls -lh /usr/local/bin/pmars
which pmars
Progressive testing approach:
Test minimal functionality first:
/usr/local/bin/pmars --help
/usr/local/bin/pmars file1.red file2.red
Add flags incrementally:
# Basic battle
/usr/local/bin/pmars -b file1.red file2.red
# With rounds
/usr/local/bin/pmars -b -r 50 file1.red file2.red
# With additional flags (test one at a time)
/usr/local/bin/pmars -b -r 50 -f file1.red file2.red
Identify problematic flags:
When encountering crashes, follow this systematic approach:
# Find minimal reproduction case
/usr/local/bin/pmars file1.red file2.red # Test without flags
/usr/local/bin/pmars -b file1.red file2.red # Add one flag
/usr/local/bin/pmars -b -r 50 file1.red file2.red # Add another
# Document which command works and which crashes
apt-get install -y gdb
# Get backtrace
gdb -batch -ex "run -b -r 50 -f file1.red file2.red" -ex "bt" /usr/local/bin/pmars
# Interactive debugging
gdb /usr/local/bin/pmars
(gdb) run -b -r 50 -f file1.red file2.red
(gdb) bt
Critical insight: If a crash occurs standalone but not under gdb, this indicates:
Do not assume a simple NULL check will fix the issue. Investigate:
Before applying source code fixes:
Example analysis:
// If crash occurs in checksum_warriors() dereferencing instBank
// Questions to ask:
// - When should instBank be initialized?
// - Are all warriors in endWar array properly initialized?
// - Is the iteration count correct?
Only after understanding root cause:
// Document why this fix is appropriate
// If instBank can legitimately be NULL when feature disabled:
if (instBank != NULL) {
// proceed with operation
}
Verify the fix:
# Rebuild after source modification
make clean && make
# Read back modified source to verify edit
grep -A5 -B5 "your_fix" modified_file.c
# Test the specific failing scenario
/usr/local/bin/pmars -b -r 50 -f file1.red file2.red
Problem: Edit operations may truncate strings or introduce errors.
Prevention:
# ALWAYS read back modified sections
cat modified_file | grep -A2 -B2 "modified_line"
# Verify file is syntactically valid (for known formats)
Problem: Applying speculative fixes without confirming root cause.
Prevention:
Problem: Modifying upstream Makefile directly may miss Debian patches.
Consideration:
# Check if debian/rules applies additional patches
cat debian/rules
# Alternative: use Debian's build system
dpkg-buildpackage -us -uc -b
Problem: Warnings in C code may indicate real bugs.
Prevention:
# Examine warnings during build
make 2>&1 | grep -i warning
# Consider building with stricter flags for diagnosis
make CFLAGS="-Wall -Wextra"
Problem: Test input files may be malformed.
Prevention:
# Verify warrior files exist and have content
ls -l file1.red file2.red
head file1.red
When working on build tasks:
P0 - Must Complete:
P1 - Important:
P2 - Nice to Have:
Apply framework: If a specific flag causes issues but core output requirement can be met without it, evaluate whether the flag is truly required or just part of an example command.
Before marking task complete:
ldd shows no X11)/usr/local/bin/pmars)# Enable sources (DEB822)
sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/debian.sources
apt-get update
# Download source
apt-get install -y dpkg-dev
cd /app && apt-get source pmars
# Modify Makefile (remove X11)
cd /app/pmars-*/src/
# Edit: Remove -DXWINGRAPHX from CFLAGS
# Edit: Comment out or clear LIB = -lX11 line
# Build and verify
make clean && make
ldd pmars | grep -i x11 # Should show nothing
# Install
cp pmars /usr/local/bin/pmars
chmod +x /usr/local/bin/pmars
# Test progressively
/usr/local/bin/pmars file1.red file2.red
/usr/local/bin/pmars -b -r 50 file1.red file2.red
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience