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