Using make to copy a set of files when directory is referenced.

While I using Eclipse, rarely I needed to use the MAKE or when I needed the knowledge he had was enough.

Now I need to do some actions, such as copying files from one directory to another whenever the presence of one or another variable and when the directory is referenced by another rule, clearing the destination before removing the files if another architecture.

Having the presence of a particular variable, such as `__AVR_ATmega328P`, `__AVR_ATmega2560` or `__ARM_xxxx` he must copy some files from `/users/extra/lib/atmega328P` or `/usr/extra/lib/atmega2560`, `/usr/extra/lib/arm/cmsis` respectively, to the `/usrs/extra/workspace/projetoZeta/lib` whenever it is referenced.

It is important to note that the `Rule` that will make this task, is a secondary customization file, as in the master file I have no way to change.

Besides that need it the secondary `Rule`, which makes copies, is automatically called by other `Rule`, without the need to interfere in each primary, where the `/users/extra/workspace/projetoZeta/lib` directory  is referenced, this should be checked and if necessary the copied files.

In the end, do not know how someone could provide me some example? I got to read the manual and even the https://www.gnu.org/software/make/manual/html_node/Echoing.html Echo I have getting use to help me debug what I'm doing at MAKE.

Parents
  • Hi Carlos.

    While I do not have the answer to your question, I could perhaps provide you with a small useful snippet...

    I've been messing with GNU make myself, however I'm not an expert. - I even tried to set up BIND once; I'm not sure I succeeded, though.

    I think that it's possible to depend on a partial path (including the pathname), thus you'd have to write a rule approximately like this:

    $(libdir)/%.o : %.o

         @echo "copy to $(libdir): $< $@"

    -You can try it out and see if it's doing what you need (and add the actual copying, once you're sure).

    Instead of duplicating all files, on Linux and Unix you can use symbolic links.

    So use

        ln -s ${dir} ${dest}

    ...in order to create a symbolic link to $dir from within $dest.

    If you need to generate an entire tree of symbolic links (that's not very likely, I know), the following snippet might come in handy:

    It first invokes a subshell (using parantheses), then changes to the directory holding $dir, generates all the directories, and then it fills it with symbolic links to the actual files.

    This way you will avoid quickly running out of harddisk space, while still having a protection against accidental file removal.

    Note: This is a bash snippet.

        (

            cd "${parentdir}"

            find "${dir}" -type d -exec mkdir "${dest}/"{} \;

            find "${dir}" -type f -exec ln -s {} "${dest}"/{} \;

        )

    $parentdir holds the directory containing $dir

    $dest is the directory where $dir and its contents will be created.

    Please notice: You will have to put the above commands on a single line in your makefile, otherwise it will not work. Something like:

        ( cd "${parentdir}"; find "${dir}" -type d -exec mkdir "${dest}/"{} \; ;find "${dir}" -type f -exec ln -s {} "${dest}"/{} \; )

    ...And of course, the line starts with  a <TAB>, not spaces.

    -But a completely different solution (and probably the correct one) would be to have all your libraries as source code, then build the sources, but output all the .o files to a subdirectory of your project.

    Eg. an "output" folder would then contain all the .o files in a directory hierarchy similar to your source hierarchy.

    This is definitely possible, but it will require a lot of work and testing.

  • Hello jensbauer!

    I think the "Make" will not meet my expectation, I think what I need is not posível, not yet. I do not think the output is to use a script as the shell to copy files. Well, anyway I see how I will still have to devote to studies of Make.

    Well, I have seen this week, by indication of the Livius, the new CMSIS-Pack concept, which seems to be well connected with what I want, I'll see how I can use it and if I can extend it for mining needs without hurting license use.

    The advantage of ASF package from Atmel is that it has everything it takes to work with Atmel, AVR or ARM is, and comes CMSIS also, but Atmel has not yet adopted the new CMSIS 4 that defines this packaging approach. And the ASF package is organized so that seems laborious separation of files, maybe I'll make a redistribution of files and place in my repository so it can be downloaded when needed.

    Concerning the use of the links, which is undoubtedly the best choice, I always used when programmed in Java, helped me a lot to manage hundreds of packages / framworks of projects without having to keep thousands of copies of jar files on it, but it seems that the GCC plugin or Eclipse CDT does not get along well with links, I have not done deep testing, but already noticed problems when trying to create references for use with my projects. Tutorial in GNU ARM Eclipse Plugin also cites such problem.

Reply
  • Hello jensbauer!

    I think the "Make" will not meet my expectation, I think what I need is not posível, not yet. I do not think the output is to use a script as the shell to copy files. Well, anyway I see how I will still have to devote to studies of Make.

    Well, I have seen this week, by indication of the Livius, the new CMSIS-Pack concept, which seems to be well connected with what I want, I'll see how I can use it and if I can extend it for mining needs without hurting license use.

    The advantage of ASF package from Atmel is that it has everything it takes to work with Atmel, AVR or ARM is, and comes CMSIS also, but Atmel has not yet adopted the new CMSIS 4 that defines this packaging approach. And the ASF package is organized so that seems laborious separation of files, maybe I'll make a redistribution of files and place in my repository so it can be downloaded when needed.

    Concerning the use of the links, which is undoubtedly the best choice, I always used when programmed in Java, helped me a lot to manage hundreds of packages / framworks of projects without having to keep thousands of copies of jar files on it, but it seems that the GCC plugin or Eclipse CDT does not get along well with links, I have not done deep testing, but already noticed problems when trying to create references for use with my projects. Tutorial in GNU ARM Eclipse Plugin also cites such problem.

Children
More questions in this forum