diff --git a/ChangeLog b/ChangeLog
index f62ef3f66a5fc97b31aab14c4c53e4fa70721686..878864aeff184b434913cf08cbcf1475a8c8dcfc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2015-03-19  Niels Möller  <nisse@diamant.hack.org>
 
+	* Makefile.in (OPT_HOGWEED_SOURCES): Deleted make variable.
+	(nettle_SOURCES, hogweed_SOURCES): Don't include optional sources
+	here.
+	(OPT_SOURCES): New variable.
+	(SOURCES): Include OPT_SOURCES.
+	(DISTFILES): Drop mini-gmp.c here, included via OPT_SOURCES.
+	(nettle_OBJS, hogweed_OBJS): Add the object files corresponding to
+	the optional source files included in the build.
+
 	* ecc-curve.h (nettle_curve25519): Removed public declaration.
 	* ecc-internal.h (_nettle_curve25519): New location, new name.
 	Updated all users.
diff --git a/Makefile.in b/Makefile.in
index e4f08b2b9717c0d44912ce5d10e66b8f57215356..b5068b1a6e6a5e2b3828a185d3a3b5cfd4209d12 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -16,7 +16,6 @@ OPT_NETTLE_OBJS = @OPT_NETTLE_OBJS@
 OPT_HOGWEED_OBJS = @OPT_HOGWEED_OBJS@
 
 OPT_NETTLE_SOURCES = @OPT_NETTLE_SOURCES@
-OPT_HOGWEED_SOURCES = @IF_MINI_GMP@ mini-gmp.c
 
 SUBDIRS = tools testsuite examples
 
@@ -136,8 +135,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
 		 umac-poly64.c umac-poly128.c umac-set-key.c \
 		 umac32.c umac64.c umac96.c umac128.c \
 		 write-be32.c write-le32.c write-le64.c \
-		 yarrow256.c yarrow_key_event.c \
-		 $(OPT_NETTLE_SOURCES)
+		 yarrow256.c yarrow_key_event.c
 
 hogweed_SOURCES = sexp.c sexp-format.c \
 		  sexp-transport.c sexp-transport-format.c \
@@ -181,8 +179,9 @@ hogweed_SOURCES = sexp.c sexp-format.c \
 		  eddsa-compress.c eddsa-decompress.c eddsa-expand.c \
 		  eddsa-hash.c eddsa-pubkey.c eddsa-sign.c eddsa-verify.c \
 		  ed25519-sha512-pubkey.c \
-		  ed25519-sha512-sign.c ed25519-sha512-verify.c \
-		  $(OPT_HOGWEED_SOURCES)
+		  ed25519-sha512-sign.c ed25519-sha512-verify.c
+
+OPT_SOURCES = fat-x86_64.c fat-arm.c mini-gmp.c
 
 HEADERS = aes.h arcfour.h arctwo.h asn1.h blowfish.h \
 	  base16.h base64.h buffer.h camellia.h cast128.h \
@@ -206,12 +205,11 @@ INSTALL_HEADERS = $(HEADERS) nettle-stdint.h bignum.h @IF_MINI_GMP@ mini-gmp.h
 
 SOURCES = $(nettle_SOURCES) $(hogweed_SOURCES) \
 	  $(getopt_SOURCES) $(internal_SOURCES) \
+	  $(OPT_SOURCES) \
 	  aesdata.c desdata.c twofishdata.c shadata.c gcmdata.c eccdata.c
 
-# FIXME: $(SOURCES) includes $(OPT_NETTLE_SOURCES) and
-# $(OPT_HOGWEED_SOURCES), which means that inclusion in this list
-# depends on which sources where included in the build. It needs to
-# always include all files, and we no duplicates.
+# NOTE: This list must include all source files, with no duplicates,
+# independently of which source files are included in the build.
 DISTFILES = $(SOURCES) $(HEADERS) getopt.h getopt_int.h \
 	.bootstrap run-tests \
 	aclocal.m4 configure.ac \
@@ -227,13 +225,15 @@ DISTFILES = $(SOURCES) $(HEADERS) getopt.h getopt_int.h \
 	cast128_sboxes.h desinfo.h desCode.h \
 	memxor-internal.h nettle-internal.h nettle-write.h \
 	gmp-glue.h ecc-internal.h fat-setup.h \
-	mini-gmp.h mini-gmp.c asm.m4 \
+	mini-gmp.h asm.m4 \
 	nettle.texinfo nettle.info nettle.html nettle.pdf sha-example.c
 
 # Rules building static libraries
-nettle_OBJS = $(nettle_SOURCES:.c=.$(OBJEXT)) $(OPT_NETTLE_OBJS)
+nettle_OBJS = $(nettle_SOURCES:.c=.$(OBJEXT)) \
+	      $(OPT_NETTLE_SOURCES:.c=.$(OBJEXT)) $(OPT_NETTLE_OBJS)
 
-hogweed_OBJS = $(hogweed_SOURCES:.c=.$(OBJEXT)) $(OPT_HOGWEED_OBJS)
+hogweed_OBJS = $(hogweed_SOURCES:.c=.$(OBJEXT)) \
+	       $(OPT_HOGWEED_OBJS) @IF_MINI_GMP@ mini-gmp.$(OBJEXT)
 
 libnettle.a: $(nettle_OBJS)
 	-rm -f $@