2013-08-06 07:16:27 -04:00
|
|
|
include config.mk
|
|
|
|
|
|
|
|
.POSIX:
|
|
|
|
.SUFFIXES: .c .o
|
|
|
|
|
2013-08-19 11:27:21 -04:00
|
|
|
HDR = arg.h grabmntinfo.h proc.h reboot.h util.h
|
2013-08-06 07:16:27 -04:00
|
|
|
LIB = \
|
2013-08-14 10:38:43 -04:00
|
|
|
util/agetcwd.o \
|
|
|
|
util/apathmax.o \
|
2013-08-06 07:16:27 -04:00
|
|
|
util/eprintf.o \
|
2013-08-14 09:19:05 -04:00
|
|
|
util/estrtol.o \
|
2013-08-14 10:38:43 -04:00
|
|
|
util/grabmntinfo.o \
|
|
|
|
util/proc.o \
|
2013-08-29 06:11:26 -04:00
|
|
|
util/putword.o \
|
2013-08-14 10:38:43 -04:00
|
|
|
util/recurse.o \
|
2013-09-04 06:27:29 -04:00
|
|
|
util/strlcat.o \
|
|
|
|
util/strlcpy.o \
|
2013-08-14 10:38:43 -04:00
|
|
|
util/tty.o
|
2013-08-06 07:16:27 -04:00
|
|
|
|
|
|
|
SRC = \
|
2013-08-15 07:54:40 -04:00
|
|
|
chvt.c \
|
2013-08-16 06:08:26 -04:00
|
|
|
clear.c \
|
2013-08-06 15:08:41 -04:00
|
|
|
df.c \
|
2013-08-07 04:52:10 -04:00
|
|
|
dmesg.c \
|
2013-09-04 08:31:06 -04:00
|
|
|
eject.c \
|
2013-08-16 06:14:55 -04:00
|
|
|
fallocate.c \
|
2013-08-15 11:02:53 -04:00
|
|
|
free.c \
|
2013-08-09 10:04:02 -04:00
|
|
|
halt.c \
|
2013-08-09 04:42:34 -04:00
|
|
|
insmod.c \
|
2013-08-09 05:23:40 -04:00
|
|
|
lsmod.c \
|
2013-09-03 08:52:47 -04:00
|
|
|
lsusb.c \
|
2013-08-09 08:45:20 -04:00
|
|
|
mkswap.c \
|
2013-08-12 07:32:34 -04:00
|
|
|
mount.c \
|
2013-08-16 06:00:43 -04:00
|
|
|
mountpoint.c \
|
2013-08-29 06:11:26 -04:00
|
|
|
pidof.c \
|
2013-08-14 09:38:56 -04:00
|
|
|
pivot_root.c \
|
2013-08-14 10:38:43 -04:00
|
|
|
ps.c \
|
2013-08-09 10:42:49 -04:00
|
|
|
rmmod.c \
|
2013-08-09 10:48:29 -04:00
|
|
|
swapoff.c \
|
2013-08-12 06:14:56 -04:00
|
|
|
swapon.c \
|
2013-08-16 06:34:52 -04:00
|
|
|
truncate.c \
|
2013-08-14 09:19:05 -04:00
|
|
|
umount.c \
|
2013-08-16 06:55:55 -04:00
|
|
|
unshare.c \
|
2013-09-04 06:27:29 -04:00
|
|
|
uptime.c \
|
|
|
|
watch.c
|
2013-08-07 06:43:55 -04:00
|
|
|
|
2013-08-06 07:16:27 -04:00
|
|
|
OBJ = $(SRC:.c=.o) $(LIB)
|
|
|
|
BIN = $(SRC:.c=)
|
|
|
|
MAN = $(SRC:.c=.1)
|
|
|
|
|
2013-08-07 06:56:03 -04:00
|
|
|
all: options binlib
|
|
|
|
|
|
|
|
options:
|
|
|
|
@echo ubase build options:
|
|
|
|
@echo "CFLAGS = $(CFLAGS)"
|
|
|
|
@echo "LDFLAGS = $(LDFLAGS)"
|
|
|
|
@echo "CC = $(CC)"
|
2013-08-06 07:16:27 -04:00
|
|
|
|
|
|
|
binlib: util.a
|
|
|
|
$(MAKE) bin
|
|
|
|
|
|
|
|
bin: $(BIN)
|
|
|
|
|
|
|
|
$(OBJ): util.h config.mk
|
|
|
|
|
|
|
|
.o:
|
|
|
|
@echo LD $@
|
|
|
|
@$(LD) -o $@ $< util.a $(LDFLAGS)
|
|
|
|
|
|
|
|
.c.o:
|
|
|
|
@echo CC $<
|
|
|
|
@$(CC) -c -o $@ $< $(CFLAGS)
|
|
|
|
|
|
|
|
util.a: $(LIB)
|
|
|
|
@echo AR $@
|
|
|
|
@$(AR) -r -c $@ $(LIB)
|
|
|
|
@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
|
2013-09-29 07:38:12 -04:00
|
|
|
@for m in $(MAN); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
|
2013-08-06 07:16:27 -04:00
|
|
|
@cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
dist: clean
|
|
|
|
@echo creating dist tarball
|
|
|
|
@mkdir -p ubase-$(VERSION)
|
2013-08-16 05:35:09 -04:00
|
|
|
@cp -r LICENSE Makefile config.mk TODO $(SRC) $(MAN) util $(HDR) ubase-$(VERSION)
|
2013-08-06 07:16:27 -04:00
|
|
|
@tar -cf ubase-$(VERSION).tar ubase-$(VERSION)
|
|
|
|
@gzip ubase-$(VERSION).tar
|
|
|
|
@rm -rf ubase-$(VERSION)
|
|
|
|
|
|
|
|
ubase-box: $(SRC) util.a
|
|
|
|
@echo creating box binary
|
|
|
|
@mkdir -p build
|
|
|
|
@cp $(HDR) build
|
|
|
|
@for f in $(SRC); do sed "s/^main(/`basename $$f .c`_&/" < $$f > build/$$f; done
|
|
|
|
@echo '#include <libgen.h>' > build/$@.c
|
2013-08-15 11:46:46 -04:00
|
|
|
@echo '#include <stdio.h>' >> build/$@.c
|
2013-08-06 07:16:27 -04:00
|
|
|
@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
|
2013-10-08 18:32:29 -04:00
|
|
|
@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
|
2013-08-06 07:16:27 -04:00
|
|
|
@for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) `basename $$f .c`_main(argc, argv);" >> build/$@.c; done
|
2013-08-15 11:46:46 -04:00
|
|
|
@echo 'else {' >> build/$@.c
|
|
|
|
@for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$@.c; done
|
2013-09-03 10:13:21 -04:00
|
|
|
@echo "putchar(0xa); }; return EXIT_SUCCESS; }" >> build/$@.c
|
2013-08-06 07:16:27 -04:00
|
|
|
@echo LD $@
|
|
|
|
@$(LD) -o $@ build/*.c util.a $(CFLAGS) $(LDFLAGS)
|
|
|
|
@rm -r build
|
|
|
|
|
|
|
|
clean:
|
|
|
|
@echo cleaning
|
|
|
|
@rm -f $(BIN) $(OBJ) $(LIB) util.a ubase-box
|