LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to write non recursive makefile (http://www.linuxquestions.org/questions/programming-9/how-to-write-non-recursive-makefile-850149/)

tushs 12-14-2010 08:48 AM

How to write non recursive makefile
 
Hi,

I want to write simple non recursive makefile, but I am not getting syntax of it. Please give me example with simple description. I had read docs, html's but I am not getting how that works please give simple example. consider I have following directory structure.

|-- Makefile
|-- app1
| `-- main.c
|-- app2
| `-- main.c
|-- mod1
| |-- mod1file1.c
| |-- mod1file1.h
| `-- module.mk
`-- mod2
|-- mod2file1.c
|-- mod2file1.h
`-- module.mk

in this case app1 and app2 are different executables. then what should be contents of Makefile, and module.mk ?

ntubski 12-14-2010 02:57 PM

Have you read Implementing non-recursive make?

tushs 01-03-2012 06:01 AM

Non recursive, multi DIR makefile template for new project
 
1 Attachment(s)
I know that This thread is very old but this link is viewed by many makefile newbies so adding some useful info.
Thanks to ntubski for useful link, most be code is modified from above link.

Here is goal,
- All source code is arranged in different meaningful directories.
- Makefile should be non recursive
- Adding new file in compilation process should be of minimum change in makefile
- All dependences of header and c source should be calculated correctly
- There should be option to customize each target compilation
- common things should be kept in one place
- whenever I do vi filena<tab> it should not ask me about non source file, this really sucks while editing source
- This template should be on internet so after next six months there should be no need for me to do same R&D :)

I had attached sample template project with this thread, following things are incomplete / or unknown to me,
- Unable to create separate build directory [so I used . as prefix for intermediate object and dep files]
- Install option is missing
- For loop in main Makefile is not working :) Don't know why
- sometime clean creates dep files.

Please feel free to update share or report bugs in above template.

colucix 01-03-2012 09:47 AM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

ntubski 01-03-2012 03:52 PM

Quote:

Originally Posted by tushs (Post 4564536)
- sometime clean creates dep files.

See my answer to Automatic make dependency generation and "clean". I'll check the other issues when I'm back on my Linux box.

ntubski 01-07-2012 11:04 AM

Quote:

Originally Posted by tushs (Post 4564536)
- Unable to create separate build directory [so I used . as prefix for intermediate object and dep files]

Multi-Architecture Builds Using GNU make could be relevant to this.

Quote:

- For loop in main Makefile is not working :) Don't know why
You tried to use a shell loop in a Makefile, that doesn't work. You can only put shell code in target build instructions:
Code:

.PHONY : check
check :
        @for mod in $(MODULE_DIRS) ; do echo $$mod ; done

## or use the shell function and echo to stderr:
$(shell for mod in $(MODULE_DIRS) ; do echo $$mod >&2 ; done)

Quote:

- sometime clean creates dep files.
A more complete explanation: Advanced Auto-Dependency Generation.


All times are GMT -5. The time now is 11:08 PM.