Added `install` and `uninstall` targets. Added documentation to Makefile

Fortune for sink's current commit: Blessing − 吉
master
Avril 2 years ago
parent 2b81bf74ba
commit dca529daf7
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,32 +1,58 @@
# Sinks all input to /dev/null
# `sink` - sinks all input to /dev/null
#
# Targets:
# `sink` (default): stripped `release` target. output: `sink`
# `release`: optimised build. output: `sink-release`
# `debug`: unoptimised build with debuginfo. output: `sink-debug`
# `clean`: remove all previous object and binary output files
#
# Environment variables:
# * `SHARED` - set to "yes" to prevent passing `--static` to cc
# * `TARGET_ARCH` - target arch (`-march=`), or set `TARGET_ARCH=` to force set to generic target. (default [release only]: `native`)
# * `CFLAGS`, `COMMON_FLAGS` - passthrough to cc
# * `LDFLAGS` - passthrough to ld
# * `DEBUG_CFLAGS`, `DEBUG_LDFLAGS` - passthrough to cc / ld on target `debug`
# * `RELEASE_CFLAGS`, `RELEASE_LDFLAGS` - passthrough to cc / ld on target `release`
#
# Make overridable only:
# * `STRIP` - Strip command for default output (stripped release) target (`make sink`). set `make STRIP=:` to prevent stripping entirely. (NOTE: When using `make install`, `STRIP=:` will not work, instead, paradoxically, set `STRIP=true`, they have the same effect for all targets)
PROJECT=sink
SRC=$(wildcard *.c)
OUTPUT=$(PROJECT)
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
COMMON_FLAGS+= -W -Wall -Wextra -Wstrict-aliasing -fno-strict-aliasing
TARGET_ARCH?=native
ifneq ($(TARGET_ARCH),)
TARGET_ARCH:=$(addprefix -march=,$(TARGET_ARCH))
endif
RELEASE_CFLAGS+= $(TARGET_ARCH) -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \
RELEASE_CFLAGS+= $(TARGET_ARCH) -fgraphite \
-floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \
-fno-stack-check
RELEASE_CFLAGS+= -O3 -flto
RELEASE_CFLAGS+= -O3 -flto -DRELEASE
RELEASE_LDFLAGS+= -Wl,-O3 -Wl,-flto
DEBUG_CFLAGS+=-Og -g3 -ggdb -gz
DEBUG_CFLAGS+=-Og -g3 -ggdb -gz -DDEBUG
DEBUG_LDFLASG+=-Wl,-g
CFLAGS += $(COMMON_FLAGS) --std=gnu17
LDFLAGS +=
ifneq ($(SHARED),yes)
CFLAGS+=--static
endif
OBJ = $(SRC:.c=.o)
STRIP=strip
# Phonies
.PHONY: $(OUTPUT)
@ -62,4 +88,10 @@ clean:
rm -f $(OUTPUT) $(PROJECT)-*
.PHONY: install
install:
install -s --strip-program=$(STRIP) -m 755 $(OUTPUT) $(DESTDIR)$(PREFIX)/bin
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(OUTPUT)

@ -6,8 +6,8 @@
#define r_stdout 1
#define r_stderr 2
#define LIKELY(e) __builtin_expect(!!(e), 1)
#define UNLIKELY(e) __builtin_expect(!!(e), 0)
#define LIKELY(e) __builtin_expect((e) != 0, 1)
#define UNLIKELY(e) __builtin_expect((e) != 0, 0)
static inline int dupall(int from)
{
@ -39,5 +39,8 @@ int main(void)
perror("failed to open /dev/null");
return 1;
}
return dupall(null);
register int rc = dupall(null);
if(LIKELY(rc)) close(null);
return rc;
}

Loading…
Cancel
Save