# Build Script Configuration Guide ## ROM Organization Environment Variables Build scripts should set these environment variables before calling `nointro-processor.sh` to control how ROMs are organized. --- ## Variables ### `KEEP_IN_ROOT_REGIONS` **Controls which regions stay in the root folder** - **Not Set**: Organize all regions into `By Region/` subfolders - **Empty String (`""`)**: Organize all regions into `By Region/` subfolders - **Comma-Separated List**: Keep specified regions in root, organize others **Examples:** ```bash export KEEP_IN_ROOT_REGIONS="USA,World" # USA and World games stay in root export KEEP_IN_ROOT_REGIONS="Japan" # Only Japan games stay in root export KEEP_IN_ROOT_REGIONS="" # All games organized by region ``` **Use Cases:** - **USA builds**: Keep USA/World games accessible in root - **Japan builds**: Keep Japan games in root, organize international releases - **Europe builds**: Keep Europe games in root --- ### `KEEP_IN_ROOT_KINDS` **Controls which ROM kinds (Beta, Proto, etc.) should NOT be organized** - **Not Set**: Organize all kinds into subfolders - **Empty String (`""`)**: Organize all kinds into subfolders - **Comma-Separated List**: Keep specified kinds in place (don't organize them) **Examples:** ```bash export KEEP_IN_ROOT_KINDS="" # Organize all kinds export KEEP_IN_ROOT_KINDS="Beta,Proto" # Don't move Beta/Proto ROMs export KEEP_IN_ROOT_KINDS="Virtual Console" # Keep VC versions in place ``` **Use Cases:** - **Most builds**: Organize everything (`KEEP_IN_ROOT_KINDS=""`) - **Dev builds**: Keep prototypes/betas accessible (`KEEP_IN_ROOT_KINDS="Beta,Proto"`) - **Archive builds**: Don't organize any kinds (keep everything as-is) --- ### `ORGANIZE_LANGUAGES_BY_SYMLINK` **Enables/disables language symlink folders** - **Not Set or `"false"`**: No language organization - **`"true"`**: Create `By Language//` folders with symlinks **Examples:** ```bash export ORGANIZE_LANGUAGES_BY_SYMLINK="false" # No language folders (USA builds) export ORGANIZE_LANGUAGES_BY_SYMLINK="true" # Create language folders (ENG builds) ``` **How it works:** - Creates virtual folders: `By Language/English/`, `By Language/French/`, etc. - Uses **symlinks** (not file copies) - no disk space duplication - Multi-language ROMs appear in multiple language folders - Symlinks are relative - portable across different mount points **Use Cases:** - **USA builds**: Disable (`false`) - all games are English anyway - **ENG builds**: Enable (`true`) - show which non-USA games have English - **ALL builds**: Enable (`true`) - organize by all available languages --- ### `LANGUAGE_EXCLUDE_REGIONS` **Prevents specified regions from getting language symlinks** - **Not Set**: Include all regions in language folders - **Empty String (`""`)**: Include all regions in language folders - **Comma-Separated List**: Exclude specified regions from language symlinks **Examples:** ```bash export LANGUAGE_EXCLUDE_REGIONS="" # All games get language symlinks export LANGUAGE_EXCLUDE_REGIONS="USA,World" # Don't create symlinks for USA/World export LANGUAGE_EXCLUDE_REGIONS="USA" # Only exclude USA ``` **Use Cases:** - **ENG builds**: Exclude `USA,World` to prevent 500+ games cluttering English folder - **Japan builds**: Exclude `Japan` if you want to keep Japanese releases separate - **Custom builds**: Exclude any region that would dominate a language folder **Why exclude USA from English?** - USA region has 500+ games, all English - Would clutter `By Language/English/` folder - These games are already in root (via `KEEP_IN_ROOT_REGIONS`) - English folder should show **non-USA** games with English translations --- ## Common Build Configurations ### USA 1G1R Build (USA Only) **Keep USA/World games in root, organize everything else** ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="false" export LANGUAGE_EXCLUDE_REGIONS="" ``` **Example Scripts:** - `build-nes-usa-1g1r.sh` (No-Intro: Nintendo Entertainment System) - `build-saturn-usa-1g1r.sh` (Redump: Sega Saturn) **Result:** ``` root/ ├── Super Mario Bros (USA).nes ├── Zelda (USA).nes ├── Tetris (World).nes └── By Region/ ├── Europe/ ├── Japan/ └── ... ``` --- ### English 1G1R Build (USA + English International) **Keep USA/World in root, create language symlinks for non-USA English games** ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" ``` **Example Scripts:** - `build-nes-eng-1g1r.sh` (No-Intro: Nintendo Entertainment System) - `build-saturn-eng-1g1r.sh` (Redump: Sega Saturn) **Result:** ``` root/ ├── Super Mario Bros (USA).nes # USA game in root ├── Zelda (USA).nes # USA game in root ├── Tetris (World).nes # World game in root ├── By Region/ │ ├── Europe/ │ │ └── Secret of Mana (Europe) (En,Fr,De).nes │ └── Japan/ │ └── Final Fantasy (Japan) (En).nes └── By Language/ ├── English/ │ ├── Secret of Mana (Europe) (En,Fr,De).nes -> ../../By Region/Europe/... │ └── Final Fantasy (Japan) (En).nes -> ../../By Region/Japan/... ├── French/ │ └── Secret of Mana (Europe) (En,Fr,De).nes -> ../../By Region/Europe/... └── German/ └── Secret of Mana (Europe) (En,Fr,De).nes -> ../../By Region/Europe/... ``` **Why this works:** - USA games stay in root (easy access to most common games) - USA games excluded from language folders (avoid cluttering English folder) - Non-USA English games organized by region - Language symlinks show which international games have English translations - Multi-language games appear in multiple language folders --- ### All Languages Build (Every Region/Language) **Keep USA/World in root, create language symlinks for ALL games** ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="" ``` **Example Scripts:** - `build-nes-all-1g1r.sh` (No-Intro: Nintendo Entertainment System) - `build-saturn-all-1g1r.sh` (Redump: Sega Saturn) **Result:** ``` root/ ├── Super Mario Bros (USA).nes ├── Metroid (USA) (En,Fr).nes ├── By Region/... └── By Language/ ├── English/ │ ├── Super Mario Bros (USA).nes -> ../../... │ ├── Metroid (USA) (En,Fr).nes -> ../../... │ ├── Final Fantasy (Japan) (En).nes -> ../../By Region/Japan/... │ └── ... ├── French/ │ ├── Metroid (USA) (En,Fr).nes -> ../../... │ └── ... ├── Japanese/ │ └── Mother 3 (Japan) (Ja).nes -> ../../By Region/Japan/... └── ... ``` --- ### All Regions Flat (No Organization) **Don't organize anything - keep all ROMs flat** ```bash export KEEP_IN_ROOT_REGIONS="" # or unset - will organize all export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="false" export LANGUAGE_EXCLUDE_REGIONS="" ``` **Result:** ``` root/ ├── By Region/ │ ├── USA/ │ │ ├── Super Mario Bros (USA).nes │ │ └── Zelda (USA).nes │ ├── Europe/... │ ├── Japan/... │ └── ... ``` **Note:** To keep truly flat (no organization at all), don't call organize-roms.sh --- ## Three-Phase Organization Process When `organize-roms.sh` runs, it executes in three phases: ### Phase 1: Region Organization (Physical Move) - Scans all ROMs in root and subfolders - Detects region from filename (USA, Europe, Japan, etc.) - Moves ROMs to `By Region//` folders - Respects `KEEP_IN_ROOT_REGIONS` (specified regions stay in root) ### Phase 2: Kind Organization (Physical Move, Recursive) - Scans root folder AND region subfolders - Detects kind from filename (Beta, Proto, Demo, etc.) - Moves ROMs to kind subfolders within current location - Respects `KEEP_IN_ROOT_KINDS` (specified kinds don't move) - Recursive: Organizes kinds in both root and `By Region/` folders ### Phase 3: Language Symlinks (Virtual Organization) - Only runs if `ORGANIZE_LANGUAGES_BY_SYMLINK="true"` - Scans all ROMs (wherever they ended up after phases 1-2) - Detects languages from filename (En, Fr, De, Es, etc.) - Creates `By Language//` folders - Creates relative symlinks pointing to original file locations - Respects `LANGUAGE_EXCLUDE_REGIONS` (specified regions don't get symlinks) - Multi-language ROMs get multiple symlinks (one per language) --- ## Key Concepts ### Physical vs Virtual Organization **Physical Organization** (Regions & Kinds): - Actually **moves** files to new locations - Files exist in one place only - Uses disk space for the files **Virtual Organization** (Languages): - Creates **symlinks** (symbolic links) - Original files stay in place - Multiple views of the same file - No additional disk space used ### On-Demand Folder Creation - Folders only created when needed - No empty `By Region/Spain/` if no Spanish games - No empty `By Language/Korean/` if no Korean games - Cleaner directory structure ### Relative Symlinks - All symlinks use relative paths: `../../By Region/Japan/...` - Portable across different mount points - Work correctly even if base directory moves - Compatible with Batocera's filesystem structure --- ## Testing Your Configuration Use the test script to validate your configuration: ```bash /data/emu/rom-groomer/tests/test-language-symlinks.sh ``` Or manually test with a small ROM set: ```bash # Set your configuration export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" # Run organization /data/emu/rom-groomer/organizers/organize-roms.sh /path/to/test/roms # Verify structure find /path/to/test/roms -type f -o -type l | sort ``` --- ## Troubleshooting ### "Too many USA games in English folder" **Problem:** 500+ USA games cluttering `By Language/English/` **Solution:** Set `LANGUAGE_EXCLUDE_REGIONS="USA,World"` ### "I want all games organized by region (none in root)" **Problem:** Some games stay in root folder **Solution:** Set `KEEP_IN_ROOT_REGIONS=""` or don't set it at all ### "Language folders are empty" **Problem:** `By Language/` folders exist but have no games **Solution:** Check that games actually have language tags in filenames like `(En)`, `(Fr)`, etc. ### "Symlinks are broken" **Problem:** Symlinks point to non-existent files **Solution:** Make sure region/kind organization completed before language symlinks were created. Run organize-roms.sh again. --- ## Migration Guide ### From Old Flag-Based System **Old way:** ```bash organize-roms.sh -r -k -l -u /path/to/roms ``` **New way:** ```bash export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" organize-roms.sh /path/to/roms ``` **Flag mapping:** - `-r` (region) → Now always enabled, use `KEEP_IN_ROOT_REGIONS` to control - `-k` (kinds) → Now always enabled, use `KEEP_IN_ROOT_KINDS` to control - `-l` (language) → `ORGANIZE_LANGUAGES_BY_SYMLINK="true"` - `-u` (USA in root) → `KEEP_IN_ROOT_REGIONS="USA,World"` --- ## See Also - [KEEP-IN-ROOT-IMPLEMENTATION.md](./KEEP-IN-ROOT-IMPLEMENTATION.md) - Technical implementation details - [ONDEMAND-FOLDERS-IMPLEMENTATION.md](./ONDEMAND-FOLDERS-IMPLEMENTATION.md) - On-demand folder creation - [organize-roms.sh](../organizers/organize-roms.sh) - Main organization script - [test-language-symlinks.sh](../tests/test-language-symlinks.sh) - Comprehensive test suite