Re: [PATCH 1/2] Clean up: Makefile.in: Correct the prerequisites

2017-07-12 Thread Michael Witten
On Tue, 11 Jul 2017 05:08:56 -, Michael Witten wrote:

> diff --git a/libtommath/Makefile.in b/libtommath/Makefile.in
> index dbcd2a0..c06187a 100644
> --- a/libtommath/Makefile.in
> +++ b/libtommath/Makefile.in
> @@ -17,7 +17,7 @@ endif
>  ifneq ($V,1)
>   @echo "   * ${CC} $@"
>  endif
> - ${silent} ${CC} -c ${CFLAGS} $^ -o $@
> + ${silent} ${CC} -c ${CFLAGS} $*.c -o $@
>
>  #default files to install
>  ifndef LIBNAME

The above change is not quite correct; primarily, it breaks
out-of-tree builds (which are already broken, and will be fixed
shortly in another patch that I'll be submitting).

The patch above alters the recipe for all object files (the rule
not shown is `%.o: %.c'); in the original, the automatic variable
`$^' is replaced with all of the prerequisites for the target in
question, but this didn't work, because another part of this patch
tells `make' that some of the prerequisites are header files, and
thus `$^' expands to include those header files as well, which the
compiler doesn't appreciate.

The solution provided here just uses the pattern-matching stem
of the target, provided by the automatic variable `$*', in order
to construct the relevant `*.c' file. Alas, during an out-of-tree
build, the stem is not enough to construct the path to the source
code that needs to be compiled.

In order to benefit from the search-for-prerequisites performed by
`make', it's necessary to use the `$^' automatic variable, so the
real solution to all of the above is just to filter the expansion
of `$^' so that only `*.c' prerequisites are placed on the command
line.

More concretely, the above patch *should* look like this:

  diff --git a/libtommath/Makefile.in b/libtommath/Makefile.in
  index dbcd2a0..c06187a 100644
  --- a/libtommath/Makefile.in
  +++ b/libtommath/Makefile.in
  @@ -17,7 +17,7 @@ endif
   ifneq ($V,1)
@echo "   * ${CC} $@"
   endif
  - ${silent} ${CC} -c ${CFLAGS} $^ -o $@
  + ${silent} ${CC} -c ${CFLAGS} $(filter %.c,$^) -o $@
  
   #default files to install
   ifndef LIBNAME

As out-of-tree builds are already broken, there's little value in
updating this particular patch; instead, the above improvement on
this patch will be incorporated in a future patch that I'll submit
soon for the purpose of fixing out-of-tree builds.

Sincerely,
Michael Witten


Re: [PATCH 2/2] Clean up: Now that `make -j' works, remove `default_options.h'

2017-07-12 Thread Michael Witten
It was safe to remove `default_options.h', but in my excitement to do so,
I forgot to take care of some administrative issues, namely that `git'
should be told to ignore that file, and the command `make clean' should
remove it, and there's now no need for a comment in `Makefile.in' about
the problems with `make -j'.

To apply this patch instead of the original, save this email to:

  /path/to/email.patch

and then apply it as follows:

  $ git am --scissors /path/to/email.patch

Here is the scissors line where `git' will cut in order to remove everything
above it.

8<8<8<8<8<8<8<8<8<8<8<8<8<
Date: Tue, 11 Jul 2017 19:56:37 -

Now, it will only be necessary to maintain `default_options.h.in',
though it does seem like a lot of trouble just to avoid having
users deal with #ifndef/#endif statements.
---
 .gitignore|   1 +
 Makefile.in   |   3 +-
 default_options.h | 466 --
 3 files changed, 2 insertions(+), 468 deletions(-)
 delete mode 100644 default_options.h

diff --git a/.gitignore b/.gitignore
index 1ef4318..010bb51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@
 /autom4te.cache
 /config.log
 /config.status
+/default_options.h
 /dbclient
 /dropbear
 /dropbearconvert
diff --git a/Makefile.in b/Makefile.in
index 885a4f0..812aa49 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -237,6 +237,7 @@ thisclean:
dropbearconvert$(EXEEXT) scp$(EXEEXT) 
scp-progress$(EXEEXT) \
dropbearmulti$(EXEEXT) *.o *.da *.bb *.bbg *.prof
-rm -rf $(prerequisites_dir)
+   -rm -f default_options.h
 
 .PHONY: distclean
 distclean: clean tidy
@@ -247,8 +248,6 @@ distclean: clean tidy
 tidy:
-rm -f *~ *.gcov */*~
 
-# default_options.h is stored in version control, could not find a workaround
-# for parallel "make -j" and dependency rules.
 default_options.h: default_options.h.in 
echo "# > > > Generated from $^, edit that file instead !" > $@.tmp
echo >> $@.tmp
diff --git a/default_options.h b/default_options.h
deleted file mode 100644
index 039d785..000
--- a/default_options.h
+++ /dev/null
@@ -1,466 +0,0 @@
-#ifndef DROPBEAR_DEFAULT_OPTIONS_H_
-#define DROPBEAR_DEFAULT_OPTIONS_H_
-/*
- > > > Read This < < <
-
-default_options.h.in (this file) documents compile-time options, and provides 
-default values.
-
-Local customisation should be added to localoptions.h which is
-used if it exists. Options defined there will override any options in this
-file (#ifndef guards added by ifndef_wrapper.sh).
-
-Options can also be defined with -DDROPBEAR_XXX in Makefile CFLAGS
-
-IMPORTANT: Many options will require "make clean" after changes */
-
-#ifndef DROPBEAR_DEFPORT
-#define DROPBEAR_DEFPORT "22"
-#endif
-
-/* Listen on all interfaces */
-#ifndef DROPBEAR_DEFADDRESS
-#define DROPBEAR_DEFADDRESS ""
-#endif
-
-/* Default hostkey paths - these can be specified on the command line */
-#ifndef DSS_PRIV_FILENAME
-#define DSS_PRIV_FILENAME "/etc/dropbear/dropbear_dss_host_key"
-#endif
-#ifndef RSA_PRIV_FILENAME
-#define RSA_PRIV_FILENAME "/etc/dropbear/dropbear_rsa_host_key"
-#endif
-#ifndef ECDSA_PRIV_FILENAME
-#define ECDSA_PRIV_FILENAME "/etc/dropbear/dropbear_ecdsa_host_key"
-#endif
-
-/* Set NON_INETD_MODE if you require daemon functionality (ie Dropbear listens
- * on chosen ports and keeps accepting connections. This is the default.
- *
- * Set INETD_MODE if you want to be able to run Dropbear with inetd (or
- * similar), where it will use stdin/stdout for connections, and each process
- * lasts for a single connection. Dropbear should be invoked with the -i flag
- * for inetd, and can only accept IPv4 connections.
- *
- * Both of these flags can be defined at once, don't compile without at least
- * one of them. */
-#ifndef NON_INETD_MODE
-#define NON_INETD_MODE 1
-#endif
-#ifndef INETD_MODE
-#define INETD_MODE 1
-#endif
-
-/* Setting this disables the fast exptmod bignum code. It saves ~5kB, but is
- * perhaps 20% slower for pubkey operations (it is probably worth experimenting
- * if you want to use this) */
-/*#define NO_FAST_EXPTMOD*/
-
-/* Set this if you want to use the DROPBEAR_SMALL_CODE option. This can save
-several kB in binary size however will make the symmetrical ciphers and hashes
-slower, perhaps by 50%. Recommended for small systems that aren't doing
-much traffic. */
-#ifndef DROPBEAR_SMALL_CODE
-#define DROPBEAR_SMALL_CODE 1
-#endif
-
-/* Enable X11 Forwarding - server only */
-#ifndef DROPBEAR_X11FWD
-#define DROPBEAR_X11FWD 1
-#endif
-
-/* Enable TCP Fowarding */
-/* 'Local' is "-L" style (client listening port forwarded via server)
- * 'Remote' is "-R" style (server listening port forwarded via client) */
-
-#ifndef DROPBEAR_CLI_LOCALTCPFWD
-#define DROPBEAR_CLI_LOCALTCPFWD 1
-#endif
-#ifndef DROPBEAR_CLI_REMOTETCPFWD
-#define DROPBEAR_CLI_REMOTETCPFWD 1
-#endif
-
-#ifndef DROPBEAR_SVR_L

[PATCH] Clean up: Makefiles: Improve support for out-of-tree builds

2017-07-12 Thread Michael Witten
The following patch should be applied after all the other patches
that I've submitted recently.

I suspect that this whole patch series will result in some debate,
and so I intend to make adjustments as issues are brought to light,
and then submit a consolidated, refreshed series that includes
all of these patches in a more coherent format.

Sincerely,
Michael Witten

To apply this patch, save this email to a file:

  /path/to/email

and then apply it:

  git am --scissors /path/to/email

Here is the scissors-line across which git will cut in order to
throw away the text above it.

8<8<8<8<8<8<8<8<8<8<8<8<8<

There's a lot going on here that makes it difficult to support
out-of-tree builds entirely, but this commit goes a long way:

This commit allows for the out-of-tree building
of the binaries for Dropbear and for the built-in
`libtom{crypto,math}' dependencies.

That's basically all users of Dropbear care about.

Overall, the key is to ensure that `make' is given good values
for the `VPATH' and `srcdir' variables, and then also to use
`$(srcdir)' where appropriate.

Setting `VPATH' and `scrdir' is as easy as ensuring that the
`configure' script is told about the various makefiles, and
then including places in those makefiles to be so configured.

The irritating part is ensuring that `$(srcdir)' is used
appropriately; the only place where this is really a problem
is in the makefiles for `libtommath', which were not written
in a way that supports out-of-tree building in general (while
it does work to build the binaries, it doesn't work to build
the ancillary files, such as the documentation).

Configure needs to know about the following files (which, at
the moment, simply provide for a working `clean' target):

  libtommath/etc/makefile
  libtommath/pics/makefile

This is achieved by adding them to `configure.ac' as files
that need to be configured; unfortunately, this seems to
require those files to end with a `.in' extension.

To keep the naming consistent, this commit renames each of
those files to `Makefile.in'.

At this point, neither of those files has been edited to include
a place for `configure' to insert a value for `VPATH' or `srcdir';
there are 2 reasons for this:

  * `git' will better be able to determine that a file has been
renamed if it has not been modified at the same time.

  * The `clean' targets in them work without modification, and
the rest of their targets are not useful to the main purpose
of this commit: To make it possible to perform out-of-tree
building of the *binaries*.

So, why not just copy those files into the out-of-tree build
directory without modifying those names or telling `configure'
about them? Well, because it's probably useful to prepare the
way for a possible future commit that does get the rest of the
targets working; then it will just be a matter of modifying
those files to do the right thing.
---
 configure.ac  | 3 ++-
 libtomcrypt/Makefile.in   | 4 ++--
 libtommath/Makefile.in| 7 ---
 libtommath/etc/{makefile => Makefile.in}  | 0
 libtommath/pics/{makefile => Makefile.in} | 0
 5 files changed, 8 insertions(+), 6 deletions(-)
 rename libtommath/etc/{makefile => Makefile.in} (100%)
 rename libtommath/pics/{makefile => Makefile.in} (100%)

diff --git a/configure.ac b/configure.ac
index 8be542a..0467d7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -828,6 +828,7 @@ AS_MKDIR_P(libtomcrypt/src/modes/ecb)
 AS_MKDIR_P(libtomcrypt/src/modes/ofb)
 AS_MKDIR_P(libtomcrypt/src/modes/f8)
 AS_MKDIR_P(libtomcrypt/src/modes/lrw)
+AS_MKDIR_P(libtomcrypt/src/modes/xts)
 AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/bit)
 AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/boolean)
 AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/choice)
@@ -848,7 +849,7 @@ AS_MKDIR_P(libtomcrypt/src/pk/katja)
 AS_MKDIR_P(libtomcrypt/src/pk/pkcs1)
 AS_MKDIR_P(libtomcrypt/src/pk/rsa)
 AS_MKDIR_P(libtomcrypt/src/prngs)
-LIBTOM_FILES="libtomcrypt/Makefile libtommath/Makefile"
+LIBTOM_FILES="libtomcrypt/Makefile libtommath/Makefile libtommath/etc/Makefile 
libtommath/pics/Makefile"
 fi
 AC_CONFIG_HEADER(config.h)
 AC_CONFIG_FILES(Makefile $LIBTOM_FILES)
diff --git a/libtomcrypt/Makefile.in b/libtomcrypt/Makefile.in
index d8f9a6d..e42b03e 100644
--- a/libtomcrypt/Makefile.in
+++ b/libtomcrypt/Makefile.in
@@ -8,8 +8,8 @@ VERSION=1.17
 
 PLATFORM := $(shell uname | sed -e 's/_.*//')
 
-
-srcdir=.
+VPATH=@srcdir@
+srcdir=@srcdir@
 
 # Compiler and Linker Names
 #CC=gcc
diff --git a/libtommath/Makefile.in b/libtommath/Makefile.in
index 2fec4ce..1f0280c 100644
--- a/libtommath/Makefile.in
+++ b/libtommath/Makefile.in
@@ -2,7 +2,8 @@
 #
 #Tom St Denis
 
-srcdir=.
+VPATH=@srcdir@
+srcdir=@srcdir@
 
 # So that libtommath can include Dropbear headers for options and m_burn()
 CFLAGS += -I$(srcdir) -I../libtomcrypt/src/headers/ 
-I$(srcdir)/../libtomcrypt/src/headers/ -I../ -I$(srcdir)/../

Re: [PATCH 1/2] Clean up: Makefile.in: Correct the prerequisites

2017-07-12 Thread Michael Witten
On Wed, 12 Jul 2017 17:34:49 -, Michael Witten wrote:

> On Tue, 11 Jul 2017 05:08:56 -, Michael Witten wrote:
>
>> diff --git a/libtommath/Makefile.in b/libtommath/Makefile.in
>> index dbcd2a0..c06187a 100644
>> --- a/libtommath/Makefile.in
>> +++ b/libtommath/Makefile.in
>> @@ -17,7 +17,7 @@ endif
>>  ifneq ($V,1)
>>  @echo "   * ${CC} $@"
>>  endif
>> -${silent} ${CC} -c ${CFLAGS} $^ -o $@
>> +${silent} ${CC} -c ${CFLAGS} $*.c -o $@
>>
>>  #default files to install
>>  ifndef LIBNAME
>
> The above change is not quite correct; primarily, it breaks
> out-of-tree builds (which are already broken, and will be fixed
> shortly in another patch that I'll be submitting).
>
> The patch above alters the recipe for all object files (the rule
> not shown is `%.o: %.c'); in the original, the automatic variable
> `$^' is replaced with all of the prerequisites for the target in
> question, but this didn't work, because another part of this patch
> tells `make' that some of the prerequisites are header files, and
> thus `$^' expands to include those header files as well, which the
> compiler doesn't appreciate.
>
> The solution provided here just uses the pattern-matching stem
> of the target, provided by the automatic variable `$*', in order
> to construct the relevant `*.c' file. Alas, during an out-of-tree
> build, the stem is not enough to construct the path to the source
> code that needs to be compiled.
>
> In order to benefit from the search-for-prerequisites performed by
> `make', it's necessary to use the `$^' automatic variable, so the
> real solution to all of the above is just to filter the expansion
> of `$^' so that only `*.c' prerequisites are placed on the command
> line.
>
> More concretely, the above patch *should* look like this:
>
>   diff --git a/libtommath/Makefile.in b/libtommath/Makefile.in
>   index dbcd2a0..c06187a 100644
>   --- a/libtommath/Makefile.in
>   +++ b/libtommath/Makefile.in
>   @@ -17,7 +17,7 @@ endif
>ifneq ($V,1)
>   @echo "   * ${CC} $@"
>endif
>   -   ${silent} ${CC} -c ${CFLAGS} $^ -o $@
>   +   ${silent} ${CC} -c ${CFLAGS} $(filter %.c,$^) -o $@
>
>#default files to install
>ifndef LIBNAME
>
> As out-of-tree builds are already broken, there's little value in
> updating this particular patch; instead, the above improvement on
> this patch will be incorporated in a future patch that I'll submit
> soon for the purpose of fixing out-of-tree builds.

Good news, everyone!

It turns out that the GCC option `-c' can be combined with `-o' only
when there is one translation unit (that is, one `*.c' file) as input
on the command line.

Thus, using the `filter' function of GNU `make' is overkill here; it
would be enough to use `$<', which is described by:

  info '(make)Automatic Variables'

with the following:

  '$<'
   The name of the first prerequisite.  If the target got its recipe
   from an implicit rule, this will be the first prerequisite added by
   the implicit rule (*note Implicit Rules::).

An `implicit rule' is described here:

  info '(make)Implicit Rules'

which states:

  You can define your own implicit rules by writing "pattern rules".

Well, the above rule in question (`%.o: %.c') is a pattern rule,
which means it defines an implicit rule, which means that `$<'
should be the one, desired translation unit.

More concretely, the above patch *should* look like this:

  diff --git a/libtommath/Makefile.in b/libtommath/Makefile.in
  index dbcd2a0..c06187a 100644
  --- a/libtommath/Makefile.in
  +++ b/libtommath/Makefile.in
  @@ -17,7 +17,7 @@ endif
   ifneq ($V,1)
@echo "   * ${CC} $@"
   endif
  - ${silent} ${CC} -c ${CFLAGS} $^ -o $@
  + ${silent} ${CC} -c ${CFLAGS} $< -o $@

   #default files to install
   ifndef LIBNAME

I'll incorporate this change as part of the final, consolidated
patch series.

Sincerely,
Michael Witten