Solved

Make file is not working properly.

Posted on 2000-05-15
3
213 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

820 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