LoginSignup
5
5

More than 5 years have passed since last update.

Mac標準搭載のApache2.2でモジュールを開発しようとした時のメモ

Posted at

まずはひな形を作成して動かそうとしたのですが、その時にいろいろはまったのでメモです。

■ 環境

  • Mac OS X Mavericks 10.9.5
  • Apache 2.2.26
  • Xcode Command Line Tools はインストール済み

1. apxsコマンドでモジュールのひな形を作成

適当なディレクトリで以下のコマンドを実行する。

apxs -g -n test

実行結果

Creating [DIR]  test
Creating [FILE] test/Makefile
Creating [FILE] test/modules.mk
Creating [FILE] test/mod_test.c
Creating [FILE] test/.deps

モジュールのひな形が作成される。

2. makeコマンドでひな形をコンパイル

作成されたtestディレクトリへ移動しmakeコマンドを実行する。

make

実行結果

/usr/share/httpd/build/special.mk:27: /usr/build/rules.mk: No such file or directory
make: *** No rule to make target `/usr/build/rules.mk'.  Stop.

「/usr/build/rules.mk」ファイルが見つからないらしい……

「/usr/share/httpd/build」以下で「rules.mk」ファイルを発見!

「Makefile」の「top_srcdir」と「top_builddir」を以下の通りに修正する。

Makefile:修正前
top_srcdir=/usr
top_builddir=/usr/
Makefile:修正後
top_srcdir=/usr/share/httpd
top_builddir=/usr/share/httpd

再度makeコマンドを実行する。

make

実行結果

/usr/share/apr-1/build-1/libtool --silent --mode=compile /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc -I/usr/local/include -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -I/usr/include/apache2 -I. -I/usr/include/apr-1 -c mod_test.c && touch mod_test.slo
env: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc: No such file or directory
make: *** [mod_test.slo] Error 1

今度は「/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc」が見つからないもよう……

とりあえず「/Applications/Xcode.app/Contents/Developer/Toolchains」ディレクトリの中を確認する。

cd /Applications/Xcode.app/Contents/Developer/Toolchains
ls

実行結果

XcodeDefault.xctoolchain

「OSX10.9.xctoolchain」が無い……

とりあえず「XcodeDefault.xctoolchain」ディレクトリの中を確認する。

ls XcodeDefault.xctoolchain/usr/bin/cc

実行結果

XcodeDefault.xctoolchain/usr/bin/cc

あった!
「XcodeDefault.xctoolchain/usr/bin/cc」を参照するようシンボリックリンクを作成する。

cd /Applications/Xcode.app/Contents/Developer/Toolchains
sudo ln -s XcodeDefault.xctoolchain OSX10.9.xctoolchain

三度目の正直、testディレクトリへ移動してmakeコマンドを実行する。

make

実行結果

/usr/share/apr-1/build-1/libtool --silent --mode=compile /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc -I/usr/local/include -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -I/usr/include/apache2 -I. -I/usr/include/apr-1 -c mod_test.c && touch mod_test.slo
mod_test.c:40:10: fatal error: 'httpd.h' file not found
#include "httpd.h"
         ^
1 error generated.
make: *** [mod_test.slo] Error 1

世の中そうそう甘くはないようです……

コンパイル時のincludeファイルの指定は「/usr/share/httpd/build/config_vars.mk」ファイルの「EXTRA_INCLUDES」で行っているもよう。

「config_vars.mk」ファイルを以下の通りに修正する。

config_vars.mk:修正前
EXTRA_INCLUDES = -I$(includedir) -I. -I/usr/include/apr-1
config_vars.mk:修正後
EXTRA_INCLUDES = -I$(includedir) -I. -I/usr/include/apr-1 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/apr-1 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/apache2

パトラッシュ、僕はもう疲れたよ……

make

実行結果

/usr/share/apr-1/build-1/libtool --silent --mode=compile /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc -I/usr/local/include -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -I/usr/include/apache2 -I. -I/usr/include/apr-1 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/apr-1 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/apache2 -c mod_test.c && touch mod_test.slo
/usr/share/apr-1/build-1/libtool --silent --mode=link /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc -I/usr/local/include -o mod_test.la -rpath /usr/libexec/apache2 -module -avoid-version mod_test.lo
warning: no debug symbols in executable (-arch x86_64)

やっとコンパイルできた。

3. コンパイルしたモジュールをインストール

testディレクトリで以下のコマンドを実行しモジュールをインストールする。

sudo make install

実行結果

/usr/share/apr-1/build-1/libtool --silent --mode=install cp mod_test.la /usr/libexec/apache2/
/usr/share/apr-1/build-1/libtool --silent --mode=install cp mod_test.la /usr/libexec/apache2/

同じ内容が2行出力されているけどインストールできた。

4. モジュールの動作確認

「httpd.conf」の最終行に以下の設定を追加してApacheを再起動する。

httpd.conf
LoadModule test_module libexec/apache2/mod_test.so
<Location /test>
    SetHandler test
</Location>

上記で設定したロケーションへアクセスして確認する。

5
5
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
5
5