sbase/Makefile

283 lines
6.6 KiB
Makefile
Raw Normal View History

2011-05-22 21:36:34 -04:00
include config.mk
.SUFFIXES:
.SUFFIXES: .o .c
HDR =\
arg.h\
2014-11-17 10:45:09 -05:00
compat.h\
crypt.h\
fs.h\
md5.h\
queue.h\
sha1.h\
sha224.h\
sha256.h\
sha384.h\
sha512.h\
sha512-224.h\
sha512-256.h\
text.h\
utf.h\
2014-11-13 13:20:51 -05:00
util.h
LIBUTF = libutf.a
LIBUTFSRC =\
libutf/fgetrune.c\
libutf/fputrune.c\
libutf/isalnumrune.c\
libutf/isalpharune.c\
libutf/isblankrune.c\
libutf/iscntrlrune.c\
libutf/isdigitrune.c\
libutf/isgraphrune.c\
libutf/isprintrune.c\
libutf/ispunctrune.c\
libutf/isspacerune.c\
libutf/istitlerune.c\
libutf/isxdigitrune.c\
libutf/lowerrune.c\
2016-10-20 12:06:18 -04:00
libutf/rune.c\
libutf/runetype.c\
libutf/upperrune.c\
libutf/utf.c\
libutf/utftorunestr.c
LIBUTIL = libutil.a
LIBUTILSRC =\
2014-11-17 11:48:01 -05:00
libutil/concat.c\
libutil/cp.c\
libutil/crypt.c\
libutil/ealloc.c\
libutil/enmasse.c\
libutil/eprintf.c\
libutil/eregcomp.c\
libutil/estrtod.c\
libutil/fnck.c\
Add *fshut() functions to properly flush file streams This has been a known issue for a long time. Example: printf "word" > /dev/full wouldn't report there's not enough space on the device. This is due to the fact that every libc has internal buffers for stdout which store fragments of written data until they reach a certain size or on some callback to flush them all at once to the kernel. You can force the libc to flush them with fflush(). In case flushing fails, you can check the return value of fflush() and report an error. However, previously, sbase didn't have such checks and without fflush(), the libc silently flushes the buffers on exit without checking the errors. No offense, but there's no way for the libc to report errors in the exit- condition. GNU coreutils solve this by having onexit-callbacks to handle the flushing and report issues, but they have obvious deficiencies. After long discussions on IRC, we came to the conclusion that checking the return value of every io-function would be a bit too much, and having a general-purpose fclose-wrapper would be the best way to go. It turned out that fclose() alone is not enough to detect errors. The right way to do it is to fflush() + check ferror on the fp and then to a fclose(). This is what fshut does and that's how it's done before each return. The return value is obviously affected, reporting an error in case a flush or close failed, but also when reading failed for some reason, the error- state is caught. the !!( ... + ...) construction is used to call all functions inside the brackets and not "terminating" on the first. We want errors to be reported, but there's no reason to stop flushing buffers when one other file buffer has issues. Obviously, functionales come before the flush and ret-logic comes after to prevent early exits as well without reporting warnings if there are any. One more advantage of fshut() is that it is even able to report errors on obscure NFS-setups which the other coreutils are unable to detect, because they only check the return-value of fflush() and fclose(), not ferror() as well.
2015-04-04 15:25:17 -04:00
libutil/fshut.c\
2014-11-17 11:48:01 -05:00
libutil/getlines.c\
libutil/human.c\
libutil/linecmp.c\
2014-11-17 11:48:01 -05:00
libutil/md5.c\
libutil/memmem.c\
2015-04-20 13:02:11 -04:00
libutil/mkdirp.c\
2014-11-17 11:48:01 -05:00
libutil/mode.c\
libutil/parseoffset.c\
2014-11-17 11:48:01 -05:00
libutil/putword.c\
libutil/reallocarray.c\
2014-11-17 11:48:01 -05:00
libutil/recurse.c\
libutil/rm.c\
libutil/sha1.c\
libutil/sha224.c\
2014-11-17 11:48:01 -05:00
libutil/sha256.c\
libutil/sha384.c\
2014-11-17 11:48:01 -05:00
libutil/sha512.c\
libutil/sha512-224.c\
libutil/sha512-256.c\
libutil/strcasestr.c\
2014-11-17 11:48:01 -05:00
libutil/strlcat.c\
2015-01-25 12:48:11 -05:00
libutil/strlcpy.c\
libutil/strsep.c\
libutil/strtonum.c\
libutil/unescape.c\
libutil/writeall.c
LIB = $(LIBUTF) $(LIBUTIL)
BIN =\
basename\
cal\
cat\
chgrp\
chmod\
chown\
chroot\
cksum\
cmp\
cols\
comm\
cp\
2014-12-16 05:59:08 -05:00
cron\
cut\
date\
2020-04-29 01:22:37 -04:00
dd\
dirname\
du\
echo\
2015-12-14 07:09:34 -05:00
ed\
env\
expand\
expr\
false\
find\
flock\
fold\
getconf\
grep\
head\
hostname\
2016-10-20 12:06:18 -04:00
join\
kill\
link\
ln\
logger\
logname\
ls\
md5sum\
mkdir\
mkfifo\
mknod\
mktemp\
mv\
nice\
nl\
nohup\
od\
paste\
2016-10-20 12:06:18 -04:00
pathchk\
printenv\
printf\
pwd\
readlink\
renice\
rev\
rm\
rmdir\
sed\
2014-12-01 12:12:07 -05:00
seq\
setsid\
2014-12-01 12:12:07 -05:00
sha1sum\
sha224sum\
2014-12-01 12:12:07 -05:00
sha256sum\
sha384sum\
2014-12-01 12:12:07 -05:00
sha512sum\
sha512-224sum\
sha512-256sum\
2014-12-01 12:12:07 -05:00
sleep\
sort\
split\
sponge\
strings\
sync\
tail\
tar\
tee\
test\
tftp\
time\
touch\
tr\
true\
tsort\
tty\
uname\
unexpand\
uniq\
unlink\
2014-12-01 12:12:07 -05:00
uudecode\
uuencode\
wc\
2015-04-27 10:24:43 -04:00
which\
whoami\
xargs\
2016-02-15 03:44:35 -05:00
xinstall\
yes
LIBUTFOBJ = $(LIBUTFSRC:.c=.o)
LIBUTILOBJ = $(LIBUTILSRC:.c=.o)
OBJ = $(BIN:=.o) $(LIBUTFOBJ) $(LIBUTILOBJ)
2016-02-15 03:44:35 -05:00
SRC = $(BIN:=.c)
MAN = $(BIN:=.1)
2011-05-22 21:36:34 -04:00
all: $(BIN)
$(BIN): $(LIB) $(@:=.o)
2011-05-22 21:36:34 -04:00
$(OBJ): $(HDR) config.mk
2011-05-22 21:36:34 -04:00
.o:
$(CC) $(LDFLAGS) -o $@ $< $(LIB)
2011-05-22 21:36:34 -04:00
.c.o:
2014-11-17 05:31:29 -05:00
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
2011-05-24 08:00:30 -04:00
2014-11-19 05:50:54 -05:00
$(LIBUTF): $(LIBUTFOBJ)
$(AR) rc $@ $?
2014-11-19 05:50:54 -05:00
$(RANLIB) $@
$(LIBUTIL): $(LIBUTILOBJ)
$(AR) rc $@ $?
2014-11-17 07:22:53 -05:00
$(RANLIB) $@
2011-05-22 21:36:34 -04:00
getconf.o: getconf.h
getconf.h: getconf.sh
./getconf.sh > $@
2011-06-08 11:26:05 -04:00
install: all
2014-11-17 05:15:44 -05:00
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
2016-02-15 03:44:35 -05:00
cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN)
mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
2014-11-17 05:15:44 -05:00
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
2014-11-17 05:15:44 -05:00
cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
2016-02-15 03:44:35 -05:00
mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
2011-06-08 06:37:00 -04:00
uninstall:
cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) [ install
cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN) install.1
2011-06-08 06:37:00 -04:00
2011-05-22 21:36:34 -04:00
dist: clean
2014-11-17 05:15:44 -05:00
mkdir -p sbase-$(VERSION)
2014-11-17 11:48:01 -05:00
cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN) libutf libutil $(HDR) sbase-$(VERSION)
2014-11-17 05:15:44 -05:00
tar -cf sbase-$(VERSION).tar sbase-$(VERSION)
gzip sbase-$(VERSION).tar
rm -rf sbase-$(VERSION)
2011-05-22 21:36:34 -04:00
sbase-box: $(LIB) $(SRC) getconf.h
2014-11-17 05:15:44 -05:00
mkdir -p build
cp $(HDR) build
cp getconf.h build
for f in $(SRC); do sed "s/^main(/$$(echo "$${f%.c}" | sed s/-/_/g)_&/" < $$f > build/$$f; done
echo '#include <libgen.h>' > build/$@.c
echo '#include <stdio.h>' >> build/$@.c
echo '#include <stdlib.h>' >> build/$@.c
echo '#include <string.h>' >> build/$@.c
echo '#include "util.h"' >> build/$@.c
for f in $(SRC); do echo "int $$(echo "$${f%.c}" | sed s/-/_/g)_main(int, char **);"; done >> build/$@.c
echo 'int main(int argc, char *argv[]) { char *s = basename(argv[0]);' >> build/$@.c
echo 'if(!strcmp(s,"sbase-box")) { argc--; argv++; s = basename(argv[0]); } if(0) ;' >> build/$@.c
echo "else if (!strcmp(s, \"install\")) return xinstall_main(argc, argv);" >> build/$@.c
echo "else if (!strcmp(s, \"[\")) return test_main(argc, argv);" >> build/$@.c
for f in $(SRC); do echo "else if(!strcmp(s, \"$${f%.c}\")) return $$(echo "$${f%.c}" | sed s/-/_/g)_main(argc, argv);"; done >> build/$@.c
echo 'else { fputs("[ ", stdout);' >> build/$@.c
for f in $(SRC); do echo "fputs(\"$${f%.c} \", stdout);"; done >> build/$@.c
echo 'putchar(0xa); }; return 0; }' >> build/$@.c
2015-09-03 14:07:16 -04:00
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB)
2014-11-17 05:15:44 -05:00
rm -r build
2011-06-15 20:53:33 -04:00
sbase-box-install: sbase-box
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f sbase-box $(DESTDIR)$(PREFIX)/bin
chmod 755 $(DESTDIR)$(PREFIX)/bin/sbase-box
2016-02-15 03:44:35 -05:00
for f in $(BIN); do ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/"$$f"; done
ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/[
2016-02-15 03:44:35 -05:00
mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
2016-02-15 03:44:35 -05:00
mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
sbase-box-uninstall: uninstall
cd $(DESTDIR)$(PREFIX)/bin && rm -f sbase-box
2011-05-22 21:36:34 -04:00
clean:
rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz
rm -f getconf.h
2014-11-17 08:02:17 -05:00
.gitignore:
{ printf '*.o\n' ; printf '/%s\n' getconf.h $(LIB) $(BIN) ; } > $@
.PHONY: all install uninstall dist sbase-box-install sbase-box-uninstall clean .gitignore