LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-14-2010, 08:48 AM   #1
tushs
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Rep: Reputation: 1
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 ?
 
Old 12-14-2010, 02:57 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,387

Rep: Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808
Have you read Implementing non-recursive make?
 
Old 01-03-2012, 06:01 AM   #3
tushs
LQ Newbie
 
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 1
Non recursive, multi DIR makefile template for new project

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.
Attached Files
File Type: txt makefiles.v6.tar.txt (30.0 KB, 22 views)
 
Old 01-03-2012, 09:47 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,453

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 01-03-2012, 03:52 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,387

Rep: Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808
Quote:
Originally Posted by tushs View Post
- 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.
 
Old 01-07-2012, 11:04 AM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,387

Rep: Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808Reputation: 808
Quote:
Originally Posted by tushs View Post
- 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.
 
  


Reply

Tags
make, makefile


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
recursive write permission on cifs mounted file system mamunbabu2001 Linux - Newbie 2 05-18-2010 08:23 AM
how to write simple makefile ? shaiva Linux - Newbie 3 09-23-2009 05:08 AM
how to write makefile for a project greghua Programming 3 01-14-2006 06:26 AM
How to write a Makefile mab_123 Linux - Software 1 07-06-2005 11:31 AM
How to write a Makefile? lpriyamb Linux - Software 2 10-15-2003 04:11 AM


All times are GMT -5. The time now is 08:10 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration