diff --git a/.gitignore b/.gitignore index d281c7b..6cbe0fb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.d *.o *.so +bin _build compile_commands.json deps diff --git a/Makefile b/Makefile index b982251..3358f0d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -REBAR?=./rebar +REBAR?=bin/rebar all: build @@ -16,6 +16,11 @@ distclean: clean build: +ifeq ($(OS),Windows_NT) + ./configure.bat +else + ./configure +endif $(REBAR) compile diff --git a/configure b/configure new file mode 100755 index 0000000..a041cd3 --- /dev/null +++ b/configure @@ -0,0 +1,41 @@ +rootdir="$(cd "${0%/*}" 2>/dev/null; echo "$PWD")" + +install_local_rebar() { + if [ ! -x "${rootdir}/bin/rebar" ]; then + if [ ! -d "${rootdir}/src/rebar" ]; then + git clone --depth 1 https://github.com/apache/couchdb-rebar.git ${rootdir}/src/rebar + fi + make -C ${rootdir}/src/rebar + if [ ! -d "${rootdir}/bin/" ]; then + mkdir ${rootdir}/bin/ + fi + mv ${rootdir}/src/rebar/rebar ${rootdir}/bin/rebar + make -C ${rootdir}/src/rebar clean + rm -rf ${rootdir}/src/rebar + fi +} + +install_local_enc() { + if [ ! -x "${rootdir}/bin/enc" ]; then + if [ ! -d "${rootdir}/src/erlang-native-compiler" ]; then + git clone --depth 1 https://github.com/davisp/erlang-native-compiler.git ${rootdir}/src/erlang-native-compiler + fi + make -C ${rootdir}/src/erlang-native-compiler + if [ ! -d "${rootdir}/bin/" ]; then + mkdir ${rootdir}/bin/ + fi + mv ${rootdir}/src/erlang-native-compiler/enc ${rootdir}/bin/enc + make -C ${rootdir}/src/erlang-native-compiler clean + rm -rf ${rootdir}/src/erlang-native-compiler + fi +} + +if [ -z "${REBAR}" ]; then + install_local_rebar + REBAR=${rootdir}/bin/rebar +fi + +if [ -z "${ENC}" ]; then + install_local_enc + ENC=${rootdir}/bin/enc +fi diff --git a/configure.ps1 b/configure.ps1 new file mode 100644 index 0000000..35ac8fc --- /dev/null +++ b/configure.ps1 @@ -0,0 +1,39 @@ +$rootdir = split-path -parent $MyInvocation.MyCommand.Definition +Push-Location $rootdir +[Environment]::CurrentDirectory = $PWD + +if ((Get-Command "rebar.cmd" -ErrorAction SilentlyContinue) -eq $null) +{ + if (-Not (Test-Path "src\rebar")) + { + git clone --depth 1 https://github.com/apache/couchdb-rebar.git $rootdir\src\rebar + } + cmd /c "cd src\rebar && $rootdir\src\rebar\bootstrap.bat" + if (-Not (Test-Path "bin")) + { + mkdir $rootdir\bin + } + cp $rootdir\src\rebar\rebar $rootdir\bin\rebar + cp $rootdir\src\rebar\rebar.cmd $rootdir\bin\rebar.cmd + make -C $rootdir\src\rebar clean + rmdir $rootdir\src\rebar + $env:Path += ";$rootdir\bin" +} + +if ((Get-Command "enc.cmd" -ErrorAction SilentlyContinue) -eq $null) +{ + if (-Not (Test-Path "bin")) + { + git clone --depth 1 https://github.com/davisp/erlang-native-compiler.git $rootdir\src\erlang-native-compiler + } + cmd /c "cd src\erlang-native-compiler && $rootdir\src\erlang-native-compiler\bootstrap.bat" + if (-Not (Test-Path "bin")) + { + mkdir $rootdir\bin + } + cp $rootdir\src\erlang-native-compiler\enc $rootdir\bin\enc + cp $rootdir\src\erlang-native-compiler\enc.cmd $rootdir\bin\enc.cmd + make -C $rootdir\src\erlang-native-compiler clean + rmdir $rootdir\src\erlang-native-compiler + $env:Path += ";$rootdir\bin" +} diff --git a/rebar b/rebar deleted file mode 100755 index b3eaa8e..0000000 Binary files a/rebar and /dev/null differ diff --git a/rebar.config b/rebar.config index b951b5e..b4e3d75 100644 --- a/rebar.config +++ b/rebar.config @@ -36,5 +36,5 @@ verbose ]}. -{pre_hooks, [{"", compile, "escript enc compile"}]}. -{post_hooks, [{"", clean, "escript enc clean"}]}. +{pre_hooks, [{"", compile, "escript bin/enc compile"}]}. +{post_hooks, [{"", clean, "escript bin/enc clean"}]}.