Quieter build

This commit is contained in:
Dan Hirsch 2012-04-30 23:35:11 +01:00
parent ddcfa5b1b2
commit a125975737
6 changed files with 124 additions and 8 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
*~
*.a
src/test_suite
lib/hush

22
Makefile Normal file
View file

@ -0,0 +1,22 @@
# Most of this is so that you can do
# $ make all
# and kick off a recursive make
# Also, "make src/all" turns into "make -C src all"
SUBDIRS = src \
lib
.DEFAULT_GOAL := all
%:
+for dir in $(SUBDIRS); do $(MAKE) -C $${dir} $@; done
define SUBDIR_TEMPLATE
$(1)/%:
$$(MAKE) -C $(1) $$*
endef
$(foreach dir,$(SUBDIRS),$(eval $(call SUBDIR_TEMPLATE,$(dir))))
#.DEFAULT:
# $(if $(findstring ./,$(dir $@)),$(error No rule to make target `$@'),$(MAKE) -C $(dir $@) $(notdir $@))

View file

@ -1,19 +1,39 @@
CFLAGS := $(shell pkg-config --cflags glib-2.0) -std=c99
CFLAGS := $(shell pkg-config --cflags glib-2.0) -std=gnu99 -Wall -Wextra -Werror
LDFLAGS := $(shell pkg-config --libs glib-2.0)
CC := gcc
# Set V=1 for verbose mode...
V := 0
CFLAGS += -DINCLUDE_TESTS
HUSH = $(TOPLEVEL)/lib/hush
.SUFFIX:
# Check to make sure variables are properly set
ifeq ($(TOPLEVEL),)
$(error $$TOPLEVEL is unset)
endif
#.SUFFIXES:
ifeq ($(V),0)
.SILENT:
endif
.DEFAULT_GOAL:=all
%.a:
%.a: | $(HUSH)
-rm -f $@
ar crv $@ $^
$(if $(findstr 0,$(V)),$(HUSH) "Archiving $@",) ar cr $@ $^
ifeq ($(V),0)
# silent mode
%.o: %.c | $(HUSH)
$(HUSH) "Compiling $<" $(CC) $(CFLAGS) -c -o $@ $<
else
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
endif
clean:
-rm -f $(OUTPUTS)
$(TOPLEVEL)/lib/hush: $(TOPLEVEL)/lib/hush.c
make -C $(TOPLEVEL)/lib hush

View file

@ -1,7 +1,12 @@
include ../common.mk
OUTPUTS := \
allocator.o
TOPLEVEL := ../
include ../common.mk
all: allocator.o
hush: hush.c
$(CC) $(CFLAGS) -o $@ $<

64
lib/hush.c Normal file
View file

@ -0,0 +1,64 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char** argv) {
// Argv[1] is the message
// argv[2] is the name of the child
// the rest are passed to the child
if (argc < 3) return 1;
printf ("\x1b[1;32m*\x1b[0m %s...", argv[1]);
char cbuf[4096];
argc-=2;
argv+=1;
for (int i = 0; i < argc; i++)
argv[i] = argv[i+1];
argv[argc] = NULL;
int fd[2];
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fd) == -1) {
printf ("\n");
execvp(argv[0], argv);
}
int pid;
if ((pid=fork()) == -1) {
printf ("\n");
execvp(argv[0], argv);
} else if (pid == 0) { // child
printf ("Child");
close(fd[1]);
dup2(fd[0],0);
dup2(0,1);
dup2(0,2);
execvp(argv[0], argv);
} else { // parent
char* cols1 = getenv("COLUMNS");
int cols;
if (cols1) { cols = atoi(cols1); } else { cols = 80; }
close(fd[0]);
int delta = 1;
int ct = 0;
while (delta != 0) {
delta = read (fd[1], cbuf+ct, 4096-ct);
ct+= delta;
}
cbuf[ct] = 0;
int status;
wait(&status);
fflush (NULL);
if (status) {
fprintf (stderr, "\x1b[%dG\x1b[1;34m[\x1b[1;31m!!\x1b[1;34m]\x1b[0m\n", cols-4);
} else if (ct) {
fprintf (stderr, "\x1b[%dG\x1b[1;34m[\x1b[0;33mWW\x1b[1;34m]\x1b[0m\n", cols-4);
} else {
fprintf (stderr, "\x1b[%dG\x1b[1;34m[\x1b[1;32mOK\x1b[1;34m]\x1b[0m\n", cols-4);
}
fflush (NULL);
printf ("%s", cbuf);
fflush (NULL);
return WEXITSTATUS(status);
}
}

View file

@ -1,9 +1,13 @@
-include ../common.mk
OUTPUTS := bitreader.o \
libhammer.a \
test_suite
TOPLEVEL := ../
include ../common.mk
all: libhammer.a test_suite
test_suite: test_suite.o libhammer.a