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