Skip to content

Commit

Permalink
Merge pull request #33 from mshumko/win_compile
Browse files Browse the repository at this point in the history
Compile IRBEM on Windows 10
  • Loading branch information
drsteve authored Jun 24, 2022
2 parents 1ceaca6 + 2ea1db8 commit d876aec
Show file tree
Hide file tree
Showing 11 changed files with 498 additions and 305 deletions.
46 changes: 44 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ['3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:

strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ['3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -80,3 +80,45 @@ jobs:
- name: Run Python tests
run: |
pytest
build-win:
runs-on: windows-2019

strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2

# - uses: msys2/setup-msys2@v2

- name: Add gfortran to PATH
shell: bash
run: |
# $env:PATH = "C:\msys64\mingw64\bin;C:\msys64\usr\bin;$env:PATH"
# gfortran --version
echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH
echo "C:\msys64\usr\bin" >> $GITHUB_PATH
echo $(gfortran --version)
- name: Build
shell: bash
run: |
make OS=win64 ENV=gfortran64 all
make OS=win64 ENV=gfortran64 install
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Python wrapper
run: |
cd python
python3 -m pip install -r requirements.txt
python3 -m pip install pytest
- name: Run Python tests
run: |
pytest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
*.so
*.o
*.dll
*.a
source/*.o
source/wrappers.inc
source/fortran_*.inc
libirbem.so
__pycache__
settings.json
*.egg-info
env/
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,46 @@ Installation
------------
IRBEM requires a [Fortran compiler](https://fortran-lang.org/learn/os_setup/install_gfortran), and can be installed on modern Windows, Linux, and Mac computers.

- The quick build procedure on Linux with gfortran:
## Linux
The quick build procedure on Linux with gfortran:
```bash
git clone https://github.com/PRBEM/IRBEM.git
cd IRBEM
make OS=linux64 ENV=gfortran64 all
make OS=linux64 ENV=gfortran64 install
```

- The quick build procedure on Mac OSX with gfortran:
## Mac OSX
The quick build procedure on Mac OSX with gfortran:
```bash
git clone https://github.com/PRBEM/IRBEM.git
cd IRBEM
make OS=osx64 ENV=gfortran64 all
make OS=osx64 ENV=gfortran64 install
```

- The quick build procedure for Windows will be created soon. In the meanwhile, one workaround is to use the Windows Subsystem for Linux (WSL).
## Windows
Here is one way to build IRBEM for 64-bit Windows using the gfortran compiler.

See the `README.install` file for more details.
1. Download and install [MSYS2](https://www.msys2.org/) and follow the [Fortran installation steps](https://www.msys2.org/#:~:text=and%20what%20for.-,Installation,-Download%20the%20installer) (summarized below).
1. Run MSYS2 MSYS terminal from the start menu and update the MSYS2 packages via ```pacman -Syu``` (pacman is its package manager).
2. Run MSYS2 MSYS from the start menu again and update the rest of the packages using ```pacman -Syu```.
3. Install the Fortran compiler and other dependencies ([base-devel](https://packages.msys2.org/group/base-devel) and [mingw-w64-x86_64-toolchain](https://packages.msys2.org/group/mingw-w64-x86_64-toolchain)) in the MSYS terminal using ```pacman -S --needed base-devel mingw-w64-x86_64-toolchain```. Use the default option `all`.
4. git is required for building IRBEM. If you don't have it, install it using [msys2-git](https://packages.msys2.org/base/git) ```pacman -S git```.
5. Add the directory where `gfortran.exe` is located to the Windows path (a good place to look for it is `C:\msys64\mingw64\bin`). You can follow these [instructions](https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee537574(v=office.14)#to-add-a-path-to-the-path-environment-variable) to add the path environmental variables.
6. Confirm that the paths are set up correctly. Run `gfortran --version` command runs. Also, check that `make` runs (it will print "make: *** No targets specified and no makefile found. Stop.").

2. Clone and install IRBEM
```bash
git clone https://github.com/PRBEM/IRBEM.git
cd IRBEM
make OS=win64 ENV=gfortran64 all
make OS=win64 ENV=gfortran64 install
```
Congratulations! Now you have compiled libirbem.dll library in the root folder of IRBEM/.


See the `README.install` or `compile/WINDOWS_INSTRUCTIONS.md` files for more details.

Contributions
-------------
Expand Down
2 changes: 0 additions & 2 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
*.o
*.so
57 changes: 57 additions & 0 deletions compile/WINDOWS_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
### Steps to compile IRBEM x64 on Windows
1. Download and install MSYS2 https://www.msys2.org/
2. Following the installation steps and update the packages:
```
pacman -Syu
```
3. Install base-devel package (https://packages.msys2.org/group/base-devel)
```
pacman -S base-devel
```
4. Install mingw-w64-x86_64-toolchain package (https://packages.msys2.org/group/mingw-w64-x86_64-toolchain). Select default `all` option during the installation.
```
pacman -S mingw-w64-x86_64-toolchain
```
Note that this is a large package but provides easiest installation process.

5. Install git package as it required by the IRBEM Makefile (https://packages.msys2.org/base/git)
```
pacman -S git
```
You can combine steps 3, 4 and 5 into one: `pacman -S base-devel mingw-w64-x86_64-toolchain git`

6. Close this terminal and open `MSYS2 MinGW x64`.
7. Navigate to the IRBEM folder. In the following example it is located at c:\libs\IRBEM\
```
cd /c
cd libs/IRBEM
```
8. (*) If you **have not cloned IRBEM library** you can do it now using `MSYS2 MinGW x64` terminal:
```
cd /c/libs/
git clone https://github.com/PRBEM/IRBEM.git
```
9. Compile the IRBEM library
```
make OS=win64 ENV=gfortran64 all
make OS=win64 ENV=gfortran64 install
```
10. Congratulations! Now you have compiled libirbem.dll library in the root folder of IRBEM.
11. Since libirbem.dll is a shared library make sure to include `c:\msys64\mingw64\bin\` into Windows Path variable:
> Press Win+x->Select "System"->In the "About" section find and open "Advanced system settings"->Click button "Environmental Variables..."->Find variable "Path" and click "Edit..."->Click "New" and include `c:\msys64\mingw64\bin\`-> Close all the windows by clicking "Ok".
Change `c:\msys64\mingw64\bin\` according to you MSYS2 installation path.

### How to compile IRBEM x32 on Windows
The steps are similar as in the previous description, except a few changes:

4. Instead of `mingw-w64-x86_64-toolchain` install package `mingw-w64-i686-toolchain`

6. Use terminal `MSYS2 MinGW x86`

9. Compile the IRBEM library
```
make OS=win32 ENV=gfortran all
make OS=win32 ENV=gfortran install
```
11. Make sure to include `mingw32` into Windows Path e.g., `c:\msys64\mingw32\bin\`
22 changes: 22 additions & 0 deletions compile/win32-gfortran.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#------------------------------------------------------------------------------
# Compilers information
# FC: Fortran Compiler
# CC: C Compiler
# LD: Linker
# FFLAGS : Fortran flags
# CFLAGS : C Flags
# LDFLAGS: Linker flags
# COMPILE_LIB_NAME : Name of the compiled library file
# INSTALL_LIB_NAME : Name of the installed library file
#------------------------------------------------------------------------------

FC = gfortran
CC = gcc
LD = gfortran

FFLAGS=-fpic -fno-second-underscore -std=legacy -ffixed-line-length-none -Wl,--add-stdcall-alias -fno-second-underscore -w -m32
CFLAGS=-fpic
LDFLAGS=-shared

COMPILE_LIB_NAME=libirbem.$(OS).$(ENV).dll
INSTALL_LIB_NAME=libirbem.dll
22 changes: 22 additions & 0 deletions compile/win64-gfortran64.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#------------------------------------------------------------------------------
# Compilers information
# FC: Fortran Compiler
# CC: C Compiler
# LD: Linker
# FFLAGS : Fortran flags
# CFLAGS : C Flags
# LDFLAGS: Linker flags
# COMPILE_LIB_NAME : Name of the compiled library file
# INSTALL_LIB_NAME : Name of the installed library file
#------------------------------------------------------------------------------

FC = gfortran
CC = gcc
LD = gfortran

FFLAGS=-fpic -fno-second-underscore -std=legacy -ffixed-line-length-none -Wl,--add-stdcall-alias -fno-second-underscore -w -m64
CFLAGS=-fpic
LDFLAGS=-shared

COMPILE_LIB_NAME=libirbem.$(OS).$(ENV).dll
INSTALL_LIB_NAME=libirbem.dll
4 changes: 2 additions & 2 deletions matlab/README.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ INSTALLATION

The IRBEM compile scripts will create the shared library file for
use with IDL or Matlab. A copy of the shared library is created in the
"matlab" subdirectory, and is given a name "onera_desp_lib.dll" or
"onera_desp_lib.so" depending on the platform. Thus, in order to
"matlab" subdirectory, and is given a name "libirbem.dll" or
"libirbem.so" depending on the platform. Thus, in order to
access the library and the wrappers, the user needs only add the
"matlab" subdirectory (e.g. "c:\onera_desp\matlab") to the Matlab
path. In order for the library to easily locate the data files that it
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions matlab/onera_desp_lib_load.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
%function onera_desp_lib_load(libfile,@prototypefunction);
%function onera_desp_lib_load(libfile,headerfile);
% checks for the presence of the onera_desp_lib dynamic library in memory
% if not present, attempts to load it using a headerfile
% if not present, attempts to load it using a headerfile (libirbem.h)
% checks environment variable IRBEM_LIB_DLL to specify the file to load
% (full file path, or a file name in the matlab search path)
% otherwise, it guesses the file name
Expand All @@ -31,7 +31,7 @@

if ~libisloaded('onera_desp_lib')
if nargin < 2
headerfile = 'onera_desp_lib.h';
headerfile = 'libirbem.h';
end

% determine DLL extension
Expand All @@ -47,7 +47,7 @@
if ~isempty(getenv('IRBEM_LIB_DLL'))
libfile = getenv('IRBEM_LIB_DLL');
else
libfile = ['onera_desp_lib.',libext];
libfile = ['libirbem.',libext];
end
end
if ~exist(libfile,'file')
Expand Down
Loading

0 comments on commit d876aec

Please sign in to comment.