[project @ 2005-10-26 10:23:47 by simonpj]
[ghc-hetmet.git] / ghc / includes / Makefile
1 # -----------------------------------------------------------------------------
2
3 TOP = ..
4 include $(TOP)/mk/boilerplate.mk
5
6 #
7 # All header files
8 #
9 H_FILES = $(filter-out gmp.h,$(wildcard *.h)) gmp.h
10
11 #
12 # Options -- if we're building unregisterised, add a couple of -D's
13 #
14 ifeq "$(GhcUnregisterised)" "YES"
15 SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
16 endif
17
18 SRC_CC_OPTS += -I. -I../rts
19
20 #
21 # Header file built from the configure script's findings
22 #
23 H_CONFIG   = ghcautoconf.h
24 H_PLATFORM = ghcplatform.h
25
26 boot :: gmp.h
27
28 all :: $(H_CONFIG) $(H_PLATFORM)
29
30 # gmp.h is copied from the GMP directory
31 gmp.h : $(FPTOOLS_TOP)/ghc/rts/gmp/gmp.h
32         $(CP) $< $@
33
34 # The fptools configure script creates the configuration header file and puts it
35 # in fptools/mk/config.h. We copy it down to here (without any PACKAGE_FOO
36 # definitions to avoid clashes), prepending some make variables specifying cpp
37 # platform variables.
38
39 ifneq "$(TARGETPLATFORM)"  "$(HOSTPLATFORM)"
40
41 $(H_CONFIG) :
42         @echo "*** Cross-compiling: please copy $(H_CONFIG) from the target system"
43         @exit 1
44
45 else
46
47 $(H_CONFIG) : $(FPTOOLS_TOP)/mk/config.h $(FPTOOLS_TOP)/mk/config.mk
48
49 $(H_CONFIG) : Makefile
50         @echo "#ifndef __GHCAUTOCONF_H__"  >$@
51         @echo "#define __GHCAUTOCONF_H__" >>$@
52 #       Turn '#define PACKAGE_FOO "blah"' into '/* #undef PACKAGE_FOO */'.
53         @sed 's,^\([     ]*\)#[  ]*define[       ][      ]*\(PACKAGE_[A-Z]*\)[   ][     ]*".*".*$$,\1/* #undef \2 */,' $(FPTOOLS_TOP)/mk/config.h >> $@
54         @echo "#endif /* __GHCAUTOCONF_H__ */"          >> $@
55         @echo "Done."
56
57 endif
58
59 $(H_PLATFORM) : Makefile
60         @echo "Creating $@..."
61         @$(RM) $@
62         @echo "#ifndef __GHCPLATFORM_H__"  >$@
63         @echo "#define __GHCPLATFORM_H__" >>$@
64         @echo >> $@
65         @echo "#define BuildPlatform_TYPE  $(HostPlatform_CPP)" >> $@
66         @echo "#define HostPlatform_TYPE   $(TargetPlatform_CPP)" >> $@
67         @echo >> $@
68         @echo "#define $(HostPlatform_CPP)_BUILD  1" >> $@
69         @echo "#define $(TargetPlatform_CPP)_HOST  1" >> $@
70         @echo >> $@
71         @echo "#define $(HostArch_CPP)_BUILD_ARCH  1" >> $@
72         @echo "#define $(TargetArch_CPP)_HOST_ARCH  1" >> $@
73         @echo "#define BUILD_ARCH  \"$(HostArch_CPP)\"" >> $@
74         @echo "#define HOST_ARCH  \"$(TargetArch_CPP)\"" >> $@
75         @echo >> $@
76         @echo "#define $(HostOS_CPP)_BUILD_OS  1" >> $@
77         @echo "#define $(TargetOS_CPP)_HOST_OS  1" >> $@
78         @echo "#define BUILD_OS  \"$(HostOS_CPP)\"" >> $@
79         @echo "#define HOST_OS  \"$(TargetOS_CPP)\"" >> $@
80 ifeq "$(HostOS_CPP)" "irix"
81         @echo "#ifndef $(IRIX_MAJOR)_HOST_OS" >> $@  
82         @echo "#define $(IRIX_MAJOR)_HOST_OS  1" >> $@  
83         @echo "#endif" >> $@  
84 endif
85         @echo >> $@
86         @echo "#define $(HostVendor_CPP)_BUILD_VENDOR  1" >> $@
87         @echo "#define $(TargetVendor_CPP)_HOST_VENDOR  1" >> $@
88         @echo "#define BUILD_VENDOR  \"$(HostVendor_CPP)\"" >> $@
89         @echo "#define HOST_VENDOR  \"$(TargetVendor_CPP)\"" >> $@
90         @echo >> $@
91         @echo "/* These TARGET macros are for backwards compatibily... DO NOT USE! */" >> $@
92         @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
93         @echo "#define $(TargetPlatform_CPP)_TARGET  1" >> $@
94         @echo "#define $(TargetArch_CPP)_TARGET_ARCH  1" >> $@
95         @echo "#define TARGET_ARCH  \"$(TargetArch_CPP)\"" >> $@
96         @echo "#define $(TargetOS_CPP)_TARGET_OS  1" >> $@  
97         @echo "#define TARGET_OS  \"$(TargetOS_CPP)\"" >> $@
98         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
99         @echo >> $@
100         @echo "#endif /* __GHCPLATFORM_H__ */"          >> $@
101         @echo "Done."
102
103 # ---------------------------------------------------------------------------
104 # Make DerivedConstants.h for the compiler
105
106 all :: DerivedConstants.h
107
108 ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
109
110 DerivedConstants.h :
111         @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
112         @exit 1
113
114 else
115
116 mkDerivedConstants.c : $(H_CONFIG)
117
118 mkDerivedConstantsHdr : mkDerivedConstants.o
119         $(CC) -o $@ $(CC_OPTS) $(LD_OPTS) mkDerivedConstants.o
120
121 DerivedConstants.h : mkDerivedConstantsHdr
122         ./mkDerivedConstantsHdr >$@
123
124 endif
125
126 CLEAN_FILES += mkDerivedConstantsHdr$(exeext) DerivedConstants.h
127
128 # -----------------------------------------------------------------------------
129 #
130
131 all :: GHCConstants.h
132
133 ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
134
135 GHCConstants.h :
136         @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
137         @exit 1
138
139 else
140
141 mkGHCConstants : mkGHCConstants.o
142         $(CC) -o $@ $(CC_OPTS) $(LD_OPTS) mkGHCConstants.o
143
144 mkGHCConstants.o : mkDerivedConstants.c
145         $(CC) -o $@ $(CC_OPTS) -c $<  -DGEN_HASKELL
146
147 GHCConstants.h : mkGHCConstants
148         ./mkGHCConstants >$@
149
150 endif
151
152 CLEAN_FILES += mkGHCConstants$(exeext) GHCConstants.h
153
154 # ---------------------------------------------------------------------------
155 # boot setup:
156 #
157 # Need config.h to make dependencies in the runtime system source.
158 #
159 boot :: all
160
161 #
162 # Install all header files
163 #
164 # Hackily set the install destination here:
165 #
166 # Note: we keep per-platform copies of all the include files
167 # (ditto for interface files). This is not *really* needed, but
168 # it gives (perhaps) a cleaner binary dist structure..might change.
169 #
170 override datadir:=$(libdir)/include
171 INSTALL_DATAS += $(H_FILES) $(H_CONFIG) $(H_PLATFORM)
172
173 #
174 # `make clean' settings:
175 #
176 CLEAN_FILES += $(H_CONFIG) $(H_PLATFORM)
177
178 #
179 # Finally, slurp in the standard targets.
180 #
181 include $(TOP)/mk/target.mk