fix regression tests for $srcdir != "."

--HG--
branch : HEAD
diff --git a/ChangeLog b/ChangeLog
index f46c667..9816e96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-06-09  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* regress/Makefile.am: add srcdir to TESTS_ENVIRONMENT.
+	* regress/mkname.c, regress/mkname.h: add.
+	* regress/fread.c, regress/name_locate.c, regress/open.c: use
+	mkname.
+
+	* man/Makefile.am: fix DESTDIR support and uninstall.
+	
 2005-01-20  Dieter Baron  <dillo@danbala.tuwien.ac.at>
 
 	* lib/zip_get_name.c (_zip_get_name): return ZIP_ER_DELETED for
diff --git a/regress/Makefile.am b/regress/Makefile.am
index fbb71a0..3e5ea4c 100644
--- a/regress/Makefile.am
+++ b/regress/Makefile.am
@@ -1,13 +1,19 @@
 noinst_PROGRAMS=buffadd open name_locate fread
+noinst_HEADERS=mkname.h
 EXTRA_PROGRAMS=ziptest deltest
 
 EXTRA_DIST=broken.zip test.zip
 
-deltest_SOURCES=deltest.c
-buffadd_SOURCES=buffadd.c
-ziptest_SOURCES=ziptest.c
+buffadd_SOURCES=	buffadd.c
+fread_SOURCES=		fread.c mkname.c
+name_locate_SOURCES=	name_locate.c mkname.c
+open_SOURCES=		open.c mkname.c
+
+deltest_SOURCES=	deltest.c
+ziptest_SOURCES=	ziptest.c
 
 TESTS=buffadd open name_locate fread
+TESTS_ENVIRONMENT=	SRCDIR=${srcdir}
 
 AM_CPPFLAGS=-I${top_srcdir}/lib
 LDADD=../lib/libzip.la
diff --git a/regress/fread.c b/regress/fread.c
index b818b83..a23d45b 100644
--- a/regress/fread.c
+++ b/regress/fread.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: fread.c,v 1.2 2005/01/17 10:46:00 dillo Exp $
+  $NiH: fread.c,v 1.3 2005/01/20 21:01:41 dillo Exp $
 
   fread.c -- test cases for reading from zip archives
-  Copyright (C) 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 
 #include "zip.h"
+#include "mkname.h"
 
 #define TEST_ZIP "broken.zip"
 
@@ -64,7 +65,7 @@
 
     fail = 0;
 
-    if ((z=zip_open(TEST_ZIP, 0, &ze)) == NULL) {
+    if ((z=zip_open(mkname(TEST_ZIP), 0, &ze)) == NULL) {
 	printf("fail: opening zip archive ``%s'' failed (%d)\n",
 	       TEST_ZIP, ze);
 	return 1;
diff --git a/regress/mkname.c b/regress/mkname.c
new file mode 100644
index 0000000..c661c53
--- /dev/null
+++ b/regress/mkname.c
@@ -0,0 +1,80 @@
+/*
+  $NiH: open.c,v 1.4 2005/01/11 18:53:16 wiz Exp $
+
+  mkname.c -- add srcdir to name
+  Copyright (C) 2005 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mkname.h"
+
+
+
+const char *
+mkname(const char *name)
+{
+    static const char *srcdir;
+    static char *fullname;
+    static int len = 0;
+    static int srcdir_done = 0;
+
+    int nlen;
+
+    if (!srcdir_done) {
+	srcdir = getenv("SRCDIR");
+	srcdir_done = 1;
+    }
+
+    if (!srcdir)
+	return name;
+
+    nlen = strlen(srcdir) + strlen(name) + 2;
+
+    if (nlen > len) {
+	if (len == 0)
+	    fullname = malloc(nlen);
+	else
+	    fullname = realloc(fullname, nlen);
+
+	if (fullname == NULL) {
+	    fprintf(stderr, "malloc failure\n");
+	    exit(2);
+	}
+    }
+
+    sprintf(fullname, "%s/%s", srcdir, name);
+
+    return fullname;
+}
diff --git a/regress/mkname.h b/regress/mkname.h
new file mode 100644
index 0000000..d85bde5
--- /dev/null
+++ b/regress/mkname.h
@@ -0,0 +1,5 @@
+#ifndef HAD_MKNAME_H
+
+const char *mkname(const char *);
+
+#endif /* mkname.h */
diff --git a/regress/name_locate.c b/regress/name_locate.c
index 142b598..11179fd 100644
--- a/regress/name_locate.c
+++ b/regress/name_locate.c
@@ -1,5 +1,5 @@
 /*
-  $NiH: name_locate.c,v 1.2 2005/01/20 21:02:34 wiz Exp $
+  $NiH: name_locate.c,v 1.3 2005/06/03 12:29:44 wiz Exp $
 
   name_locate.c -- test cases for finding files in zip archives
   Copyright (C) 2005 Dieter Baron and Thomas Klausner
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 
 #include "zip.h"
+#include "mkname.h"
 
 #define TEST_ZIP	"test.zip"
 
@@ -56,7 +57,7 @@
 
     fail = 0;
 
-    if ((z=zip_open(TEST_ZIP, 0, &ze)) == NULL) {
+    if ((z=zip_open(mkname(TEST_ZIP), 0, &ze)) == NULL) {
 	printf("fail: opening zip archive ``%s'' failed (%d)\n",
 	       TEST_ZIP, ze);
 	return 1;
diff --git a/regress/open.c b/regress/open.c
index 750e773..236b23a 100644
--- a/regress/open.c
+++ b/regress/open.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: open.c,v 1.3 2004/11/17 21:55:17 wiz Exp $
+  $NiH: open.c,v 1.4 2005/01/11 18:53:16 wiz Exp $
 
   open.c -- test cases for opening zip archives
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 
 #include "zip.h"
+#include "mkname.h"
 
 int open_fail(const char *, int, const char *, int, int);
 int open_success(const char *, int, const char *, int);
@@ -55,7 +56,7 @@
 
     remove("nosuchfile");
     fail += open_fail("nosuchfile", 0, "non-existing", ZIP_ER_OPEN, ENOENT);
-    fail += open_fail("Makefile", 0, "non-zip", ZIP_ER_NOZIP, 0);
+    fail += open_fail("Makefile.am", 0, "non-zip", ZIP_ER_NOZIP, 0);
     fail += open_fail("test.zip", ZIP_EXCL, "existing-excl", ZIP_ER_EXISTS, 0);
     /* ZIP_ER_OPEN */
     /* ZIP_ER_READ */
@@ -78,7 +79,7 @@
 
     errno = 0;
 
-    if ((z=zip_open(fname, flags, &ze)) != NULL) {
+    if ((z=zip_open(mkname(fname), flags, &ze)) != NULL) {
 	printf("fail: opening %s succeeded\n", desc);
 	zip_close(z);
 	return 1;
@@ -100,7 +101,7 @@
     struct zip *z;
     int ze, num;
 
-    if ((z=zip_open(fname, flags, &ze)) == NULL) {
+    if ((z=zip_open(mkname(fname), flags, &ze)) == NULL) {
 	printf("fail: opening %s failed (%d)\n", desc, ze);
 	return 1;
     }