Makefile (5187B)
1 include config.mk 2 3 .SUFFIXES: 4 .SUFFIXES: .o .c 5 6 HDR = \ 7 arg.h \ 8 config.h \ 9 passwd.h \ 10 proc.h \ 11 queue.h \ 12 reboot.h \ 13 rtc.h \ 14 text.h \ 15 util.h 16 17 LIBUTIL = libutil.a 18 LIBUTILSRC = \ 19 libutil/agetcwd.c \ 20 libutil/agetline.c \ 21 libutil/apathmax.c \ 22 libutil/concat.c \ 23 libutil/ealloc.c \ 24 libutil/eprintf.c \ 25 libutil/estrtol.c \ 26 libutil/estrtoul.c \ 27 libutil/explicit_bzero.c \ 28 libutil/passwd.c \ 29 libutil/proc.c \ 30 libutil/putword.c \ 31 libutil/recurse.c \ 32 libutil/strlcat.c \ 33 libutil/strlcpy.c \ 34 libutil/tty.c 35 36 LIB = $(LIBUTIL) 37 38 BIN = \ 39 chvt \ 40 clear \ 41 ctrlaltdel \ 42 dd \ 43 df \ 44 dmesg \ 45 eject \ 46 fallocate \ 47 free \ 48 freeramdisk \ 49 fsfreeze \ 50 getty \ 51 halt \ 52 hwclock \ 53 id \ 54 insmod \ 55 killall5 \ 56 last \ 57 lastlog \ 58 login \ 59 lsmod \ 60 lsusb \ 61 mesg \ 62 mknod \ 63 mkswap \ 64 mount \ 65 mountpoint \ 66 pagesize \ 67 passwd \ 68 pidof \ 69 pivot_root \ 70 ps \ 71 readahead \ 72 respawn \ 73 rmmod \ 74 stat \ 75 su \ 76 swaplabel \ 77 swapoff \ 78 swapon \ 79 switch_root \ 80 sysctl \ 81 truncate \ 82 umount \ 83 unshare \ 84 uptime \ 85 vtallow \ 86 watch \ 87 who 88 89 MAN1 = \ 90 chvt.1 \ 91 clear.1 \ 92 dd.1 \ 93 df.1 \ 94 dmesg.1 \ 95 eject.1 \ 96 fallocate.1 \ 97 free.1 \ 98 id.1 \ 99 login.1 \ 100 mesg.1 \ 101 mknod.1 \ 102 mountpoint.1 \ 103 pagesize.1 \ 104 passwd.1 \ 105 pidof.1 \ 106 ps.1 \ 107 respawn.1 \ 108 stat.1 \ 109 su.1 \ 110 truncate.1 \ 111 unshare.1 \ 112 uptime.1 \ 113 vtallow.1 \ 114 watch.1 \ 115 who.1 116 117 MAN8 = \ 118 ctrlaltdel.8 \ 119 freeramdisk.8 \ 120 fsfreeze.8 \ 121 getty.8 \ 122 halt.8 \ 123 hwclock.8 \ 124 insmod.8 \ 125 killall5.8 \ 126 lastlog.8 \ 127 lsmod.8 \ 128 lsusb.8 \ 129 mkswap.8 \ 130 mount.8 \ 131 pivot_root.8 \ 132 readahead.8 \ 133 rmmod.8 \ 134 swaplabel.8 \ 135 swapoff.8 \ 136 swapon.8 \ 137 switch_root.8 \ 138 sysctl.8 \ 139 umount.8 140 141 LIBUTILOBJ = $(LIBUTILSRC:.c=.o) 142 OBJ = $(BIN:=.o) $(LIBUTILOBJ) 143 SRC = $(BIN:=.c) 144 145 all: $(BIN) 146 147 $(BIN): $(LIB) 148 149 $(OBJ): $(HDR) config.mk 150 151 config.h: 152 cp config.def.h $@ 153 154 .o: 155 $(LD) $(LDFLAGS) -o $@ $< $(LIB) $(LDLIBS) 156 157 .c.o: 158 $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< 159 160 $(LIBUTIL): $(LIBUTILOBJ) 161 $(AR) -r -c $@ $? 162 $(RANLIB) $@ 163 164 install: all 165 mkdir -p $(DESTDIR)$(PREFIX)/bin 166 cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin 167 cd $(DESTDIR)$(PREFIX)/bin && chmod 755 $(BIN) 168 mkdir -p $(DESTDIR)$(MANPREFIX)/man1 169 for m in $(MAN1); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done 170 mkdir -p $(DESTDIR)$(MANPREFIX)/man8 171 for m in $(MAN8); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man8/"$$m"; done 172 cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN1) 173 cd $(DESTDIR)$(MANPREFIX)/man8 && chmod 644 $(MAN8) 174 175 uninstall: 176 cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) 177 cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN1) 178 cd $(DESTDIR)$(MANPREFIX)/man8 && rm -f $(MAN8) 179 180 dist: clean 181 mkdir -p ubase-$(VERSION) 182 cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN1) $(MAN8) libutil $(HDR) config.def.h ubase-$(VERSION) 183 tar -cf ubase-$(VERSION).tar ubase-$(VERSION) 184 gzip ubase-$(VERSION).tar 185 rm -rf ubase-$(VERSION) 186 187 ubase-box: $(LIB) $(SRC) 188 mkdir -p build 189 cp $(HDR) build 190 cp config.h build 191 for f in $(SRC); do sed "s/^main(/`basename $$f .c`_&/" < $$f > build/$$f; done 192 echo '#include <libgen.h>' > build/$@.c 193 echo '#include <stdio.h>' >> build/$@.c 194 echo '#include <stdlib.h>' >> build/$@.c 195 echo '#include <string.h>' >> build/$@.c 196 echo '#include "util.h"' >> build/$@.c 197 for f in $(SRC); do echo "int `basename $$f .c`_main(int, char **);" >> build/$@.c; done 198 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 199 for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) return `basename $$f .c`_main(argc, argv);" >> build/$@.c; done 200 echo 'else {' >> build/$@.c 201 for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$@.c; done 202 echo "putchar(0xa); }; return 0; }" >> build/$@.c 203 $(LD) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB) $(LDLIBS) 204 rm -r build 205 206 clean: 207 rm -f $(BIN) $(OBJ) $(LIB) ubase-box ubase-$(VERSION).tar.gz 208 209 .PHONY: 210 all install uninstall dist ubase-box clean