Solved

Make file is not working properly.

Posted on 2000-05-15
3
210 Views
Last Modified: 2010-04-21
I written the following make file.

Makefile

SOURCE=GenLog.java\
        GenMessageItem.java\
        GenMessageCollection.java\
        GenErrorLogger.java\
        GenComponentLogger.java

CLASSES=GenLog.class\
        GenMessageItem.class\
        GenMessageCollection.class\
        GenErrorLogger.class\
        GenComponentLogger.class

$(CLASSES):$(SOURCE)
        javac $(SOURCE)

clean :
        rm $(CLASSES)

1. make - This generated .class files.
2. I changed one source code
3. make - I am expecting that, it need to compile only that .java file.
                 all java files are independent.
   Instead of compiling changed file it is compiling all .java files.

what is the problem?

I am using  GNU make
0
Comment
Question by:polimetla
3 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 2812699
Well, the Makefile is just following instructions. You told it that the class files depended on the sources ($(CLASSES):$(SOURCE)) and then you told it what to do, i.e. "javac $(SOURCE). Since $(SOURCE) expands to everything listed in "SOURCE:" it compiled everything.

What you wnat it to tell it how to compile a single object from its corresponding source. A rule likke:

%.class:  %.java
          javac $<

will do that. So the makefile ouht to look something like:

%.class:  %.java
          javac $<

SOURCE=   GenLog.java\
          GenMessageItem.java\
          GenMessageCollection.java\
          GenErrorLogger.java\
          GenComponentLogger.java

CLASSES=  GenLog.class\
          GenMessageItem.class\
          GenMessageCollection.class\
          GenErrorLogger.class\
          GenComponentLogger.class

all:      $(CLASSES)

clean:
          rm $(CLASSES)

should do what you want.
0
 

Accepted Solution

by:
forraidp earned 10 total points
ID: 2873666
Your problem is in your $(CLASS) target.  In the line

 javac $(SOURCE)

$(SOURCE) will substitute all sources and thus compile all source files.  You can eliminate the SOURCE macro, set up a suffix rule, and add a generic target:

# Clear existing suffixes
..SUFFIXES:

# Add your suffixes
..SUFFIXES: .class .java

#  Add the suffix rule
..java.class:
    javac $<

all: $(CLASSES)
0
 
LVL 1

Author Comment

by:polimetla
ID: 2874401
Answer accepted
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now