| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | include config.mk | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 12:12:14 -08:00
										 |  |  | .SUFFIXES: | 
					
						
							|  |  |  | .SUFFIXES: .o .c | 
					
						
							| 
									
										
										
										
											2012-05-16 12:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | HDR =\
 | 
					
						
							|  |  |  | 	arg.h\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 15:45:09 +00:00
										 |  |  | 	compat.h\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	crypt.h\
 | 
					
						
							|  |  |  | 	fs.h\
 | 
					
						
							|  |  |  | 	md5.h\
 | 
					
						
							|  |  |  | 	queue.h\
 | 
					
						
							|  |  |  | 	sha1.h\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 10:05:31 +01:00
										 |  |  | 	sha224.h\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	sha256.h\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 10:05:31 +01:00
										 |  |  | 	sha384.h\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	sha512.h\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 11:36:59 +01:00
										 |  |  | 	sha512-224.h\
 | 
					
						
							|  |  |  | 	sha512-256.h\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	text.h\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 15:41:44 +00:00
										 |  |  | 	utf.h\
 | 
					
						
							| 
									
										
										
										
											2014-11-13 18:20:51 +00:00
										 |  |  | 	util.h | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 15:41:44 +00:00
										 |  |  | LIBUTF = libutf.a | 
					
						
							|  |  |  | LIBUTFSRC =\
 | 
					
						
							| 
									
										
										
										
											2015-02-11 20:13:43 +01:00
										 |  |  | 	libutf/fgetrune.c\
 | 
					
						
							| 
									
										
										
										
											2015-02-11 20:58:00 +01:00
										 |  |  | 	libutf/fputrune.c\
 | 
					
						
							| 
									
										
										
										
											2015-02-11 15:44:54 +01:00
										 |  |  | 	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 09:06:18 -07:00
										 |  |  | 	libutf/rune.c\
 | 
					
						
							|  |  |  | 	libutf/runetype.c\
 | 
					
						
							|  |  |  | 	libutf/upperrune.c\
 | 
					
						
							|  |  |  | 	libutf/utf.c\
 | 
					
						
							|  |  |  | 	libutf/utftorunestr.c | 
					
						
							| 
									
										
										
										
											2014-11-17 15:41:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | LIBUTIL = libutil.a | 
					
						
							|  |  |  | LIBUTILSRC =\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00: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 21:25:17 +02:00
										 |  |  | 	libutil/fshut.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	libutil/getlines.c\
 | 
					
						
							|  |  |  | 	libutil/human.c\
 | 
					
						
							| 
									
										
										
										
											2016-03-07 02:04:29 +01:00
										 |  |  | 	libutil/linecmp.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	libutil/md5.c\
 | 
					
						
							| 
									
										
										
										
											2016-02-29 00:47:10 +01:00
										 |  |  | 	libutil/memmem.c\
 | 
					
						
							| 
									
										
										
										
											2015-04-20 18:02:11 +01:00
										 |  |  | 	libutil/mkdirp.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	libutil/mode.c\
 | 
					
						
							| 
									
										
										
										
											2015-09-30 01:19:01 +02:00
										 |  |  | 	libutil/parseoffset.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	libutil/putword.c\
 | 
					
						
							| 
									
										
										
										
											2015-03-10 21:16:21 +01:00
										 |  |  | 	libutil/reallocarray.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	libutil/recurse.c\
 | 
					
						
							|  |  |  | 	libutil/rm.c\
 | 
					
						
							|  |  |  | 	libutil/sha1.c\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 10:05:31 +01:00
										 |  |  | 	libutil/sha224.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	libutil/sha256.c\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 10:05:31 +01:00
										 |  |  | 	libutil/sha384.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	libutil/sha512.c\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 11:36:59 +01:00
										 |  |  | 	libutil/sha512-224.c\
 | 
					
						
							|  |  |  | 	libutil/sha512-256.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-20 23:43:08 +00:00
										 |  |  | 	libutil/strcasestr.c\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	libutil/strlcat.c\
 | 
					
						
							| 
									
										
										
										
											2015-01-25 17:48:11 +00:00
										 |  |  | 	libutil/strlcpy.c\
 | 
					
						
							| 
									
										
										
										
											2015-01-29 21:52:44 +01:00
										 |  |  | 	libutil/strsep.c\
 | 
					
						
							| 
									
										
										
										
											2015-01-30 13:48:33 +00:00
										 |  |  | 	libutil/strtonum.c\
 | 
					
						
							| 
									
										
										
										
											2017-01-01 17:00:32 -08:00
										 |  |  | 	libutil/unescape.c\
 | 
					
						
							|  |  |  | 	libutil/writeall.c | 
					
						
							| 
									
										
										
										
											2014-11-17 12:12:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 15:41:44 +00:00
										 |  |  | LIB = $(LIBUTF) $(LIBUTIL) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | BIN =\
 | 
					
						
							|  |  |  | 	basename\
 | 
					
						
							|  |  |  | 	cal\
 | 
					
						
							|  |  |  | 	cat\
 | 
					
						
							|  |  |  | 	chgrp\
 | 
					
						
							|  |  |  | 	chmod\
 | 
					
						
							|  |  |  | 	chown\
 | 
					
						
							|  |  |  | 	chroot\
 | 
					
						
							|  |  |  | 	cksum\
 | 
					
						
							|  |  |  | 	cmp\
 | 
					
						
							|  |  |  | 	cols\
 | 
					
						
							|  |  |  | 	comm\
 | 
					
						
							|  |  |  | 	cp\
 | 
					
						
							| 
									
										
										
										
											2014-12-16 10:59:08 +00:00
										 |  |  | 	cron\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	cut\
 | 
					
						
							|  |  |  | 	date\
 | 
					
						
							|  |  |  | 	dirname\
 | 
					
						
							|  |  |  | 	du\
 | 
					
						
							|  |  |  | 	echo\
 | 
					
						
							| 
									
										
										
										
											2015-12-14 12:09:34 +00:00
										 |  |  | 	ed\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	env\
 | 
					
						
							|  |  |  | 	expand\
 | 
					
						
							|  |  |  | 	expr\
 | 
					
						
							|  |  |  | 	false\
 | 
					
						
							| 
									
										
										
										
											2015-02-19 17:47:21 -08:00
										 |  |  | 	find\
 | 
					
						
							| 
									
										
										
										
											2015-10-07 10:16:18 +01:00
										 |  |  | 	flock\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	fold\
 | 
					
						
							| 
									
										
										
										
											2015-10-01 00:59:40 +02:00
										 |  |  | 	getconf\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	grep\
 | 
					
						
							|  |  |  | 	head\
 | 
					
						
							|  |  |  | 	hostname\
 | 
					
						
							| 
									
										
										
										
											2016-10-20 09:06:18 -07:00
										 |  |  | 	join\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	kill\
 | 
					
						
							|  |  |  | 	link\
 | 
					
						
							|  |  |  | 	ln\
 | 
					
						
							| 
									
										
										
										
											2014-12-04 11:34:39 +00:00
										 |  |  | 	logger\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	logname\
 | 
					
						
							|  |  |  | 	ls\
 | 
					
						
							|  |  |  | 	md5sum\
 | 
					
						
							|  |  |  | 	mkdir\
 | 
					
						
							|  |  |  | 	mkfifo\
 | 
					
						
							| 
									
										
										
										
											2020-03-01 15:58:37 -08:00
										 |  |  | 	mknod\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	mktemp\
 | 
					
						
							|  |  |  | 	mv\
 | 
					
						
							|  |  |  | 	nice\
 | 
					
						
							|  |  |  | 	nl\
 | 
					
						
							|  |  |  | 	nohup\
 | 
					
						
							| 
									
										
										
										
											2015-09-28 21:02:17 -04:00
										 |  |  | 	od\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	paste\
 | 
					
						
							| 
									
										
										
										
											2016-10-20 09:06:18 -07:00
										 |  |  | 	pathchk\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	printenv\
 | 
					
						
							|  |  |  | 	printf\
 | 
					
						
							|  |  |  | 	pwd\
 | 
					
						
							|  |  |  | 	readlink\
 | 
					
						
							|  |  |  | 	renice\
 | 
					
						
							| 
									
										
										
										
											2016-03-26 17:23:03 +01:00
										 |  |  | 	rev\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	rm\
 | 
					
						
							|  |  |  | 	rmdir\
 | 
					
						
							| 
									
										
										
										
											2015-02-10 10:34:46 +00:00
										 |  |  | 	sed\
 | 
					
						
							| 
									
										
										
										
											2014-12-01 09:12:07 -08:00
										 |  |  | 	seq\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	setsid\
 | 
					
						
							| 
									
										
										
										
											2014-12-01 09:12:07 -08:00
										 |  |  | 	sha1sum\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 10:05:31 +01:00
										 |  |  | 	sha224sum\
 | 
					
						
							| 
									
										
										
										
											2014-12-01 09:12:07 -08:00
										 |  |  | 	sha256sum\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 10:05:31 +01:00
										 |  |  | 	sha384sum\
 | 
					
						
							| 
									
										
										
										
											2014-12-01 09:12:07 -08:00
										 |  |  | 	sha512sum\
 | 
					
						
							| 
									
										
										
										
											2016-02-24 11:36:59 +01:00
										 |  |  | 	sha512-224sum\
 | 
					
						
							|  |  |  | 	sha512-256sum\
 | 
					
						
							| 
									
										
										
										
											2014-12-01 09:12:07 -08:00
										 |  |  | 	sleep\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	sort\
 | 
					
						
							|  |  |  | 	split\
 | 
					
						
							|  |  |  | 	sponge\
 | 
					
						
							|  |  |  | 	strings\
 | 
					
						
							|  |  |  | 	sync\
 | 
					
						
							|  |  |  | 	tail\
 | 
					
						
							|  |  |  | 	tar\
 | 
					
						
							|  |  |  | 	tee\
 | 
					
						
							|  |  |  | 	test\
 | 
					
						
							| 
									
										
										
										
											2015-08-14 12:58:02 +01:00
										 |  |  | 	tftp\
 | 
					
						
							| 
									
										
										
										
											2015-02-27 13:31:04 -08:00
										 |  |  | 	time\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	touch\
 | 
					
						
							|  |  |  | 	tr\
 | 
					
						
							|  |  |  | 	true\
 | 
					
						
							| 
									
										
										
										
											2016-02-17 01:17:33 +01:00
										 |  |  | 	tsort\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	tty\
 | 
					
						
							|  |  |  | 	uname\
 | 
					
						
							|  |  |  | 	unexpand\
 | 
					
						
							|  |  |  | 	uniq\
 | 
					
						
							|  |  |  | 	unlink\
 | 
					
						
							| 
									
										
										
										
											2014-12-01 09:12:07 -08:00
										 |  |  | 	uudecode\
 | 
					
						
							|  |  |  | 	uuencode\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	wc\
 | 
					
						
							| 
									
										
										
										
											2015-04-27 16:24:43 +02:00
										 |  |  | 	which\
 | 
					
						
							| 
									
										
										
										
											2015-12-14 10:55:25 +01:00
										 |  |  | 	whoami\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:22:10 +00:00
										 |  |  | 	xargs\
 | 
					
						
							| 
									
										
										
										
											2016-02-15 09:44:35 +01:00
										 |  |  | 	xinstall\
 | 
					
						
							| 
									
										
										
										
											2014-11-17 12:12:10 +00:00
										 |  |  | 	yes | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 15:41:44 +00:00
										 |  |  | LIBUTFOBJ = $(LIBUTFSRC:.c=.o) | 
					
						
							|  |  |  | LIBUTILOBJ = $(LIBUTILSRC:.c=.o) | 
					
						
							|  |  |  | OBJ = $(BIN:=.o) $(LIBUTFOBJ) $(LIBUTILOBJ) | 
					
						
							| 
									
										
										
										
											2016-02-15 09:44:35 +01:00
										 |  |  | SRC = $(BIN:=.c) | 
					
						
							|  |  |  | MAN = $(BIN:=.1) | 
					
						
							| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 13:50:19 +00:00
										 |  |  | all: $(BIN) | 
					
						
							| 
									
										
										
										
											2013-07-18 15:28:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 17:37:21 +00:00
										 |  |  | $(BIN): $(LIB) $(@:=.o) | 
					
						
							| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 18:26:38 +00:00
										 |  |  | $(OBJ): $(HDR) config.mk | 
					
						
							| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | .o: | 
					
						
							| 
									
										
										
										
											2015-08-01 00:09:40 +02:00
										 |  |  | 	$(CC) $(LDFLAGS) -o $@ $< $(LIB) | 
					
						
							| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | .c.o: | 
					
						
							| 
									
										
										
										
											2014-11-17 10:31:29 +00:00
										 |  |  | 	$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< | 
					
						
							| 
									
										
										
										
											2011-05-24 13:00:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-19 10:50:54 +00:00
										 |  |  | $(LIBUTF): $(LIBUTFOBJ) | 
					
						
							| 
									
										
										
										
											2015-02-03 13:22:04 +09:00
										 |  |  | 	$(AR) rc $@ $? | 
					
						
							| 
									
										
										
										
											2014-11-19 10:50:54 +00:00
										 |  |  | 	$(RANLIB) $@ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(LIBUTIL): $(LIBUTILOBJ) | 
					
						
							| 
									
										
										
										
											2015-02-03 13:22:04 +09:00
										 |  |  | 	$(AR) rc $@ $? | 
					
						
							| 
									
										
										
										
											2014-11-17 12:22:53 +00:00
										 |  |  | 	$(RANLIB) $@ | 
					
						
							| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 15:55:22 -07:00
										 |  |  | getconf.o: getconf.h | 
					
						
							| 
									
										
										
										
											2015-12-14 21:22:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 15:55:22 -07:00
										 |  |  | getconf.h: getconf.sh | 
					
						
							|  |  |  | 	./getconf.sh > $@ | 
					
						
							| 
									
										
										
										
											2015-12-14 21:22:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 16:26:05 +01:00
										 |  |  | install: all | 
					
						
							| 
									
										
										
										
											2014-11-17 10:15:44 +00:00
										 |  |  | 	mkdir -p $(DESTDIR)$(PREFIX)/bin | 
					
						
							|  |  |  | 	cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin | 
					
						
							| 
									
										
										
										
											2016-02-15 09:44:35 +01:00
										 |  |  | 	cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN) | 
					
						
							|  |  |  | 	mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install | 
					
						
							| 
									
										
										
										
											2014-11-17 10:15:44 +00:00
										 |  |  | 	mkdir -p $(DESTDIR)$(MANPREFIX)/man1 | 
					
						
							| 
									
										
										
										
											2015-02-01 16:33:46 +01:00
										 |  |  | 	for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done | 
					
						
							| 
									
										
										
										
											2014-11-17 10:15:44 +00:00
										 |  |  | 	cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN) | 
					
						
							| 
									
										
										
										
											2016-02-15 09:44:35 +01:00
										 |  |  | 	mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1 | 
					
						
							| 
									
										
										
										
											2011-06-08 11:37:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | uninstall: | 
					
						
							| 
									
										
										
										
											2016-02-15 09:44:27 +00:00
										 |  |  | 	cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) [ install | 
					
						
							| 
									
										
										
										
											2016-12-27 13:29:15 +01:00
										 |  |  | 	cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN) install.1 | 
					
						
							| 
									
										
										
										
											2011-06-08 11:37:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | dist: clean | 
					
						
							| 
									
										
										
										
											2014-11-17 10:15:44 +00:00
										 |  |  | 	mkdir -p sbase-$(VERSION) | 
					
						
							| 
									
										
										
										
											2014-11-17 16:48:01 +00:00
										 |  |  | 	cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN) libutf libutil $(HDR) sbase-$(VERSION) | 
					
						
							| 
									
										
										
										
											2014-11-17 10:15:44 +00:00
										 |  |  | 	tar -cf sbase-$(VERSION).tar sbase-$(VERSION) | 
					
						
							|  |  |  | 	gzip sbase-$(VERSION).tar | 
					
						
							|  |  |  | 	rm -rf sbase-$(VERSION) | 
					
						
							| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-05 18:13:16 -07:00
										 |  |  | sbase-box: $(LIB) $(SRC) getconf.h | 
					
						
							| 
									
										
										
										
											2014-11-17 10:15:44 +00:00
										 |  |  | 	mkdir -p build | 
					
						
							|  |  |  | 	cp $(HDR) build | 
					
						
							| 
									
										
										
										
											2016-10-03 15:55:22 -07:00
										 |  |  | 	cp getconf.h build | 
					
						
							| 
									
										
										
										
											2016-02-24 11:36:59 +01:00
										 |  |  | 	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 11:07:16 -07:00
										 |  |  | 	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB) | 
					
						
							| 
									
										
										
										
											2014-11-17 10:15:44 +00:00
										 |  |  | 	rm -r build | 
					
						
							| 
									
										
										
										
											2011-06-16 01:53:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-28 13:23:15 +01: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 09:44:35 +01:00
										 |  |  | 	for f in $(BIN); do ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/"$$f"; done | 
					
						
							| 
									
										
										
										
											2015-02-28 13:23:15 +01:00
										 |  |  | 	ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/[ | 
					
						
							| 
									
										
										
										
											2016-02-15 09:44:35 +01:00
										 |  |  | 	mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install | 
					
						
							| 
									
										
										
										
											2015-02-28 13:23:15 +01: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 | 
					
						
							|  |  |  | 	cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN) | 
					
						
							| 
									
										
										
										
											2016-02-15 09:44:35 +01:00
										 |  |  | 	mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1 | 
					
						
							| 
									
										
										
										
											2015-02-28 13:23:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-15 09:47:16 +00:00
										 |  |  | sbase-box-uninstall: uninstall | 
					
						
							|  |  |  | 	cd $(DESTDIR)$(PREFIX)/bin && rm -f sbase-box | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-23 02:36:34 +01:00
										 |  |  | clean: | 
					
						
							| 
									
										
										
										
											2014-11-30 11:57:04 +00:00
										 |  |  | 	rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz | 
					
						
							| 
									
										
										
										
											2016-10-03 15:55:22 -07:00
										 |  |  | 	rm -f getconf.h | 
					
						
							| 
									
										
										
										
											2014-11-17 13:02:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-13 13:52:52 -07:00
										 |  |  | .gitignore: | 
					
						
							|  |  |  | 	{ printf '*.o\n' ; printf '/%s\n' getconf.h $(LIB) $(BIN) ; } > $@ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PHONY: all install uninstall dist sbase-box sbase-box-install sbase-box-uninstall clean .gitignore |