sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

Makefile (6746B)


      1 include config.mk
      2 
      3 .SUFFIXES:
      4 .SUFFIXES: .o .c
      5 
      6 HDR =\
      7 	arg.h\
      8 	compat.h\
      9 	crypt.h\
     10 	fs.h\
     11 	md5.h\
     12 	queue.h\
     13 	sha1.h\
     14 	sha224.h\
     15 	sha256.h\
     16 	sha384.h\
     17 	sha512.h\
     18 	sha512-224.h\
     19 	sha512-256.h\
     20 	text.h\
     21 	utf.h\
     22 	util.h
     23 
     24 LIBUTF = libutf.a
     25 LIBUTFSRC =\
     26 	libutf/fgetrune.c\
     27 	libutf/fputrune.c\
     28 	libutf/isalnumrune.c\
     29 	libutf/isalpharune.c\
     30 	libutf/isblankrune.c\
     31 	libutf/iscntrlrune.c\
     32 	libutf/isdigitrune.c\
     33 	libutf/isgraphrune.c\
     34 	libutf/isprintrune.c\
     35 	libutf/ispunctrune.c\
     36 	libutf/isspacerune.c\
     37 	libutf/istitlerune.c\
     38 	libutf/isxdigitrune.c\
     39 	libutf/lowerrune.c\
     40 	libutf/rune.c\
     41 	libutf/runetype.c\
     42 	libutf/upperrune.c\
     43 	libutf/utf.c\
     44 	libutf/utftorunestr.c
     45 
     46 LIBUTIL = libutil.a
     47 LIBUTILSRC =\
     48 	libutil/concat.c\
     49 	libutil/cp.c\
     50 	libutil/crypt.c\
     51 	libutil/ealloc.c\
     52 	libutil/enmasse.c\
     53 	libutil/eprintf.c\
     54 	libutil/eregcomp.c\
     55 	libutil/estrtod.c\
     56 	libutil/fnck.c\
     57 	libutil/fshut.c\
     58 	libutil/getlines.c\
     59 	libutil/human.c\
     60 	libutil/linecmp.c\
     61 	libutil/md5.c\
     62 	libutil/memmem.c\
     63 	libutil/mkdirp.c\
     64 	libutil/mode.c\
     65 	libutil/parseoffset.c\
     66 	libutil/putword.c\
     67 	libutil/reallocarray.c\
     68 	libutil/recurse.c\
     69 	libutil/rm.c\
     70 	libutil/sha1.c\
     71 	libutil/sha224.c\
     72 	libutil/sha256.c\
     73 	libutil/sha384.c\
     74 	libutil/sha512.c\
     75 	libutil/sha512-224.c\
     76 	libutil/sha512-256.c\
     77 	libutil/strcasestr.c\
     78 	libutil/strlcat.c\
     79 	libutil/strlcpy.c\
     80 	libutil/strsep.c\
     81 	libutil/strtonum.c\
     82 	libutil/unescape.c\
     83 	libutil/writeall.c
     84 
     85 LIB = $(LIBUTF) $(LIBUTIL)
     86 
     87 BIN =\
     88 	basename\
     89 	cal\
     90 	cat\
     91 	chgrp\
     92 	chmod\
     93 	chown\
     94 	chroot\
     95 	cksum\
     96 	cmp\
     97 	cols\
     98 	comm\
     99 	cp\
    100 	cron\
    101 	cut\
    102 	date\
    103 	dirname\
    104 	du\
    105 	echo\
    106 	ed\
    107 	env\
    108 	expand\
    109 	expr\
    110 	false\
    111 	find\
    112 	flock\
    113 	fold\
    114 	getconf\
    115 	grep\
    116 	head\
    117 	hostname\
    118 	join\
    119 	kill\
    120 	link\
    121 	ln\
    122 	logger\
    123 	logname\
    124 	ls\
    125 	md5sum\
    126 	mkdir\
    127 	mkfifo\
    128 	mktemp\
    129 	mv\
    130 	nice\
    131 	nl\
    132 	nohup\
    133 	od\
    134 	paste\
    135 	pathchk\
    136 	printenv\
    137 	printf\
    138 	pwd\
    139 	readlink\
    140 	renice\
    141 	rev\
    142 	rm\
    143 	rmdir\
    144 	sed\
    145 	seq\
    146 	setsid\
    147 	sha1sum\
    148 	sha224sum\
    149 	sha256sum\
    150 	sha384sum\
    151 	sha512sum\
    152 	sha512-224sum\
    153 	sha512-256sum\
    154 	sleep\
    155 	sort\
    156 	split\
    157 	sponge\
    158 	strings\
    159 	sync\
    160 	tail\
    161 	tar\
    162 	tee\
    163 	test\
    164 	tftp\
    165 	time\
    166 	touch\
    167 	tr\
    168 	true\
    169 	tsort\
    170 	tty\
    171 	uname\
    172 	unexpand\
    173 	uniq\
    174 	unlink\
    175 	uudecode\
    176 	uuencode\
    177 	wc\
    178 	which\
    179 	whoami\
    180 	xargs\
    181 	xinstall\
    182 	yes
    183 
    184 LIBUTFOBJ = $(LIBUTFSRC:.c=.o)
    185 LIBUTILOBJ = $(LIBUTILSRC:.c=.o)
    186 OBJ = $(BIN:=.o) $(LIBUTFOBJ) $(LIBUTILOBJ)
    187 SRC = $(BIN:=.c)
    188 MAN = $(BIN:=.1)
    189 
    190 all: $(BIN)
    191 
    192 $(BIN): $(LIB) $(@:=.o)
    193 
    194 $(OBJ): $(HDR) config.mk
    195 
    196 .o:
    197 	$(CC) $(LDFLAGS) -o $@ $< $(LIB)
    198 
    199 .c.o:
    200 	$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
    201 
    202 $(LIBUTF): $(LIBUTFOBJ)
    203 	$(AR) rc $@ $?
    204 	$(RANLIB) $@
    205 
    206 $(LIBUTIL): $(LIBUTILOBJ)
    207 	$(AR) rc $@ $?
    208 	$(RANLIB) $@
    209 
    210 getconf.o: getconf.h
    211 
    212 getconf.h: getconf.sh
    213 	./getconf.sh > $@
    214 
    215 install: all
    216 	mkdir -p $(DESTDIR)$(PREFIX)/bin
    217 	cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
    218 	cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN)
    219 	mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
    220 	mkdir -p $(DESTDIR)$(MANPREFIX)/man1
    221 	for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
    222 	cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
    223 	mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
    224 
    225 uninstall:
    226 	cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) [ install
    227 	cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN) install.1
    228 
    229 dist: clean
    230 	mkdir -p sbase-$(VERSION)
    231 	cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN) libutf libutil $(HDR) sbase-$(VERSION)
    232 	tar -cf sbase-$(VERSION).tar sbase-$(VERSION)
    233 	gzip sbase-$(VERSION).tar
    234 	rm -rf sbase-$(VERSION)
    235 
    236 sbase-box: $(LIB) $(SRC) getconf.h
    237 	mkdir -p build
    238 	cp $(HDR) build
    239 	cp getconf.h build
    240 	for f in $(SRC); do sed "s/^main(/$$(echo "$${f%.c}" | sed s/-/_/g)_&/" < $$f > build/$$f; done
    241 	echo '#include <libgen.h>'                                                                                                     > build/$@.c
    242 	echo '#include <stdio.h>'                                                                                                     >> build/$@.c
    243 	echo '#include <stdlib.h>'                                                                                                    >> build/$@.c
    244 	echo '#include <string.h>'                                                                                                    >> build/$@.c
    245 	echo '#include "util.h"'                                                                                                      >> build/$@.c
    246 	for f in $(SRC); do echo "int $$(echo "$${f%.c}" | sed s/-/_/g)_main(int, char **);"; done                                    >> build/$@.c
    247 	echo 'int main(int argc, char *argv[]) { char *s = basename(argv[0]);'                                                        >> build/$@.c
    248 	echo 'if(!strcmp(s,"sbase-box")) { argc--; argv++; s = basename(argv[0]); } if(0) ;'                                          >> build/$@.c
    249 	echo "else if (!strcmp(s, \"install\")) return xinstall_main(argc, argv);"                                                    >> build/$@.c
    250 	echo "else if (!strcmp(s, \"[\")) return test_main(argc, argv);"                                                              >> build/$@.c
    251 	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
    252 	echo 'else { fputs("[ ", stdout);'                                                                                            >> build/$@.c
    253 	for f in $(SRC); do echo "fputs(\"$${f%.c} \", stdout);"; done                                                                >> build/$@.c
    254 	echo 'putchar(0xa); }; return 0; }'                                                                                           >> build/$@.c
    255 	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB)
    256 	rm -r build
    257 
    258 sbase-box-install: sbase-box
    259 	mkdir -p $(DESTDIR)$(PREFIX)/bin
    260 	cp -f sbase-box $(DESTDIR)$(PREFIX)/bin
    261 	chmod 755 $(DESTDIR)$(PREFIX)/bin/sbase-box
    262 	for f in $(BIN); do ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/"$$f"; done
    263 	ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/[
    264 	mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
    265 	mkdir -p $(DESTDIR)$(MANPREFIX)/man1
    266 	for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
    267 	cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
    268 	mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
    269 
    270 sbase-box-uninstall: uninstall
    271 	cd $(DESTDIR)$(PREFIX)/bin && rm -f sbase-box
    272 
    273 clean:
    274 	rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz
    275 	rm -f getconf.h
    276 
    277 .gitignore:
    278 	{ printf '*.o\n' ; printf '/%s\n' getconf.h $(LIB) $(BIN) ; } > $@
    279 
    280 .PHONY: all install uninstall dist sbase-box sbase-box-install sbase-box-uninstall clean .gitignore