1#
2# ECLiPSe III Compiler
3#
4# $Id: Makefile.in,v 1.7 2010/03/19 05:55:38 jschimpf Exp $
5#
6# BEGIN LICENSE BLOCK
7# Version: CMPL 1.1
8#
9# The contents of this file are subject to the Cisco-style Mozilla Public
10# License Version 1.1 (the "License"); you may not use this file except
11# in compliance with the License.  You may obtain a copy of the License
12# at www.eclipse-clp.org/license.
13# 
14# Software distributed under the License is distributed on an "AS IS"
15# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
16# the License for the specific language governing rights and limitations
17# under the License. 
18# 
19# The Original Code is  The ECLiPSe Constraint Logic Programming System. 
20# The Initial Developer of the Original Code is  Cisco Systems, Inc. 
21# Portions created by the Initial Developer are
22# Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
23# 
24# Contributor(s): Joachim Schimpf.
25# 
26# END LICENSE BLOCK
27
28ARCH = @ARCH@
29top_srcdir = @top_srcdir@
30PREFIX = @prefix@
31
32BOOTDIR = $(top_srcdir)/Kernel
33STABLE_ECLIPSE = $(PREFIX)/bin/$(ARCH)/eclipse
34
35DEBUG = off
36
37COMPILER_MODULES = \
38	ecl_compiler.ecl \
39	compiler_analysis.ecl \
40	compiler_codegen.ecl \
41	compiler_common.ecl \
42	compiler_indexing.ecl \
43	compiler_normalise.ecl \
44	compiler_peephole.ecl \
45	compiler_regassign.ecl \
46	compiler_map.ecl \
47	compiler_varclass.ecl \
48	source_processor.ecl
49
50INCLUDE_FILES = \
51	compiler_builtins.ecl \
52	compiler_compound.ecl
53
54OTHER_FILES = \
55	compiler_test.ecl
56
57PRIVATE_ECI = \
58	$(COMPILER_MODULES:%.ecl=%.eci)
59
60PUBLIC_ECI = \
61	$(PREFIX)/lib/source_processor.eci
62
63PUBLIC_ECL = \
64	$(PREFIX)/lib/source_processor.ecl
65
66LOCAL_ECO = $(COMPILER_MODULES:%.ecl=%.eco)
67
68AUX_ECO = $(COMPILER_MODULES:%.ecl=aux_%.eco)
69
70BOOT_ECO = $(COMPILER_MODULES:%.ecl=$(BOOTDIR)/lib/%.eco)
71
72PUBLIC_ECO =
73
74
75# force deletion of targets when command failed
76.DELETE_ON_ERROR:
77
78default:
79	@echo "You can make the following:"
80	@echo "  make aux_eco		Make stage-1 compiler (aux_xxx.eco files)"
81	@echo "  make eco		Make stage-2 compiler (xxx.eco files) using stage-1"
82	@echo "  make test[o]		Run unit tests (on local xxx.eco files)"
83	@echo "  make bootfiles	Build and install xxx.eco files in kernel lib/"
84	@echo "  make install		Build and install .eci file"
85	@echo "  make test[o]_installed Run unit tests on installed compiler"
86	@echo "  make ecoclean		Remove stage-2 .eco files"
87	@echo "  make doc		Generate documentation in doc/"
88	@echo "  make cover		Run unit tests and produce output in coverage/"
89	@echo "  make pretty		Pretty-print sources in pretty/"
90	@echo "  make xxx.lst		Compile to .lst assembly files"
91	@echo "  make xxx.asm		Compile to .asm loadable files"
92
93
94
95PERM = a+r,u+w,go-w
96DIRPERM = 2755
97
98.SUFFIXES:	$(SUFFIXES) .ecl .eci .eco
99
100%/.eco/stamp:
101	mkdir -p $(@D)
102	@/bin/chmod $(DIRPERM) $(@D)
103	@touch $@; /bin/chmod $(PERM) $@
104
105
106#----------------------------------------------------------------------
107# Cleanup
108#----------------------------------------------------------------------
109
110clean:	ecoclean
111	rm -rf *.eci *.lst .asm *.res doc pretty coverage
112
113# This does NOT remove the boot files in $(BOOTDIR)/lib,
114# nor the aux_*.eco files (because they cannot be remade easily once
115# the compiler sources have been edited)
116ecoclean:
117	rm -f $(LOCAL_ECO)
118
119
120#----------------------------------------------------------------------
121# Build new compiler .eco files using STABLE_ECLIPSE's stable
122# compiler, using a two-stage process. This is necessary if
123# the new code is so incompatible with the stable one that
124# the modules cannot be shared during the compilation process.
125#
126# Stage 1: build the compiler under different module/file names
127#	(aux_ecl_compiler.eco), also using aux_source_processor, etc
128#
129# Stage 2: compile the compiler again with this aux_ecl_compiler.eco,
130#	giving ecl_compiler.eco
131#
132#----------------------------------------------------------------------
133
134aux_eco:		$(AUX_ECO)
135
136eco:			$(LOCAL_ECO)
137
138# Replicate all changes here for aux_compiler_xxx below!
139compiler_common.eco:		source_processor.eco
140compiler_analysis.eco:		compiler_common.eco compiler_map.eco
141compiler_codegen.eco:		compiler_common.eco \
142			compiler_compound.ecl compiler_builtins.ecl
143compiler_indexing.eco:		compiler_common.eco
144compiler_normalise.eco:		compiler_common.eco
145compiler_peephole.eco:		compiler_common.eco
146compiler_regassign.eco:		compiler_common.eco
147compiler_varclass.eco:		compiler_common.eco compiler_map.eco
148ecl_compiler.eco:	compiler_common.eco compiler_normalise.eco \
149			compiler_analysis.eco compiler_codegen.eco \
150			compiler_indexing.eco compiler_peephole.eco \
151			compiler_regassign.eco compiler_varclass.eco \
152			source_processor.eco
153
154aux_compiler_common.eco:	aux_source_processor.eco
155aux_compiler_analysis.eco:	aux_compiler_common.eco aux_compiler_map.eco
156aux_compiler_codegen.eco:	aux_compiler_common.eco \
157			compiler_compound.ecl compiler_builtins.ecl
158aux_compiler_indexing.eco:	aux_compiler_common.eco
159aux_compiler_normalise.eco:	aux_compiler_common.eco
160aux_compiler_peephole.eco:	aux_compiler_common.eco
161aux_compiler_regassign.eco:	aux_compiler_common.eco
162aux_compiler_varclass.eco:	aux_compiler_common.eco aux_compiler_map.eco
163aux_ecl_compiler.eco:	aux_compiler_common.eco aux_compiler_normalise.eco \
164			aux_compiler_analysis.eco aux_compiler_codegen.eco \
165			aux_compiler_indexing.eco aux_compiler_peephole.eco \
166			aux_compiler_regassign.eco aux_compiler_varclass.eco \
167			aux_source_processor.eco
168
169
170# Stage 1: build compiler under a different name (aux_ecl_compiler.eco)
171
172aux_%.eco:	%.ecl auxmap.ecl
173	$(STABLE_ECLIPSE) -e "compile(auxmap),\
174		compile(\"$<\",\
175		[output:eco(\"$@\")])"
176	-@/bin/chmod $(PERM) $@
177
178# Stage 2: build compiler_xxx.eco using the aux_ecl_compiler from stage 1
179# Don't add an AUX_ECO dependency here - we want to keep stage-1 stable!
180%.eco:	%.ecl
181	$(STABLE_ECLIPSE) -e "ensure_loaded(aux_ecl_compiler),\
182		aux_ecl_compiler:compile(\"$<\",\
183		[debug:$(DEBUG),output:eco,srcroot:\"..\"])"
184	-@/bin/chmod $(PERM) $@
185
186
187# Single-stage build - can be done if no incompatible changes
188# If using this, comment out the stage-2 rule above!
189#%.eco:	%.ecl
190#	$(STABLE_ECLIPSE) -e "compile(\"$<\",\
191#		[debug:$(DEBUG),output:eco,load:none,srcroot:\"..\"])"
192#	-@/bin/chmod $(PERM) $@
193
194
195%.lst:	%.ecl
196	$(STABLE_ECLIPSE) -e "ensure_loaded(aux_ecl_compiler),\
197		aux_ecl_compiler:compile(\"$<\",\
198		[debug:$(DEBUG),output:listing,srcroot:\"..\"])"
199
200%.asm:	%.ecl
201	$(STABLE_ECLIPSE) -e "ensure_loaded(aux_ecl_compiler),\
202		aux_ecl_compiler:compile(\"$<\",\
203		[debug:$(DEBUG),output:asm,srcroot:\"..\"])"
204
205
206#----------------------------------------------------------------------
207# Test
208#----------------------------------------------------------------------
209
210# Run unit tests and compare with reference output
211# First compile the test harness using the stable compiler,
212# then run it, testing the compiler in the local .eco files
213
214test:	$(LOCAL_ECO) compiler_test.eco
215	$(STABLE_ECLIPSE) -e "ensure_loaded(ecl_compiler),\
216		ensure_loaded(compiler_test),ftest"
217	@if diff test.ref test.res ; then echo Compiler unit test ok ; \
218	else echo Compiler unit test failed ; false ; fi
219
220testo:	$(LOCAL_ECO) compiler_test.eco
221	$(STABLE_ECLIPSE) -e "ensure_loaded(ecl_compiler),\
222		ensure_loaded(compiler_test),ftesto"
223	@if diff testo.ref testo.res ; then echo Optimised Compiler unit test ok ; \
224	else echo Compiler unit test failed ; false ; fi
225
226test_installed:
227	$(STABLE_ECLIPSE) -e "compile(compiler_test),ftest"
228	@if diff test.ref test.res ; then echo Compiler unit test ok ; \
229	else echo Compiler unit test failed ; false ; fi
230
231testo_installed:
232	$(STABLE_ECLIPSE) -e "compile(compiler_test),ftesto"
233	@if diff testo.ref testo.res ; then echo Optimised Compiler unit test ok ; \
234	else echo Compiler unit test failed ; false ; fi
235
236refs:
237	mv test.res test.ref
238	mv testo.res testo.ref
239
240
241# Run unit tests and generate coverage output in coverage/ subdirectory
242
243cover:	$(LOCAL_ECO) compiler_test.eco
244	@$(STABLE_ECLIPSE) -b compiler_test.eco -e ctest
245
246
247#----------------------------------------------------------------------
248# Installation
249#----------------------------------------------------------------------
250
251bootfiles:	$(BOOT_ECO)
252
253$(BOOTDIR)/lib/%.eco:	%.eco
254	/bin/cp $< $@
255	-@/bin/chmod $(PERM) $@
256
257
258install:	$(PUBLIC_ECI) $(PUBLIC_ECO) $(PUBLIC_ECL)
259
260$(PREFIX)/lib/%.eci:	%.ecl $(PREFIX)/lib/.stamp
261	$(STABLE_ECLIPSE) -e "lib(document), icompile(\"$(*F)\",\"$(@D)\")"
262	-@/bin/chmod $(PERM) $@
263
264$(PREFIX)/lib/%.ecl:	%.ecl $(PREFIX)/lib/.stamp
265	/bin/cp $< $@
266	@/bin/chmod $(PERM) $@
267
268
269#----------------------------------------------------------------------
270# Generate internal documentation
271#----------------------------------------------------------------------
272
273%.eci:	%.ecl $(BOOT_ECO)
274	$(STABLE_ECLIPSE) -e "lib(document),ensure_loaded(ecl_compiler),icompile(\"$(*F)\",\"$(@D)\")"
275
276
277doc:	doc/index.html
278
279doc/index.html:	$(PRIVATE_ECI)
280	$(STABLE_ECLIPSE) -e "lib(document),ecis_to_htmls(.,doc,\"\",\"ECLiPSe III Compiler\")"
281
282
283# Pretty-print the sources
284
285pretty:	pretty/index.html
286
287pretty/index.html: $(COMPILER_MODULES)
288	-@$(STABLE_ECLIPSE) -e \
289	    "lib(pretty_printer),ensure_loaded(ecl_compiler),argv(all,[_|F]),pretty_print(F,[link_back:\"../doc/index.html\"])" \
290	    -- $(COMPILER_MODULES)
291
292
293