Build system improvements
[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 $(call trace, build-perl($1,$2))
23 # $1 = dir
24 # $2 = distdir
25
26 ifeq "$$($1_$2_TOPDIR)" "YES"
27 $1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
28 else
29 $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
30 endif
31
32 ifeq "$$(phase_1_or_later)" "YES"
33 $(call all-target,$1_$2,$$($1_$2_INPLACE))
34 endif
35
36 $(call clean-target,$1,$2,$1/$2 $$($1_$2_INPLACE))
37 .PHONY: clean_$1
38 clean_$1 : clean_$1_$2
39
40 # INPLACE_BIN etc. might be empty if we're cleaning
41 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
42 ifneq "$$(BINDIST)" "YES"
43 $1/$2/$$($1_$2_PROG).prl: $1/$$($1_PERL_SRC) $$(UNLIT) | $$$$(dir $$$$@)/.
44 "$$(UNLIT)" $$(UNLIT_OPTS) $$< $$@
45 endif
46
47 $1/$2/$$($1_$2_PROG): $1/$2/$$($1_$2_PROG).prl
48 "$$(RM)" $$(RM_OPTS) $$@
49 echo '#!$$(PERL)' >> $$@
50 echo '$$$$TARGETPLATFORM = "$$(TARGETPLATFORM)";' >> $$@
51 echo '$$$$TABLES_NEXT_TO_CODE = "$(GhcEnableTablesNextToCode)";' >> $$@
52 cat $$< >> $$@
53
54 $$($1_$2_INPLACE): $1/$2/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
55 "$$(CP)" $$< $$@
56 $$(EXECUTABLE_FILE) $$@
57
58 ifneq "$$($1_$2_INSTALL_IN)" ""
59 BINDIST_PERL_SOURCES += $1/$2/$$($1_$2_PROG).prl
60
61 install: install_$1_$2
62
63 .PHONY: install_$1_$2
64 install_$1_$2: $1/$2/$$($1_$2_PROG)
65 $$(call INSTALL_DIR,"$$($1_$2_INSTALL_IN)")
66 $$(call INSTALL_SCRIPT,$$(INSTALL_OPTS),$$<,"$$($1_$2_INSTALL_IN)")
67 endif
68 endif
69
70 endef