[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / interpreter / adr.mk
1 ################################################################
2 # Start of Makefile
3 #
4 # To use this, try the following:
5 # cd ../..
6 # rm -f config.cache && autoheader && autoconf && ./configure --enable-hc-boot && make -C ghc/includes boot
7 # cd ghc/interpreter
8 # make hugs Prelude.hs
9 # ./hugs -h300k
10 ################################################################
11
12 # This rule goes first to make it the default choice
13 default         :: hugs 
14
15 RTS_DIR = ..
16
17 CPPFLAGS        += -I$(RTS_DIR)/includes 
18 CPPFLAGS        += -D__HUGS__ 
19
20 CC              = gcc
21
22 CFLAGS          += -Wall 
23 CFLAGS          += -Wno-unused 
24 CFLAGS          += -W
25 CFLAGS          += -Wstrict-prototypes
26 CFLAGS          += -Wmissing-prototypes 
27 CFLAGS          += -Wmissing-declarations
28 #CFLAGS         += -Wredundant-decls 
29 #CFLAGS         += -Wnested-externs
30 #CFLAGS         += -Wshadow
31 CFLAGS          += -Winline
32 CFLAGS          += -Waggregate-return
33
34 #CFLAGS         += -ggdb3 -O0    # debug with gdb, minimal confusion
35 #CFLAGS         += -pg -O2       # Profile with gprof
36 #CFLAGS         += -pg -g        # Profile more with gprof
37 #CFLAGS         += -pg -g -a     # Profile basic blocks with gprof (disnae work)
38 CFLAGS          += -O2           # we just want to run it!
39 #CFLAGS         += -O2 -g        # we just want to run it!
40
41 LIBS            += -lm           # math - may not need it
42 #LIBS           += -lreadline    # cool library
43 #LIBS           += -lmcheck      # GNU extension - consistency check malloc usage
44 #LIBS           += -ldl          # dynamic loading
45
46 YACC            = bison -y
47 RM              = /bin/rm -f
48
49 # grep include *.c | grep .c\"
50 #INCFILES       = parser.c preds.c kind.c timer.c scc.c
51
52 C_FILES         = $(wildcard *.c)
53 Y_FILES         = $(wildcard *.y)
54
55 OBJECTS         = hugs.o connect.o \
56                   storage.o machdep.o charset.o input.o output.o \
57                   static.o modules.o interface.o type.o subst.o link.o \
58                   compiler.o desugar.o pmc.o pat.o derive.o \
59                   stg.o translate.o pp.o \
60                   codegen.o free.o lift.o stgSubst.o optimise.o \
61                   dynamic.o
62
63 source:
64         echo $(addsuffix .h,$(basename $(OBJECTS)))
65
66 ################################################################
67 # Building the rts library
68
69 # Two ways to link Hugs:
70 # o Static link to libHSrts.a using -rdynamic so that GHC generated .so files
71 #   can access libHSrts.a
72 # o Dynamic link to libHSrts.so
73 # There's not that much to choose between these two methods: static linking
74 # makes debugging easier, dynamic linking will make delivered systems
75 # smaller (if you use multiple clients).
76 ################################################################
77
78 .PHONY: libgmp.a libHSrts.a libHSrts.so
79 libgmp.a:
80            @$(MAKE) -C $(RTS_DIR)/rts/gmp libgmp.a
81 libHSrts.a:
82            @$(MAKE) -C $(RTS_DIR)/rts -fadr libHSrts.a
83 libHSrts.so:
84            @$(MAKE) -C $(RTS_DIR)/rts -fadr libHSrts.so
85
86 # libHS_cbits.so: $(wildcard ../lib/std/cbits/*.c)
87 #         @$(MAKE) -C ../lib/std/cbits libHS_cbits.a
88 #         rm -f $@
89 #         $(CC) -shared $(patsubst %.c,%.o,$^) -L$(HOME)/lib -lc -o $@ 
90
91 libHS_cbits.so: $(wildcard ../lib/std/cbits/*.c)
92           rm -f $@
93 #         $(CC) -shared $(CPPFLAGS) -D__CONCURRENT_HASKELL__ $^ -lc -o $@ 
94 #         dlltool --def libHS_cbits.def --output-exp libHS_cbits.exp --output-lib libHS_cbits.a --dllname libHS_cbits.dll
95           $(CC) -c $(CPPFLAGS) -D__CONCURRENT_HASKELL__ $^ -lc
96 #         $(LD) -o libHS_cbits.dll libHS_cbits.exp 
97
98 CBITS_C = $(wildcard ../lib/std/cbits/*.c)
99 CBITS_O = allocMem.o closeFile.o createDirectory.o directoryAux.o echoAux.o errno.o fileEOF.o fileGetc.o fileLookAhead.o fileObject.o filePosn.o filePutc.o fileSize.o flushFile.o freeFile.o getBufferMode.o getCPUTime.o getClockTime.o getCurrentDirectory.o getDirectoryContents.o getLock.o inputReady.o openFile.o readFile.o removeDirectory.o removeFile.o renameDirectory.o renameFile.o seekFile.o setBuffering.o setCurrentDirectory.o showTime.o system.o timezone.o toClockSec.o toLocalTime.o toUTCTime.o writeError.o writeFile.o                      
100
101 libHS_cbits.dll: $(CBITS_O)
102         $(LD) --image-base=0x3000000 -o libHS_cbits.dll libHS_cbits.exp $(CBITS_O) -lcygwin -lkernel32
103
104 clean:: 
105         rm -f libHS_cbits.so
106
107 LIBS += $(RTS_DIR)/rts/libHSrts.a $(RTS_DIR)/rts/gmp/libgmp.a
108 #LIBS += $(RTS_DIR)/rts/libHSrts.so
109 #LIBS += -L$(HOME)/lib -lgmp
110 #LIBS += -lbfd -liberty 
111 LIBS += -ladvapi32
112
113 SHARED_LINK = gcc -shared 
114
115
116 hugs            : $(OBJECTS) libHSrts.a libgmp.a
117                   $(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) $(OBJECTS) $(LIBS) -o hugs 
118 #                 $(CC) $(LDFLAGS) -rdynamic $(CPPFLAGS) $(CFLAGS) $(OBJECTS) $(LIBS) -o hugs 
119                   
120 clean           ::
121                   $(RM) *.o *.so
122                   $(RM) depends.mk
123                   $(RM) TAGS
124                   $(RM) hugs
125 #default        :: TAGS
126 TAGS            ::
127                   etags *.[ych] ../{interpreter,rts,includes}/*.{y,hc,c,S,h}
128
129 # copied from the standard rules so that I can use @ to make it quieter
130 # you'll want to comment this out if you have to debug this Makefile
131 %.o             : %.c
132                   @echo Compiling $<
133                   @$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
134
135 %.c             : %.y
136                   -$(YACC) $<
137                   mv y.tab.c $@
138 clean           ::
139                   $(RM) parser.c
140
141 ################################################################
142 # Various test libraries:
143 ################################################################
144
145 AB.so: A.o B.o
146         $(SHARED_LINK) $^ -o $@
147
148 AB.myhi: A.myhi B.myhi
149         cat $^ > $@
150
151
152 ################################################################
153 # Building .so files I can load into Hugs
154 ################################################################
155
156 .PRECIOUS: A.hc B.hc C.hc D.hc 
157
158 %.hc: %.hs
159         $(RTS_DIR)/driver/ghc -recomp -i$(RTS_DIR)/lib/std -C $<
160
161 # The substitutions rename constructor wrappers to match our expectations
162 # And replace Z-encoded $ signs with underscores
163 %.c: %.hc
164         echo "#include \"Rts.h\"" >  $@
165         cat  $<                   >> $@
166         perl -p -i -e "s/a_closure/A_closure/g" $@
167         perl -p -i -e "s/b_closure/B_closure/g" $@
168         perl -p -i -e "s/mkT_closure/MkT_closure/g" $@
169         perl -p -i -e "s/Z36/_/g" $@
170
171 HCFLAGS += -DDEBUG=1 
172 HCFLAGS += -DDEBUG_EXTRA=1 
173 HCFLAGS += -ULAZY_BLACKHOLING 
174 HCFLAGS += -DUSE_MINIINTERPRETER=1 
175 HCFLAGS += -DINTERPRETER_ONLY=1 
176 HCFLAGS += -DNO_REGS
177
178 # The substitutions rename constructor wrappers to match our expectations
179 %.o: %.hc
180         echo "#include \"Rts.h\"" >> $<.c
181         cat  $<                   >> $<.c
182         perl -p -i -e "s/Comb_a_closure/Comb_A_closure/g" $<.c
183         perl -p -i -e "s/Comb_b_closure/Comb_B_closure/g" $<.c
184         $(CC) $(CPPFLAGS) $(CFLAGS) $(HCFLAGS) -xc -c $<.c -o $@
185
186 %.so: %.c
187         gcc -shared $(CPPFLAGS) $(CFLAGS) $(HCFLAGS) $< -lm -lbfd -liberty -o $@
188
189 ################################################################
190 # Floppy disk for me to take home at night
191 ################################################################
192
193 # We avoid using zip because we're fed up being bitten by the
194 # default=non-recursive bug
195 floppy:         clean
196                 mount /mnt/floppy
197                 tar zcvf /mnt/floppy/stghugs.tgz . --exclude=CVS
198                 umount /mnt/floppy
199
200 ################################################################
201 # Prelude
202 ################################################################
203
204 # HPPFLAGS += "-DBEGIN_FOR_HUGS={-"
205 # HPPFLAGS += "-DEND_FOR_HUGS=-}"
206
207 HPP = gcc -E -P -traditional -xc -DSTD_PRELUDE=0 $(HPPFLAGS) $(CPPFLAGS) -Iprelude -Ilibrary -I.
208 UNLIT = ../utils/unlit/unlit
209
210 # we cleanup by deleting adjacent blank lines - which just happen to be the
211 # only duplicate adjacent lines in all the files we process
212 CLEANUP = uniq
213
214 # Fiendishly cunning this: 
215 # o PreludeBuiltin.hs contains the BODY of the libraries it requires.
216 # o All the other libraries just contain the HEAD of the file.
217 Prelude.hs      : $(wildcard prelude/*.hs) $(wildcard library/*.hs) $(wildcard ../lib/*/*.lhs) libHS_cbits.dll $(RTS_DIR)/includes/options.h
218                 @ echo Building PreludeBuiltin
219                 @ $(HPP) ../lib/std/PrelHandle.lhs     | $(UNLIT) - PrelHandle.unlit
220                 @ $(HPP) ../lib/std/PrelIOBase.lhs     | $(UNLIT) - PrelIOBase.unlit
221                 @ $(HPP) ../lib/std/PrelException.lhs  | $(UNLIT) - PrelException.unlit
222                 @ $(HPP) ../lib/std/PrelDynamic.lhs    | $(UNLIT) - PrelDynamic.unlit
223                 @ $(HPP) -DBODY ../lib/std/IO.lhs      | $(UNLIT) - IO.unlit
224                 @ $(HPP) -DHEAD ../lib/std/IO.lhs      | $(UNLIT) - IO.hs
225                 @ $(HPP) -DBODY prelude/Prelude.hs     | $(CLEANUP) > PreludeBuiltin.hs
226                 @ $(HPP) -DHEAD prelude/Prelude.hs     | $(CLEANUP) > Prelude.hs
227                 @ $(HPP) -DHEAD library/Array.hs       | $(CLEANUP) > Array.hs      
228                 @ $(HPP) -DHEAD library/Char.hs        | $(CLEANUP) > Char.hs             
229                 @ $(HPP) -DHEAD library/Ix.hs          | $(CLEANUP) > Ix.hs               
230                 @ $(HPP) -DHEAD library/List.hs        | $(CLEANUP) > List.hs             
231                 @ $(HPP) -DHEAD library/Maybe.hs       | $(CLEANUP) > Maybe.hs            
232                 @ $(HPP) -DHEAD library/Numeric.hs     | $(CLEANUP) > Numeric.hs    
233                 @ $(HPP) -DHEAD library/Ratio.hs       | $(CLEANUP) > Ratio.hs      
234                 @ $(HPP) -DHEAD library/UnicodePrims.hs| $(CLEANUP) > UnicodePrims.hs      
235                 @ $(HPP) -DHEAD prelude/PreludeIO.hs   | $(CLEANUP) > PreludeIO.hs  
236                 @ $(HPP) -DHEAD prelude/PreludeList.hs | $(CLEANUP) > PreludeList.hs
237                 @ $(HPP) -DHEAD prelude/PreludeText.hs | $(CLEANUP) > PreludeText.hs      
238                 @ $(HPP) -DHEAD prelude/PrelConc.hs    | $(CLEANUP) > PrelConc.hs
239                 @ echo "Building standard libraries"
240                 @ $(HPP) library/Complex.hs       > Complex.hs            
241                 @ $(HPP) library/Monad.hs         > Monad.hs      
242                 @ $(HPP) ../lib/std/System.lhs    > System.lhs  
243                 @ $(HPP) ../lib/std/Directory.lhs > Directory.lhs         
244                 @ $(HPP) ../lib/std/Locale.lhs    > Locale.lhs  
245                 @ $(HPP) ../lib/std/Random.lhs    > Random.lhs  
246                 @ $(HPP) ../lib/std/CPUTime.lhs   > CPUTime.lhs  
247                 @ $(HPP) ../lib/std/Time.lhs      > Time.lhs  
248                 @ echo "And some standard libraries which ain't done yet"
249                 @ # $(HPP) library/IO.hs            > IO.hs               
250                 @ #
251                 @ echo "Building Hugs-GHC libraries"
252                 @ $(HPP) ../lib/exts/ST.lhs        > ST.lhs     
253                 @ $(HPP) ../lib/misc/Pretty.lhs    > Pretty.lhs     
254                 @ $(HPP) ../lib/exts/IOExts.lhs    > IOExts.lhs     
255                 @ $(HPP) ../lib/exts/NumExts.lhs   > NumExts.lhs     
256                 @ $(HPP) ../lib/exts/Dynamic.lhs   > Dynamic.lhs     
257                 @ $(HPP) ../lib/exts/Bits.lhs      > Bits.lhs     
258                 @ $(HPP) ../lib/exts/Exception.lhs > Exception.lhs     
259                 @ $(HPP) library/Int.hs     > Int.hs     
260                 @ $(HPP) library/Word.hs    > Word.hs     
261                 @ $(HPP) ../lib/exts/Addr.lhs    > Addr.lhs     
262                 @ $(HPP) ../lib/concurrent/Channel.lhs    > Channel.lhs    
263                 @ $(HPP) ../lib/concurrent/ChannelVar.lhs > ChannelVar.lhs 
264                 @ $(HPP) ../lib/concurrent/Concurrent.lhs > Concurrent.lhs 
265                 @ $(HPP) ../lib/concurrent/Merge.lhs      > Merge.lhs      
266                 @ $(HPP) ../lib/concurrent/SampleVar.lhs  > SampleVar.lhs 
267                 @ $(HPP) ../lib/concurrent/Semaphore.lhs  > Semaphore.lhs 
268                 @ echo "And some libraries which ain't converted yet"
269                 @ # $(HPP) ../lib/exts/Foreign.lhs          > Foreign.lhs 
270                 @ #
271                 @ # $(HPP) ../lib/concurrent/Parallel.lhs   > Parallel.lhs   
272
273 clean           ::
274                 $(RM) Array.hs           Dynamic.lhs        NumExts.lhs        Pretty.lhs
275                 $(RM) Bits.lhs           Exception.lhs      Numeric.hs         Ratio.hs
276                 $(RM) Channel.lhs        IOExts.lhs         PrelConc.hs        ST.lhs
277                 $(RM) ChannelVar.lhs     Ix.hs              Prelude.hs         SampleVar.lhs
278                 $(RM) Char.hs            List.hs            PreludeBuiltin.hs  Semaphore.lhs
279                 $(RM) Complex.hs         Maybe.hs           PreludeIO.hs       System.lhs
280                 $(RM) Concurrent.lhs     Merge.lhs          PreludeList.hs     UnicodePrims.hs
281                 $(RM) Directory.lhs      Monad.hs           PreludeText.hs
282                 $(RM) Locale.lhs Int.hs IO.hs Addr.lhs Time.lhs Word.hs
283                 $(RM) *.unlit
284
285 ################################################################
286 # Greencard:
287 #
288 # This works - at least, it seems to:
289 #
290 # echo "runGreenCard \"--target ffi StdDIS.gc\"" | ./hugs -w -h500k ../../green-card/src/GreenCard.lhs
291 # make StdDIS_stub.so
292 # env LD_LIBRARY_PATH=. ./hugs -h300k StdDIS.hs 
293 ################################################################
294
295
296 ################################################################
297 # Regression tests (Unix only).  Run "make install" first
298
299 # Uses runstdtest (from ghc-0.26/ghc/glafp-utils/scripts), perl 5
300 # and /bin/sh (Bourne shell).
301 #
302 # "make check" generates a lot of output to explain what is going on
303 # and reassure you that progress is being made.  This is great if you've
304 # never run these tests before - but if you just want to reassure yourself
305 # that nothing has broken since the last release, you might prefer to
306 # run this command which removes all the explanations and success
307 # stories - leaving just the useful output.
308 #
309 #  make check | grep -v "^--" -
310 #
311 ################################################################
312
313 check           : hugs Prelude.hs
314                   ./test/runtests test/static/*.hs
315                   ./test/runtests test/typechecker/*.hs
316                   ./test/runtests test/runtime/*.hs
317                   ./test/runtests test/std/*.hs
318                   ./test/runtests test/exts/*.hs
319 clean           ::
320                   $(RM) testFile
321
322 ################################################################
323 # Dependencies
324 ################################################################
325
326 DEP_FILES       = $(addsuffix .d,$(basename $(C_FILES)) $(basename $(Y_FILES)))
327
328 include $(DEP_FILES)
329
330 #Copied from the gmake manual - builds a dependency file for every C file
331 %.d             : %.c
332                 @echo "Making dependency file $@"
333                 @$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \
334                  | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@ \
335                  ; [ -s $@ ] || rm -f $@'
336
337 clean::
338         $(RM) $(DEP_FILES)
339
340 ################################################################
341 # End of Makefile
342 ################################################################