1 ################################################################
4 # To use this, try the following:
6 # rm -f config.cache && autoheader && autoconf && ./configure --enable-hc-boot && make -C ghc/includes boot
10 ################################################################
12 # This rule goes first to make it the default choice
17 CPPFLAGS += -I$(RTS_DIR)/includes
18 CPPFLAGS += -D__HUGS__
25 CFLAGS += -Wstrict-prototypes
26 CFLAGS += -Wmissing-prototypes
27 CFLAGS += -Wmissing-declarations
28 #CFLAGS += -Wredundant-decls
29 #CFLAGS += -Wnested-externs
32 CFLAGS += -Waggregate-return
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!
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
49 # grep include *.c | grep .c\"
50 #INCFILES = parser.c preds.c kind.c timer.c scc.c
52 C_FILES = $(wildcard *.c)
53 Y_FILES = $(wildcard *.y)
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 \
64 echo $(addsuffix .h,$(basename $(OBJECTS)))
66 ################################################################
67 # Building the rts library
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 ################################################################
78 .PHONY: libgmp.a libHSrts.a libHSrts.so
80 @$(MAKE) -C $(RTS_DIR)/rts/gmp libgmp.a
82 @$(MAKE) -C $(RTS_DIR)/rts -fadr libHSrts.a
84 @$(MAKE) -C $(RTS_DIR)/rts -fadr libHSrts.so
86 # libHS_cbits.so: $(wildcard ../lib/std/cbits/*.c)
87 # @$(MAKE) -C ../lib/std/cbits libHS_cbits.a
89 # $(CC) -shared $(patsubst %.c,%.o,$^) -L$(HOME)/lib -lc -o $@
91 libHS_cbits.so: $(wildcard ../lib/std/cbits/*.c)
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
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
101 libHS_cbits.dll: $(CBITS_O)
102 $(LD) --image-base=0x3000000 -o libHS_cbits.dll libHS_cbits.exp $(CBITS_O) -lcygwin -lkernel32
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
113 SHARED_LINK = gcc -shared
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
127 etags *.[ych] ../{interpreter,rts,includes}/*.{y,hc,c,S,h}
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
133 @$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
141 ################################################################
142 # Various test libraries:
143 ################################################################
146 $(SHARED_LINK) $^ -o $@
148 AB.myhi: A.myhi B.myhi
152 ################################################################
153 # Building .so files I can load into Hugs
154 ################################################################
156 .PRECIOUS: A.hc B.hc C.hc D.hc
159 $(RTS_DIR)/driver/ghc -recomp -i$(RTS_DIR)/lib/std -C $<
161 # The substitutions rename constructor wrappers to match our expectations
162 # And replace Z-encoded $ signs with underscores
164 echo "#include \"Rts.h\"" > $@
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" $@
172 HCFLAGS += -DDEBUG_EXTRA=1
173 HCFLAGS += -ULAZY_BLACKHOLING
174 HCFLAGS += -DUSE_MINIINTERPRETER=1
175 HCFLAGS += -DINTERPRETER_ONLY=1
178 # The substitutions rename constructor wrappers to match our expectations
180 echo "#include \"Rts.h\"" >> $<.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 $@
187 gcc -shared $(CPPFLAGS) $(CFLAGS) $(HCFLAGS) $< -lm -lbfd -liberty -o $@
189 ################################################################
190 # Floppy disk for me to take home at night
191 ################################################################
193 # We avoid using zip because we're fed up being bitten by the
194 # default=non-recursive bug
197 tar zcvf /mnt/floppy/stghugs.tgz . --exclude=CVS
200 ################################################################
202 ################################################################
204 # HPPFLAGS += "-DBEGIN_FOR_HUGS={-"
205 # HPPFLAGS += "-DEND_FOR_HUGS=-}"
207 HPP = gcc -E -P -traditional -xc -DSTD_PRELUDE=0 $(HPPFLAGS) $(CPPFLAGS) -Iprelude -Ilibrary -I.
208 UNLIT = ../utils/unlit/unlit
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
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
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
271 @ # $(HPP) ../lib/concurrent/Parallel.lhs > Parallel.lhs
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
285 ################################################################
288 # This works - at least, it seems to:
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 ################################################################
296 ################################################################
297 # Regression tests (Unix only). Run "make install" first
299 # Uses runstdtest (from ghc-0.26/ghc/glafp-utils/scripts), perl 5
300 # and /bin/sh (Bourne shell).
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.
309 # make check | grep -v "^--" -
311 ################################################################
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
322 ################################################################
324 ################################################################
326 DEP_FILES = $(addsuffix .d,$(basename $(C_FILES)) $(basename $(Y_FILES)))
330 #Copied from the gmake manual - builds a dependency file for every C file
332 @echo "Making dependency file $@"
333 @$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \
334 | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@ \
335 ; [ -s $@ ] || rm -f $@'
340 ################################################################
342 ################################################################