LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 09-15-2010, 10:14 PM   #1
UltimateDesi
LQ Newbie
 
Registered: Sep 2010
Posts: 11

Rep: Reputation: 1
can somebody please help me with Makefile


i want to gave much details as possible.

working directory (~/a1/shell)

in the shell directory i have Makefile that i need help with.

also in the shell directory i have subdirectory's (obj, src, include)

obj subdirectory is empty
src subdirectory i have these files inside: parser.c, shutil.c, sshell.c
include subdirectory i have these files inside: parser.h, shell.h

My current Makefile


Quote:
# Beginning of Makefile
OBJS = shutil.o parser.o sshell.o
HEADER_FILES = shell.h parser.h
EXECUTABLE = sshell
CFLAGS = -Wall
CC = gcc
# End of configuration options

#What needs to be built to make all files and dependencies
all: $(EXECUTABLE)

#Create the main executable
$(EXECUTABLE): $(OBJS)
$(CC) -o $(EXECUTABLE) $(OBJS)

#Recursively build object files
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<

#Define dependencies for objects based on header files
#We are overly conservative here, parser.o should depend on parser.h only
$(OBJS) : $(HEADER_FILES)

clean:
-rm -f $(EXECUTABLE) *.o
run: $(EXECUTABLE)
./$(EXECUTABLE)

tarball:
-rm -f $(EXECUTABLE) *.o
(cd .. ; tar czf UltimateDesi_a1.tar.z shell )

# End of Makefile
I wanted it so: all .o files are created in the obj subdirectory, and my application, sshell, is created in the shell directory.

i am getting this error when i run the make run: No rule to make target 'shell.h', needed by 'shutil.o'. stop

Can somebody please help me, i am new to Makefile and new to unix/linux.
 
Old 09-15-2010, 11:18 PM   #2
Jerry Mcguire
Member
 
Registered: Jul 2009
Location: Hong Kong SAR
Distribution: RedHat, Fedora
Posts: 201

Rep: Reputation: 31
The following is what I usually do. You have to modify the paths somehow...

Makefile:
Code:
#!make
SHELL := /bin/sh

# there may be more executables in your system
executables=sshell
CFLAGS=-Wall
CC=gcc

# need to tell make that 'all' is not a target output
.PHONY : all
all: $(executables)

# write your executable's dependencies by yourself for each executable in your system.
sshell: sshell.o a.o b.o c.o
<A TAB CHARACTER HERE>$(CC) -o $@ $^

# write the following dependencies by the command `gcc -MM *.cc *.c`
# no need to write the command if your source file extensions is default to 'make'.  i.e. 'make' knows how to make a.o from a.c
a.o: a.c a.h
b.o: b.c
c.o: c.c c.h
sshell.o a.h c.h
Then `make all` will do its work.

See http://www.gnu.org/software/make/manual/make.html

Last edited by Jerry Mcguire; 09-15-2010 at 11:20 PM.
 
  


Reply



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
make: Warning: Both `makefile' and `Makefile' exist ? malli42108 Solaris / OpenSolaris 5 10-24-2009 09:09 AM
Is it mandatory to have the name of the makefile as 'Makefile' for kernal module comp narender.d Linux - Kernel 3 05-29-2009 06:26 AM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:25 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration