Files
zed-packager/Makefile
Rawleenc ba86192bfd
All checks were successful
Build and Release Zed Editor / check-version (push) Successful in 4s
Build and Release Zed Editor / build-and-release (push) Has been skipped
feat: fail build if dependency detection returns no packages
Add error message and exit if find-deps.sh does not detect any
dependencies. This prevents building a broken package with missing
library requirements.
2025-10-14 11:54:00 +02:00

157 lines
5.8 KiB
Makefile

.PHONY: all clean download extract deb help list-deps
# Variables
GITHUB_REPO = zed-industries/zed
ARCH = x86_64
ARCHIVE_NAME = zed-linux-$(ARCH).tar.gz
BUILD_DIR = build
EXTRACT_DIR = $(BUILD_DIR)/extracted
DEB_DIR = $(BUILD_DIR)/deb
CONTROL_DIR = $(DEB_DIR)/DEBIAN
FIND_DEPS_SCRIPT = ./find-deps.sh
# Determine the latest stable version
VERSION := $(shell curl -s https://api.github.com/repos/$(GITHUB_REPO)/releases/latest | jq -r '.tag_name' | sed 's/^v//')
DOWNLOAD_URL := $(shell curl -s https://api.github.com/repos/$(GITHUB_REPO)/releases/latest | jq -r '.assets[] | select(.name == "$(ARCHIVE_NAME)") | .browser_download_url')
# Package name
PACKAGE_NAME = zed-editor
DEB_FILE = $(BUILD_DIR)/$(PACKAGE_NAME)_$(VERSION)_amd64.deb
all: deb
help:
@echo "Makefile to create a .deb package for Zed Editor (using /usr layout)"
@echo ""
@echo "Available targets:"
@echo " all - Build the .deb package (default target)"
@echo " download - Download the archive from GitHub"
@echo " extract - Extract the archive"
@echo " deb - Create the .deb package"
@echo " list-deps - List dynamic library dependencies"
@echo " clean - Clean up temporary files"
@echo " help - Display this help"
@echo ""
@echo "Detected version: $(VERSION)"
# Download the archive if it doesn't exist
download: $(BUILD_DIR)/$(ARCHIVE_NAME)
$(BUILD_DIR)/$(ARCHIVE_NAME):
@echo "Downloading Zed v$(VERSION)..."
@mkdir -p $(BUILD_DIR)
@if [ -z "$(DOWNLOAD_URL)" ]; then \
echo "Error: unable to find download URL"; \
exit 1; \
fi
@wget -q --show-progress -O $@ "$(DOWNLOAD_URL)"
@echo "Download complete: $@"
# Extract the archive
extract: $(EXTRACT_DIR)/.extracted
$(EXTRACT_DIR)/.extracted: $(BUILD_DIR)/$(ARCHIVE_NAME)
@echo "Extracting archive..."
@mkdir -p $(EXTRACT_DIR)
@tar -xzf $(BUILD_DIR)/$(ARCHIVE_NAME) -C $(EXTRACT_DIR)
@touch $@
@echo "Extraction complete"
# List dependencies dynamically
list-deps: $(EXTRACT_DIR)/.extracted
@echo "Analyzing library dependencies..."
@chmod +x $(FIND_DEPS_SCRIPT)
@$(FIND_DEPS_SCRIPT) $(EXTRACT_DIR)/zed.app/lib
# Create the .deb package
deb: $(DEB_FILE)
$(DEB_FILE): $(EXTRACT_DIR)/.extracted
@echo "Building .deb package with /usr layout..."
@mkdir -p $(CONTROL_DIR)
@mkdir -p $(DEB_DIR)/usr/bin
@mkdir -p $(DEB_DIR)/usr/libexec
@mkdir -p $(DEB_DIR)/usr/share/applications
@mkdir -p $(DEB_DIR)/usr/share/icons/hicolor/512x512/apps
@mkdir -p $(DEB_DIR)/usr/share/icons/hicolor/1024x1024/apps
@mkdir -p $(DEB_DIR)/usr/share/doc/zed-editor
# Copy application files (excluding bundled libraries)
@echo "Copying binaries..."
@cp $(EXTRACT_DIR)/zed.app/bin/zed $(DEB_DIR)/usr/bin/
@cp $(EXTRACT_DIR)/zed.app/libexec/zed-editor $(DEB_DIR)/usr/libexec/
# Copy desktop file and icons
@echo "Copying desktop files and icons..."
@cp $(EXTRACT_DIR)/zed.app/share/applications/zed.desktop $(DEB_DIR)/usr/share/applications/
@sed -i '/^\[Desktop Entry\]/a StartupWMClass=dev.zed.Zed' $(DEB_DIR)/usr/share/applications/zed.desktop
@cp $(EXTRACT_DIR)/zed.app/share/icons/hicolor/512x512/apps/zed.png $(DEB_DIR)/usr/share/icons/hicolor/512x512/apps/
@cp $(EXTRACT_DIR)/zed.app/share/icons/hicolor/1024x1024/apps/zed.png $(DEB_DIR)/usr/share/icons/hicolor/1024x1024/apps/
# Copy licenses
@cp $(EXTRACT_DIR)/zed.app/licenses.md $(DEB_DIR)/usr/share/doc/zed-editor/
# Create control file with library dependencies
@echo "Creating control file with dependencies..."
@chmod +x $(FIND_DEPS_SCRIPT)
@echo "Detecting library dependencies..."
@DEPS=$$($(FIND_DEPS_SCRIPT) --quiet --format makefile $(EXTRACT_DIR)/zed.app/lib); \
if [ -z "$$DEPS" ]; then \
echo ""; \
echo "ERROR: Failed to detect library dependencies!"; \
echo "The dependency detection script did not return any packages."; \
echo "This may indicate a problem with:"; \
echo " - The find-deps.sh script"; \
echo " - The bundled libraries in $(EXTRACT_DIR)/zed.app/lib"; \
echo " - Missing system tools (ldd, dpkg-query, etc.)"; \
echo ""; \
echo "Please investigate and fix the issue before building."; \
echo "Run 'make list-deps' for more details."; \
echo ""; \
exit 1; \
fi; \
echo "Package: $(PACKAGE_NAME)" > $(CONTROL_DIR)/control; \
echo "Version: $(VERSION)" >> $(CONTROL_DIR)/control; \
echo "Section: editors" >> $(CONTROL_DIR)/control; \
echo "Priority: optional" >> $(CONTROL_DIR)/control; \
echo "Architecture: amd64" >> $(CONTROL_DIR)/control; \
echo "Depends: $$DEPS" >> $(CONTROL_DIR)/control; \
echo " Detected dependencies: $$DEPS"; \
echo "Maintainer: Zed Packager <packager@local>" >> $(CONTROL_DIR)/control; \
echo "Description: Zed - A high-performance, multiplayer code editor" >> $(CONTROL_DIR)/control; \
echo " Zed is a next-generation code editor designed for" >> $(CONTROL_DIR)/control; \
echo " high-performance collaboration with humans and AI." >> $(CONTROL_DIR)/control; \
echo " ." >> $(CONTROL_DIR)/control; \
echo " This package uses system libraries instead of bundled ones." >> $(CONTROL_DIR)/control; \
echo "Homepage: https://zed.dev" >> $(CONTROL_DIR)/control
# Copy maintainer scripts
@echo "Creating maintainer scripts..."
@cp postinst $(CONTROL_DIR)/postinst
@cp postrm $(CONTROL_DIR)/postrm
# Set permissions
@echo "Setting permissions..."
@chmod 755 $(DEB_DIR)/usr/bin/zed
@chmod 755 $(DEB_DIR)/usr/libexec/zed-editor
@chmod 755 $(CONTROL_DIR)/postinst
@chmod 755 $(CONTROL_DIR)/postrm
# Build the .deb package
@echo "Creating .deb package..."
@dpkg-deb --build $(DEB_DIR) $(DEB_FILE)
@echo ""
@echo "✓ Package successfully created: $(DEB_FILE)"
@echo ""
@echo "Dependencies were automatically detected from bundled libraries."
@echo "Run 'make list-deps' to see the full dependency analysis."
@echo ""
@echo "To install: sudo dpkg -i $(DEB_FILE)"
@echo "If dependencies are missing: sudo apt-get install -f"
# Clean up
clean:
@echo "Cleaning up..."
@rm -rf $(BUILD_DIR)
@echo "Cleanup complete"