fixup Makefile for srcdir != objdir and for a couple of other smaller problems
authorMathieu Lacage <mathieu.lacage@gmail.com>
Sat, 10 Sep 2011 14:26:47 +0200
changeset 622 e8fb49ea3542
parent 621 69aa13c1c436
child 623 579e0d816d2f
fixup Makefile for srcdir != objdir and for a couple of other smaller problems
Makefile
test/Makefile
--- a/Makefile	Sat Sep 10 14:06:41 2011 +0200
+++ b/Makefile	Sat Sep 10 14:26:47 2011 +0200
@@ -1,11 +1,11 @@
-SRCDIR= $(dir $(firstword $(MAKEFILE_LIST)))
+SRCDIR= $(abspath $(dir $(firstword $(MAKEFILE_LIST))))/
 BLDDIR= $(PWD)/
 #DEBUG=-DDPRINTF_DEBUG_ENABLE
 DEBUG+=-DMALLOC_DEBUG_ENABLE
 #OPT=-O2
 LDSO_SONAME=ldso
 VALGRIND_CFLAGS=$(shell $(SRCDIR)get-valgrind-cflags.py)
-CFLAGS+=-g3 -Wall -Werror $(DEBUG) $(OPT) $(VALGRIND_CFLAGS) -D_GNU_SOURCE -Wp,-MD,.$*.d
+CFLAGS+=-g3 -Wall -Werror $(DEBUG) $(OPT) $(VALGRIND_CFLAGS) -D_GNU_SOURCE -Wp,-MD,$(dir $@).$(notdir $@).d
 CXXFLAGS+=$(CFLAGS)
 LDFLAGS+=$(OPT)
 INSTALL:=install
@@ -33,18 +33,23 @@
 	$(INSTALL) -t $(PREFIX)/bin  readversiondef elfedit 
 
 test: FORCE internal-tests
-	$(MAKE) -C test
-	$(MAKE) -C test run
+	mkdir -p test;
+	$(MAKE) -C test -f $(SRCDIR)/test/Makefile
+	$(MAKE) -C test -f $(SRCDIR)/test/Makefile run
 	./internal-tests
 
 test-valgrind: FORCE
-	$(MAKE) -C test
-	$(MAKE) -C test run-valgrind
+	mkdir -p test
+	$(MAKE) -C test -f $(SRCDIR)/test/Makefile
+	$(MAKE) -C test -f $(SRCDIR)/test/Makefile run-valgrind
 
 FORCE:
 
 LDSO_ARCH_SRC=\
 
+# for valgrind macros
+alloc.o: CFLAGS+=-Wno-unused-but-set-variable
+
 LDSO_SOURCE=\
 avprintf-cb.c \
 dprintf.c vdl-utils.c vdl-log.c \
@@ -125,6 +130,7 @@
 	-rm -f ldso.version libdl.version vdl-config.h 2>/dev/null
 	-rm -f .*.d 2>/dev/null
 	-rmdir $(ARCH) 2>/dev/null
+	mkdir -p test
 	$(MAKE) -C test -f $(SRCDIR)test/Makefile clean
 
--include $(SRC:%.o=.deps/%.d)
\ No newline at end of file
+-include $(SRC:%.o=.%.o.d)
\ No newline at end of file
--- a/test/Makefile	Sat Sep 10 14:06:41 2011 +0200
+++ b/test/Makefile	Sat Sep 10 14:26:47 2011 +0200
@@ -1,13 +1,16 @@
+SRCDIR= $(abspath $(dir $(firstword $(MAKEFILE_LIST))))/
+BLDDIR= $(PWD)/
+VPATH=$(SRCDIR)
 CFLAGS=-g3 -Wall -Werror
 CXXFLAGS=$(CFLAGS)
 LDFLAGS=-Wl,--warn-unresolved-symbols -L.
 LINKER=$(CC)
 MACHINE_MAKEFILE=Makefile.$(shell uname -p)
 
-include $(MACHINE_MAKEFILE)
+include $(SRCDIR)$(MACHINE_MAKEFILE)
 
 TESTS=test0 test0_1 test0_2 test1 test2 test3 test4 test5 test6 test7 test8 test8_5 test9 test10 test11 test15 test12 test13 test14 test16 test17 test18 test19 test21 test20 $(TEST64)
-TARGETS=hello libq.so libp.so libn.so libo.so circular-dep libl.so libk.so libj.so libi.so libh.so libg.so libf.so libe.so libd.so libb.so liba.so libefl.so $(LIB64) \
+TARGETS=hello libq.so libp.so libn.so libo.o libo.so circular-dep libl.so libk.so libj.so libi.so libh.so libg.so libf.so libe.so libd.so libb.so liba.so libefl.so $(LIB64) \
  $(TESTS) $(addsuffix -ldso,$(TESTS))
 
 all: $(TARGETS)
@@ -25,12 +28,23 @@
 	@../elfedit $@ ../ldso
 run-valgrind-test%: test%-ldso FORCE
 	@-LD_LIBRARY_PATH=.:../ ./run-valgrind.py ./$<; \
-		if test $$? -eq 0; then echo "PASS $@"; else echo "FAIL $@ -- LD_LIBRARY_PATH=.:../ ./run-valgrind.py ./$<"; fi
-run-test%: test%-ldso FORCE
+		if test $$? -eq 0; then 						\
+			echo "PASS $@"; 						\
+		else 									\
+			echo "FAIL $@ -- LD_LIBRARY_PATH=.:../ ./run-valgrind.py ./$<"; \
+		fi
+run-test%: test%-ldso $(OUTPUT_DIR) FORCE
+	@-mkdir -p $(OUTPUT_DIR) 2>/dev/null
 	@-$(TEST_PRE_COMMAND)
 	@-LD_LIBRARY_PATH=.:../ ./$< > $(OUTPUT_DIR)/test$* 2>/dev/null || true;
-	@-diff -q $(OUTPUT_DIR)/test$* $(OUTPUT_DIR)/test$*.ref > /dev/null; \
-		if test $$? -eq 0; then echo "PASS $@"; else echo "FAIL $@  -- LD_LIBRARY_PATH=.:../ ./$<"; fi
+	@-diff -q $(OUTPUT_DIR)/test$* $(SRCDIR)$(OUTPUT_DIR)/test$*.ref > /dev/null; \
+		if test $$? -eq 0; then 				\
+			echo "PASS $@"; 				\
+		else 							\
+			echo "FAIL $@  -- LD_LIBRARY_PATH=.:../ ./$<"; 	\
+		fi
+$(OUTPUT_DIR):
+	mkdir -p $@ 2>/dev/null
 diff-test%:
 	@-diff -u $(OUTPUT_DIR)/test$*.ref $(OUTPUT_DIR)/test$*
 update-test%: 
@@ -41,8 +55,6 @@
 
 
 
-hello.o: hello.c
-hello: hello.o
 
 lib%.o: lib%.c
 	$(CC) $(CFLAGS) -fpic -c -o $@ $<
@@ -58,6 +70,8 @@
 test%: test%.o
 	$(LINKER) $(LDFLAGS) -ldl -o $@ $<
 
+test7.o: CFLAGS+=-Wno-unused-but-set-variable
+
 circular-dep:
 	$(CC) $(LDFLAGS) -shared -ldl -ln -o libo.so libo.o
 	$(CC) $(LDFLAGS) -shared -ldl -lo -o libn.so libn.o