Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Fix prefix and other stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Apr 15, 2014
1 parent a37f695 commit e04f84b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
46 changes: 28 additions & 18 deletions Makefile
Expand Up @@ -10,6 +10,15 @@ BINARY_DIR := $(CURDIR)/binary
INSTALL_DIR := # install at root
INSTALL_PREFIX := /usr
PATH := $(PATH):$(CURDIR)/$(BUILD_DIR)/$(FLEXDLL_DIR)
SED := $(shell which gsed || which sed)

ifeq ($(which x86_64-w64-mingw32-gcc),)
FLEX_TARGET := build_mingw
FLEX_FILES := flexdll_mingw.o flexdll_initer_mingw.o
else
FLEX_TARGET := build_mingw build_mingw64
FLEX_FILES := flexdll_mingw.o flexdll_initer_mingw.o flexdll_mingw64.o flexdll_initer_mingw64.o
endif

ifeq ($(MINGW_HOST),i686-w64-mingw32)
BUILD_CC := gcc -m32
Expand All @@ -32,8 +41,9 @@ $(BUILD_DIR):
patches:
mkdir -p patches
find patches.in | grep '.patch' | while read i; do \
sed -e 's#@mingw_host@#$(MINGW_HOST)#g' < $$i > \
`echo $$i | sed -e 's#patches.in#patches#'`; \
$(SED) -e 's#@mingw_host@#$(MINGW_HOST)#g' \
-e 's#@prefix@#$(INSTALL_PREFIX)#g' < $$i > \
`echo $$i | $(SED) -e 's#patches.in#patches#'`; \
done
cp patches.in/series patches

Expand All @@ -46,7 +56,7 @@ stamp-quilt-patches: patches $(BUILD_DIR)
flexdll: stamp-build-flexdll

stamp-build-flexdll: stamp-quilt-patches
cd $(BUILD_DIR)/$(FLEXDLL_DIR) && make flexlink.exe build_mingw build_mingw64
cd $(BUILD_DIR)/$(FLEXDLL_DIR) && make flexlink.exe $(FLEX_TARGET)
rm -f $(BUILD_DIR)/$(FLEXDLL_DIR)/flexlink
ln -s flexlink.exe $(BUILD_DIR)/$(FLEXDLL_DIR)/flexlink
touch stamp-build-flexdll
Expand Down Expand Up @@ -86,10 +96,10 @@ stamp-prepare-cross-build: stamp-patch-mingw-include
cp -f $(BUILD_DIR)/$(OCAML_DIR)/config/s-nt.h $(BUILD_DIR)/$(OCAML_DIR)/config/s.h
# config/Makefile is a custom one which we supply.
rm -f $(BUILD_DIR)/$(OCAML_DIR)/config/Makefile
sed \
-e "s,@prefix@,/usr/$(MINGW_HOST),g" \
-e "s,@bindir@,/usr/$(MINGW_HOST)/bin,g" \
-e "s,@libdir@,/usr/$(MINGW_HOST)/lib/ocaml,g" \
$(SED) \
-e "s,@prefix@,$(INSTALL_PREFIX)/$(MINGW_HOST),g" \
-e "s,@bindir@,$(INSTALL_PREFIX)/$(MINGW_HOST)/bin,g" \
-e "s,@libdir@,$(INSTALL_PREFIX)/$(MINGW_HOST)/lib/ocaml,g" \
-e "s,@otherlibraries@,$(OTHER_LIBS),g" \
-e "s,@arch@,$(ARCH),g" \
-e "s,@mingw_system@,$(MINGW_SYSTEM),g" \
Expand Down Expand Up @@ -206,8 +216,9 @@ binary: stamp-binary-all

stamp-binary-all: stamp-build-findlib
# Install findlib
# Create this dir to please install..
mkdir -p $(BINARY_DIR)$(INSTALL_PREFIX)/lib/ocaml
# Create these dirs to please install..
mkdir -p $(BINARY_DIR)/usr/lib/ocaml
mkdir -p $(BINARY_DIR)/usr/local/lib/ocaml
cd $(BUILD_DIR)/$(FINDLIB_DIR) && make install \
prefix=$(BINARY_DIR)
# Remove ocamlfind binary - we will use the native version.
Expand All @@ -222,29 +233,28 @@ stamp-binary-all: stamp-build-findlib
# Override /etc/%{_mingw_target}-ocamlfind.conf with our
# own version.
rm $(BINARY_DIR)/etc/$(MINGW_HOST)-ocamlfind.conf
sed \
$(SED) \
-e "s,@libdir@,$(INSTALL_PREFIX)/$(MINGW_HOST)/lib,g" \
-e 's,@target@,$(MINGW_HOST),g' \
< files/findlib/ocamlfind.conf.in \
> $(BINARY_DIR)/etc/$(MINGW_HOST)-ocamlfind.conf
# Install flexlink binary
mkdir -p $(BINARY_DIR)$(INSTALL_PREFIX)/lib/flexdll
cd $(BUILD_DIR)/$(FLEXDLL_DIR) && install -m 0755 flexlink.exe flexdll_mingw.o flexdll_initer_mingw.o \
flexdll_mingw64.o flexdll_initer_mingw64.o \
cd $(BUILD_DIR)/$(FLEXDLL_DIR) && install -m 0755 flexlink.exe $(FLEX_FILES) \
$(BINARY_DIR)$(INSTALL_PREFIX)/lib/flexdll
# Nothing in /usr/$(MINGW_HOST)/lib/ocaml should 'a priori' be executable except flexlink.exe..
# Nothing in $(INSTALL_PREFIX)/$(MINGW_HOST)/lib/ocaml should 'a priori' be executable except flexlink.exe..
find $(BINARY_DIR)$(INSTALL_PREFIX)/$(MINGW_HOST)/lib/ocaml -type f -executable | grep -v flexlink.exe | while read i; do \
chmod -x $$i; done
# Now make all script with #!/usr/bin/ocamlrun executables
grep -r -l '#!/usr/$(MINGW_HOST)/bin/ocamlrun' $(BINARY_DIR)$(INSTALL_PREFIX)/bin | while read i; do \
sed -e 's|#!/usr/$(MINGW_HOST)/bin/ocamlrun|#!/usr/bin/$(MINGW_HOST)-ocamlrun|' -i $$i; \
# Now make all script with #!$(INSTALL_PREFIX)/$(MINGW_HOST)/bin/ocamlrun executables
grep -r -l '#!$(INSTALL_PREFIX)/$(MINGW_HOST)/bin/ocamlrun' $(BINARY_DIR)$(INSTALL_PREFIX)/bin | while read i; do \
$(SED) -e 's|#!$(INSTALL_PREFIX)/$(MINGW_HOST)/bin/ocamlrun|#!$(INSTALL_PREFIX)/bin/$(MINGW_HOST)-ocamlrun|' -i $$i; \
chmod +x $$i; done
# Remove rm -rf $(BINARY_DIR)$(INSTALL_PREFIX)/$(MINGW_HOST)/bin: all binaries should be prefixed and living in /usr/bin..
# Remove rm -rf $(BINARY_DIR)$(INSTALL_PREFIX)/$(MINGW_HOST)/bin: all binaries should be prefixed and living in $(INSTALL_PREFIX)/$(MINGW_HOST)/bin..
rm -rf $(BINARY_DIR)$(INSTALL_PREFIX)/$(MINGW_HOST)/bin
touch stamp-binary-all

install: stamp-binary-all
find $(BINARY_DIR) -type f | sed -e s'#$(BINARY_DIR)##g' | while read i; do \
find $(BINARY_DIR) -type f | $(SED) -e s'#$(BINARY_DIR)##g' | while read i; do \
[ -d $(INSTALL_DIR)`dirname $$i` ] || mkdir -p $(INSTALL_DIR)`dirname $$i`; \
cp -f $(BINARY_DIR)/$$i $(INSTALL_DIR)`dirname $$i`; \
done
Expand Down
22 changes: 18 additions & 4 deletions patches.in/flexdll-cross-mingw.patch
@@ -1,7 +1,7 @@
Index: mingw-ocaml/build/flexdll/Makefile
===================================================================
--- mingw-ocaml.orig/build/flexdll/Makefile 2014-01-27 06:33:36.326284060 -0600
+++ mingw-ocaml/build/flexdll/Makefile 2014-01-27 06:33:36.302285732 -0600
--- mingw-ocaml.orig/build/flexdll/Makefile
+++ mingw-ocaml/build/flexdll/Makefile
@@ -1,8 +1,6 @@
VERSION = 0.31
all: flexlink.exe support
Expand All @@ -11,7 +11,7 @@ Index: mingw-ocaml/build/flexdll/Makefile
MINGW_PREFIX = i686-w64-mingw32
MINCC = $(MINGW_PREFIX)-gcc

@@ -45,11 +43,7 @@
@@ -45,11 +43,7 @@ OCAMLOPT = ocamlopt
#OCAMLOPT = FLEXLINKFLAGS=-real-manifest ocamlopt
#LINKFLAGS = unix.cmxa

Expand All @@ -24,7 +24,7 @@ Index: mingw-ocaml/build/flexdll/Makefile

support:
for i in $(CHAINS); do $(MAKE) build_$$i ; done
@@ -62,7 +56,7 @@
@@ -62,7 +56,7 @@ build_mingw64: flexdll_mingw64.o flexdll

OBJS = version.ml coff.ml cmdline.ml create_dll.ml reloc.ml

Expand All @@ -33,3 +33,17 @@ Index: mingw-ocaml/build/flexdll/Makefile
@echo Building flexlink.exe with TOOLCHAIN=$(TOOLCHAIN)
rm -f flexlink.exe
$(OCAMLOPT) -w -105 -o flexlink.exe $(LINKFLAGS) $(OBJS)
Index: mingw-ocaml/build/flexdll/reloc.ml
===================================================================
--- mingw-ocaml.orig/build/flexdll/reloc.ml
+++ mingw-ocaml/build/flexdll/reloc.ml
@@ -28,8 +28,7 @@ let flexdir =
try
let s = Sys.getenv "FLEXDIR" in
if s = "" then raise Not_found else s
- with Not_found ->
- Filename.dirname Sys.executable_name
+ with Not_found -> "@prefix@/@mingw_host@/lib/flexdll"

(* Temporary files *)

6 changes: 3 additions & 3 deletions patches.in/flexdll-fix-get_output1.patch
@@ -1,8 +1,8 @@
Index: mingw-ocaml/build/flexdll/reloc.ml
===================================================================
--- mingw-ocaml.orig/build/flexdll/reloc.ml 2014-01-26 18:40:56.852322925 -0600
+++ mingw-ocaml/build/flexdll/reloc.ml 2014-01-26 18:40:56.828324592 -0600
@@ -82,7 +82,9 @@
--- mingw-ocaml.orig/build/flexdll/reloc.ml
+++ mingw-ocaml/build/flexdll/reloc.ml
@@ -81,7 +81,9 @@ let get_output ?(use_bash = false) cmd =
r

let get_output1 ?use_bash cmd =
Expand Down
12 changes: 6 additions & 6 deletions patches.in/ocaml-fix-opt-link-opts.patch
Expand Up @@ -7,7 +7,7 @@ Index: mingw-ocaml/build/ocaml/otherlibs/win32unix/Makefile.nt
CAMLOBJS=unix.cmo unixLabels.cmo
LINKOPTS=-cclib $(WSOCKLIB)
-LDOPTS=-ldopt $(WSOCKLIB)
+LDOPTS=-L/usr/@mingw_host@/lib -ldopt $(WSOCKLIB)
+LDOPTS=-L@prefix@/@mingw_host@/lib -ldopt $(WSOCKLIB)
EXTRACAMLFLAGS=-nolabels
EXTRACFLAGS=-I../unix
HEADERS=unixsupport.h socketaddr.h
Expand All @@ -19,7 +19,7 @@ Index: mingw-ocaml/build/ocaml/otherlibs/str/Makefile
COBJS=strstubs.$(O)
CLIBNAME=camlstr
CAMLOBJS=str.cmo
+LDOPTS=-L/usr/@mingw_host@/lib
+LDOPTS=-L@prefix@/@mingw_host@/lib

include ../Makefile

Expand All @@ -31,7 +31,7 @@ Index: mingw-ocaml/build/ocaml/otherlibs/num/Makefile
ratio.cmo num.cmo arith_status.cmo
CMIFILES=big_int.cmi nat.cmi num.cmi ratio.cmi arith_status.cmi
COBJS=bng.$(O) nat_stubs.$(O)
+LDOPTS=-L/usr/@mingw_host@/lib
+LDOPTS=-L@prefix@/@mingw_host@/lib

include ../Makefile

Expand All @@ -44,7 +44,7 @@ Index: mingw-ocaml/build/ocaml/otherlibs/win32graph/Makefile.nt
WIN32LIBS=$(call SYSLIB,kernel32) $(call SYSLIB,gdi32) $(call SYSLIB,user32)
LINKOPTS=-cclib "\"$(WIN32LIBS)\""
-LDOPTS=-ldopt "$(WIN32LIBS)"
+LDOPTS=-L/usr/@mingw_host@/lib -ldopt "$(WIN32LIBS)"
+LDOPTS=-L@prefix@/@mingw_host@/lib -ldopt "$(WIN32LIBS)"

include ../Makefile.nt

Expand All @@ -56,7 +56,7 @@ Index: mingw-ocaml/build/ocaml/otherlibs/bigarray/Makefile.nt
COBJS=bigarray_stubs.$(O) mmap_win32.$(O)
CAMLOBJS=bigarray.cmo
HEADERS=bigarray.h
+LDOPTS=-L/usr/@mingw_host@/lib
+LDOPTS=-L@prefix@/@mingw_host@/lib

include ../Makefile.nt

Expand All @@ -68,7 +68,7 @@ Index: mingw-ocaml/build/ocaml/otherlibs/systhreads/Makefile.nt
COMPFLAGS=-w +33 -warn-error A -g
MKLIB=../../boot/ocamlrun ../../tools/ocamlmklib
CFLAGS=-I../../byterun $(EXTRACFLAGS)
+LDOPTS=-L/usr/@mingw_host@/lib
+LDOPTS=-L@prefix@/@mingw_host@/lib

CAMLOBJS=thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo
CMIFILES=$(CAMLOBJS:.cmo=.cmi)
4 changes: 2 additions & 2 deletions patches.in/ocaml-hardcode_mingw_include.patch
Expand Up @@ -5,7 +5,7 @@
let compile_only = ref false (* -c *)
and output_name = ref (None : string option) (* -o *)
-and include_dirs = ref ([] : string list)(* -I *)
+and include_dirs = ref (["/usr/@mingw_host@/lib"] : string list)(* -I *)
+and include_dirs = ref (["@prefix@/@mingw_host@/lib"] : string list)(* -I *)
and no_std_include = ref false (* -nostdlib *)
and print_types = ref false (* -i *)
and make_archive = ref false (* -a *)
Expand All @@ -16,7 +16,7 @@
and c_libs = ref [] (* libs to pass to mksharedlib and ocamlc -cclib *)
and c_opts = ref [] (* options to pass to mksharedlib and ocamlc -ccopt *)
-and ld_opts = ref [] (* options to pass only to the linker *)
+and ld_opts = ref ["-I /usr/@mingw_host@/lib"] (* options to pass only to the linker *)
+and ld_opts = ref ["-I @prefix@/@mingw_host@/lib"] (* options to pass only to the linker *)
and ocamlc = ref (compiler_path "ocamlc")
and ocamlopt = ref (compiler_path "ocamlopt")
and output = ref "a" (* Output name for Caml part of library *)

0 comments on commit e04f84b

Please sign in to comment.