ubase

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

Makefile (6003B)


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