Writing Makefile

Thread Tools Search this Thread
Top Forums Programming Writing Makefile
# 1  
Old 12-05-2007
Writing Makefile

Hello All;
I am going to write an application in C/C++ which has so many source files and hence created

many subdirectories. My area of concern is to write makefile. What i thought that each

subdirectory would have own makefile and wanted to have one parent makefile which will call all

makefile one by one and build all source files. For example:

| | |
-----|-------- --------|--------- ------|-------
| | | | | |
src hdr src hdr src hdr

A(folder) -> B,C,D (under A directory 3 subdirectory B,C, and D present)
B(directory)->src and hdr subdirectory
c(directory)->src and hdr subdirectory
d(directory)->src and hdr subdirectory

What i want that I should have one makefile under src directory of B, C and D folder. Also i

should have one parent makefile under A folder. So my idea is that if i run A directory makefile

then all subdirectories source files should compiled and generate executable in A folder.

Can somebody help me to write makefile for the above scenario??

Appreciate your any help.

Nikhil Ranjan
# 2  
Old 12-05-2007
This should be a start

        set -e; \
        for d in $(DIRS); do \
                (cd ../$$d && $(MAKE)) || exit 1; \


Last edited by vino; 12-05-2007 at 04:43 AM..
# 3  
Old 12-05-2007
Thanks Vino for your quick response. But whatever you have given is very high level makefile. Can you pls help me to understand your thought. what is debug and release?? Is it possible for you to explain each line??

# 4  
Old 12-05-2007
I have modified the code snippet. That should be easy to understand.

Usually debug and release are two build modes. One is for debug purposes and the other is for release purpose. You can ignore that for now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers


Hey everybody, This may be stup*d question for you, but i am new in unix and i wonder how can i make the rules for translating and linking my .c "primjer1.c", "primjer2.c" and "primjer3.c" in makefile. Thank you. (7 Replies)
Discussion started by: jskako
7 Replies

2. UNIX for Dummies Questions & Answers

Help with MakeFile

I'm really confused how to use a makefile. Are you supposed to be make a file from emacs called MakeFile and put code in there to compile? I am trying to create a makefile to compile two .cpp files in my current directory to produce two .o files and then link them... What I did was make a... (1 Reply)
Discussion started by: jzhang172
1 Replies

3. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

4. UNIX for Advanced & Expert Users

Makefile executing another Makefile first?

I have 2 libraries in 2 different directories that I build with Makefiles. library B depends on library A. If I modify a .cpp file in library A and run lib B's Makefile can I have B's makefile to automatically rebuild library A? I am now rebuilding A, followed by B... but I'd like B to... (0 Replies)
Discussion started by: wwuster
0 Replies

5. Programming

Writing makefile for newlib 1.17.0

hi, i am using newlib 1.17.0 by redhat,for one of my ARM 7 projects. There are a number of functions in newlib that are not relevant to my project.I wish to cut down on the size of the C library by removing these functions. I am aware writing the appropriate rules in Makefile will do my job.... (2 Replies)
Discussion started by: sanmk4890
2 Replies

6. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

7. UNIX for Dummies Questions & Answers


Hi, I've searched for makefile in Google and read the pages and tried, but can't seem to understand or get the results as shown in the examples. Can someone help on this? i normally compile my c files like this gcc sampleFile.c -o sampleFile how do I use makefile now instead? (4 Replies)
Discussion started by: scmay
4 Replies

8. Shell Programming and Scripting

makefile help

i'd like to execute a particular command if i'm running gcc version 3.2 for instance. my approach is as follows: GCC_VERSION := `gcc --version | head -1` suppose the result of `gcc --version | head -1` was gcc 3.2 then i'd like to perform the following: ifeq ($(GCC_VERSION), "gcc 3.2")... (1 Reply)
Discussion started by: pieter023
1 Replies

9. UNIX for Dummies Questions & Answers


I'm new to the admin world, and I'm trying to install the GNU C Compiler to work on my project. I got the source code, and was able to configure it. Most of the info I've read tells me the next step is to run a command called "make". when I run it, I get a "command not found" message. I've... (4 Replies)
Discussion started by: ECBROWN
4 Replies

10. UNIX for Advanced & Expert Users


Can anyone tell me what does ?= do example VARIABLE ?= /somepath This is being used in makefile (1 Reply)
Discussion started by: raagbansal
1 Replies
Login or Register to Ask a Question