Avoid unnecessary recompilation after ./configure (helps #3228)
[ghc.git] / Makefile
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 ifeq "$(wildcard distrib/)" ""
14
15 # We're in a bindist
16
17 .PHONY: default
18 default:
19 @echo 'Run "make install" to install'
20 @false
21
22 .PHONY: install
23 install:
24 $(MAKE) -r --no-print-directory -f ghc.mk install BINDIST=YES NO_INCLUDE_DEPS=YES
25
26 .PHONY: show
27 show:
28 $(MAKE) -r --no-print-directory -f ghc.mk $@
29
30 else
31
32 default : all
33 @:
34
35 # For help, type 'make help'
36 .PHONY: help
37 help :
38 @cat MAKEHELP
39
40 ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
41 -include mk/config.mk
42 else
43 include mk/config.mk
44 ifeq "$(ProjectVersion)" ""
45 $(error Please run ./configure first)
46 endif
47 endif
48
49 include mk/custom-settings.mk
50
51 # No need to update makefiles for these targets:
52 REALGOALS=$(filter-out bootstrapping-files framework-pkg clean clean_% distclean maintainer-clean show help,$(MAKECMDGOALS))
53
54 # configure touches certain files even if they haven't changed. This
55 # can mean a lot of unnecessary recompilation after a re-configure, so
56 # here we cache the old versions of these files so we can restore the
57 # timestamps.
58 #
59 define check-configure-file
60 # $1 = file
61 if ! test -f $1.old; then \
62 echo "backing up $1"; \
63 cp $1 $1.old; \
64 touch -r $1 $1.old; \
65 else \
66 if test $1 -nt $1.old; then \
67 if cmp $1 $1.old; then \
68 echo "$1 has been touched, but has not changed"; \
69 touch -r $1.old $1; \
70 else \
71 echo "$1 has changed"; \
72 cp $1 $1.old; \
73 touch -r $1 $1.old; \
74 fi \
75 fi \
76 fi
77 endef
78
79 # NB. not the same as saying '%: ...', which doesn't do the right thing:
80 # it does nothing if we specify a target that already exists.
81 .PHONY: $(REALGOALS)
82 $(REALGOALS) all:
83 @$(call check-configure-file,mk/config.mk)
84 @$(call check-configure-file,mk/project.mk)
85 @$(call check-configure-file,compiler/ghc.cabal)
86
87 @echo "===--- updating makefiles phase 0"
88 $(MAKE) -r --no-print-directory -f ghc.mk phase=0 just-makefiles
89 ifneq "$(OMIT_PHASE_1)" "YES"
90 @echo "===--- updating makefiles phase 1"
91 $(MAKE) -r --no-print-directory -f ghc.mk phase=1 just-makefiles
92 endif
93 ifneq "$(OMIT_PHASE_2)" "YES"
94 @echo "===--- updating makefiles phase 2"
95 $(MAKE) -r --no-print-directory -f ghc.mk phase=2 just-makefiles
96 endif
97 ifneq "$(OMIT_PHASE_3)" "YES"
98 @echo "===--- updating makefiles phase 3"
99 $(MAKE) -r --no-print-directory -f ghc.mk phase=3 just-makefiles
100 endif
101 @echo "===--- finished updating makefiles"
102 $(MAKE) -r --no-print-directory -f ghc.mk $@
103
104 binary-dist:
105 ifeq "$(mingw32_TARGET_OS)" "1"
106 $(MAKE) -r --no-print-directory -f ghc.mk windows-binary-dist
107 $(MAKE) -r --no-print-directory -f ghc.mk windows-installer
108 else
109 rm -f bindist-list
110 $(MAKE) -r --no-print-directory -f ghc.mk bindist BINDIST=YES
111 $(MAKE) -r --no-print-directory -f ghc.mk binary-dist
112 endif
113
114 clean distclean maintainer-clean:
115 $(MAKE) -r --no-print-directory -f ghc.mk $@ CLEANING=YES
116 test ! -d testsuite || $(MAKE) -C testsuite $@
117
118 $(filter clean_%, $(MAKECMDGOALS)) : clean_% :
119 $(MAKE) -r --no-print-directory -f ghc.mk $@ CLEANING=YES
120
121 bootstrapping-files show:
122 $(MAKE) -r --no-print-directory -f ghc.mk $@
123
124 ifeq "$(darwin_TARGET_OS)" "1"
125 framework-pkg:
126 $(MAKE) -C distrib/MacOS $@
127 endif
128
129 # If the user says 'make A B', then we don't want to invoke two
130 # instances of the rule above in parallel:
131 .NOTPARALLEL:
132
133 endif