diff options
author | Yorhel <git@yorhel.nl> | 2021-07-17 10:10:24 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-07-18 09:40:59 +0200 |
commit | ee92f403eff2f83964e0a4ba83277c9677566c76 (patch) | |
tree | 1ae7ed95ab7f9ed86d0481cc6c914ca8f6ece85b | |
parent | e9c8d12c0f14b6763e34a8d2bff16091499e8360 (diff) |
Add Makefile with some standard/handy tools
+ a failed initial attempt at producing static binaries.
-rw-r--r-- | .gitignore | 10 | ||||
-rw-r--r-- | Makefile | 82 | ||||
-rw-r--r-- | ncdu.pod (renamed from doc/ncdu.pod) | 0 | ||||
-rw-r--r-- | src/scan.zig | 2 |
4 files changed, 88 insertions, 6 deletions
@@ -1,7 +1,7 @@ +*.swp +*~ +ncdu.1 +ncurses +static-*/ zig-cache/ zig-out/ -ncdu.1 -*~ -*.swp -static/* -!static/build.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fcea0f8 --- /dev/null +++ b/Makefile @@ -0,0 +1,82 @@ +# Optional semi-standard Makefile with some handy tools. +# Ncdu itself can be built with just the zig build system. + +PREFIX ?= /usr/local +BINDIR ?= ${PREFIX}/bin +MANDIR ?= ${PREFIX}/share/man/man1 + +NCDU_VERSION=$(shell grep 'program_version = "' src/main.zig | sed -e 's/^.*"\(.\+\)".*$$/\1/') + +debug: + zig build + +release: + zig build -Drelease-fast + +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 + mkdir -p ${MANDIR} + install -m0644 ncdu.1 ${MANDIR}/ + +uninstall: uninstall-bin uninstall-doc + +# XXX: Ideally, these would also remove the directories created by 'install' if they are empty. +uninstall-bin: + rm -f ${BINDIR}/ncdu + +uninstall-doc: + rm -f ${MANDIR}/ncdu.1 + +dist: doc + 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 + tar -cophzf ncdu-${NCDU_VERSION}.tar.gz --sort=name ncdu-${NCDU_VERSION} + rm -rf ncdu-${NCDU_VERSION} + + +# ASSUMPTION: the ncurses source tree has been extracted into ncurses/ +# BUG: Zig writes to zig-* in this directory, not the TARGET-specific build one. +# BUG: Doesn't seem to do any static linking :( +static: + mkdir -p static-${TARGET}/nc static-${TARGET}/inst/pkg + cd static-${TARGET}/nc && ../../ncurses/configure --prefix="`pwd`/../inst"\ + --with-pkg-config-libdir="`pwd`/../inst/pkg"\ + --without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs\ + --without-tests --enable-pc-files --without-pkg-config --without-shared --without-debug\ + --without-gpm --without-sysmouse --enable-widec --with-default-terminfo-dir=/usr/share/terminfo\ + --with-terminfo-dirs=/usr/share/terminfo:/lib/terminfo:/usr/local/share/terminfo\ + --with-fallbacks="screen linux vt100 xterm xterm-256color" --host=${TARGET}\ + CC="zig cc --target=${TARGET}"\ + LD="zig cc --target=${TARGET}"\ + AR="zig ar" RANLIB="zig ranlib"\ + CPPFLAGS=-D_GNU_SOURCE && make && make install.libs + cd static-${TARGET} && PKG_CONFIG_LIBDIR="`pwd`/inst/pkg" zig build -Dtarget=${TARGET}\ + --build-file ../build.zig --search-prefix inst/ --cache-dir zig -Drelease-fast=true + @# Alternative approach, bypassing zig-build, but this still refuses to do static linking ("UnableToStaticLink") + @# cd static-${TARGET} && zig build-exe -target ${TARGET} -lc -Iinst/include -Iinst/include/ncursesw -Linst/lib -lncursesw -static ../src/main.zig ../src/ncurses_refs.c + #rm -rf static-${TARGET} + +static-target-%: + $(MAKE) static TARGET=$* + +static-all:\ + # static-target-x86_64-linux-musl \ # Works, but doesn't link statically + # static-target-aarch64-linux-musl \ # Same + # static-target-i386-linux-musl # Broken, linker errors diff --git a/src/scan.zig b/src/scan.zig index 60fcaca..def9c1a 100644 --- a/src/scan.zig +++ b/src/scan.zig @@ -653,7 +653,7 @@ const Import = struct { // (May store fewer characters in the case of \u escapes, it's not super precise) fn string(self: *Self, buf: []u8) []u8 { if (self.next() != '"') self.die("expected '\"'"); - var n: u64 = 0; + var n: usize = 0; while (true) { const ch = self.next(); switch (ch) { |