最近、新しい機能がxmakeに追加されました。プロジェクトのソースコードの場合、makefileまたはさまざまなmake関連のプロジェクト記述ファイル(例:xmake.lua、makefile.am、cmakelist.txtなど)を作成する必要はありません。 。)
xmakeはそれらを直接コンパイルできます。これはどのように行われますか?簡単に言えば、実装の原則は次のとおりです。
- まず、現在のディレクトリでxmakeがサポートするすべてのソースコードファイルをスキャンします
- コードを分析し、どのコードがメインエントリ機能を持っているかを検出します
- メインエントリのないすべてのコードは静的ライブラリにコンパイルされます
- メインエントリを持つコードは、他の静的ライブラリプログラムをリンクしながら、実行可能プログラムにコンパイルされます
この種のコードスキャンとインテリジェントコンパイルは非常に簡単です。現在、xmakeはマルチレベルディレクトリスキャンをサポートしていません。シングルレベルディレクトリのコードのみをスキャンしてコンパイルします。。
オープンソースコードの移植とコンパイル
この方法はあまり賢くなく、多くの制限がありますが、コンパイルして実行するコードを一時的に作成するか、単純なオープンソースライブラリコードを一時的にクロスコンパイルする必要があります。
この方法で十分です。次の実用的な例を見てみましょう。
zlib-1.2.10のソースコードのコピーをダウンロードしました。コンパイルするには、zlibのソースディレクトリに入力して実行するだけです。
$ cd zlib-1.2.10
$ xmake
以上です。出力は次のとおりです。
xmake.lua not found, scanning files ..
target(zlib-1.2): static
[+]: ./adler32.c
[+]: ./compress.c
[+]: ./crc32.c
[+]: ./deflate.c
[+]: ./gzclose.c
[+]: ./gzlib.c
[+]: ./gzread.c
[+]: ./gzwrite.c
[+]: ./infback.c
[+]: ./inffast.c
[+]: ./inflate.c
[+]: ./inftrees.c
[+]: ./trees.c
[+]: ./uncompr.c
[+]: ./zutil.c
xmake.lua generated, scan ok!��
checking for the architecture ... x86_64
checking for the Xcode SDK version for macosx ... 10.12
checking for the target minimal version ... 10.12
checking for the c compiler (cc) ... xcrun -sdk macosx clang
checking for the c++ compiler (cxx) ... xcrun -sdk macosx clang
checking for the objc compiler (mm) ... xcrun -sdk macosx clang
checking for the objc++ compiler (mxx) ... xcrun -sdk macosx clang++
checking for the swift compiler (sc) ... xcrun -sdk macosx swiftc
checking for the assember (as) ... xcrun -sdk macosx clang
checking for the linker (ld) ... xcrun -sdk macosx clang++
checking for the static library archiver (ar) ... xcrun -sdk macosx ar
checking for the static library extractor (ex) ... xcrun -sdk macosx ar
checking for the shared library linker (sh) ... xcrun -sdk macosx clang++
checking for the debugger (dd) ... xcrun -sdk macosx lldb
checking for the golang compiler (go) ... go
configure
{
ex = "xcrun -sdk macosx ar"
, sh = "xcrun -sdk macosx clang++"
, host = "macosx"
, ar = "xcrun -sdk macosx ar"
, buildir = "build"
, as = "xcrun -sdk macosx clang"
, plat = "macosx"
, xcode_dir = "/Applications/Xcode.app"
, arch = "x86_64"
, mxx = "xcrun -sdk macosx clang++"
, go = "go"
, target_minver = "10.12"
, ccache = "ccache"
, mode = "release"
, clean = true
, cxx = "xcrun -sdk macosx clang"
, cc = "xcrun -sdk macosx clang"
, dd = "xcrun -sdk macosx lldb"
, kind = "static"
, ld = "xcrun -sdk macosx clang++"
, xcode_sdkver = "10.12"
, sc = "xcrun -sdk macosx swiftc"
, mm = "xcrun -sdk macosx clang"
}
configure ok!
clean ok!
[00%]: ccache compiling.release ./adler32.c
[06%]: ccache compiling.release ./compress.c
[13%]: ccache compiling.release ./crc32.c
[20%]: ccache compiling.release ./deflate.c
[26%]: ccache compiling.release ./gzclose.c
[33%]: ccache compiling.release ./gzlib.c
[40%]: ccache compiling.release ./gzread.c
[46%]: ccache compiling.release ./gzwrite.c
[53%]: ccache compiling.release ./infback.c
[60%]: ccache compiling.release ./inffast.c
[66%]: ccache compiling.release ./inflate.c
[73%]: ccache compiling.release ./inftrees.c
[80%]: ccache compiling.release ./trees.c
[86%]: ccache compiling.release ./uncompr.c
[93%]: ccache compiling.release ./zutil.c
[100%]: archiving.release libzlib-1.2.a
build ok!��
出力結果から、xmakeが現在のディレクトリ内のすべての.cコードを検出してスキャンし、静的ライブラリプログラムであるはずのメインエントリがないことがわかります。したがって、xmakeを実行すると、直接になります。静的ライブラリlibzlib-1.2.aにコンパイルされます
xmake.luaも書き込まれていません。実際、スキャンが完了すると、xmakeは現在のディレクトリにxmake.luaのコピーを自動的に生成するため、次回のコンパイル時に再スキャンして確認する必要はありません。
自動生成されたxmake.luaコンテンツは次のとおりです。
-- define target
target("zlib-1.2")
-- set kind
set_kind("static")
-- add files
add_files("./adler32.c")
add_files("./compress.c")
add_files("./crc32.c")
add_files("./deflate.c")
add_files("./gzclose.c")
add_files("./gzlib.c")
add_files("./gzread.c")
add_files("./gzwrite.c")
add_files("./infback.c")
add_files("./inffast.c")
add_files("./inflate.c")
add_files("./inftrees.c")
add_files("./trees.c")
add_files("./uncompr.c")
add_files("./zutil.c")
この種のオープンソースライブラリのように、configure; make
それは問題ない、直接コンパイルするためのメイクファイルも提供していると言うかもしれません。確かにそうです。ここでは例を示します。。
もちろん、多くのオープンソースライブラリがクロスコンパイルされている場合configure
でも、独自の組み込みライブラリを介して処理するのは非常に面倒です。クロスコンパイルにはxmakeを使用する方が便利です。。
インスタントコードの記述、コンパイル、実行
xmakeのこのスキャンコードコンパイル機能の主な目的は、あまり考えずに一時的にテストコードを記述してコードを直接入力し、それをすばやく実行しxmake run
て検証結果をデバッグできるようにすることです。。
例えば:
簡単なmain.cテストプログラムを作成して印刷しhello world!
たい。makefileを作成したり、gccコマンドを直接使用したりする場合は、非常に面倒です。次のことを行う必要があります。
gcc ./main.c -o demo
./demo
最速の方法は、2行のコマンドも実行する必要があり、xmakeを使用する場合は、以下を実行するだけで済みます。
xmake run
これで、コードが自動的に検出された後、対応するxmake.luaが自動的に生成され、自動的にコンパイルされ、自動的に実行されて、次のように出力されます。
hello world!
ダースを超えるコードファイル、手動でgccを入力する方法、またはmakefileを作成する方法がある場合、ギャップはさらに明白になります。xmakeを使用すると、コマンドは1行だけで済みます。
xmake run
多言語サポート
この種のコード検出とインスタントコンパイルは、多言語をサポートし、c / c ++をサポートするだけでなく、objc / swiftもサポートし、後でgolang(開発中)もサポートします。
たとえば、fmdbiosオープンソースフレームワークコードをダウンロードしました。
.
├── FMDB.h
├── FMDatabase.h
├── FMDatabase.m
├── FMDatabaseAdditions.h
├── FMDatabaseAdditions.m
├── FMDatabasePool.h
├── FMDatabasePool.m
├── FMDatabaseQueue.h
├── FMDatabaseQueue.m
├── FMResultSet.h
└── FMResultSet.m
iOS用の静的ライブラリにコンパイルしたいがxmake.luaやmakefileを書きたくない場合は、xmakeのこの新機能を使用して直接実行するだけです。
$ xmake f -p iphoneos; xmake
以上です。出力は次のとおりです。
xmake.lua not found, scanning files ..
target(FMDB): static
[+]: ./FMDatabase.m
[+]: ./FMDatabaseAdditions.m
[+]: ./FMDatabasePool.m
[+]: ./FMDatabaseQueue.m
[+]: ./FMResultSet.m
xmake.lua generated, scan ok!��
checking for the architecture ... armv7
checking for the Xcode SDK version for iphoneos ... 10.1
checking for the target minimal version ... 10.1
checking for the c compiler (cc) ... xcrun -sdk iphoneos clang
checking for the c++ compiler (cxx) ... xcrun -sdk iphoneos clang
checking for the objc compiler (mm) ... xcrun -sdk iphoneos clang
checking for the objc++ compiler (mxx) ... xcrun -sdk iphoneos clang++
checking for the assember (as) ... gas-preprocessor.pl xcrun -sdk iphoneos clang
checking for the linker (ld) ... xcrun -sdk iphoneos clang++
checking for the static library archiver (ar) ... xcrun -sdk iphoneos ar
checking for the static library extractor (ex) ... xcrun -sdk iphoneos ar
checking for the shared library linker (sh) ... xcrun -sdk iphoneos clang++
checking for the swift compiler (sc) ... xcrun -sdk iphoneos swiftc
configure
{
ex = "xcrun -sdk iphoneos ar"
, ccache = "ccache"
, host = "macosx"
, ar = "xcrun -sdk iphoneos ar"
, buildir = "build"
, as = "/usr/local/share/xmake/tools/utils/gas-preprocessor.pl xcrun -sdk iphoneos clang"
, arch = "armv7"
, mxx = "xcrun -sdk iphoneos clang++"
, cxx = "xcrun -sdk iphoneos clang"
, target_minver = "10.1"
, xcode_dir = "/Applications/Xcode.app"
, clean = true
, sh = "xcrun -sdk iphoneos clang++"
, cc = "xcrun -sdk iphoneos clang"
, ld = "xcrun -sdk iphoneos clang++"
, mode = "release"
, kind = "static"
, plat = "iphoneos"
, xcode_sdkver = "10.1"
, sc = "xcrun -sdk iphoneos swiftc"
, mm = "xcrun -sdk iphoneos clang"
}
configure ok!
clean ok!
[00%]: ccache compiling.release ./FMDatabase.m
[20%]: ccache compiling.release ./FMDatabaseAdditions.m
[40%]: ccache compiling.release ./FMDatabasePool.m
[60%]: ccache compiling.release ./FMDatabaseQueue.m
[80%]: ccache compiling.release ./FMResultSet.m
[100%]: archiving.release libFMDB.a
build ok!��
複数の実行可能ファイルを同時にコンパイルする
出力結果の最初の部分はコードの分析結果です。現在サポートされているのは単一レベルのディレクトリ構造コードスキャンのみですが、複数の実行可能ファイルの検出とコンパイルを同時にサポートできます。
例としてlibjpegのオープンソースライブラリを取り上げましょう。
jpeg-6bディレクトリに入ったら、次のコマンドを実行します。
$ xmake
出力は次のとおりです。
xmake.lua not found, scanning files ..
target(jpeg-6b): static
[+]: ./cdjpeg.c
[+]: ./example.c
[+]: ./jcapimin.c
[+]: ./jcapistd.c
[+]: ./jccoefct.c
[+]: ./jccolor.c
[+]: ./jcdctmgr.c
[+]: ./jchuff.c
[+]: ./jcinit.c
[+]: ./jcmainct.c
[+]: ./jcmarker.c
[+]: ./jcmaster.c
[+]: ./jcomapi.c
[+]: ./jcparam.c
[+]: ./jcphuff.c
[+]: ./jcprepct.c
[+]: ./jcsample.c
[+]: ./jctrans.c
[+]: ./jdapimin.c
[+]: ./jdapistd.c
[+]: ./jdatadst.c
[+]: ./jdatasrc.c
[+]: ./jdcoefct.c
[+]: ./jdcolor.c
[+]: ./jddctmgr.c
[+]: ./jdhuff.c
[+]: ./jdinput.c
[+]: ./jdmainct.c
[+]: ./jdmarker.c
[+]: ./jdmaster.c
[+]: ./jdmerge.c
[+]: ./jdphuff.c
[+]: ./jdpostct.c
[+]: ./jdsample.c
[+]: ./jdtrans.c
[+]: ./jerror.c
[+]: ./jfdctflt.c
[+]: ./jfdctfst.c
[+]: ./jfdctint.c
[+]: ./jidctflt.c
[+]: ./jidctfst.c
[+]: ./jidctint.c
[+]: ./jidctred.c
[+]: ./jmemansi.c
[+]: ./jmemmgr.c
[+]: ./jmemname.c
[+]: ./jmemnobs.c
[+]: ./jquant1.c
[+]: ./jquant2.c
[+]: ./jutils.c
[+]: ./rdbmp.c
[+]: ./rdcolmap.c
[+]: ./rdgif.c
[+]: ./rdppm.c
[+]: ./rdrle.c
[+]: ./rdswitch.c
[+]: ./rdtarga.c
[+]: ./transupp.c
[+]: ./wrbmp.c
[+]: ./wrgif.c
[+]: ./wrppm.c
[+]: ./wrrle.c
[+]: ./wrtarga.c
target(ansi2knr): binary
[+]: ./ansi2knr.c
target(cjpeg): binary
[+]: ./cjpeg.c
target(ckconfig): binary
[+]: ./ckconfig.c
target(djpeg): binary
[+]: ./djpeg.c
target(jpegtran): binary
[+]: ./jpegtran.c
target(rdjpgcom): binary
[+]: ./rdjpgcom.c
target(wrjpgcom): binary
[+]: ./wrjpgcom.c
xmake.lua generated, scan ok!��
checking for the architecture ... x86_64
checking for the Xcode SDK version for macosx ... 10.12
checking for the target minimal version ... 10.12
checking for the c compiler (cc) ... xcrun -sdk macosx clang
checking for the c++ compiler (cxx) ... xcrun -sdk macosx clang
checking for the objc compiler (mm) ... xcrun -sdk macosx clang
checking for the objc++ compiler (mxx) ... xcrun -sdk macosx clang++
checking for the swift compiler (sc) ... xcrun -sdk macosx swiftc
checking for the assember (as) ... xcrun -sdk macosx clang
checking for the linker (ld) ... xcrun -sdk macosx clang++
checking for the static library archiver (ar) ... xcrun -sdk macosx ar
checking for the static library extractor (ex) ... xcrun -sdk macosx ar
checking for the shared library linker (sh) ... xcrun -sdk macosx clang++
checking for the debugger (dd) ... xcrun -sdk macosx lldb
checking for the golang compiler (go) ... go
configure
{
ex = "xcrun -sdk macosx ar"
, sh = "xcrun -sdk macosx clang++"
, host = "macosx"
, ar = "xcrun -sdk macosx ar"
, buildir = "build"
, as = "xcrun -sdk macosx clang"
, plat = "macosx"
, xcode_dir = "/Applications/Xcode.app"
, arch = "x86_64"
, mxx = "xcrun -sdk macosx clang++"
, go = "go"
, target_minver = "10.12"
, ccache = "ccache"
, mode = "release"
, clean = true
, cxx = "xcrun -sdk macosx clang"
, cc = "xcrun -sdk macosx clang"
, dd = "xcrun -sdk macosx lldb"
, kind = "static"
, ld = "xcrun -sdk macosx clang++"
, xcode_sdkver = "10.12"
, sc = "xcrun -sdk macosx swiftc"
, mm = "xcrun -sdk macosx clang"
}
configure ok!
clean ok!
[00%]: ccache compiling.release ./cdjpeg.c
[00%]: ccache compiling.release ./example.c
[00%]: ccache compiling.release ./jcapimin.c
[00%]: ccache compiling.release ./jcapistd.c
[00%]: ccache compiling.release ./jccoefct.c
[00%]: ccache compiling.release ./jccolor.c
[01%]: ccache compiling.release ./jcdctmgr.c
[01%]: ccache compiling.release ./jchuff.c
[01%]: ccache compiling.release ./jcinit.c
[01%]: ccache compiling.release ./jcmainct.c
[01%]: ccache compiling.release ./jcmarker.c
[02%]: ccache compiling.release ./jcmaster.c
[02%]: ccache compiling.release ./jcomapi.c
[02%]: ccache compiling.release ./jcparam.c
[02%]: ccache compiling.release ./jcphuff.c
[02%]: ccache compiling.release ./jcprepct.c
[03%]: ccache compiling.release ./jcsample.c
[03%]: ccache compiling.release ./jctrans.c
[03%]: ccache compiling.release ./jdapimin.c
[03%]: ccache compiling.release ./jdapistd.c
[03%]: ccache compiling.release ./jdatadst.c
[04%]: ccache compiling.release ./jdatasrc.c
[04%]: ccache compiling.release ./jdcoefct.c
[04%]: ccache compiling.release ./jdcolor.c
[04%]: ccache compiling.release ./jddctmgr.c
[04%]: ccache compiling.release ./jdhuff.c
[05%]: ccache compiling.release ./jdinput.c
[05%]: ccache compiling.release ./jdmainct.c
[05%]: ccache compiling.release ./jdmarker.c
[05%]: ccache compiling.release ./jdmaster.c
[05%]: ccache compiling.release ./jdmerge.c
[06%]: ccache compiling.release ./jdphuff.c
[06%]: ccache compiling.release ./jdpostct.c
[06%]: ccache compiling.release ./jdsample.c
[06%]: ccache compiling.release ./jdtrans.c
[06%]: ccache compiling.release ./jerror.c
[07%]: ccache compiling.release ./jfdctflt.c
[07%]: ccache compiling.release ./jfdctfst.c
[07%]: ccache compiling.release ./jfdctint.c
[07%]: ccache compiling.release ./jidctflt.c
[07%]: ccache compiling.release ./jidctfst.c
[08%]: ccache compiling.release ./jidctint.c
[08%]: ccache compiling.release ./jidctred.c
[08%]: ccache compiling.release ./jmemansi.c
[08%]: ccache compiling.release ./jmemmgr.c
[08%]: ccache compiling.release ./jmemname.c
[09%]: ccache compiling.release ./jmemnobs.c
[09%]: ccache compiling.release ./jquant1.c
[09%]: ccache compiling.release ./jquant2.c
[09%]: ccache compiling.release ./jutils.c
[09%]: ccache compiling.release ./rdbmp.c
[10%]: ccache compiling.release ./rdcolmap.c
[10%]: ccache compiling.release ./rdgif.c
[10%]: ccache compiling.release ./rdppm.c
[10%]: ccache compiling.release ./rdrle.c
[10%]: ccache compiling.release ./rdswitch.c
[11%]: ccache compiling.release ./rdtarga.c
[11%]: ccache compiling.release ./transupp.c
[11%]: ccache compiling.release ./wrbmp.c
[11%]: ccache compiling.release ./wrgif.c
[11%]: ccache compiling.release ./wrppm.c
[12%]: ccache compiling.release ./wrrle.c
[12%]: ccache compiling.release ./wrtarga.c
[12%]: archiving.release libjpeg-6b.a
[12%]: ccache compiling.release ./wrjpgcom.c
[25%]: linking.release wrjpgcom
[25%]: ccache compiling.release ./ansi2knr.c
[37%]: linking.release ansi2knr
[37%]: ccache compiling.release ./jpegtran.c
[50%]: linking.release jpegtran
[50%]: ccache compiling.release ./djpeg.c
[62%]: linking.release djpeg
[62%]: ccache compiling.release ./ckconfig.c
[75%]: linking.release ckconfig
[75%]: ccache compiling.release ./rdjpgcom.c
[87%]: linking.release rdjpgcom
[87%]: ccache compiling.release ./cjpeg.c
[100%]: linking.release cjpeg
build ok!��
静的ライブラリを扱う場合、xmakeは多くの実行可能テストプログラムも分析し、残りのコードはテストプログラムがリンクされているlibjpeg.aの静的ライブラリにコンパイルされていることがわかります。。
target(ansi2knr): binary
[+]: ./ansi2knr.c
target(cjpeg): binary
[+]: ./cjpeg.c
target(ckconfig): binary
[+]: ./ckconfig.c
target(djpeg): binary
[+]: ./djpeg.c
target(jpegtran): binary
[+]: ./jpegtran.c
target(rdjpgcom): binary
[+]: ./rdjpgcom.c
target(wrjpgcom): binary
[+]: ./wrjpgcom.c
発生したいくつかの問題と制限
xmakeの現在の自動分析と検出は、次の点であまり賢くありません。
- 特別なコンパイルオプションが必要
- 他のディレクトリでのヘッダーファイル検索に依存する必要があります
- さまざまなソースファイルを条件付きでコンパイルする必要があります
- 同じディレクトリに複数の静的ライブラリを生成する必要があります
- マルチレベルのディレクトリサポートが必要なソースコードライブラリ
上記の状況では、xmakeは自動化されたインテリジェント処理をまだリリースしていません。制限1、2は、次のような半手動の方法で解決できます。
$ xmake f --cxflags="" --ldflags="" --includedirs="" --linkdirs=""; xmake
自動的に検出してコンパイルする場合は、ソースコードプロジェクトに必要な特別なコンパイルオプションを手動で構成すると、コンパイルを直接渡すことができます
制限3は、当面はソースコードを削除することでのみ解決できます。今jpegをコンパイルしたコードと同じように、実際にはディレクトリの下に同時に存在します。
jmemdos.c
jmemmac.c
jmemansi.c
そのうちの2つはコンパイルできず、削除する必要があります。。
個人ホームページ:TBOOXオープンソースプロジェクト