1############################################################
2# Define subdirectories
3#
4
5CMP = $(dir compiler)
6SYS = $(dir system)
7SIM = $(dir simulator)
8TAB = $(dir tables)
9DIS = $(dir disassembler)
10FNT = $(dir front)
11TBL = $(dir tables)
12LOD = $(dir loader)
13LNK = $(dir linker)
14TST = $(dir test)
15INC = $(dir include)
16
17############################################################
18# Compile flags
19#
20
21OCAMLINCLUDES += $(CMP) $(DIS) $(SIM) $(LOD)
22OCAMLFLAGS= -w -A
23CFLAGS += -g
24
25############################################################
26# Compilation files
27#
28
29CMP_ML[] =
30    $(CMP)/absyn
31    $(CMP)/annvariables
32    $(CMP)/bytecode
33    $(CMP)/clausegen
34    $(CMP)/clauses
35    $(CMP)/codegen
36    $(CMP)/compile
37    $(CMP)/errormsg
38    $(CMP)/instr
39    $(CMP)/lplex
40    $(CMP)/lpyacc
41    $(CMP)/option
42    $(CMP)/parse
43    $(CMP)/pervasive
44    $(CMP)/pervasiveutils
45    $(CMP)/preabsyn
46    $(CMP)/processclauses
47    $(CMP)/registers
48    $(CMP)/spitcode
49    $(CMP)/symbol
50    $(CMP)/table
51    $(CMP)/translate
52    $(CMP)/typereduction
53    $(CMP)/types
54
55DEP_ML[] =
56    $(CMP)/compile
57    $(CMP)/lplex
58    $(CMP)/lpyacc
59    $(CMP)/errormsg
60    $(CMP)/symbol
61    $(CMP)/preabsyn
62    $(CMP)/table
63
64PAR_ML[] =
65    $(CMP)/absyn
66    $(CMP)/clauses
67    $(CMP)/compile
68    $(CMP)/errormsg
69    $(CMP)/explicit
70    $(CMP)/lplex
71    $(CMP)/lpyacc
72    $(CMP)/option
73    $(CMP)/parse
74    $(CMP)/pervasive
75    $(CMP)/pervasiveutils
76    $(CMP)/preabsyn
77    $(CMP)/symbol
78    $(CMP)/table
79    $(CMP)/translate
80    $(CMP)/types
81
82DIS_ML[] =
83    $(DIS)/context
84    $(DIS)/disassembly
85    $(DIS)/label
86
87FNT_ML[] =
88    $(FNT)/parseargs
89
90FNT_C[] =
91    $(FNT)/ccode_stubs_c
92    $(FNT)/front_c
93    $(FNT)/query_c
94    $(FNT)/readterm_c
95    $(FNT)/ocaml_wrap
96
97FNT_ML_TO_C[] =
98    $(FNT)/module
99    $(FNT)/query
100    $(FNT)/front
101    $(FNT)/readterm
102    $(FNT)/simerrors
103    $(FNT)/ccode_stubs
104
105SIM_C[] =
106    $(SIM)/abstmachine
107    $(SIM)/dataformats
108    $(SIM)/hnorm
109    $(SIM)/hnormlocal
110    $(SIM)/hopu
111    $(SIM)/io-datastructures
112    $(SIM)/mcstring
113    $(SIM)/printterm
114    $(SIM)/simdispatch
115    $(SIM)/siminit
116    $(SIM)/siminstr
117    $(SIM)/siminstrlocal
118    $(SIM)/simulator
119    $(SIM)/trail
120    $(SIM)/types
121    $(SIM)/builtins/builtins
122    $(SIM)/builtins/compexp
123    $(SIM)/builtins/evalexp
124    $(SIM)/builtins/io
125    $(SIM)/builtins/meta
126    $(SIM)/builtins/readterm
127
128SYS_C[] =
129    $(SYS)/error
130    $(SYS)/memory
131    $(SYS)/message
132    $(SYS)/stream
133
134TBL_C[] =
135    $(TBL)/instructions
136    $(TBL)/pervasives
137    $(TBL)/pervinit
138
139LOD_ML[] =
140    $(LOD)/loadmodtab
141
142LOD_C[] =
143    $(LOD)/bvrtab
144    $(LOD)/code
145    $(LOD)/const
146    $(LOD)/file
147    $(LOD)/hashtab
148    $(LOD)/implgoal
149    $(LOD)/importtab
150    $(LOD)/kind
151    $(LOD)/loader
152    $(LOD)/loadmodtab
153    $(LOD)/searchtab
154    $(LOD)/strings
155    $(LOD)/tyskel
156
157LNK_C[] =
158    $(LNK)/bvrtab
159    $(LNK)/CallResolution
160    $(LNK)/code
161    $(LNK)/const
162    $(LNK)/file
163    $(LNK)/hashtab
164    $(LNK)/implgoal
165    $(LNK)/importtab
166    $(LNK)/kind
167    $(LNK)/module
168    $(LNK)/linker_message
169    $(LNK)/rename
170    $(LNK)/stringspace
171    $(LNK)/tree
172    $(LNK)/tyskel
173    $(LNK)/vector
174    $(LNK)/VectorRW
175    $(FNT)/linker_c
176
177INC_C[] =
178    $(INC)/obstack
179
180DIS_MAIN = $(FNT)/disassemblerfront
181CMP_MAIN = $(FNT)/compilerfront
182SIM_MAIN = $(FNT)/simulatorfront
183LNK_MAIN = $(FNT)/linkerfront
184DEP_MAIN = $(FNT)/dependfront
185PAR_MAIN = $(FNT)/parsefront
186
187############################################################
188# Platform specific changes
189#
190
191if $(mem $(SYSNAME), Linux)
192    YACC = bison -by
193    LEX = flex
194    export
195
196if $(mem $(OSTYPE), Cygwin Win32)
197    YACC = bison -by
198    LEX = flex
199    CC = i686-pc-mingw32-gcc
200    INC_C[] += $(INC)/byteswap $(INC)/search
201    export
202
203if $(mem $(SYSNAME), Darwin)
204    INC_C[] += $(INC)/byteswap $(INC)/search
205    export
206
207if $(mem $(SYSNAME), OpenBSD)
208    INC_C[] += $(INC)/search
209    export
210
211if $(mem $(SYSNAME), DragonFly)
212    INC_C[] += $(INC)/search
213    export
214
215
216############################################################
217# Generated Files
218#
219
220.SUBDIRS: tables_gen
221
222INSTR_ML_FILES[] =
223    $(CMP)/instr.mli
224    $(CMP)/instr.ml
225
226INSTR_C_FILES[] =
227    $(TBL)/instructions.h
228    $(TBL)/instructions.c
229    $(SIM)/simdispatch.c
230
231INSTR_FILES[] =
232    $(INSTR_ML_FILES)
233    $(INSTR_C_FILES)
234
235PERV_ML_FILES[] =
236    $(CMP)/pervasive.mli
237    $(CMP)/pervasive.ml
238
239PERV_C_FILES[] =
240    $(TBL)/pervasives.h
241    $(TBL)/pervasives.c
242
243PERV_FILES[] =
244    $(PERV_ML_FILES)
245    $(PERV_C_FILES)
246
247LocalCGeneratedFiles($(INSTR_C_FILES) $(PERV_C_FILES))
248LocalOCamlGeneratedFiles($(INSTR_ML_FILES) $(PERV_ML_FILES))
249
250INSTR_GEN = tables_gen/instrformats/instr_gen$(EXE)
251$(INSTR_FILES): $(INSTR_GEN)
252    cd $(dirname $(INSTR_GEN)) && ./$(basename $(INSTR_GEN))
253
254
255PERV_GEN = tables_gen/pervasives/perv_gen$(EXE)
256PERV_IN = pervasives.in
257$(PERV_FILES): $(PERV_GEN)
258    cd $(dirname $(PERV_GEN)) && ./$(basename $(PERV_GEN)) $(PERV_IN)
259
260.PHONY: gen
261gen: $(INSTR_ML_FILES) $(PERV_ML_FILES) $(INSTR_C_FILES) $(PERV_C_FILES)
262
263
264############################################################
265# Include subdirectories
266#
267
268.SUBDIRS: compiler disassembler front include linker loader simulator system tables
269    if $(file-exists OMakefile)
270        include OMakefile
271
272
273############################################################
274# Build Targets
275#
276
277# If the file "prebuilt" exists then assume the binaries are
278# already built by a 3rd party tool
279
280if $(not $(file-exists prebuilt))
281  OCamlProgram(tjcc, $(CMP_MAIN) $(CMP_ML) $(LOD_ML) $(FNT_ML))
282
283  OCamlProgram(tjdis, $(DIS_MAIN) $(CMP_ML) $(LOD_ML) $(DIS_ML) $(FNT_ML))
284
285  OCamlProgram(tjdepend, $(DEP_MAIN) $(DEP_ML) $(FNT_ML))
286
287  OCamlProgram(tjparse, $(PAR_MAIN) $(PAR_ML) $(FNT_ML))
288
289  # The simulator and linker require linking with C code
290
291  section
292    StaticCLibrary(libsim, \
293      $(SIM_C) $(SYS_C) $(TBL_C) $(FNT_C) $(LOD_C) $(LNK_C) $(INC_C))
294    OCAML_CLIBS += libsim
295    OCamlProgram(tjsim, \
296      $(SIM_MAIN) $(LOD_ML) $(CMP_ML) $(FNT_ML) $(FNT_ML_TO_C))
297
298  section
299    StaticCLibrary(liblink, $(SIM_C) $(SYS_C) $(TBL_C) $(LNK_C) $(INC_C))
300    OCAML_CLIBS += liblink
301    OCamlProgram(tjlink, $(LNK_MAIN) $(FNT_ML))
302
303
304TJCC = $(CWD)/tjcc$(EXE)
305TJSIM = $(CWD)/tjsim$(EXE)
306TJDIS = $(CWD)/tjdis$(EXE)
307TJLINK = $(CWD)/tjlink$(EXE)
308TJDEPEND = $(CWD)/tjdepend$(EXE)
309TJPARSE = $(CWD)/tjparse$(EXE)
310
311.PHONY: all
312all: $(TJCC) $(TJSIM) $(TJDIS) $(TJLINK) $(TJDEPEND) $(TJPARSE)
313
314############################################################
315# Testing Targets
316#
317# Defined last so that it can see TJCC, etc
318
319if $(file-exists $(TST))
320   .SUBDIRS: $(TST)
321
322.PHONY: test
323test: compiler-test compiler-negative-test linker-test system-test
324