Skip to content

Commit 01a46f6

Browse files
committed
Allow building using native GNU make
Avoid the use of sed when building Compat.ml and use the NUL device.
1 parent 56fdf1f commit 01a46f6

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
msvs-detect text eol=lf
44
checkenv text eol=lf
5+
Compat.cmd text eol=crlf

Compat.cmd

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@setlocal
2+
@echo off
3+
4+
:: This can be done as (slightly long) one-liner, but embedded in Makefile it
5+
:: encodes the knowledge that GNU make uses batch files internally, which is a
6+
:: bit brittle. findstr /N is a trick to allow blank lines to be included. More
7+
:: subtly, it allows tagged blank lines to be detected.
8+
for /f "tokens=1* delims=:" %%a in ('findstr /N /R "^" %2') do (
9+
rem Handle blank lines in the file
10+
if "%%b" equ "" (
11+
echo.
12+
) else (
13+
for /f "tokens=1* delims=@" %%l in ("%%b") do (
14+
rem If %%l == %%b then the line didn't contain @ - we already know the
15+
rem line isn't blank.
16+
if "%%l" equ "%%b" (
17+
echo %%l
18+
) else (
19+
if %1 lss %%l00 (
20+
if "%%m" equ "" (
21+
echo.
22+
) else (
23+
echo %%m
24+
)
25+
)
26+
)
27+
)
28+
)
29+
)

Makefile

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,28 @@
88
VERSION = 0.42
99
all: flexlink.exe support
1010

11-
OCAML_CONFIG_FILE=$(shell cygpath -ad "$(shell ocamlopt -where 2>/dev/null)/Makefile.config" 2>/dev/null)
11+
export override OCAML_DETECT_CMD = detect
12+
SHELL_IS_CMD := \
13+
$(if $(filter %OCAML_DETECT_CMD%, $(shell echo %OCAML_DETECT_CMD%)),,true)
14+
unexport OCAML_DETECT_CMD
15+
undefine DETECT_WINDOWS_SHELL
16+
17+
NULL_DEVICE := $(if $(SHELL_IS_CMD), NUL, /dev/null)
18+
19+
ifeq ($(SHELL_IS_CMD),)
20+
RM_F = rm -f $(1)
21+
TOUCH = touch
22+
else
23+
RM_F = $(if $(wildcard $(1)),del /f $(subst /,\,$(wildcard ($1))))
24+
TOUCH = type NUL >
25+
endif
26+
27+
OCAML_CONFIG_FILE=$(shell cygpath -ad "$(shell ocamlopt -where 2>$(NULL_DEVICE))/Makefile.config" 2>$(NULL_DEVICE))
1228
include $(OCAML_CONFIG_FILE)
1329
OCAMLOPT=ocamlopt
1430
EMPTY=
1531
SPACE=$(EMPTY) $(EMPTY)
16-
OCAML_VERSION:=$(firstword $(subst ~, ,$(subst +, ,$(shell $(OCAMLOPT) -version 2>/dev/null))))
32+
OCAML_VERSION:=$(firstword $(subst ~, ,$(subst +, ,$(shell $(OCAMLOPT) -version 2>$(NULL_DEVICE)))))
1733
ifeq ($(OCAML_VERSION),)
1834
OCAML_VERSION:=0
1935
COMPAT_VERSION:=0
@@ -148,8 +164,8 @@ build_mingw64: flexdll_mingw64.o flexdll_initer_mingw64.o
148164
OBJS = version.ml Compat.ml coff.ml cmdline.ml create_dll.ml reloc.ml
149165

150166
COMPILER-$(COMPAT_VERSION):
151-
rm -f COMPILER-*
152-
touch COMPILER-$(COMPAT_VERSION)
167+
$(call RM_F, COMPILER-*)
168+
$(TOUCH) COMPILER-$(COMPAT_VERSION)
153169

154170
test_ver = $(shell if [ $(COMPAT_VERSION) -ge $(1) ] ; then echo ge ; fi)
155171

@@ -163,11 +179,15 @@ COMPAT_LEVEL = $(eval COMPAT_LEVEL := \
163179
$$(if $$(call test_ver,40700),407)))$(COMPAT_LEVEL)
164180

165181
Compat.ml: Compat.ml.in COMPILER-$(COMPAT_VERSION)
182+
ifeq ($(SHELL_IS_CMD),)
166183
sed -e '$(if $(COMPAT_LEVEL),/^$(subst $(SPACE),@\|^,$(COMPAT_LEVEL))@/d;)s/^[0-9]*@//' $< > $@
184+
else
185+
Compat.cmd $(COMPAT_VERSION) $< > $@
186+
endif
167187

168188
flexlink.exe: $(OBJS) $(RES)
169189
@echo Building flexlink.exe with TOOLCHAIN=$(TOOLCHAIN) for OCaml $(OCAML_VERSION)
170-
rm -f flexlink.exe
190+
$(call RM_F, flexlink.exe)
171191
$(RES_PREFIX) $(OCAMLOPT) -o flexlink.exe $(LINKFLAGS) $(OBJS)
172192

173193
version.res: version.rc

0 commit comments

Comments
 (0)