2013-08-06 11:16:27 +00:00
|
|
|
include config.mk
|
|
|
|
|
|
|
|
.POSIX:
|
|
|
|
.SUFFIXES: .c .o
|
|
|
|
|
2013-08-14 14:38:43 +00:00
|
|
|
HDR = arg.h grabmntinfo.h proc.h util.h
|
2013-08-06 11:16:27 +00:00
|
|
|
LIB = \
|
2013-08-14 14:38:43 +00:00
|
|
|
util/agetcwd.o \
|
|
|
|
util/apathmax.o \
|
2013-08-06 11:16:27 +00:00
|
|
|
util/eprintf.o \
|
2013-08-14 13:19:05 +00:00
|
|
|
util/estrtol.o \
|
2013-08-14 14:38:43 +00:00
|
|
|
util/grabmntinfo.o \
|
|
|
|
util/proc.o \
|
|
|
|
util/recurse.o \
|
|
|
|
util/tty.o
|
2013-08-06 11:16:27 +00:00
|
|
|
|
|
|
|
SRC = \
|
2013-08-15 11:54:40 +00:00
|
|
|
chvt.c \
|
2013-08-06 19:08:41 +00:00
|
|
|
df.c \
|
2013-08-07 08:52:10 +00:00
|
|
|
dmesg.c \
|
2013-08-15 15:02:53 +00:00
|
|
|
free.c \
|
2013-08-09 14:04:02 +00:00
|
|
|
halt.c \
|
2013-08-09 08:42:34 +00:00
|
|
|
insmod.c \
|
2013-08-09 09:23:40 +00:00
|
|
|
lsmod.c \
|
2013-08-09 12:45:20 +00:00
|
|
|
mkswap.c \
|
2013-08-12 11:32:34 +00:00
|
|
|
mount.c \
|
2013-08-14 13:38:56 +00:00
|
|
|
pivot_root.c \
|
2013-08-14 14:38:43 +00:00
|
|
|
ps.c \
|
2013-08-09 13:55:50 +00:00
|
|
|
reboot.c \
|
2013-08-09 14:42:49 +00:00
|
|
|
rmmod.c \
|
2013-08-14 13:19:05 +00:00
|
|
|
stat.c \
|
2013-08-09 14:48:29 +00:00
|
|
|
swapoff.c \
|
2013-08-12 10:14:56 +00:00
|
|
|
swapon.c \
|
2013-08-14 13:19:05 +00:00
|
|
|
umount.c \
|
2013-08-12 10:14:56 +00:00
|
|
|
unshare.c
|
2013-08-07 10:43:55 +00:00
|
|
|
|
2013-08-06 11:16:27 +00:00
|
|
|
OBJ = $(SRC:.c=.o) $(LIB)
|
|
|
|
BIN = $(SRC:.c=)
|
|
|
|
MAN = $(SRC:.c=.1)
|
|
|
|
|
2013-08-07 10:56:03 +00:00
|
|
|
all: options binlib
|
|
|
|
|
|
|
|
options:
|
|
|
|
@echo ubase build options:
|
|
|
|
@echo "CFLAGS = $(CFLAGS)"
|
|
|
|
@echo "LDFLAGS = $(LDFLAGS)"
|
|
|
|
@echo "CC = $(CC)"
|
2013-08-06 11:16:27 +00: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
|
|
|
|
@cp -f $(MAN) $(DESTDIR)$(MANPREFIX)/man1
|
|
|
|
@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)
|
|
|
|
@cp -r LICENSE Makefile config.mk $(SRC) $(MAN) util $(HDR) ubase-$(VERSION)
|
|
|
|
@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
|
|
|
|
@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(0) ;' >> build/$@.c
|
|
|
|
@for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) `basename $$f .c`_main(argc, argv);" >> build/$@.c; done
|
|
|
|
@printf 'else eprintf("%%s: unknown program\\n", s); return EXIT_SUCCESS; }\n' >> build/$@.c
|
|
|
|
@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
|