Solved

Make file is not working properly.

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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 …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

809 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