1 #**************************************************************************
2 #* *
3 #* OCaml *
4 #* *
5 #* Xavier Leroy, projet Cristal, INRIA Rocquencourt *
6 #* *
7 #* Copyright 1999 Institut National de Recherche en Informatique et *
8 #* en Automatique. *
9 #* *
10 #* All rights reserved. This file is distributed under the terms of *
11 #* the GNU Lesser General Public License version 2.1, with the *
12 #* special exception on linking described in the file LICENSE. *
13 #* *
14 #**************************************************************************
15
16 # The Makefile for generating the configuration file
17
18 ROOTDIR = ..
19
20 include $(ROOTDIR)/Makefile.config
21
22 ifeq "$(UNIX_OR_WIN32)" "win32"
23 ifeq "$(wildcard $(ROOTDIR)/flexdll/Makefile)" ""
24 FLEXDLL_DIR =
25 else
26 FLEXDLL_DIR = $(if $(wildcard $(ROOTDIR)/flexdll/flexdll_*.$(O)),+flexdll)
27 endif
28 else
29 FLEXDLL_DIR =
30 endif
31
32 FLEXLINK_FLAGS ?=
33
34 # Escape special characters in the argument string.
35 # There are four characters that need escaping:
36 # - backslash and ampersand, which are special in the replacement text
37 # of sed's "s" command
38 # - exclamation mark, which is the delimiter we use for sed's "s" command
39 # - single quote, which interferes with shell quoting. We are inside
40 # single quotes already, so the proper escape is '\''
41 # (close single quotation, insert single quote character,
42 # reopen single quotation).
43 SED_ESCAPE=$(subst ','\'',$(subst !,\!,$(subst &,\&,$(subst \,\\,$1))))
44
45 # Escape special characters in an OCaml string literal "..."
46 # There are two: backslash and double quote.
47 OCAML_ESCAPE=$(subst ",\",$(subst \,\\,$1))
48
49 # SUBST generates the sed substitution for the variable *named* in $1
50 SUBST=-e 's!%%$1%%!$(call SED_ESCAPE,$($1))!'
51
52 # SUBST_STRING does the same, for a variable that occurs between "..."
53 # in config.mlp. Thus, backslashes and double quotes must be escaped.
54 SUBST_STRING=-e 's!%%$1%%!$(call SED_ESCAPE,$(call OCAML_ESCAPE,$($1)))!'
55
56 # SUBST_QUOTE does the same, adding OCaml quotes around non-empty strings
57 # (see FLEXDLL_DIR which must empty if FLEXDLL_DIR is empty but an OCaml
58 # string otherwise)
59 SUBST_QUOTE2=\
60 -e 's!%%$1%%!$(if $2,$(call SED_ESCAPE,"$(call OCAML_ESCAPE,$2)"))!'
61 SUBST_QUOTE=$(call SUBST_QUOTE2,$1,$($1))
62
63 FLEXLINK_LDFLAGS=$(if $(OC_LDFLAGS), -link "$(OC_LDFLAGS)")
64
65 config.ml: config.mlp $(ROOTDIR)/Makefile.config Makefile
66 sed $(call SUBST,AFL_INSTRUMENT) \
67 $(call SUBST,ARCH) \
68 $(call SUBST_STRING,ARCMD) \
69 $(call SUBST_STRING,ASM) \
70 $(call SUBST,ASM_CFI_SUPPORTED) \
71 $(call SUBST_STRING,BYTECCLIBS) \
72 $(call SUBST_STRING,CC) \
73 $(call SUBST_STRING,CCOMPTYPE) \
74 $(call SUBST_STRING,OUTPUTOBJ) \
75 $(call SUBST_STRING,EXT_ASM) \
76 $(call SUBST_STRING,EXT_DLL) \
77 $(call SUBST_STRING,EXE) \
78 $(call SUBST_STRING,EXT_LIB) \
79 $(call SUBST_STRING,EXT_OBJ) \
80 $(call SUBST,FLAMBDA) \
81 $(call SUBST,WITH_FLAMBDA_INVARIANTS) \
82 $(call SUBST_STRING,FLEXLINK_FLAGS) \
83 $(call SUBST_QUOTE,FLEXDLL_DIR) \
84 $(call SUBST,HOST) \
85 $(call SUBST_STRING,LIBDIR) \
86 $(call SUBST,LIBUNWIND_AVAILABLE) \
87 $(call SUBST,LIBUNWIND_LINK_FLAGS) \
88 $(call SUBST_STRING,MKDLL) \
89 $(call SUBST_STRING,MKEXE) \
90 $(call SUBST_STRING,FLEXLINK_LDFLAGS) \
91 $(call SUBST_STRING,MKMAINDLL) \
92 $(call SUBST,MODEL) \
93 $(call SUBST_STRING,NATIVECCLIBS) \
94 $(call SUBST_STRING,OCAMLC_CFLAGS) \
95 $(call SUBST_STRING,OCAMLC_CPPFLAGS) \
96 $(call SUBST_STRING,OCAMLOPT_CFLAGS) \
97 $(call SUBST_STRING,OCAMLOPT_CPPFLAGS) \
98 $(call SUBST_STRING,PACKLD) \
99 $(call SUBST,PROFINFO_WIDTH) \
100 $(call SUBST_STRING,RANLIBCMD) \
101 $(call SUBST,FORCE_SAFE_STRING) \
102 $(call SUBST,DEFAULT_SAFE_STRING) \
103 $(call SUBST,WINDOWS_UNICODE) \
104 $(call SUBST,SUPPORTS_SHARED_LIBRARIES) \
105 $(call SUBST,SYSTEM) \
106 $(call SUBST,SYSTHREAD_SUPPORT) \
107 $(call SUBST,TARGET) \
108 $(call SUBST,WITH_FRAME_POINTERS) \
109 $(call SUBST,WITH_PROFINFO) \
110 $(call SUBST,WITH_SPACETIME) \
111 $(call SUBST,ENABLE_CALL_COUNTS) \
112 $(call SUBST,FLAT_FLOAT_ARRAY) \
113 $(call SUBST,FUNCTION_SECTIONS) \
114 $(call SUBST,CC_HAS_DEBUG_PREFIX_MAP) \
115 $(call SUBST,AS_HAS_DEBUG_PREFIX_MAP) \
116 $< > $@
117
118 # Test for the substitution functions above
119
120 ALLCHARS= \
121 !"\#\$\%&'()*+,-./ \
122 0123456789:;<=>? \
123 @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ \
124 `abcdefghijklmnopqrstuvwxyz{|}~
125
126 TMPFILE=testdata.tmp
127 TMPSCRIPT=ocamlscript.tmp
128
129 test-subst:
130 $(file >$(TMPFILE),$(ALLCHARS))
131 echo '%%ALLCHARS%%' | sed $(call SUBST,ALLCHARS) | cmp $(TMPFILE) -
132 @rm $(TMPFILE)
133 @echo "Test passed"
134
135 # This test assumes there is a working OCaml in the path
136
137 test-subst-string:
138 $(file >$(TMPFILE),$(ALLCHARS))
139 echo 'print_string "%%ALLCHARS%%"; print_newline();;' \
140 | sed $(call SUBST_STRING,ALLCHARS) > $(TMPSCRIPT) && \
141 ocaml $(TMPSCRIPT) | cmp $(TMPFILE) -
142 @rm $(TMPFILE) $(TMPSCRIPT)
143 @echo "Test passed"
144