Understanding Copyleft Licenses: GPL, LGPL, and AGPL
Master copyleft licenses and their implications. Learn about GPL, LGPL, AGPL differences and how they affect your code.
Table of Contents
What is Copyleft?
Copyleft is a method for making software free and requiring all modified and extended versions to be free as well. It uses copyright law to ensure software remains free, inverting copyright's traditional purpose of restricting distribution.
Understanding Copyleft Philosophy
The Four Freedoms
Copyleft licenses guarantee these essential freedoms:
- Freedom 0: Run the program for any purpose
- Freedom 1: Study and modify the source code
- Freedom 2: Redistribute copies
- Freedom 3: Distribute modified versions
Copyleft vs. Permissive
| Aspect | Copyleft (GPL) | Permissive (MIT) |
|---|---|---|
| Philosophy | Freedom preservation | Maximum flexibility |
| Derivative works | Must be same license | Any license allowed |
| Source disclosure | Required | Optional |
| Commercial use | Allowed with source | Allowed without source |
| Community benefit | Guaranteed | Optional |
Major Copyleft Licenses
GPL (GNU General Public License)
GPL v2 (1991)
Key Features:- Most popular copyleft license
- Used by Linux kernel
- Binary distribution triggers obligations
- Source must be provided with binaries
# Triggers GPL obligations
./configure && make && make install
cp binary /usr/bin/ # Distribution!
# Does NOT trigger (internal use)
./configure && make
./binary # Internal use onlyGPL v3 (2007)
Additional Protections:- Patent protection clauses
- Anti-tivoization (anti-DRM)
- Compatibility with Apache 2.0
- International terminology
// GPL v3 prevents this:
if (verify_signature(binary) != OFFICIAL_SIGNATURE) {
refuse_to_run(); // GPL v3 forbids this restriction
}LGPL (Lesser GPL)
Designed for Libraries:// Dynamic linking - Usually OK
#include <lgpl_library.h>
dlopen("liblgpl.so", RTLD_LAZY);
// Static linking - Triggers LGPL
#include "lgpl_source.c" // Now your code has obligations- LGPL v2.1: Original library copyleft
- LGPL v3: Includes GPL v3 protections
AGPL (Affero GPL)
Network Copyleft:// Regular GPL - No source obligation for SaaS
app.get('/api', (req, res) => {
useGPLCode(); // No distribution, no obligation
});
// AGPL - Must provide source to network users!
app.get('/api', (req, res) => {
useAGPLCode(); // Network use triggers obligations
});
// AGPL compliance
app.get('/source', (req, res) => {
res.download('source-code.tar.gz'); // Required!
});Weak vs. Strong Copyleft
Strong Copyleft (GPL, AGPL)
Characteristics:- Affects entire combined work
- All derivatives must use same license
- Maximum freedom preservation
# main.py (Your code)
import gpl_module # Strong copyleft
class YourApp: # Must be GPL now!
def method(self):
gpl_module.function()Weak Copyleft (LGPL, MPL, EPL)
Characteristics:- Limited scope (file or library level)
- Allows proprietary combinations
- Balance between freedom and flexibility
// mpl-file.js (MPL 2.0) - Must stay open
export function mplFunction() {
// Modifications must be shared
}
// your-file.js (Proprietary) - Can stay closed
import { mplFunction } from './mpl-file.js';
function proprietaryFunction() {
mplFunction(); // OK to keep this file proprietary
}// EPL Module - Must stay open
package org.eclipse.eplmodule;
public class EPLClass {
// Modifications must be shared
}
// Your Module - Can be proprietary
package com.yourcompany.proprietary;
import org.eclipse.eplmodule.EPLClass;
public class ProprietaryClass extends EPLClass {
// Can remain proprietary if separate module
}Copyleft Compatibility Matrix
Inter-License Compatibility
| Your License | Can Include | Cannot Include | Special Cases |
|---|---|---|---|
| GPL v2 | GPL v2, LGPL v2.1, MIT, BSD | GPL v3, Apache 2.0, AGPL | "or later" clause helps |
| GPL v3 | GPL v2+, GPL v3, LGPL v3, Apache 2.0 | GPL v2-only, AGPL | Can combine with AGPL |
| AGPL v3 | GPL v3, LGPL v3, MIT, BSD | GPL v2, proprietary | Strongest copyleft |
| LGPL v2.1 | Any (with conditions) | - | Dynamic linking usually OK |
| MPL 2.0 | Any at file boundary | - | File-level copyleft |
Upgrade Paths
graph LR
MIT --> GPL2[GPL v2]
MIT --> GPL3[GPL v3]
MIT --> AGPL[AGPL v3]
BSD --> GPL2
BSD --> GPL3
Apache2[Apache 2.0] --> GPL3
GPL2 --> GPL3[GPL v3 if "or later"]
GPL3 --> AGPLCompliance Requirements
GPL Compliance Checklist
## Source Code Distribution
### Method 1: Accompany with Source
- [ ] Include complete source code
- [ ] Include build scripts
- [ ] Include installation instructions
- [ ] Match binary version exactly
### Method 2: Written Offer
- [ ] Valid for 3 years
- [ ] Available to any third party
- [ ] Nominal fee for physical media only
- [ ] Include contact information
### Method 3: Network Distribution
- [ ] Provide download link
- [ ] Same location as binary
- [ ] No additional barriers
- [ ] Equivalent access methodLGPL Compliance
# Required for LGPL compliance
provide_source_code()
enable_relinking() # User must be able to relink
provide_object_files() # If statically linked
preserve_lgpl_notices()
document_modifications()AGPL Compliance
// server.js - AGPL compliance
app.use('/source', (req, res) => {
// Must provide corresponding source
const sourceArchive = generateSourceArchive({
includeModifications: true,
includeBuildScripts: true,
includeDocumentation: true
});
res.download(sourceArchive);
});
// Display in UI
function AGPLNotice() {
return (
<footer>
<a href="/source">
Source code available (AGPL v3)
</a>
</footer>
);
}Working with Copyleft Code
Strategy 1: Embrace Copyleft
Project Structure:
License: GPL v3
Benefits:
- Competitor improvements returned
- Strong community contributions
- No proprietary forks
Examples:
- Linux Kernel
- GCC
- GIMPStrategy 2: Isolation Techniques
# Process Isolation
import subprocess
# GPL code in separate process
result = subprocess.run(['gpl-tool', '--process', data],
capture_output=True)
# Your code remains proprietary
# Service Isolation
import requests
# GPL service running separately
response = requests.post('http://gpl-service/api', json=data)
# No license contaminationStrategy 3: Dual Licensing
// Commercial license for paying customers
if (customer.hasPaid()) {
return commercialLicense;
}
// GPL for open source users
return GPLv3License;Common Misconceptions
Myth: "GPL Prohibits Commercial Use"
Truth: GPL explicitly allows commercial use and selling# Totally legal under GPL
sell_gpl_software() {
price="$500"
provide_source_code="yes"
offer_support="optional"
}Myth: "LGPL is Safe for Proprietary Use"
Truth: Still has requirements, especially for static linking// Dynamic linking - Generally OK
void* lib = dlopen("lgpl.so", RTLD_LAZY);
// Static linking - Obligations!
#include "lgpl_library.c" // Must enable relinkingMyth: "Internal Use Triggers Copyleft"
Truth: Only distribution triggers obligations# No obligations - Internal use
def internal_system():
use_gpl_code() # No distribution, no obligations
# Obligations triggered - Distribution
def distributed_product():
use_gpl_code() # Must provide sourceCopyleft in Different Contexts
Open Source Projects
Benefits:- Ensures contributions return
- Prevents embrace-extend-extinguish
- Builds collaborative community
- May limit commercial adoption
- Requires careful dependency management
- Legal complexity
Commercial Products
When Viable:# Dual licensing model
if use_case == "open_source":
license = "GPL"
elif use_case == "commercial":
license = "Proprietary" # For fee
# Service model (AGPL doesn't affect)
if deployment == "internal_service":
agpl_ok = True # Provide source via APIAcademic/Research
Advantages:- Ensures research remains open
- Promotes collaboration
- Prevents proprietary capture
- May conflict with commercialization goals
- University policies vary
- Grant requirements
Enforcement and Legal Aspects
Enforcement Mechanisms
## Copyleft Enforcement Process
1. **Discovery**
- Community reports
- Compliance testing
- Market monitoring
2. **Notification**
- Private contact
- Compliance opportunity
- Documentation request
3. **Resolution**
- Source code release
- Compliance plan
- Ongoing monitoring
4. **Legal Action** (Last Resort)
- Cease and desist
- Litigation
- InjunctionNotable Enforcement Cases
| Case | Outcome | Impact |
|---|---|---|
| BusyBox/GPL | Multiple settlements | Established GPL enforceability |
| Oracle v. Google | Fair use ruling | API copyrightability |
| VMware/Linux | Ongoing | Kernel module boundaries |
| Artifex v. Hancom | Settlement | AGPL enforcement |
Best Practices
For Copyleft Projects
## Copyleft Project Best Practices
1. **Clear Documentation**
- LICENSE file in root
- COPYING for GPL tradition
- README with license section
2. **Contributor Agreement**
- CLA or DCO
- Clear contribution terms
- Patent grants if applicable
3. **Compliance Help**
- HOW-TO-COMPLY.md
- Build instructions
- Contact informationFor Using Copyleft Code
Compliance Process:
1. Inventory:
- List all copyleft dependencies
- Track versions
- Note modifications
2. Analysis:
- Determine obligations
- Check compatibility
- Identify boundaries
3. Implementation:
- Source provision mechanism
- Attribution requirements
- Build reproducibility
4. Verification:
- Regular audits
- Automated checking
- Legal reviewTools and Resources
License Analysis Tools
# Scan for copyleft licenses
scancode --license --copyleft project/
# Check GPL compliance
gpl-compliance-checker --strict
# SPDX generation with copyleft flags
spdx-sbom --flag-copyleft --output sbom.spdxCompliance Automation
# compliance_check.py
import license_checker
def check_copyleft_compliance(project_path):
"""Automated copyleft compliance verification"""
licenses = license_checker.scan(project_path)
copyleft_licenses = [
'GPL-2.0', 'GPL-3.0', 'AGPL-3.0',
'LGPL-2.1', 'LGPL-3.0', 'MPL-2.0'
]
issues = []
for package, license in licenses.items():
if license in copyleft_licenses:
if not has_source_provision(package):
issues.append(f"{package}: Missing source provision")
if not has_attribution(package):
issues.append(f"{package}: Missing attribution")
return issuesConclusion
Copyleft licenses are powerful tools for preserving software freedom. They're not anti-commercial but rather pro-freedom, ensuring that improvements benefit everyone. Whether you choose copyleft depends on your goals:
- Use copyleft to ensure freedoms and community benefit
- Avoid copyleft if you need proprietary flexibility
- Understand obligations before using copyleft code
- Respect the philosophy behind the license choice
Remember: Copyleft is about preserving freedom, not preventing commerce. Many successful businesses thrive with copyleft software.