Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.unix.programmer > #548
| From | Marco Parrone <marco@marcoparrone.com> |
|---|---|
| Newsgroups | comp.unix.programmer |
| Subject | Re: Makefile.am and bin_PROGRAMS |
| References | <652a85a9-2316-407a-aacb-231cad0f4e72@hd10g2000vbb.googlegroups.com> |
| Date | 2011-05-12 07:41 +0200 |
| Message-ID | <m3zkmsscey.fsf@marcoparrone.com> (permalink) |
| Organization | TIN.IT (http://www.tin.it) |
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>
Back to comp.unix.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web