Skip to content

Commit

Permalink
feat: sync with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
konosubakonoakua committed May 30, 2024
1 parent dda6626 commit 2723e3d
Show file tree
Hide file tree
Showing 13 changed files with 610 additions and 704 deletions.
8 changes: 7 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# SPDX-FileCopyrightText: 2021-2023 Yoran Heling <[email protected]>
# SPDX-FileCopyrightText: Yorhel <[email protected]>
# SPDX-License-Identifier: MIT

2.4 - 2024-04-21
- Now requires Zig 0.12
- Revert default color scheme back to 'off'
- Rewrite man page in mdoc, drop pod2man dependency
- Fix updating parent dir error status on refresh

2.3 - 2023-08-04
- Now requires Zig 0.11
- Add --(enable|disable)-natsort options
Expand Down
31 changes: 14 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2021-2023 Yoran Heling <[email protected]>
# SPDX-FileCopyrightText: Yorhel <[email protected]>
# SPDX-License-Identifier: MIT

# Optional semi-standard Makefile with some handy tools.
Expand All @@ -9,12 +9,12 @@ ZIG ?= zig
PREFIX ?= /usr/local
BINDIR ?= ${PREFIX}/bin
MANDIR ?= ${PREFIX}/share/man/man1
ZIG_FLAGS ?= -Doptimize=ReleaseFast
ZIG_FLAGS ?= --release

NCDU_VERSION=$(shell grep 'program_version = "' src/main.zig | sed -e 's/^.*"\(.\+\)".*$$/\1/')

.PHONY: build
build: release doc
.PHONY: build test
build: release

release:
$(ZIG) build ${ZIG_FLAGS}
Expand All @@ -25,21 +25,13 @@ debug:
clean:
rm -rf zig-cache zig-out

distclean: clean
rm -f ncdu.1

doc: ncdu.1

ncdu.1: ncdu.pod src/main.zig
pod2man --center "ncdu manual" --release "ncdu-${NCDU_VERSION}" ncdu.pod >ncdu.1

install: install-bin install-doc

install-bin: release
mkdir -p ${BINDIR}
install -m0755 zig-out/bin/ncdu ${BINDIR}/

install-doc: doc
install-doc:
mkdir -p ${MANDIR}
install -m0644 ncdu.1 ${MANDIR}/

Expand All @@ -52,10 +44,10 @@ uninstall-bin:
uninstall-doc:
rm -f ${MANDIR}/ncdu.1

dist: doc
dist:
rm -f ncdu-${NCDU_VERSION}.tar.gz
mkdir ncdu-${NCDU_VERSION}
for f in ncdu.1 `git ls-files | grep -v ^\.gitignore`; do mkdir -p ncdu-${NCDU_VERSION}/`dirname $$f`; ln -s "`pwd`/$$f" ncdu-${NCDU_VERSION}/$$f; done
for f in `git ls-files | grep -v ^\.gitignore`; do mkdir -p ncdu-${NCDU_VERSION}/`dirname $$f`; ln -s "`pwd`/$$f" ncdu-${NCDU_VERSION}/$$f; done
tar -cophzf ncdu-${NCDU_VERSION}.tar.gz --sort=name ncdu-${NCDU_VERSION}
rm -rf ncdu-${NCDU_VERSION}

Expand All @@ -73,14 +65,14 @@ static-%.tar.gz:
CC="${ZIG} cc --target=$*"\
LD="${ZIG} cc --target=$*"\
AR="${ZIG} ar" RANLIB="${ZIG} ranlib"\
CPPFLAGS=-D_GNU_SOURCE && make && make install.libs
CPPFLAGS=-D_GNU_SOURCE && make -j8 && make install.libs
@# zig-build - cleaner approach but doesn't work, results in a dynamically linked binary.
@#cd static-$* && PKG_CONFIG_LIBDIR="`pwd`/inst/pkg" zig build -Dtarget=$*
@# --build-file ../build.zig --search-prefix inst/ --cache-dir zig -Drelease-fast=true
@# Alternative approach, bypassing zig-build
cd static-$* && ${ZIG} build-exe -target $*\
-Iinst/include -Iinst/include/ncursesw -lc inst/lib/libncursesw.a\
--cache-dir zig-cache -static -fstrip -O ReleaseFast ../src/main.zig ../src/ncurses_refs.c
--cache-dir zig-cache -static -fstrip -O ReleaseFast ../src/main.zig
cd static-$* && mv main ncdu && tar -czf ../static-$*.tar.gz ncdu
rm -rf static-$*

Expand All @@ -101,3 +93,8 @@ static:\
static-linux-x86 \
static-linux-aarch64 \
static-linux-arm

test:
zig build test
mandoc -T lint ncdu.1
reuse lint
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
SPDX-FileCopyrightText: 2021-2023 Yoran Heling <[email protected]>
SPDX-FileCopyrightText: Yorhel <[email protected]>
SPDX-License-Identifier: MIT
-->

Expand All @@ -20,7 +20,7 @@ C version (1.x).

## Requirements

- Zig 0.11.0
- Zig 0.12.0
- Some sort of POSIX-like OS
- ncurses libraries and header files

Expand Down
26 changes: 12 additions & 14 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
// SPDX-FileCopyrightText: 2021-2023 Yoran Heling <[email protected]>
// SPDX-FileCopyrightText: Yorhel <[email protected]>
// SPDX-License-Identifier: MIT

const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const optimize = b.standardOptimizeOption(.{
.preferred_optimize_mode = .ReleaseFast,
});

const pie = b.option(bool, "pie", "Build with PIE support (by default false)") orelse false;

const exe = b.addExecutable(.{
.name = "ncdu",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});

exe.pie = pie;
exe.root_module.linkSystemLibrary("ncursesw", .{});
// https://github.com/ziglang/zig/blob/b52be973dfb7d1408218b8e75800a2da3dc69108/build.zig#L551-L554
if (exe.target.isDarwin()) {
if (target.result.isDarwin()) {
// useful for package maintainers
exe.headerpad_max_install_names = true;
}
linkNcurses(exe);
exe.pie = pie;
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
Expand All @@ -35,21 +38,16 @@ pub fn build(b: *std.Build) void {
run_step.dependOn(&run_cmd.step);

const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
linkNcurses(unit_tests);
unit_tests.pie = pie;
unit_tests.root_module.linkSystemLibrary("ncursesw", .{});

const run_unit_tests = b.addRunArtifact(unit_tests);

const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
}

pub fn linkNcurses(compile_step: *std.Build.CompileStep) void {
compile_step.linkSystemLibrary("ncursesw");
compile_step.linkLibC();
compile_step.addCSourceFile(.{ .file = .{ .path = "src/ncurses_refs.c" }, .flags = &.{} });
}
Loading

0 comments on commit 2723e3d

Please sign in to comment.