diff --git a/ChangeLog b/ChangeLog
index 91142861b0a29fee5e61c168eaaf7ecb94ac0fc4..c440c6a9690e671c69ba7d94ba98d4e8b2e14b24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-10-20  Niels Möller  <nisse@lysator.liu.se>
+
+	* config.make.in: Insert $(PRE_CPPFLAGS) and $(PRE_LDFLAGS) before
+	$(CPPFLAGS) and $(LDFLAGS). This mechanism replaces $(INCLUDES).
+
+	* examples/Makefile.in (PRE_CPPFLAGS, PRE_LDFLAGS): Use these
+	flags to get -I.. and -L.. early on the command line.
+	* testsuite/Makefile.in: Likewise
+	* tools/Makefile.in: Likewise.
+
 2004-10-20  Niels Möller  <niels@s3.kth.se>
 
 	* Makefile.in: In the assembler rules, there's no need to look in
diff --git a/config.make.in b/config.make.in
index f00c42108fead550e814ecc7848abb28c686440e..24a305f446ea76bf6a2b48794296b772a57e49d0 100644
--- a/config.make.in
+++ b/config.make.in
@@ -54,8 +54,11 @@ libdir =	@libdir@
 includedir =	@includedir@
 infodir =	@infodir@
 
-COMPILE = $(CC) $(CPPFLAGS) $(INCLUDES) $(DEFS) $(CFLAGS) $(CCPIC) $(DEP_FLAGS)
-LINK = $(CC) $(CFLAGS) $(LDFLAGS)
+# PRE_CPPFLAGS and PRE_LDFLAGS lets each Makefile.in prepend its own
+# flags before CPPFLAGS and LDFLAGS.
+
+COMPILE = $(CC) $(PRE_CPPFLAGS) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(CCPIC) $(DEP_FLAGS)
+LINK = $(CC) $(CFLAGS) $(PRE_LDFLAGS) $(LDFLAGS)
 
 # Disable builtin rule
 %$(EXEEXT) : %.c
diff --git a/examples/Makefile.in b/examples/Makefile.in
index 73216db3e27a64057f7fb84fc919e670ecedd269..9a835332dbeaa2b8714a7a210a9a4f39867ad4db 100644
--- a/examples/Makefile.in
+++ b/examples/Makefile.in
@@ -7,7 +7,8 @@ top_srcdir = @top_srcdir@
 
 include ../config.make
 
-INCLUDES = -I.. -I$(top_srcdir)
+PRE_CPPFLAGS = -I.. -I$(top_srcdir)
+PRE_LDFLAGS = -L..
 
 OPENSSL_LIBFLAGS = @OPENSSL_LIBFLAGS@
 TARGETS = nettle-benchmark @RSA_EXAMPLES@
@@ -23,12 +24,12 @@ DISTFILES= $(SOURCES) Makefile.in $(TS_ALL) run-tests setup-env teardown-env \
 all: $(TARGETS)
 
 .c.$(OBJEXT):
-	$(COMPILE) -I.. -c $<
+	$(COMPILE) -c $<
 .o$(EXEEXT):
-	$(LINK) $^ $(LIBS) -L.. -lnettle -o $@
+	$(LINK) $^ -lnettle $(LIBS) -o $@
 
 nettle-benchmark: nettle-benchmark.o nettle-openssl.o ../libnettle.a
-	$(LINK) $^ $(LIBS) -L.. -lnettle $(OPENSSL_LIBFLAGS) -o $@
+	$(LINK) $^ -lnettle $(LIBS) $(OPENSSL_LIBFLAGS) -o $@
 
 $(TARGETS) : io.o ../libnettle.a
 
diff --git a/testsuite/Makefile.in b/testsuite/Makefile.in
index 14c61564eccb4e1e17fcfbc157d4649b39154425..77d0d114f6e32b0398b46e5df680f11f8289d3ac 100644
--- a/testsuite/Makefile.in
+++ b/testsuite/Makefile.in
@@ -7,7 +7,8 @@ top_srcdir = @top_srcdir@
 
 include ../config.make
 
-INCLUDES = -I.. -I$(top_srcdir)
+PRE_CPPFLAGS = -I.. -I$(top_srcdir)
+PRE_LDFLAGS = -L..
 
 TS_SOURCES = aes-test.c arcfour-test.c arctwo-test.c \
 	     blowfish-test.c cast128-test.c \
@@ -38,7 +39,7 @@ all: $(TARGETS)
 	$(COMPILE) -I.. -c $< && $(DEP_PROCESS)
 
 .o$(EXEEXT):
-	$(LINK) $< testutils.o $(LIBS) -L.. -lnettle -o $@
+	$(LINK) $< testutils.o -lnettle $(LIBS) -o $@
 # .c$(EXEEXT):
 # 	$(COMPILE) -I..
 # 	$(CC) $(CFLAGS) $(LDFLAGS) $*.o testutils.o -L.. -lnettle $(LIBS) -o $@
diff --git a/tools/Makefile.in b/tools/Makefile.in
index ba7f65e5485ba9b1ad777b171dbcb9db47b50bbd..70f31b65b2e63fcf106ff962c1fd9c8aefe89950 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -7,7 +7,8 @@ top_srcdir = @top_srcdir@
 
 include ../config.make
 
-INCLUDES = -I.. -I$(top_srcdir)
+PRE_CPPFLAGS = -I.. -I$(top_srcdir)
+PRE_LDFLAGS = -L..
 
 TARGETS = sexp-conv nettle-lfib-stream
 
@@ -21,10 +22,10 @@ SOURCES = $(sexp_conv_SOURCES) nettle-lfib-stream.c
 DISTFILES = $(SOURCES) Makefile.in getopt.h input.h misc.h output.h parse.h
 
 sexp-conv: $(sexp_conv_SOURCES:.c=.$(OBJEXT)) ../libnettle.a
-	$(LINK) $^ $(LIBS) -L.. -lnettle -o $@
+	$(LINK) $^ -lnettle $(LIBS) -o $@
 
 nettle-lfib-stream: nettle-lfib-stream.$(OBJEXT) ../libnettle.a
-	$(LINK) $^ $(LIBS) -L.. -lnettle -o $@
+	$(LINK) $^ -lnettle $(LIBS) -o $@
 
 .c.$(OBJEXT):
 	$(COMPILE) -c $< && $(DEP_PROCESS)