[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Separate dirs for source (.c .java) and build files (.class .o)
From: |
Alexander Farber |
Subject: |
Separate dirs for source (.c .java) and build files (.class .o) |
Date: |
Sun, 18 Dec 2005 20:48:55 +0100 |
Hello,
I realize, that the question about a separate build dir is asked often here
and have also studied the manual and http://make.paulandlesley.org/
but I'm still not happy with my small Makefile pasted below (even though
it kind of works) and I wonder, if I could get any improvement proposals.
Additionally I have both .java files (for the Java-client Pref.jar) and .[ch]
files (producing a target file called pref). And also the Java source file
Pref.java unfortunately produces 2 files: Pref.class and Pref$1.class
The .au and .gif files for Pref.jar are in the "media" dir
The .c and .h files are in the "server" dir
The .java files are in the "java-client" dir
I'd like .class and .o files go into "build" dir
I'd like the target files pref and Pref.jar go into the top dir (near Makefile).
Also I don't understand, why do I have to add $(addprefix media ...)
into the rule below, even though I have the "media" dir in the VPATH?
Pref.jar: $(CLASSES) $(MEDIA)
jar cvf $@ $(addprefix media/, $(MEDIA)) \
$(addprefix -C $(BUILD) , $(notdir $(CLASSES)))
And why is
javac ... java-client/Pref.java
called twice?
And here is my Makefile and at the bottom the output:
CC = gcc
JAVAC = javac
CFLAGS = -Wall -DNDEBUG
JFLAGS = -target 1.1 -encoding KOI8_R -J-Dfile.encoding=KOI8_R \
-d $(BUILD) -classpath $(BUILD) -sourcepath java-client
VPATH = media server java-client
DUMMY := $(shell mkdir -p build)
BUILD = build
MEDIA = cards.gif money.au deal.au kuku.au
SERVER = pref.c client.c table.c node.c util.c
CLIENT = Board.java \
Card.java \
Client.java \
Const.java \
Net.java \
Pool.java \
Position.java \
Pref.java \
PrefCanvas.java \
PrefEvent.java \
PrefEventMulticaster.java \
PrefListener.java
OBJECTS = $(SERVER:%.c=$(BUILD)/%.o)
CLASSES = $(CLIENT:%.java=$(BUILD)/%.class) $(BUILD)/'Pref$$1.class'
all: Pref.jar pref
Pref.jar: $(CLASSES) $(MEDIA)
jar cvf $@ $(addprefix media/, $(MEDIA)) \
$(addprefix -C $(BUILD) , $(notdir $(CLASSES)))
$(BUILD)/'Pref$$1.class': Pref.java
$(JAVAC) $(JFLAGS) $<
$(BUILD)/%.class: %.java
$(JAVAC) $(JFLAGS) $<
pref: $(OBJECTS)
$(CC) $(LDFLAGS) $^ -o $@
$(BUILD)/%.o: %.c pref.h
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(CLASSES) $(OBJECTS) jshrink.log pref Pref.jar
.PHONY: all clean
--------->8---------->8------------
javac -target 1.1 -encoding KOI8_R -J-Dfile.encoding=KOI8_R -d build
-classpath build -sourcepath java-client java-client/Board.java
javac -target 1.1 -encoding KOI8_R -J-Dfile.encoding=KOI8_R -d build
-classpath build -sourcepath java-client java-client/Pool.java
javac -target 1.1 -encoding KOI8_R -J-Dfile.encoding=KOI8_R -d build
-classpath build -sourcepath java-client java-client/Pref.java
javac -target 1.1 -encoding KOI8_R -J-Dfile.encoding=KOI8_R -d build
-classpath build -sourcepath java-client java-client/Pref.java
jar cvf Pref.jar media/cards.gif media/money.au media/deal.au media/kuku.au \
-C build Board.class -C build Card.class -C build Client.class -C
build Const.class -C build Net.class -C build Pool.class -C build
Position.class -C build Pref.class -C build PrefCanvas.class -C build
PrefEvent.class -C build PrefEventMulticaster.class -C build
PrefListener.class -C build 'Pref$1.class'
gcc -Wall -DNDEBUG -c server/pref.c -o build/pref.o
gcc -Wall -DNDEBUG -c server/client.c -o build/client.o
gcc -Wall -DNDEBUG -c server/table.c -o build/table.o
gcc -Wall -DNDEBUG -c server/node.c -o build/node.o
gcc -Wall -DNDEBUG -c server/util.c -o build/util.o
gcc build/pref.o build/client.o build/table.o build/node.o build/util.o -o pref
--------->8---------->8------------
Thank you for any input
Alex
- Separate dirs for source (.c .java) and build files (.class .o),
Alexander Farber <=