57406766ca1f020a442ea57cd0ce7f99a25eec7c
[ghc.git] / rules / build-perl.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13
14 # Build a perl script. Invoke like this:
15 #
16 # driver/mangler_PERL_SRC = ghc-asm.lprl
17 # driver/mangler_dist_PROG = ghc-asm
18 #
19 # $(eval $(call build-perl,driver/mangler,dist))
20
21 define build-perl
22 # $1 = dir
23 # $2 = distdir
24
25 ifeq "$$($1_$2_LIBEXEC)" "YES"
26 $1_$2_INPLACE = $(INPLACE_LIB)/$$($1_$2_PROG)
27 else
28 $1_$2_INPLACE = $(INPLACE_BIN)/$$($1_$2_PROG)
29 endif
30
31 $(call all-target,$$($1_$2_INPLACE))
32
33 $(call clean-target,$1,$2,$1/$2 $$($1_$2_INPLACE))
34 .PHONY: clean_$1
35 clean_$1 : clean_$1_$2
36
37 # INPLACE_BIN etc. might be empty if we're cleaning
38 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
39 ifneq "$$(BINDIST)" "YES"
40 $1/$2/$$($1_$2_PROG).prl: $1/$$($1_PERL_SRC) $$(UNLIT)
41 "$$(MKDIRHIER)" $1/$2
42 "$$(RM)" $$(RM_OPTS) $$@
43 "$$(UNLIT)" $$(UNLIT_OPTS) $$< $$@
44
45 $1/$2/$$($1_$2_PROG): $1/$2/$$($1_$2_PROG).prl
46 "$$(RM)" $$(RM_OPTS) $$@
47 echo '#!$$(PERL)' >> $$@
48 echo '$$$$TARGETPLATFORM = "$$(TARGETPLATFORM)";' >> $$@
49 cat $$< >> $$@
50 $$(EXECUTABLE_FILE) $$@
51
52 $$($1_$2_INPLACE): $1/$2/$$($1_$2_PROG)
53 "$$(MKDIRHIER)" $$(dir $$@)
54 "$$(RM)" $$(RM_OPTS) $$@
55 "$$(CP)" $$< $$@
56 $$(EXECUTABLE_FILE) $$@
57 endif
58 endif
59
60 endef