下載完chromium代碼後開始編譯,這就引出了chromium 的gyp 構建過程,即由gyp文件生成Makefile文件。gyp構建系統沒有采用遞歸make。
兩步完成構建過程,在src目錄下
src$ . build/android/envsetup.sh // 環境設置
src$ android_gyp // 生成工程文件,進而可以生成Makefile文件
開始的gyp文件是build/all_android.gyp,它包含了最頂層的目標,幷包含其他gpy文件。默認目標是ALL。
當然也可以只編譯某一個目標,例如content_shell_apk就是其中一個目標,在content/content_shell.gypi中,這樣就只編譯content_shel及其依賴模塊。
可以分析一下build/android/envsetup.sh腳本文件
該文件最後聲明瞭一個函數就是android_gyp(該函數是build/gyp_chromiumd得封裝), 所以也在最後直接調用該函數,這樣就不在運行android_gyp了。
瞭解了all_android.gyp就可以進行必要的裁剪了,而不是所有的模塊都編譯,例如去掉test模塊的編譯。
gyp構建系統參考:http://blog.csdn.net/qq295445028/article/details/7859103
簡單列一下gyp/gypi文件格式
gyp文件就是一個JSON格式的文件,一般包含如下字段:(參考build/all.gyp文件)
conditions(條件判斷),includes(包含的構建文件),target_defaults(構建目標默認屬性),targets(構建目標列表),variables(構建文件使用的變量)
1. conditions
分爲普通的conditions(在load構建文件之後立即計算)和target_conditions(在計算完成依賴之後然後來進行計算),兩個過程分別就是early and late phases階段。對於conditions寫法非常簡單:
'conditions':[
['OS==Linux',{'sources':['linux_interface.cc']}], // 系統環境變量的判斷 linux平臺下,變量sources加入linux_interface.cc文件
['notifications==0', {'sources!': [ // 用戶自定義變量的判斷
'renderer/notification_provider.cc',
'renderer/active_notification_tracker.cc',
],
]
2. target
3. includes
4. actions
5. variables
以content shell爲例,如何編譯cc/cpp文件時加入某個宏(以ENABLE_PLUGINS爲例)呢?相當於全局宏
首先要找對gyp文件,先找到target 爲so的地方,很容易在content_shell.gypi中找到下面的target_name
'target_name': 'libcontent_shell_content_view', 它又依賴與“content_shell_lib”
而content_shell_lib依賴於chromium各目錄下gyp文件的某一個target(這些target最終生成.a文件)。所以
搜索ENABLE_PLUGINS後,發現都在content目錄下使用,所以可以找到content.gyp文件,加入宏即可
部分代碼如下(還需要加入用戶自定義變量enable_plugins,這樣plugin相關代碼纔會編譯)
'variables': {
'chromium_code': 1, # Use higher warning level.
'enable_plugins': 1,
'chromium_enable_vtune_jit_for_v8%': 0, # enable the vtune support for V8 engine.
'directxsdk_exists': '<!pymod_do_main(dir_exists ../third_party/directxsdk)',
},
'target_defaults': {
'defines': ['CONTENT_IMPLEMENTATION', 'ENABLE_PLUGINS=1'],
...
參考:
GYP相關文檔: https://code.google.com/p/gyp/w/list
build system: http://www.wy182000.com/2011/09/01/buildsystem/