Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.unix.programmer > #543 > unrolled thread

Makefile.am and bin_PROGRAMS

Started byme <ecosta.tmp@gmail.com>
First post2011-05-11 18:28 -0700
Last post2011-05-12 03:25 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.unix.programmer


Contents

  Makefile.am and bin_PROGRAMS me <ecosta.tmp@gmail.com> - 2011-05-11 18:28 -0700
    Re: Makefile.am and bin_PROGRAMS Marco Parrone <marco@marcoparrone.com> - 2011-05-12 07:41 +0200
      Re: Makefile.am and bin_PROGRAMS me <ecosta.tmp@gmail.com> - 2011-05-12 03:25 -0700

#543 — Makefile.am and bin_PROGRAMS

Fromme <ecosta.tmp@gmail.com>
Date2011-05-11 18:28 -0700
SubjectMakefile.am and bin_PROGRAMS
Message-ID<652a85a9-2316-407a-aacb-231cad0f4e72@hd10g2000vbb.googlegroups.com>
Hi guys,

Within a project's Makefile.am, I have three different names within
the `bin_PROGRAMS' variable, so I'm reusing common code to produce 3
different binaries.

In one of them, I'd like to hardcode it's name on the resulting binary
for security reasons. So my question is, how could I "extract" such
name from the `bin_PROGRAMS' variable?

I haven't found a way of doing this. Mi original idea is to somehow
get it, and then add it to it's CPPFLAGS, like -DBINARY_NAME=\"name\"

I could adopt some convention which I guess would make eveything
easier, such as having this name as the first in the list given to
`bin_PROGRAMS'.

Any idea or hints on how to achieve this? Pointers to some free
software package known to do the same would be much appreciated as
well.

Regards,

Eduardo,

[toc] | [next] | [standalone]


#548

FromMarco Parrone <marco@marcoparrone.com>
Date2011-05-12 07:41 +0200
Message-ID<m3zkmsscey.fsf@marcoparrone.com>
In reply to#543
me <ecosta.tmp@gmail.com> writes:

> Hi guys,
>
> Within a project's Makefile.am, I have three different names within
> the `bin_PROGRAMS' variable, so I'm reusing common code to produce 3
> different binaries.
>
> In one of them, I'd like to hardcode it's name on the resulting binary
> for security reasons. So my question is, how could I "extract" such
> name from the `bin_PROGRAMS' variable?
>
> I haven't found a way of doing this. Mi original idea is to somehow
> get it, and then add it to it's CPPFLAGS, like -DBINARY_NAME=\"name\"
>
> I could adopt some convention which I guess would make eveything
> easier, such as having this name as the first in the list given to
> `bin_PROGRAMS'.
>
> Any idea or hints on how to achieve this? Pointers to some free
> software package known to do the same would be much appreciated as
> well.
>
> Regards,
>
> Eduardo,

Hi, you can do what you want in this way:

for every target, you create a different .c file which provides the
global variable containing the binary name.

[marco@marcohost prova2]$ for x in *.{h,c,am,ac}; do echo "----- $x -----"; cat $x; echo "----- end of $x -----"; done
----- common1.h -----
#ifndef COMMON1_H
#define COMMON1_H
extern char *binary_name; /* provided by progX.c */
#endif
----- end of common1.h -----
----- common1.c -----
#include <stdio.h>
#include "common1.h"
int main (int arg, char *argv[]) { printf ("%s\n",binary_name); return 0; }
----- end of common1.c -----
----- proga.c -----
#include "common1.h"
char *binary_name = "proga";
----- end of proga.c -----
----- progb.c -----
#include "common1.h"
char *binary_name = "progb";
----- end of progb.c -----
----- progc.c -----
#include "common1.h"
char *binary_name = "progc";
----- end of progc.c -----
----- Makefile.am -----
bin_PROGRAMS = proga progb progc
proga_SOURCES = common1.c proga.c
progb_SOURCES = common1.c progb.c
progc_SOURCES = common1.c progc.c
----- end of Makefile.am -----
----- configure.ac -----
AC_INIT(prova, 0.1.0, my@email.address)
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(prova, 0.1.0)
AC_CONFIG_SRCDIR(common1.c)
AC_C_CONST
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
----- end of configure.ac -----
[marco@marcohost prova2]$ aclocal; autoconf; automake --foreign --add-missing; ./configure; make; ./proga; ./progb; ./progc
...
proga
progb
progc
[marco@marcohost prova2]$ 

Goodbye,
Marco.

-- 
Marco Parrone <marco@marcoparrone.com>

[toc] | [prev] | [next] | [standalone]


#550

Fromme <ecosta.tmp@gmail.com>
Date2011-05-12 03:25 -0700
Message-ID<1407314c-0322-41a0-a16a-6f2a382f87d0@s14g2000vbi.googlegroups.com>
In reply to#548
On 12 mayo, 06:41, Marco Parrone <ma...@marcoparrone.com> wrote:
> me <ecosta....@gmail.com> writes:
> > Hi guys,
>
> > Within a project's Makefile.am, I have three different names within
> > the `bin_PROGRAMS' variable, so I'm reusing common code to produce 3
> > different binaries.
>
> > In one of them, I'd like to hardcode it's name on the resulting binary
> > for security reasons. So my question is, how could I "extract" such
> > name from the `bin_PROGRAMS' variable?
>
> > I haven't found a way of doing this. Mi original idea is to somehow
> > get it, and then add it to it's CPPFLAGS, like -DBINARY_NAME=\"name\"
>
> > I could adopt some convention which I guess would make eveything
> > easier, such as having this name as the first in the list given to
> > `bin_PROGRAMS'.
>
> > Any idea or hints on how to achieve this? Pointers to some free
> > software package known to do the same would be much appreciated as
> > well.
>
> > Regards,
>
> > Eduardo,
>
> Hi, you can do what you want in this way:
>
> for every target, you create a different .c file which provides the
> global variable containing the binary name.
>
> [marco@marcohost prova2]$ for x in *.{h,c,am,ac}; do echo "----- $x -----"; cat $x; echo "----- end of $x -----"; done
> ----- common1.h -----
> #ifndef COMMON1_H
> #define COMMON1_H
> extern char *binary_name; /* provided by progX.c */
> #endif
> ----- end of common1.h -----
> ----- common1.c -----
> #include <stdio.h>
> #include "common1.h"
> int main (int arg, char *argv[]) { printf ("%s\n",binary_name); return 0; }
> ----- end of common1.c -----
> ----- proga.c -----
> #include "common1.h"
> char *binary_name = "proga";
> ----- end of proga.c -----
> ----- progb.c -----
> #include "common1.h"
> char *binary_name = "progb";
> ----- end of progb.c -----
> ----- progc.c -----
> #include "common1.h"
> char *binary_name = "progc";
> ----- end of progc.c -----
> ----- Makefile.am -----
> bin_PROGRAMS = proga progb progc
> proga_SOURCES = common1.c proga.c
> progb_SOURCES = common1.c progb.c
> progc_SOURCES = common1.c progc.c
> ----- end of Makefile.am -----
> ----- configure.ac -----
> AC_INIT(prova, 0.1.0, m...@email.address)
> AC_CANONICAL_HOST
> AC_CANONICAL_TARGET
> AM_INIT_AUTOMAKE(prova, 0.1.0)
> AC_CONFIG_SRCDIR(common1.c)
> AC_C_CONST
> AC_CONFIG_FILES([Makefile])
> AC_OUTPUT
> ----- end of configure.ac -----
> [marco@marcohost prova2]$ aclocal; autoconf; automake --foreign --add-missing; ./configure; make; ./proga; ./progb; ./progc
> ...
> proga
> progb
> progc
> [marco@marcohost prova2]$
>
> Goodbye,
> Marco.
>
> --
> Marco Parrone <ma...@marcoparrone.com>

Hi Marco,

Thanks for your answer. I just needed to hardcode one of them, but I
actually wanted to harcode it "dinamically". Little after writing
here, and reviewing my makefile.info, I noticed I missed the `word'
function. All I had to do is the following:

bin_PROGRAMS = proga progb progc

proga_CPPFLAGS= -DBINARY_NAME=\"$(word 1, $(bin_PROGRAMS))\" ...

Thanks!

Regards,

[toc] | [prev] | [standalone]


Back to top | Article view | comp.unix.programmer


csiph-web