Automake: embedding text files in binary target

894 Views Asked by At

I need to embed several text files in a binary. It's currently done with two lines added in configure.in script that do "clean" and perform objcopy to the $target.o files. Don't ask WHY it's required, in this app, it just is.

What I want to do is write some automake (Makefile.am) difinitions that would list those text files as source and tell make to objcopy them into *.o files I need to link with the final target. I could also add them to CLEANFILES, which I want.

Now, I know I say final_LDADD, but I can't find the way to tell automake/configure to do that trick.

Help...

2

There are 2 best solutions below

0
On BEST ANSWER

Something like:

libxxx.a : text1.o text2.o
    $(AR) cru $@ $^

text1.o : text1.txt
    $(OBJCOPY) $< $@
text2.o : text2.txt
    $(OBJCOPY) $< $@

...

final_LDADD = libxxx.a

...

CLEANFILES += libxxx.a text1.o text2.o
1
On

Slightly modified ldav1s's solution:

object_files = file0.o file1.o file2.o ... fileN.o

all:
    for SQL in $$(echo ${object_files} | sed -r 's~\.o\b~~g'); do \
        $(OBJCOPY) $$SQL $$SQL.o; \
    done;

CLEANFILES = ${object_files}