summaryrefslogtreecommitdiff
path: root/rules/build-perl.mk
blob: e13185d85d780895f67db716eca485b549682afc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -----------------------------------------------------------------------------
#
# (c) 2009 The University of Glasgow
#
# This file is part of the GHC build system.
#
# To understand how the build system works and how to modify it, see
#      http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
#      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
#
# -----------------------------------------------------------------------------


# Build a perl script.  Invoke like this:
#
# driver/mangler_PERL_SRC = ghc-asm.lprl
# driver/mangler_dist_PROG = ghc-asm
#
# $(eval $(call build-perl,driver/mangler,dist))

define build-perl
$(call trace, build-perl($1,$2))
# $1 = dir
# $2 = distdir

ifeq "$$($1_$2_TOPDIR)" "YES"
$1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
else
$1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
endif

$(call all-target,$1_$2,$$($1_$2_INPLACE))

$(call clean-target,$1,$2,$1/$2 $$($1_$2_INPLACE))
.PHONY: clean_$1
clean_$1 : clean_$1_$2

# INPLACE_BIN etc. might be empty if we're cleaning
ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
ifneq "$$(BINDIST)" "YES"
$1/$2/$$($1_$2_PROG).prl: $1/$$($1_PERL_SRC) $$(UNLIT) | $$$$(dir $$$$@)/.
	"$$(UNLIT)" $$(UNLIT_OPTS) $$< $$@
endif

$1/$2/$$($1_$2_PROG): $1/$2/$$($1_$2_PROG).prl
	"$$(RM)" $$(RM_OPTS) $$@
	echo '#!$$(PERL)'                                  >> $$@
	echo '$$$$TARGETPLATFORM  = "$$(TARGETPLATFORM)";' >> $$@
	echo '$$$$TABLES_NEXT_TO_CODE  = "$(GhcEnableTablesNextToCode)";' >> $$@
	cat $$<                                            >> $$@

$$($1_$2_INPLACE): $1/$2/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
	"$$(CP)" $$< $$@
	$$(EXECUTABLE_FILE) $$@

ifneq "$$($1_$2_INSTALL_IN)" ""
BINDIST_PERL_SOURCES += $1/$2/$$($1_$2_PROG).prl

install: install_$1_$2

.PHONY: install_$1_$2
install_$1_$2: $1/$2/$$($1_$2_PROG)
	$$(call INSTALL_DIR,"$$($1_$2_INSTALL_IN)")
	$$(call INSTALL_SCRIPT,$$(INSTALL_OPTS),$$<,"$$($1_$2_INSTALL_IN)")
endif
endif

endef