Use /usr/bin/test if it exists, and fix test syntax.
[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 # On Solaris, the builtin test doesn't support -nt, you have to use
55 # /usr/bin/test. On MSYS, however, /usr/bin/test does not exist. How
56 # nice.
57 TEST=$(if $(wildcard /usr/bin/test),/usr/bin/test,test)
58
59 # configure touches certain files even if they haven't changed. This
60 # can mean a lot of unnecessary recompilation after a re-configure, so
61 # here we cache the old versions of these files so we can restore the
62 # timestamps.
63 #
64 define check-configure-file
65 # $1 = file
66 if $(TEST) ! -f $1.old; then \
67 echo "backing up $1"; \
68 cp $1 $1.old; \
69 touch -r $1 $1.old; \
70 else \
71 if $(TEST) $1 -nt $1.old; then \
72 if cmp $1 $1.old; then \
73 echo "$1 has been touched, but has not changed"; \
74 touch -r $1.old $1; \
75 else \
76 echo "$1 has changed"; \
77 cp $1 $1.old; \
78 touch -r $1 $1.old; \
79 fi \
80 fi \
81 fi
82 endef
83
84 # NB. not the same as saying '%: ...', which doesn't do the right thing:
85 # it does nothing if we specify a target that already exists.
86 .PHONY: $(REALGOALS)
87 $(REALGOALS) all:
88 @$(call check-configure-file,mk/config.mk)
89 @$(call check-configure-file,mk/project.mk)
90 @$(call check-configure-file,compiler/ghc.cabal)
91
92 @echo "===--- updating makefiles phase 0"
93 $(MAKE) -r --no-print-directory -f ghc.mk phase=0 just-makefiles
94 ifneq "$(OMIT_PHASE_1)" "YES"
95 @echo "===--- updating makefiles phase 1"
96 $(MAKE) -r --no-print-directory -f ghc.mk phase=1 just-makefiles
97 endif
98 ifneq "$(OMIT_PHASE_2)" "YES"
99 @echo "===--- updating makefiles phase 2"
100 $(MAKE) -r --no-print-directory -f ghc.mk phase=2 just-makefiles
101 endif
102 ifneq "$(OMIT_PHASE_3)" "YES"
103 @echo "===--- updating makefiles phase 3"
104 $(MAKE) -r --no-print-directory -f ghc.mk phase=3 just-makefiles
105 endif
106 @echo "===--- finished updating makefiles"
107 $(MAKE) -r --no-print-directory -f ghc.mk $@
108
109 binary-dist:
110 ifeq "$(mingw32_TARGET_OS)" "1"
111 $(MAKE) -r --no-print-directory -f ghc.mk windows-binary-dist
112 $(MAKE) -r --no-print-directory -f ghc.mk windows-installer
113 else
114 rm -f bindist-list
115 $(MAKE) -r --no-print-directory -f ghc.mk bindist BINDIST=YES
116 $(MAKE) -r --no-print-directory -f ghc.mk binary-dist
117 endif
118
119 clean distclean maintainer-clean:
120 $(MAKE) -r --no-print-directory -f ghc.mk $@ CLEANING=YES
121 test ! -d testsuite || $(MAKE) -C testsuite $@
122
123 $(filter clean_%, $(MAKECMDGOALS)) : clean_% :
124 $(MAKE) -r --no-print-directory -f ghc.mk $@ CLEANING=YES
125
126 bootstrapping-files show:
127 $(MAKE) -r --no-print-directory -f ghc.mk $@
128
129 ifeq "$(darwin_TARGET_OS)" "1"
130 framework-pkg:
131 $(MAKE) -C distrib/MacOS $@
132 endif
133
134 # If the user says 'make A B', then we don't want to invoke two
135 # instances of the rule above in parallel:
136 .NOTPARALLEL:
137
138 endif