Files
zed-packager/Makefile
Rawleenc 9402877ce2
All checks were successful
Build and Release Zed Editor / check-version (push) Successful in 4s
Build and Release Zed Editor / build-and-release (push) Successful in 40s
fix: remove desktop file modifications
2025-10-13 14:52:43 +02:00

140 lines
5.6 KiB
Makefile

.PHONY: all clean download extract deb help
# 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
# 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"
@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 " 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"
# Create the .deb package
deb: $(DEB_FILE)
$(DEB_FILE): $(EXTRACT_DIR)/.extracted
@echo "Building .deb package..."
@mkdir -p $(CONTROL_DIR)
@mkdir -p $(DEB_DIR)/opt/zed
@mkdir -p $(DEB_DIR)/usr/bin
@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
# Copy application files
@echo "Copying files..."
@cp -r $(EXTRACT_DIR)/zed.app/* $(DEB_DIR)/opt/zed/
# Create symbolic link for the binary
@ln -sf /opt/zed/bin/zed $(DEB_DIR)/usr/bin/zed
# Copy desktop file and icons
@cp $(EXTRACT_DIR)/zed.app/share/applications/zed.desktop $(DEB_DIR)/usr/share/applications/
@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/
# Create control file
@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 "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 "Homepage: https://zed.dev" >> $(CONTROL_DIR)/control
# Create postinst script to update icon cache
@echo "#!/bin/sh" > $(CONTROL_DIR)/postinst
@echo "set -e" >> $(CONTROL_DIR)/postinst
@echo "if [ \"\$$1\" = \"configure\" ] || [ \"\$$1\" = \"abort-upgrade\" ] || [ \"\$$1\" = \"abort-deconfigure\" ] || [ \"\$$1\" = \"abort-remove\" ]; then" >> $(CONTROL_DIR)/postinst
@echo " if command -v gtk-update-icon-cache >/dev/null 2>&1; then" >> $(CONTROL_DIR)/postinst
@echo " gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true" >> $(CONTROL_DIR)/postinst
@echo " fi" >> $(CONTROL_DIR)/postinst
@echo " if command -v update-desktop-database >/dev/null 2>&1; then" >> $(CONTROL_DIR)/postinst
@echo " update-desktop-database -q /usr/share/applications || true" >> $(CONTROL_DIR)/postinst
@echo " fi" >> $(CONTROL_DIR)/postinst
@echo "fi" >> $(CONTROL_DIR)/postinst
@echo "exit 0" >> $(CONTROL_DIR)/postinst
# Create postrm script to update icon cache on removal
@echo "#!/bin/sh" > $(CONTROL_DIR)/postrm
@echo "set -e" >> $(CONTROL_DIR)/postrm
@echo "if [ \"\$$1\" = \"remove\" ] || [ \"\$$1\" = \"purge\" ]; then" >> $(CONTROL_DIR)/postrm
@echo " if command -v gtk-update-icon-cache >/dev/null 2>&1; then" >> $(CONTROL_DIR)/postrm
@echo " gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true" >> $(CONTROL_DIR)/postrm
@echo " fi" >> $(CONTROL_DIR)/postrm
@echo " if command -v update-desktop-database >/dev/null 2>&1; then" >> $(CONTROL_DIR)/postrm
@echo " update-desktop-database -q /usr/share/applications || true" >> $(CONTROL_DIR)/postrm
@echo " fi" >> $(CONTROL_DIR)/postrm
@echo "fi" >> $(CONTROL_DIR)/postrm
@echo "exit 0" >> $(CONTROL_DIR)/postrm
# Set permissions
@chmod 755 $(DEB_DIR)/opt/zed/bin/zed
@chmod 755 $(DEB_DIR)/opt/zed/libexec/zed-editor
@chmod 755 $(CONTROL_DIR)/postinst
@chmod 755 $(CONTROL_DIR)/postrm
@find $(DEB_DIR)/opt/zed/lib -type f -name "*.so*" -exec chmod 644 {} \;
# Build the .deb package
@echo "Creating .deb package..."
@dpkg-deb --build $(DEB_DIR) $(DEB_FILE)
@echo ""
@echo "✓ Package successfully created: $(DEB_FILE)"
@echo ""
@echo "To install: sudo dpkg -i $(DEB_FILE)"
# Clean up
clean:
@echo "Cleaning up..."
@rm -rf $(BUILD_DIR)
@echo "Cleanup complete"