Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Custom Makefiles

I'd like to manage my project build using a custom makefile, but have not figured out how to do so. I still want to utilize the Eclipse-based IDE for editing source, debugging, etc., but want to control the build process with make. Is this possible?

We're currently working on a project that requires support for both Nios and Nios II and I'd like to have all the source files shown in my project view, but build different targets based on the processor:

make nios

make nios2

I'd also like targets for:

make clean

make debug

make run

etc.

Thanks,

-Mark

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This is possible. The "Advanced C/C++ Project" is intended for just that purpose. (Use File->New->Project->Advanced C/C++ Project to create one).

    You can then add your design files and a Makefile.

    The only requirement for the makefile is that it has an "all" and a "clean" target.

    Then a build of the project will do make all and a rebuild will do a make clean all.

    You can then happily edit source & debug in the IDE.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you for the information.

    I had tried this, but noticed in the Eclipse IDE help that Altera does "not recommend" using the advance project stationary. If others are using this option reliably, then perhaps the documentation hasn't been updated.

    Again thanks for the quick reply.

    -Mark
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    That's right, the advanced project isn't recommended, which is saying please use the C/C++ application project where possible as it manages the makefiles and generally makes life easier (especially for people not used to make). However, based on what you want to do, it seems like the Advanced project is what you should use, provided you are comfortable writing and using makefiles. Then there's nothing magic about the build process - just have your all and clean target in there, and the rest is up to the user.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I've been using the C++ Advanced project to manage my builds. What I've found usefull is to allow the IDE to manage the syslib and use an advanced C++ Project project to build the application.

    Once you make the decision to manage you own application makefiles I think you have 2 paths you can take.

    - you can create your own makefiles from scratch and have them reference the syslib and build the elf and whatever other output you need. Requires understanding the output in detail.

    - OR you can create an IDE managed project that uses the target syslib and then take the makefile from the application Debug or Release directory and copy it to your advanced C++ project. Then start hacking it up as needed. You can still use the underlying rules files provided by Altera to build the elf etc but you can add in you own code as well. This requires less knowledge of the tool chain.

    I've taken the second approach and it's worked pretty well. We have an extensive library of existing code with makefiles that I just wanted to link in and so this give me the control I want. I just added a rule to the app makefile saying the the elf was dependent on my library and how to build it. Pretty straight forward. I used the LDDEPS macro to add my dependency to the elf like this:# LDDEPS is defined in the altera HAL build makefiles and the elf is dependent on it.

    LDDEPS+= mylib

    .PHONY : mylib

    Then added a rule like this to cause it to build:

    mylib:

    @echo ====== Making my libraries ======

    $(MAKE) -C mylibdir $(MAKECMDGOALS)

    @echo ====== Done making my libraries. ======

    To get clean to work:

    clean: libclean

    libclean:

    @echo ====== Cleaning the libraries ======

    $(MAKE) -C mydir clean

    @echo ====== Done cleaning the libraries. ======

    That's about it.