2003/09/15 09:37:16
[org.ibex.core.git] / Makefile
1 #############################################################################
2 #
3 # The XWT Makefile
4 #
5
6 all:      JVM Darwin Linux Win32 Solaris
7
8 JVM:        build/JVM/xwt.jar
9 Linux:    ; make gcj platform=Linux   target=i686-pc-linux-gnu    link_flags="-lX11 -lXext --static"
10 Solaris:  ; make gcj platform=Solaris target=sparc-sun-solaris2.7 link_flags="-lX11 -lXext"
11 Win32:    ; make gcj platform=Win32   target=i686-pc-mingw32      link_flags="-Wl,--subsystem,windows -lcomdlg32" target_bin=xwt.exe
12 Darwin:   ; make gcj platform=Darwin target=powerpc-apple-darwin link_flags="$(darwin_linker_flags)"
13
14 # default
15 platform            := JVM
16
17 darwin_libdir       := upstream/install/powerpc-apple-darwin/lib
18 darwin_linker_flags := -Wl,-dylib_file,/usr/lib/libSystem.B.dylib:$(darwin_libdir)/libSystem.B.dylib
19 darwin_linker_flags += -Wl,-dylib_file,/usr/lib/system/libmathCommon.A.dylib:$(darwin_libdir)/libmathCommon.A.dylib
20 darwin_linker_flags += -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:$(darwin_libdir)/libGL.dylib
21 darwin_linker_flags += -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib:$(darwin_libdir)/libGLU.dylib
22 darwin_linker_flags += -lSystem.B -lmathCommon.A -lGL -lGLU
23
24
25 #############################################################################
26 # Configurables:
27 #
28 target_bin             := xwt.$(shell echo $(platform) | tr A-Z a-z)
29 jikes_flags            := -nowarn -sourcepath src/
30 gcc_optimizations      := -O2
31 #gcc_optimizations      := -O9 -ffast-math -fomit-frame-pointer -foptimize-sibling-calls
32 #gcc_optimizations      += -finline-functions -funroll-loops -ffunction-sections -fdata-sections
33 gcc_flags              := -nostdinc $(gcc_optimizations) -Ibuild/h -Iupstream/jpeg-6b/src/ -Iupstream/jpeg-6b/build-$(target)/
34 gcj_flags              := -fCLASSPATH=build/java
35 gcj                    := upstream/install/bin/$(target)-gcj $(gcc_flags) $(gcj_flags)
36 g++                    := upstream/install/bin/$(target)-gcj $(gcc_flags)
37 gcc                    := upstream/install/bin/$(target)-gcc $(gcc_flags)
38 jar                    := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
39
40 include Makefile.upstream
41
42 # HACK: FIXME
43 ifeq ($(platform),Darwin)
44 superclass_org.xwt.plat.Platform:; echo org.xwt.plat.OpenGL
45 else
46 superclass_org.xwt.plat.Platform:;
47 endif
48
49 # figure out what stuff in org.xwt.plat.* this platform requires (its superclasses)
50 superclass_%: 
51         @echo $*
52         @make -s superclass_org.xwt.plat.$(shell grep extends src/`echo $* | sed s_\\\\._/_g`.java | head -n 1 | sed s_.\*extends\ __ | sed s_\ .\*__)
53
54 all_java_sources  := $(patsubst src/%.java,     build/java/%.java, $(shell find src -name '*.java'))
55 all_java_sources  += $(patsubst src/%.java.pp,  build/java/%.java, $(shell find src -name \*.java.pp))
56 plat_deps         := $(shell test x$(platform) == x"" || make -s superclass_org.xwt.plat.$(platform) platform= )
57 java_sources      := $(filter-out build/java/org/xwt/plat/%, $(all_java_sources))
58 java_sources      += $(patsubst org.xwt.plat.%, build/java/org/xwt/plat/%.java, $(plat_deps))
59
60 build/java/%.java: src/%.java ; @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
61 build/cc/%.cc:     src/%.c    ; @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
62 build/c/jpeg/%.c:     upstream/jpeg-6b/src/%.c
63         @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
64
65 build/java/%.java: src/%.java.pp
66         @make -s build/class/org/xwt/util/Preprocessor.class
67         @echo -e "\n\033[1mpreprocessing   .java.pp -> .java:  $<\033[0m"
68         mkdir -p `dirname $@`
69         rm -f $@
70         java -cp build/class org.xwt.util.Preprocessor < $< > $@
71
72 build/class/%.class: build/java/%.java .jikes
73         @echo -e "\n\033[1mcompiling          .java -> .class: $<\033[0m"
74         mkdir -p build/class
75         @./.jikes $<
76
77 compile: .compile
78 .compile: $(java_sources) $(patsubst src/%, build/java/%, $(shell ls src/org/xwt/plat/*.java))
79         @echo -e "\n\033[1mcompiling          .java -> .class: src/**/*.java\033[0m"
80         mkdir -p build/class
81         @./.jikes $^
82         touch .compile
83
84 # PHASE 4: gcj-generated headers
85 java_headers          := $(all_java_sources:build/java/%.java=build/h/%.h) 
86 build/h/%.h: build/class/%.class .compile
87         @echo -e "\n\033[1mextracting        .class -> .h:     $<\033[0m"
88         mkdir -p `dirname $@`
89         ls `echo $< | sed s/.class\$$//`*.class |\
90                  sed s_build/class/__ | sed s/.class\$$//g | sed s_/_._g | (cd build/class; xargs ../../upstream/install/bin/$(target)-gcjh -d ../h --classpath .)
91
92 # a hack since we've disabled gcj's awt implementation
93 build/$(platform)/org/xwt/plat/Java2.java.o:
94         touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
95 build/$(platform)/org/xwt/plat/AWT.java.o:
96         touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
97
98 build/$(platform)/%.java.o: build/java/%.java
99         @echo -e "\n\033[1mcompiling          .java -> .o:     $<\033[0m"
100         mkdir -p `dirname $@`
101         $(gcj) -c $< -o $@
102
103 build/$(platform)/org/xwt/plat/$(platform).cc.o: src/org/xwt/plat/$(platform).cc src/org/xwt/plat/*.cc $(java_headers) .configure_jpeg-6b_$(target)
104         @echo -e "\n\033[1mcompiling            .cc -> .o:     $<\033[0m"
105         mkdir -p `dirname $@`
106         $(g++) -Iupstream/install/lib/gcc-lib/$(target)/3.3/include/ -Iupstream/install/$(target)/include -I/usr/X11R6/include/  -Ibuild/h -Wno-multichar -Iupstream/install/include -c $< -o $@
107
108 build/$(platform)/jpeg-6b/%.c.o: upstream/jpeg-6b/src/%.c
109         @echo -e "\n\033[1mcompiling             .c -> .o:     $<\033[0m"
110         mkdir -p `dirname $@`
111         $(gcc) -Ibuild/h -c $< -o $@
112
113 # PHASE 5: linking
114 jpeg_sources    := jdapimin.c jdapistd.c jcomapi.c jcparam.c jdmaster.c jdinput.c jdmainct.c jdcoefct.c jdpostct.c jdmarker.c
115 jpeg_sources    += jdhuff.c jdphuff.c jddctmgr.c jidctint.c jidctfst.c jidctflt.c jidctred.c jdsample.c jdcolor.c jdmerge.c
116 jpeg_sources    += jquant1.c jquant2.c jerror.c jutils.c jmemnobs.c jmemmgr.c
117
118 upstream/jpeg-6b/build-$(target)/libjpeg.a: .install_jpeg-6b_$(target)
119 $(target_bin): upstream/jpeg-6b/build-$(target)/libjpeg.a $(java_sources:build/java/%.java=build/$(platform)/%.java.o) build/$(platform)/org/xwt/plat/$(platform).cc.o
120         @echo -e "\n\033[1mlinking               .o -> $(target_bin)\033[0m"
121         mkdir -p build/$(platform)
122         PATH=upstream/install/bin:$$PATH $(gcj) -v --main=org.xwt.Main -o build/$(platform)/$(target_bin) $^ $(jpeg_sources:%.c=upstream/jpeg-6b/build-$(target)/%.o) -Lupstream/install/$(target)/lib $(link_flags)
123
124
125 ##############################################################################
126 # Special treatment:
127 #
128
129 #build/java/org/xwt/Builtin.java: $(shell ls src/org/xwt/builtin/*.png src/org/xwt/builtin/*.xwt src/org/xwt/builtin/*.xwf)
130 #       @mkdir -p `dirname $@` build build/java build/class build/h build
131 #       echo -e "\n\033[1mzipping/uuencoding  .xwt -> .java:  build/java/org/xwt/Builtin.java\033[0m"
132 #       echo "package org.xwt;"                  >  build/java/org/xwt/Builtin.java
133 #       echo "class Builtin {"                   >> build/java/org/xwt/Builtin.java
134 #       echo "public static String encoded = "   >> build/java/org/xwt/Builtin.java
135 #       cd src; $(jar) cf ../.builtin.xwar $(^:src/%=%)
136 #       mimencode .builtin.xwar | sed s_.\*_\"\\0\"\ +_ >> build/java/org/xwt/Builtin.java
137 #       echo "\"\"; }"                           >> build/java/org/xwt/Builtin.java
138
139
140 # compile is here to force compilation of the .class files (they get used via -Ibuild) without
141 # having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
142 gcj: .compile .vendor .install_gcc-3.3_$(target) $(target_bin)
143 build/JVM/xwt.jar: .compile
144         @echo -e "\n\033[1marchiving         .class -> .jar:   build/JVM/xwt.jar\033[0m"
145         mkdir -p build/JVM
146         echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
147         cd build/class; $(jar) cfm ../JVM/xwt.jar ../JVM/.manifest `find . -name \*.class`;
148
149
150
151 ##############################################################################
152 # Freetype
153 #
154
155 build/mips/%.c.o: src/%.c
156         make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
157         mkdir -p $(@D)
158         echo -e "\n\033[1mcompiling $< -> $@ (mips)\033[0m"
159         upstream/install/bin/mips-unknown-elf-gcc -march=r3000 -I upstream/freetype-2.1.4/src/include -c -o $@ $<
160
161 build/mips/freetype.mips: build/mips/org/xwt/imp/Freetype.c.o build/mips/org/xwt/imp/crt0.c.o build/mips/org/xwt/imp/syscalls.c.o
162         make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
163         @echo -e "\n\033[1mlinking               .o -> .mips:  $@\033[0m"
164         mkdir -p build/mips
165         upstream/install/bin/mips-unknown-elf-gcc \
166                 -nostdlib \
167                 --static \
168                 -march=mips1 \
169                 -T src/org/xwt/imp/linker.ld \
170                 -Lbuild/mips \
171                 -Lupstream/freetype-2.1.4/src/objs \
172                 -o $@ \
173                 build/mips/org/xwt/imp/Freetype.c.o \
174                 --strip \
175                 -lfreetype
176
177 #build/java/org/xwt/imp/Freetype.java: build/mips/freetype.mips build/class/org/xwt/imp/MIPS.class
178 #       @echo -e "\n\033[1mtranslating        .mips -> .java:  $@\033[0m"
179 #       mkdir -p build/java/org/xwt/imp/
180 #       rm -f $@
181 #       java -cp build/class org.xwt.imp.MIPS org.xwt.imp.Freetype build/mips/freetype.mips > build/java/org/xwt/imp/Freetype.java
182
183
184
185 ##############################################################################
186 # Maintainer stuff: generating numbered builds, proposing patches
187 #
188
189 update-build:
190         cvs tag -F xwt-$(current_build)
191         (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
192         mv next.build- next.build
193         echo -n "Next build will be "
194         cat next.build
195         cvs update CHANGES
196         echo "" >> CHANGES
197         echo `date +%d-%b`" =========== build $(current_build) ================================================" >> CHANGES
198         echo committing...
199         cvs commit -m 'this comment should not appear in CHANGES' next.build CHANGES
200         echo committed.
201
202 propose-patch:
203         @echo -n "Please type a one-line description of this bug: "; \
204         read A; \
205         echo; \
206         echo "Please type any additional comments that explain this patch."; \
207         echo "If this patch fixes a bug, include a link to bugs.xwt.org."; \
208         echo "When you are done, press control-d on a new line."; \
209         echo; \
210         (       echo -e "HELO patcher"; \
211                 echo -e "MAIL FROM:$(USER)@xwt.org"; \
212                 echo -e "RCPT TO: patches@xwt.org"; \
213                 echo -e "DATA"; \
214                 echo -e "From: $(USER)@xwt.org"; \
215                 echo -e "To: patches@xwt.org"; \
216                 echo -e "Subject: proposed patch to $(this_branch): $$A"; \
217                 echo -e ""; \
218                 cat; \
219                 echo; \
220                 cvs diff -Bud; \
221                 echo .; \
222         ) > .message
223         bash -c "cat .message > /dev/tcp/mail.xwt.org/25"     # /dev/tcp is faked by bash; not part of the os
224
225 current_build         := $(shell cat next.build)
226 this_branch           := $(shell tail -c +2 CVS/Tag 2>/dev/null || echo HEAD)
227 this_branch_flag      := $(shell test $(this_branch) = HEAD && echo || echo -r $(this_branch))
228
229 # pre-depend on compile as a sanity check
230 dist: compile
231         # this will fail if we haven't checked-in since the comment is null; we want this.
232         cvs commit -m '' > /dev/null
233         cvs tag -F xwt-$(current_build)
234
235         echo "***********************************************************"
236         echo "*  This build is $(current_build)"
237         echo "***********************************************************"
238
239         ifeq ($(shell uname -n),serverbeach.megacz.com)
240                 (make $(silent) dist-private 2>&1) >> .make-dist.out || \
241                         (tail -n 200 .make-dist.out | mail -s "Build $(current_build) FAILED" cvs@xwt.org; false)
242                 tail -n 200 .make-dist.out | \
243                         mail -s "Unsigned binaries of $(current_build) are now available" cvs@xwt.org
244         else
245                 echo -e 'export JAVA_HOME=/usr/lib/j2sdk1.4\n cd /home/xwt\n date=`date +%d-%b-%H%M`\n mkdir xwt-$$date\n cd xwt-$$date\n /usr/bin/cvs -d /cvs co $(this_branch_flag) xwt\n mv xwt/* .\n mv xwt/.* .\n rmdir xwt\n touch .make-dist.out\n nohup make dist &> /dev/null &\n echo\n cat .make-dist.out' | ssh xwt@xwt.org | grep -v "make...:.\(Entering\|Leaving\).directory"
246         endif
247
248 dist-private:
249         make $(silent) update-build
250
251         # preserve gcc across builds so we don't have to remake it
252         mkdir -p $(HOME)/dist.xwt.org-gcc
253         mv gcc gcc-
254         ln -s $(HOME)/dist.xwt.org-gcc gcc
255         mv -f gcc-/Makefile gcc/
256         mv -f gcc-/*.patch gcc/
257
258         # build it
259         nice -n 19 make all
260
261         echo
262         echo === master.dist.xwt.org ==================================
263
264         echo "copying xwt.jar to distribution area..."
265         cp xwt.jar /var/www/master.dist.xwt.org/xwt-$(current_build).jar.unsigned
266
267         echo "stripping xwt.exe and copying it to the distribution area..."
268         $(strip) build/Win32/xwt.exe -o /var/www/master.dist.xwt.org/xwt-$(current_build).exe.unsigned
269
270         echo "copying xwt.linux to distribution area..."
271         $(strip) build/Linux/xwt.linux -o /var/www/master.dist.xwt.org/xwt-$(current_build).linux.unsigned
272
273         echo "creating source tarball in distribution area..."
274         CVSROOT=/cvs cvs export -r xwt-$(current_build) xwt
275         mv xwt xwt-$(current_build)
276         tar cvzf /var/www/master.dist.xwt.org/xwt-$(current_build).tgz xwt-$(current_build)
277
278         echo
279         echo "*** DONE ******************************************"