LoginSignup
4
3

XCrySDenのmacos Monterey/Ventura上でのビルド

Last updated at Posted at 2022-09-21

これまで長らくMac上でXCrySDenのビルドがうまくいかず、ビルドでエラーが発生しなくてもまともに動作せず、OSをアップデートする度に試し、いつもうまくいっていませんでした。macos Montereyにアップデートしたのを機にビルドしてみたところ、意外とすんなりいったので、特筆することはありませんが、記録を残しておきます。

Venturaに更新しても同じ手順でうまくいきました。

環境

  • MacBook Pro (13-inch, M1, 2020)
  • Chip Apple M1
  • macOS Monterey
  • Homebew 3.6.2 (Homebrew/homebrew-core (git revision a00122a7143; last commit 2022-09-21))
  • gcc (brew install gccでインストールしたもの)

もしくは

  • MacBook Pro (13-inch, M2, 2023)
  • Chip Apple M2
  • macOS Ventra Version 13.6
  • Homebew 4.1.13
  • gcc (brew install gccでインストールしたもの)

インストールしたXCrySDenのバージョン

  • xcrysden 1.6.2

ビルド

以下のMake.sysを利用します。

Make.sys
#########################################################################
#
#  Make.sys for X11 semishared compilation on Mac OS X
#
#  It will download Tcl, Tk, Togl, and FTTW3 tarballs from the
#  internet and compile them for use with X11. After compilation they
#  are installed in external/lib & external/include.
#
#
#  This Make.sys uses the XQuartz.
#
########################################################################

#------------------------------------------------------------------------
# if you have a GNU make it is better to set the MAKE variable to point
# to gnu make
#------------------------------------------------------------------------
MAKE = make

#------------------------------------------------------------------------
# compilers & flags
#------------------------------------------------------------------------
# C-preprocessor flags
CPPFLAGS ?=
# C-compiler flags
CFLAGS += -ffast-math -funroll-loops -fPIC -pedantic -Wall

CC     = gcc 
LDLIB  = -ldl
MATH   = -lm -lc

FFLAGS  += -static-libgfortran -static-libgcc -fdefault-double-8 -fdefault-real-8 -O2
FC      = gfortran 

#------------------------------------------------------------------------
# X-libraries & include files
#------------------------------------------------------------------------
X_LIB     = -lXmu -lX11 
X_INCDIR  = -I/opt/X11/include

#------------------------------------------------------------------------
# EXTERNAL LIBRARIES: Tcl/Tk/Mesa/Togl/FFTW
#------------------------------------------------------------------------

# setting to "yes" will compile the corresponding library in external/src/
COMPILE_TCLTK    = yes
COMPILE_TOGL     = yes
COMPILE_MESA     = no
COMPILE_FFTW     = no
# this is only used for some testing purposes
COMPILE_MESCHACH = no

# Do we want a shared library version of Tcl/Tk/Mesa/Togl?  If we want
# shared then set the following flags to: --enable-shared else set the
# following flag to: --disable-shared

TCLTK_OPTIONS  = --enable-shared \
               --with-x CFLAGS=-I/opt/X11/include --x-includes=/opt/X11/include --x-libraries=/opt/X11/lib
TOGL_OPTIONS   = --enable-shared --with-tcl=$(TOPDIR)/external/lib --with-tk=$(TOPDIR)/external/lib \
               --with-x CFLAGS=-I/opt/X11/include --x-includes=/opt/X11/include --x-libraries=/opt/X11/lib 
MESA_OPTIONS   = --enable-shared
GLU_OPTIONS    = --enable-shared
MESA_TARGET    = linux
FFTW_OPTIONS   = --enable-shared
#------------------------------------------------------------------------
#
# Libraries
#
#------------------------------------------------------------------------

TCL_LIB      = -L$(TOPDIR)/external/lib -ltcl$(TCL_VER2)
TK_LIB       = -ltk$(TCL_VER2)
TOGL_LIB     = -lTogl$(TOGL_VER)
GLU_LIB      = -L/opt/X11/lib -lGLU
GL_LIB       = -lGL
FFTW3_LIB    = -L/opt/homebrew/lib -lfftw3

#------------------------------------------------------------------------
#
# Include directories
#
#------------------------------------------------------------------------

TCL_INCDIR      = -I$(TOPDIR)/external/include
TK_INCDIR       =
TOGL_INCDIR     =
GL_INCDIR       = -I/opt/X11/include
FFTW3_INCDIR    = -I/opt/homebrew/include

#------------------------------------------------------------------------

作成したMake.sysをxcrysdenのトップディレクトリに置き、あとは

make all

を実行するだけで必要なライブラリは自動でダウンロードされ、ビルドが行われます。

ビルドが問題なく終了した後にXCRYSDEN_TOPDIRを適正に指定するだけで問題無く動作します。

XCrySDenだけでは不自由なことも多いのでVESTAも欠かせませんが、XCrySDenだとスクリプティングが出来きるので同じ操作を繰り返す時には便利です。pw.xの入出力を直接読み込んでくれるのも便利です。これから論文でXCrySDenで作った図が使えるかもしれない、と思うと今からとても楽しみで、まだ何も書いていないのにワクワクしています。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3