diff --git a/qpkg/Makefile b/qpkg/Makefile index f261296..42c500f 100644 --- a/qpkg/Makefile +++ b/qpkg/Makefile @@ -1,19 +1,74 @@ +SHELL = /bin/bash + +OBJS_qpkg = gobble.o id.o prereq.o qpkg.o jrb.o +OBJS_rbtest = rbtest.o jrb.o +OBJS = $(OBJS_qpkg) $(OBJS_rbtest) + CFLAGS = -Wall -Wshadow -Wmissing-prototypes -g -O # -O, so that we get data flow analysis, which helps to find more bugs #LDFLAGS=-pg -OBJS = gobble.o id.o prereq.o qpkg.o jrb.o -OBJS_rbtest = rbtest.o jrb.o +# ----- Verbosity control ----------------------------------------------------- -all: qpkg rbtest +CC_normal := $(CC) +DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG + +CC_quiet = @echo " CC " $@ && $(CC_normal) +DEPEND_quiet = @$(DEPEND_normal) + +ifeq ($(V),1) + CC = $(CC_normal) + DEPEND = $(DEPEND_normal) +else + CC = $(CC_quiet) + DEPEND = $(DEPEND_quiet) +endif + +# ----- Rules ----------------------------------------------------------------- + +.PHONY: all jlime openwrt clean spotless + +all: qpkg rbtest jlime: - $(MAKE) clean - $(MAKE) CC=mipsel-linux-gcc + $(MAKE) clean + $(MAKE) CC_normal=mipsel-linux-gcc -qpkg: $(OBJS) +# +# OpenWRT uses mipsel-openwrt-linux-* and mipsel-openwrt-linux-uclibc-*. +# They should both be available, but just in case, let's improve our odds +# of picking a compiler that actualy exists. +# -rbtest: $(OBJS_rbtest) +openwrt: + $(MAKE) clean + $(MAKE) CC_normal=$(shell \ + n=`which mipsel-openwrt-linux-gcc`; \ + echo "$${n:-`which mipsel-openwrt-linux-uclibc-gcc`}") + +qpkg: $(OBJS_qpkg) + +rbtest: $(OBJS_rbtest) + +# ----- Cleanup --------------------------------------------------------------- clean: - rm -f $(OBJS) $(OBJS_rbtest) + rm -f $(OBJS) $(OBJS:.o=.d) + +spotless: clean + rm -f qpkg rbtest + +# ----- Dependencies ---------------------------------------------------------- + +# compile and generate dependencies, from fped, based on +# http://scottmcpeak.com/autodepend/autodepend.html + +%.o: %.c + $(CC) -c $(CFLAGS) $*.c -o $*.o + $(DEPEND) $*.c | \ + sed -e \ + '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \ + -e '$${g;p;}' -e d >$*.d; \ + [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; } + +-include $(OBJS:.o=.d) diff --git a/qpkg/gobble.c b/qpkg/gobble.c index 6407c60..04f17b7 100644 --- a/qpkg/gobble.c +++ b/qpkg/gobble.c @@ -403,6 +403,27 @@ fail: } +/* + * We should be able to test for __UCLIBC_HAS_ADVANCED_REALTIME__ specifically, + * but that doesn't work for some reason. So let's just omit posix_madvise on + * __UCLIBC__ in general. + */ + + +#if !defined(__UCLIBC__) + +static int do_madvise(void *addr, size_t len, int advice) +{ + return posix_madvise(addr, len, advice); +} + +#else /* __UCLIBC__ */ + +#define do_madvise(addr, len, advice) 0 + +#endif /* __UCLIBC__ */ + + void gobble(const char *name) { int fd; @@ -423,12 +444,12 @@ void gobble(const char *name) perror("mmap"); exit(1); } - if (posix_madvise(map, st.st_size, POSIX_MADV_WILLNEED) < 0) { + if (do_madvise(map, st.st_size, POSIX_MADV_WILLNEED) < 0) { perror("posix_madvise(POSIX_MADV_WILLNEED)"); exit(1); } gobble_buf(name, map, st.st_size); - if (posix_madvise(map, st.st_size, POSIX_MADV_RANDOM) < 0) { + if (do_madvise(map, st.st_size, POSIX_MADV_RANDOM) < 0) { perror("posix_madvise(POSIX_MADV_RANDOM)"); exit(1); }