ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit 0c008b65ee3dc4992087fb58aa798bc109c63b89
parent ae7aafc127d8439fad3250afe7b6f28d44690d39
Author: sin <sin@2f30.org>
Date:   Sun, 30 Nov 2014 12:09:34 +0000

Bring in the sbase Makefile updates to ubase

Diffstat:
MMakefile | 267+++++++++++++++++++++++++++++++++++++------------------------------------------
Mconfig.mk | 8+++++---
2 files changed, 130 insertions(+), 145 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,11 +1,11 @@ include config.mk -.POSIX: -.SUFFIXES: .c .o +.SUFFIXES: +.SUFFIXES: .o .c HDR = \ arg.h \ - config.def.h \ + config.h \ passwd.h \ proc.h \ queue.h \ @@ -14,73 +14,76 @@ HDR = \ text.h \ util.h -LIB = \ - libutil/agetcwd.o \ - libutil/agetline.o \ - libutil/apathmax.o \ - libutil/concat.o \ - libutil/ealloc.o \ - libutil/eprintf.o \ - libutil/estrtol.o \ - libutil/estrtoul.o \ - libutil/explicit_bzero.o \ - libutil/passwd.o \ - libutil/proc.o \ - libutil/putword.o \ - libutil/recurse.o \ - libutil/strlcat.o \ - libutil/strlcpy.o \ - libutil/tty.o - -SRC = \ - last.c \ - lastlog.c \ - chvt.c \ - clear.c \ - ctrlaltdel.c \ - dd.c \ - df.c \ - dmesg.c \ - eject.c \ - fallocate.c \ - free.c \ - freeramdisk.c \ - fsfreeze.c \ - getty.c \ - halt.c \ - hwclock.c \ - id.c \ - insmod.c \ - killall5.c \ - login.c \ - lsmod.c \ - lsusb.c \ - mesg.c \ - mknod.c \ - mkswap.c \ - mount.c \ - mountpoint.c \ - pagesize.c \ - passwd.c \ - pidof.c \ - pivot_root.c \ - ps.c \ - readahead.c \ - respawn.c \ - rmmod.c \ - stat.c \ - su.c \ - swaplabel.c \ - swapoff.c \ - swapon.c \ - switch_root.c \ - sysctl.c \ - truncate.c \ - umount.c \ - unshare.c \ - uptime.c \ - watch.c \ - who.c +LIBUTIL = libutil.a +LIBUTILSRC = \ + libutil/agetcwd.c \ + libutil/agetline.c \ + libutil/apathmax.c \ + libutil/concat.c \ + libutil/ealloc.c \ + libutil/eprintf.c \ + libutil/estrtol.c \ + libutil/estrtoul.c \ + libutil/explicit_bzero.c \ + libutil/passwd.c \ + libutil/proc.c \ + libutil/putword.c \ + libutil/recurse.c \ + libutil/strlcat.c \ + libutil/strlcpy.c \ + libutil/tty.c + +LIB = $(LIBUTIL) + +BIN = \ + chvt \ + clear \ + ctrlaltdel \ + dd \ + df \ + dmesg \ + eject \ + fallocate \ + free \ + freeramdisk \ + fsfreeze \ + getty \ + halt \ + hwclock \ + id \ + insmod \ + killall5 \ + last \ + lastlog \ + login \ + lsmod \ + lsusb \ + mesg \ + mknod \ + mkswap \ + mount \ + mountpoint \ + pagesize \ + passwd \ + pidof \ + pivot_root \ + ps \ + readahead \ + respawn \ + rmmod \ + stat \ + su \ + swaplabel \ + swapoff \ + swapon \ + switch_root \ + sysctl \ + truncate \ + umount \ + unshare \ + uptime \ + watch \ + who MAN1 = \ chvt.1 \ @@ -133,93 +136,73 @@ MAN8 = \ sysctl.8 \ umount.8 -OBJ = $(SRC:.c=.o) $(LIB) -BIN = $(SRC:.c=) lastb +LIBUTILOBJ = $(LIBUTILSRC:.c=.o) +OBJ = $(BIN:=.o) $(LIBUTILOBJ) +SRC = $(BIN:=.c) -all: options binlib +all: $(BIN) -options: - @echo ubase build options: - @echo "CFLAGS = $(CFLAGS)" - @echo "LDFLAGS = $(LDFLAGS)" - @echo "CC = $(CC)" +$(BIN): $(LIB) -binlib: libutil.a - $(MAKE) bin - -bin: $(BIN) - -$(OBJ): config.h util.h config.mk +$(OBJ): $(HDR) config.mk config.h: - @echo creating $@ from config.def.h - @cp config.def.h $@ + cp config.def.h $@ .o: - @echo LD $@ - @$(LD) -o $@ $< libutil.a $(LDFLAGS) + $(LD) $(LDFLAGS) -o $@ $< $(LIB) .c.o: - @echo CC $< - @$(CC) -c -o $@ $< $(CFLAGS) + $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< -libutil.a: $(LIB) - @echo AR $@ - @$(AR) -r -c $@ $? - @ranlib $@ - -lastb: last - ln -f last lastb +$(LIBUTIL): $(LIBUTILOBJ) + $(AR) -r -c $@ $? + $(RANLIB) $@ install: all - @echo installing executables to $(DESTDIR)$(PREFIX)/bin - @mkdir -p $(DESTDIR)$(PREFIX)/bin - @cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin - @cd $(DESTDIR)$(PREFIX)/bin && chmod 755 $(BIN) - @echo installing manual pages to $(DESTDIR)$(MANPREFIX)/man1 - @mkdir -p $(DESTDIR)$(MANPREFIX)/man1 - @for m in $(MAN1); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done - @echo installing manual pages to $(DESTDIR)$(MANPREFIX)/man8 - @mkdir -p $(DESTDIR)$(MANPREFIX)/man8 - @for m in $(MAN8); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man8/"$$m"; done - @chmod 644 $(DESTDIR)$(MANPREFIX)/man1/$(MAN1) - @chmod 644 $(DESTDIR)$(MANPREFIX)/man8/$(MAN8) + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin + cd $(DESTDIR)$(PREFIX)/bin && chmod 755 $(BIN) + mkdir -p $(DESTDIR)$(MANPREFIX)/man1 + for m in $(MAN1); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done + mkdir -p $(DESTDIR)$(MANPREFIX)/man8 + for m in $(MAN8); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man8/"$$m"; done + cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN1) + cd $(DESTDIR)$(MANPREFIX)/man8 && chmod 644 $(MAN8) uninstall: - @echo removing executables from $(DESTDIR)$(PREFIX)/bin - @cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) - @echo removing manual pages from $(DESTDIR)$(MANPREFIX)/man1 - @cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN) + cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) + cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN1) + cd $(DESTDIR)$(MANPREFIX)/man8 && rm -f $(MAN8) dist: clean - @echo creating dist tarball - @mkdir -p ubase-$(VERSION) - @cp -r LICENSE Makefile config.mk TODO $(SRC) $(MAN) libutil $(HDR) ubase-$(VERSION) - @tar -cf ubase-$(VERSION).tar ubase-$(VERSION) - @gzip ubase-$(VERSION).tar - @rm -rf ubase-$(VERSION) - -ubase-box: config.h $(SRC) libutil.a - @echo creating box binary - @mkdir -p build - @cp $(HDR) build - @cp config.h build - @for f in $(SRC); do sed "s/^main(/`basename $$f .c`_&/" < $$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 `basename $$f .c`_main(int, char **);" >> build/$@.c; done - @echo 'int main(int argc, char *argv[]) { char *s = basename(argv[0]); if(!strcmp(s,"ubase-box")) { argc--; argv++; s = basename(argv[0]); } if(0) ;' >> build/$@.c - @for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) return `basename $$f .c`_main(argc, argv);" >> build/$@.c; done - @echo 'else {' >> build/$@.c - @for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$@.c; done - @echo "putchar(0xa); }; return 0; }" >> build/$@.c - @echo LD $@ - @$(LD) -o $@ build/*.c libutil.a $(CFLAGS) $(LDFLAGS) - @rm -r build + mkdir -p ubase-$(VERSION) + cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN1) $(MAN8) libutil $(HDR) config.def.h ubase-$(VERSION) + tar -cf ubase-$(VERSION).tar ubase-$(VERSION) + gzip ubase-$(VERSION).tar + rm -rf ubase-$(VERSION) + +ubase-box: $(LIB) $(SRC) + mkdir -p build + cp $(HDR) build + cp config.h build + for f in $(SRC); do sed "s/^main(/`basename $$f .c`_&/" < $$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 `basename $$f .c`_main(int, char **);" >> build/$@.c; done + echo 'int main(int argc, char *argv[]) { char *s = basename(argv[0]); if(!strcmp(s,"ubase-box")) { argc--; argv++; s = basename(argv[0]); } if(0) ;' >> build/$@.c + for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) return `basename $$f .c`_main(argc, argv);" >> build/$@.c; done + echo 'else {' >> build/$@.c + for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$@.c; done + echo "putchar(0xa); }; return 0; }" >> build/$@.c + $(LD) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB) + rm -r build clean: - @echo cleaning - @rm -f $(BIN) $(OBJ) $(LIB) libutil.a ubase-box + rm -f $(BIN) $(OBJ) $(LIB) ubase-box ubase-$(VERSION).tar.gz + +.PHONY: + all install uninstall dist ubase-box clean diff --git a/config.mk b/config.mk @@ -5,9 +5,11 @@ VERSION = 0.1 PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man -#CC = gcc -#CC = musl-gcc +CC = cc LD = $(CC) +AR = ar +RANLIB = ranlib + CPPFLAGS = -D_XOPEN_SOURCE -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -CFLAGS = -std=c99 -Wall -Wextra $(CPPFLAGS) +CFLAGS = -std=c99 -Wall -Wextra LDFLAGS = -s -lcrypt # -static