Add Makefile and zcat(1)

This commit is contained in:
Mark 2020-07-29 18:11:29 +03:00
parent 92bd67fd10
commit 9eb3f547b3
2 changed files with 49 additions and 3 deletions

View File

@ -8,6 +8,10 @@ CFLAGS?=-ggdb \
-Iinclude
LDFLAGS?=-lgcc
bin_zcat_FLAGS=-I lib/zlib-1.2.11
bin_zcat_LIBS=$(O)/lib/zlib/libz.a
S=$(abspath .)
O=build
BINS=$(O)/bin/login \
@ -20,6 +24,10 @@ BINS=$(O)/bin/login \
$(O)/bin/grep \
$(O)/bin/sleep \
$(O)/bin/mkdir \
$(O)/bin/head \
$(O)/bin/zcat \
$(O)/bin/showkey \
$(O)/bin/com \
$(O)/sbin/mount \
$(O)/sbin/lspci \
$(O)/sbin/acpid \
@ -33,10 +41,16 @@ BINS=$(O)/bin/login \
# $(O)/sbin/umount \
# $(O)/sbin/insmod \
all: mkdirs $(BINS)
all: mkdirs libs $(BINS)
libs:
if [ ! -f $(O)/lib/zlib/Makefile ]; then \
cd $(O)/lib/zlib && CC=$(CROSS_COMPILE)gcc AR=$(CROSS_COMPILE)ar $(S)/lib/zlib-1.2.11/configure; \
fi
make -C $(O)/lib/zlib
mkdirs:
mkdir -p $(O)/bin $(O)/sbin
mkdir -p $(O)/bin $(O)/sbin $(O)/lib/zlib
clean:
rm -rf $(O)
@ -45,6 +59,11 @@ install: all
$(foreach bin,$(BINS), \
install -m0755 $(bin) $(DESTDIR)/$(bin:$(O)/%=%); \
)
ln -sf /bin/pager $(DESTDIR)/bin/less
ln -sf /bin/pager $(DESTDIR)/bin/more
$(O)/%: %.c
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
@$(CC) $($(subst /,_,$(@:$(O)/%=%))_FLAGS) \
$(LDFLAGS) $(CFLAGS) -o $@ \
$< \
$($(subst /,_,$(@:$(O)/%=%))_LIBS)

27
progs/base/bin/zcat.c Normal file
View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <zlib.h>
int main(int argc, char **argv) {
gzFile file;
char buf[1024];
ssize_t bread;
if (argc != 2) {
fprintf(stderr, "usage: %s FILENAME\n", argv[0]);
return 1;
}
file = gzopen(argv[1], "r");
if (!file) {
perror(argv[1]);
return 1;
}
while ((bread = gzread(file, buf, sizeof(buf))) > 0) {
fwrite(buf, 1, bread, stdout);
}
gzclose(file);
return 0;
}