# Coral Package Manager

Coral is the package manager for Zygaena, written in [Reef](https://github.com/reef-lang/reef).

## Building

### Prerequisites

- Reef compiler (`reefc`) version 0.1.6+
- On illumos: source the development environment first

### Quick Start

```bash
# On illumos - source the environment
source /opt/zygaena-env.sh

# Build coral
cd ~/repos/zygaena/coral
reefc build -l socket -l nsl

# The binary is created at build/coral
./build/coral --help
```

### Build Options

```bash
# Basic build (Linux/macOS)
reefc build

# illumos/Solaris (requires socket libraries)
reefc build -l socket -l nsl

# Type-check only (no compilation)
reefc build --check

# Verbose output
reefc build -v

# Keep generated C code for debugging
reefc build --keep-c
```

### Installation

After building, install to your PATH:

```bash
# Option 1: Copy to /usr/local/bin (requires root)
sudo cp build/coral /usr/local/bin/

# Option 2: Copy to user bin
mkdir -p ~/bin
cp build/coral ~/bin/
export PATH="$HOME/bin:$PATH"
```

## Usage

```bash
coral --help              # Show help
coral build <port>        # Build a package from port
coral install <pkg>       # Install package(s)
coral remove <pkg>        # Remove package(s)
coral upgrade [pkg]       # Upgrade package(s)
coral info <pkg>          # Show package info
coral list                # List installed packages
coral files <pkg>         # List files owned by package
coral owner <file>        # Find which package owns a file
coral search <term>       # Search for packages
coral depends <pkg>       # Show dependency tree
coral sync                # Update ports tree
coral outdated            # Show outdated packages
coral db status           # Show database status
coral clean status        # Show build artifact status
coral ports new cat/name  # Scaffold a new port
coral ports cache status  # Show ports index status
```

## Project Structure

```
coral/
├── reef.toml             # Project manifest
├── src/
│   ├── main.reef         # Entry point, CLI dispatch
│   ├── types.reef        # Shared type definitions
│   ├── commands/         # Command implementations
│   │   ├── build.reef
│   │   ├── install.reef
│   │   ├── remove.reef
│   │   └── ...
│   ├── core/             # Core functionality
│   │   ├── port.reef     # Port file parsing
│   │   ├── portindex.reef # Ports index (MsgPack cache)
│   │   ├── package.reef  # Package operations
│   │   ├── database.reef # Package database
│   │   ├── resolver.reef # Dependency resolution
│   │   └── ...
│   └── util/             # Utilities
│       ├── http.reef     # HTTP downloads
│       ├── archive.reef  # Archive handling
│       └── ...
├── test/                 # Tests
├── build/                # Build output (generated)
└── docs/                 # Documentation
```

## Configuration

Coral uses TOML for configuration. See `docs/` for details on:
- Port file format (`package.toml`)
- Repository configuration
- Build scripts (`build.reef`)

## License

BSD-2-Clause
