root/rules/build-prog.mk

Revision fe05c0224ec00ff71742e62674a47f346cd1b3e3, 5.6 KB (checked in by Ian Lynagh <igloo@…>, 6 months ago)

Remove some unnecessary touch's

They made a dependency cycle in the rules used to build the touch
program on Windows.

  • Property mode set to 100644
Line 
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 program.  Invoke like this:
15#
16# utils/genapply_MODULES = Main
17# utils/genapply_HC_OPTS = -package Cabal
18# utils/genapply_dist_PROG = genapply
19#
20# $(eval $(call build-prog,utils/genapply,dist-install,1))
21
22define build-prog
23$(call trace, build-prog($1,$2,$3))
24$(call profStart, build-prog($1,$2,$3))
25# $1 = dir
26# $2 = distdir
27# $3 = GHC stage to use (0 == bootstrapping compiler)
28
29ifneq "$$(CLEANING)" "YES"
30ifeq "$$($1_$2_PROG)" ""
31$$(error $1_$2_PROG is not set)
32endif
33endif
34
35ifeq "$$(findstring $3,0 1 2)" ""
36$$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
37endif
38
39$(call clean-target,$1,$2,$1/$2)
40
41ifneq "$$($1_$2_NOT_NEEDED)" "YES"
42$$(eval $$(call build-prog-helper,$1,$2,$3))
43endif
44$(call profEnd, build-prog($1,$2,$3))
45endef
46
47
48define build-prog-helper
49# $1 = dir
50# $2 = distdir
51# $3 = GHC stage to use (0 == bootstrapping compiler)
52
53ifeq "$$($1_USES_CABAL)" "YES"
54$1_$2_USES_CABAL = YES
55endif
56
57$(call package-config,$1,$2,$3)
58
59$1_$2_depfile_base = $1/$2/build/.depend
60
61ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
62ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
63$1_$2_INPLACE = $$(error $1_$2 should not be installed inplace, but INPLACE var evaluated)
64else
65$1_$2_INPLACE =
66endif
67else
68# Where do we install the inplace version?
69ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
70$1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
71else
72ifeq "$$($1_$2_TOPDIR)" "YES"
73$1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
74else
75$1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
76endif
77endif
78endif
79
80ifeq "$$($1_$2_USES_CABAL)" "YES"
81$(call build-package-data,$1,$2,$3)
82ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
83ifeq "$3" "0"
84include $1/$2/package-data.mk
85else ifeq "$(phase)" "final"
86include $1/$2/package-data.mk
87endif
88endif
89endif
90
91$(call all-target,$1,all_$1_$2)
92$(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
93
94# INPLACE_BIN might be empty if we're distcleaning
95ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
96ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
97$$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
98        "$$(CP)" -p $$< $$@
99endif
100endif
101
102$(call shell-wrapper,$1,$2)
103
104$1_$2_WAYS = v
105
106$(call hs-sources,$1,$2)
107$(call c-sources,$1,$2)
108
109# --- IMPLICIT RULES
110
111# Just the 'v' way for programs
112$(call distdir-way-opts,$1,$2,v,$3)
113
114ifeq "$3" "0"
115# For stage 0, we use GHC to compile C sources so that we don't have to
116# worry about where the RTS header files are
117$(call c-suffix-rules,$1,$2,v,YES)
118else
119ifeq "$$($1_$2_UseGhcForCC)" "YES"
120$(call c-suffix-rules,$1,$2,v,YES)
121else
122$(call c-suffix-rules,$1,$2,v,NO)
123endif
124endif
125
126$(call hs-suffix-rules,$1,$2,v)
127$$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
128  $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
129
130$(call c-objs,$1,$2,v)
131$(call hs-objs,$1,$2,v)
132
133$1_$2_LINK_WITH_GCC = NO
134ifeq "$$(BootingFromHc)" "YES"
135$1_$2_LINK_WITH_GCC = YES
136endif
137
138ifeq "$$($1_$2_v_HS_OBJS)" ""
139# We don't want to link the GHC RTS into C-only programs. There's no
140# point, and it confuses the test that all GHC-compiled programs
141# were compiled with the right GHC.
142$1_$2_GHC_LD_OPTS = -no-auto-link-packages -no-hs-main
143endif
144
145ifneq "$$(BINDIST)" "YES"
146# The quadrupled $'s here are because the _v_LIB variables aren't
147# necessarily set when this part of the makefile is read
148$1/$2/build/tmp/$$($1_$2_PROG) : \
149    $$(foreach dep,$$($1_$2_DEP_NAMES),\
150        $$(if $$(filter ghc,$$(dep)),\
151            $(if $(filter 0,$3),$$(compiler_stage1_v_LIB),\
152            $(if $(filter 1,$3),$$(compiler_stage2_v_LIB),\
153            $(if $(filter 2,$3),$$(compiler_stage2_v_LIB),\
154            $$(error Bad build stage)))),\
155        $$$$(libraries/$$(dep)_dist-$(if $(filter 0,$3),boot,install)_v_LIB)))
156
157ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
158$1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
159        "$$($1_$2_HC)" -o $$@ $$($1_$2_v_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_GHC_LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
160else
161$1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
162        "$$($1_$2_CC)" -o $$@ $$($1_$2_v_ALL_CC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$($1_$2_v_EXTRA_CC_OPTS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
163endif
164
165# Note [lib-depends] if this program is built with stage1 or greater, we
166# need to depend on the libraries too.  NB. since $(ALL_STAGE1_LIBS) and
167# $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
168# been included, this introduces an ordering dependency.
169ifneq "$$(CLEANING)" "YES"
170ifneq "$3" "0"
171ifneq "$$($1_$2_HS_SRCS)" ""
172ifeq "$$(strip $$(ALL_STAGE1_LIBS))" ""
173$$(error ordering failure in $1 ($2): ALL_STAGE1_LIBS is empty)
174endif
175endif
176$1/$2/build/tmp/$$($1_$2_PROG) : $$(ALL_STAGE1_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
177endif
178endif
179endif
180
181ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
182$(call all-target,$1_$2,$$($1_$2_INPLACE))
183endif
184$(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
185
186ifeq "$$($1_$2_INSTALL)" "YES"
187ifeq "$$($1_$2_TOPDIR)" "YES"
188INSTALL_TOPDIRS += $1/$2/build/tmp/$$($1_$2_PROG)
189else
190INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
191endif
192endif
193
194$(call dependencies,$1,$2,$3)
195
196endef
Note: See TracBrowser for help on using the browser.