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