Solved

Make file is not working properly.

Posted on 2000-05-15
3
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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…
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.
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.

734 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