Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ jobs:
- uses: actions/checkout@v4

- name: Build with ${{ matrix.compiler }}
run: make CC=${{ matrix.compiler }}
run: |
if [ "${{ matrix.os }}" = "macos-latest" ]; then
make darwin
else
make CC=${{ matrix.compiler }}
fi

- name: Run unit tests
run: make test
Expand Down
203 changes: 113 additions & 90 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,101 +1,124 @@
PROGNAME=emsys
PREFIX=/usr/local
VERSION?=git-$(shell git rev-parse --short HEAD 2>/dev/null | sed 's/^/git-/' || echo "")
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/man/man1
OBJECTS=main.o wcwidth.o unicode.o buffer.o region.o undo.o transform.o find.o pipe.o tab.o register.o fileio.o terminal.o display.o keymap.o edit.o prompt.o compat.o

# Platform Detection: 3-Platform Strategy
#
# emsys supports exactly 3 platforms:
# 1. POSIX - Default for all Unix systems (Linux, *BSD, macOS, Solaris, AIX, HP-UX, etc.)
# 2. Android - Android/Termux with optimizations
# 3. MSYS2 - Windows MSYS2 environment
#
# If no platform argument specified or platform is not android/msys2, assume POSIX.

UNAME_S = $(shell uname -s)

# Default: assume POSIX-compliant system
DETECTED_PLATFORM = posix

# Exception 1: Android/Termux detection (multiple methods for reliability)
ifdef ANDROID_ROOT
DETECTED_PLATFORM = android
endif
ifneq (,$(TERMUX))
DETECTED_PLATFORM = android
endif
ifeq ($(shell test -d /data/data/com.termux && echo termux),termux)
DETECTED_PLATFORM = android
endif

# Exception 2: MSYS2 detection
ifneq (,$(findstring MSYS_NT,$(UNAME_S)))
DETECTED_PLATFORM = msys2
endif
ifneq (,$(findstring MINGW,$(UNAME_S)))
DETECTED_PLATFORM = msys2
endif
ifneq (,$(findstring CYGWIN,$(UNAME_S)))
DETECTED_PLATFORM = msys2
endif

# Allow override via command line: make PLATFORM=android
PLATFORM ?= $(DETECTED_PLATFORM)

CFLAGS+=-std=c99 -Wall -Wextra -pedantic -Wno-pointer-sign -Werror=incompatible-pointer-types -DEMSYS_BUILD_DATE=\"$(shell date '+%Y-%m-%dT%H:%M:%S%z')\" -DEMSYS_VERSION=\"$(VERSION)\"

# Optional feature disabling
DISABLE_PIPE ?= 0

# Apply platform-specific settings
ifeq ($(PLATFORM),android)
CC = clang
CFLAGS += -O2 -fPIC -fPIE -DNDEBUG
LDFLAGS += -pie
# Android disables pipe by default
DISABLE_PIPE = 1
endif
ifeq ($(PLATFORM),msys2)
CFLAGS += -D_GNU_SOURCE
endif
# All other platforms (posix) use standard POSIX C99 flags

# Apply optional feature flags
ifeq ($(DISABLE_PIPE),1)
CFLAGS += -DEMSYS_DISABLE_PIPE
endif

all: $(PROGNAME)

debug: CFLAGS+=-g -O0
debug: $(PROGNAME)
PROGNAME = emsys
PREFIX = /usr/local
SHELL = /bin/sh

test: $(PROGNAME)
@./tests/run_tests.sh
# Version handling - fallback for when git is not available
VERSION = 1.0.0

# Standard C99 compiler settings
CC = cc

# Enable BSD and POSIX features portably
CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -Wno-pointer-sign -D_DEFAULT_SOURCE -D_BSD_SOURCE -O2

# Installation directories
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/man/man1
DOCDIR = $(PREFIX)/share/doc/emsys

$(PROGNAME): config.h $(OBJECTS)
$(CC) -o $@ $(OBJECTS) $(LDFLAGS)
# Source files
OBJECTS = main.o wcwidth.o unicode.o buffer.o region.o undo.o transform.o \
find.o pipe.o tab.o register.o fileio.o terminal.o display.o \
keymap.o edit.o prompt.o util.o

# Default target with git version detection
all:
@VERSION="`git describe --tags --always --dirty 2>/dev/null || echo $(VERSION)`"; \
make VERSION="$$VERSION" $(PROGNAME)

install: $(PROGNAME) $(PROGNAME).1
mkdir -pv $(BINDIR)
mkdir -pv $(MANDIR)
mkdir -pv $(PREFIX)/share/doc/
install -m 0755 $(PROGNAME) $(BINDIR)
install -m 0644 README.md $(PREFIX)/share/doc/$(PROGNAME).md
install -m 0644 $(PROGNAME).1 $(MANDIR)/$(PROGNAME).1
# Link the executable
$(PROGNAME): $(OBJECTS)
$(CC) -o $(PROGNAME) $(OBJECTS) $(LDFLAGS)

# POSIX suffix rule for .c to .o
.SUFFIXES: .c .o
.c.o:
$(CC) $(CFLAGS) -DEMSYS_VERSION=\"$(VERSION)\" -c $<

# Simple header dependency
$(OBJECTS): config.h

# Copy default config if it doesn't exist
config.h:
cp config.def.h $@
cp config.def.h config.h


# Installation
install: $(PROGNAME)
mkdir -p $(BINDIR) $(MANDIR) $(DOCDIR)
cp $(PROGNAME) $(BINDIR)/
-cp $(PROGNAME).1 $(MANDIR)/ 2>/dev/null
-cp README.md $(DOCDIR)/ 2>/dev/null
chmod 755 $(BINDIR)/$(PROGNAME)

# Removal
uninstall:
rm -f $(BINDIR)/$(PROGNAME)
rm -f $(MANDIR)/$(PROGNAME).1
rm -f $(DOCDIR)/README.md
-rmdir $(DOCDIR) 2>/dev/null

# Cleanup
clean:
rm -f $(OBJECTS) $(PROGNAME)

distclean: clean
rm -f config.h

# Testing
test: $(PROGNAME)
./tests/run_tests.sh

check: test

# Sorry Dave
hal:
make clean
make CFLAGS="$(CFLAGS) -D_POSIX_C_SOURCE=200112L -Werror" $(PROGNAME)
make test

# Development targets
debug:
make CFLAGS="$(CFLAGS) -g -O0" $(PROGNAME)


format:
clang-format -i *.c *.h

# Platform-specific variants
android:
make CC=clang CFLAGS="$(CFLAGS) -fPIC -fPIE -DEMSYS_DISABLE_PIPE" LDFLAGS="-pie" $(PROGNAME)

clean:
rm -rf *.o
rm -rf *.exe
rm -rf $(PROGNAME)
rm -rf tests/*.o

msys2:
make CFLAGS="$(CFLAGS) -D_GNU_SOURCE" $(PROGNAME)

minimal:
make CFLAGS="$(CFLAGS) -DEMSYS_DISABLE_PIPE -Os" $(PROGNAME)

solaris:
VERSION="$(VERSION)" make CC=cc CFLAGS="-xc99 -D__EXTENSIONS__ -O2 -errtags=yes -erroff=E_ARG_INCOMPATIBLE_WITH_ARG_L" $(PROGNAME)


darwin:
make CC=clang CFLAGS="$(CFLAGS) -D_DARWIN_C_SOURCE" $(PROGNAME)



# Help
help:
@echo "emsys build targets:"
@echo " all Build emsys (default)"
@echo " install Install to PREFIX ($(PREFIX))"
@echo " uninstall Remove installed files"
@echo " clean Remove object files"
@echo " test Run basic test"
@echo " debug Build with debug symbols"
@echo " android Build for Android/Termux"
@echo " darwin Build for macOS/Darwin"
@echo " msys2 Build for MSYS2"
@echo " minimal Build minimal version"
@echo " solaris Build for Solaris Developer Studio"
@echo " check Alias for test"
@echo " format Format code with clang-format"
@echo " hal HAL-9000 compliance"
2 changes: 1 addition & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void rowDelChar(struct editorBuffer *bufr, erow *row, int at) {
bufr->dirty = 1;
}

struct editorBuffer *newBuffer() {
struct editorBuffer *newBuffer(void) {
struct editorBuffer *ret = xmalloc(sizeof(struct editorBuffer));
ret->indent = 0;
ret->markx = -1;
Expand Down
94 changes: 0 additions & 94 deletions compat.c

This file was deleted.

19 changes: 0 additions & 19 deletions compat.h

This file was deleted.

Loading