Codebase list mozc / 0c4e877 debian / patches / support-kfreebsd.patch
0c4e877

Tree @0c4e877 (Download .tar.gz)

support-kfreebsd.patch @0c4e877raw · history · blame

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
Description: Support kFreeBSD
Forwarded: None 
Author: Nobuhiri Iwamatsu <iwamatsu@debian.org>
Bug-Debian: No
Last-Update: 2012-06-14

From e45c381a2a9a9a727ec4f7a2cea3b1635d951b85 Mon Sep 17 00:00:00 2001
From: Nobuhiro Iwamatsu <iwamatsu@debian.org>
Date: Fri, 15 Jun 2012 12:26:28 +0900
Subject: [PATCH] Fix kfreebsd

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
---
 base/base.gyp                                    |    4 +-
 base/cpu_stats.cc                                |    6 +-
 base/flags.h                                     |    2 +-
 base/iconv.cc                                    |    4 ++
 base/logging.cc                                  |    5 --
 base/mutex.cc                                    |    3 +-
 base/mutex.h                                     |    6 +-
 base/password_manager.cc                         |    2 +-
 base/process.cc                                  |    8 +--
 base/run_level.cc                                |    2 +-
 base/thread.h                                    |    3 +-
 base/util.cc                                     |   17 +++--
 base/util_test.cc                                |    2 +-
 build_mozc.py                                    |   83 +++++++++++++++++++---
 build_tools/mozc_version.py                      |    9 +++
 chrome/skk/skk.gyp                               |    2 +-
 client/client.cc                                 |    2 +-
 config/stats_config_util_test.cc                 |    2 +-
 gui/base/locale_util.cc                          |    2 +-
 gui/config_dialog/config_dialog.cc               |    8 +--
 gui/config_dialog/keybinding_editor.cc           |    8 +--
 gui/config_dialog/keymap_editor.cc               |    2 +-
 gui/dictionary_tool/dictionary_tool.cc           |    2 +-
 gui/gui.gyp                                      |    2 +-
 gui/qt_libraries.gypi                            |    2 +-
 gui/word_register_dialog/word_register_dialog.cc |    2 +-
 gui/zinnia.gyp                                   |    2 +-
 gyp/common.gypi                                  |   18 +++--
 handwriting/handwriting.gyp                      |    2 +-
 ipc/ipc_path_manager.cc                          |    6 +-
 ipc/ipc_path_manager_test.cc                     |    2 +-
 ipc/unix_ipc.cc                                  |   10 +--
 languages/chewing/chewing.gyp                    |    2 +-
 languages/hangul/hangul.gyp                      |    2 +-
 net/net.gyp                                      |    2 +-
 protobuf/genproto.gypi                           |    2 +-
 protobuf/protobuf.gyp                            |    6 +-
 session/session_converter_interface.h            |    2 +-
 session/session_test.cc                          |    4 +-
 39 files changed, 170 insertions(+), 80 deletions(-)

diff --git a/base/base.gyp b/base/base.gyp
index eb71957..28a6a3f 100755
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -104,7 +104,7 @@
         # shared among *host* binaries and *target* binaries. This means that
         # you should implement *host* binaries by using limited libraries
         # which are also available on NDK.
-        ['OS=="linux" and target_platform!="Android" and '
+        ['OS=="gnu-kfreebsd" or (OS=="linux" and target_platform!="Android") and '
          'not (target_platform=="NaCl" and _toolset=="target")', {
           'defines': [
             'HAVE_LIBRT=1',
@@ -235,7 +235,7 @@
             ],
           }
         }],
-        ['OS=="linux" and target_platform!="Android"', {
+        ['OS=="gnu-kfreebsd" or (OS=="linux" and target_platform!="Android")', {
           'cflags': [
             '<!@(<(pkg_config_command) --cflags-only-other openssl)',
           ],
diff --git a/base/cpu_stats.cc b/base/cpu_stats.cc
index e915b35..a53141d 100755
--- a/base/cpu_stats.cc
+++ b/base/cpu_stats.cc
@@ -122,7 +122,7 @@ float CPUStats::GetSystemCPULoad() {
 
 #endif  // OS_MACOSX
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // NOT IMPLEMENTED
   // TODO(taku): implement Linux version
   // can take the info from /proc/stats
@@ -177,7 +177,7 @@ float CPUStats::GetCurrentProcessCPULoad() {
       TimeValueTToInt64(task_times_info.system_time);
 #endif  // OS_MACOSX
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // not implemented
   const uint64 total_times = 0;
   const uint64 cpu_times = 0;
@@ -209,7 +209,7 @@ size_t CPUStats::GetNumberOfProcessors() const {
   return static_cast<size_t>(basic_info.avail_cpus);
 #endif  // OS_MACOSX
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // Not implemented
   return 1;
 #endif  // OS_LINUX
diff --git a/base/flags.h b/base/flags.h
index 4b2004f..838f2e5 100755
--- a/base/flags.h
+++ b/base/flags.h
@@ -75,7 +75,7 @@ extern void InitGoogleInternal(const char *arg0,
 // so that CrashReportHandler() is resovled in link time
 inline void InstallBreakpad() {
 #ifdef GOOGLE_JAPANESE_INPUT_BUILD
-#ifndef OS_LINUX
+#if !defined(OS_LINUX) && !defined(OS_GNU_KFREEBSD) && !defined(OS_FREEBSD)
   if (StatsConfigUtil::IsEnabled()) {
     CrashReportHandler::Initialize(false);
   }
diff --git a/base/iconv.cc b/base/iconv.cc
index 84c6380..6785171 100755
--- a/base/iconv.cc
+++ b/base/iconv.cc
@@ -52,7 +52,11 @@ bool IconvHelper(iconv_t ic, const string &input, string *output) {
   size_t olen_org = olen;
   iconv(ic, 0, &ilen, 0, &olen);  // reset iconv state
   while (ilen != 0) {
+#ifdef OS_FREEBSD
+    if (iconv(ic, (const char **)(&ibuf), &ilen, &obuf, &olen)
+#else
     if (iconv(ic, reinterpret_cast<char **>(&ibuf), &ilen, &obuf, &olen)
+#endif
         == static_cast<size_t>(-1)) {
       return false;
     }
diff --git a/base/logging.cc b/base/logging.cc
index 10578ef..06d5b15 100755
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -75,12 +75,7 @@ string Logging::GetLogMessageHeader() {
   char buf[512];
   snprintf(buf, sizeof(buf),
            "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d %u "
-#if !defined(OS_LINUX) || defined(__native_client__)
-// = OS_WINDOWS or OS_MACOSX or __native_client__
-           "%u",
-#else
            "%lu",
-#endif
            1900 + tm_time.tm_year,
            1 + tm_time.tm_mon,
            tm_time.tm_mday,
diff --git a/base/mutex.cc b/base/mutex.cc
index 930e24d..44d58c0 100755
--- a/base/mutex.cc
+++ b/base/mutex.cc
@@ -44,7 +44,8 @@ namespace mozc {
 
 // Wrapper for Windows InterlockedCompareExchange
 namespace {
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
+// TODO(taku):
 // Linux doesn't provide InterlockedCompareExchange-like function.
 inline int InterlockedCompareExchange(volatile int *target,
                                       int new_value,
diff --git a/base/mutex.h b/base/mutex.h
index c5df9c8..7cc89b3 100755
--- a/base/mutex.h
+++ b/base/mutex.h
@@ -97,10 +97,14 @@ class Mutex {
 #define PTHREAD_MUTEX_RECURSIVE_VALUE PTHREAD_MUTEX_RECURSIVE
 #endif
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #define PTHREAD_MUTEX_RECURSIVE_VALUE PTHREAD_MUTEX_RECURSIVE_NP
 #endif
 
+#ifdef OS_FREEBSD
+#define PTHREAD_MUTEX_RECURSIVE_VALUE PTHREAD_MUTEX_RECURSIVE
+#endif
+
     pthread_mutexattr_t attr;
     pthread_mutexattr_init(&attr);
     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_VALUE);
diff --git a/base/password_manager.cc b/base/password_manager.cc
index aa8b6b4..42718af 100755
--- a/base/password_manager.cc
+++ b/base/password_manager.cc
@@ -363,7 +363,7 @@ class DeprecatedMacPasswordManager : public PasswordManagerInterface {
 // this module to other Linux distro, you might want to implement
 // a new password manager which adopts some secure mechanism such
 // like gnome-keyring.
-#if defined OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 typedef PlainPasswordManager DefaultPasswordManager;
 #endif
 
diff --git a/base/process.cc b/base/process.cc
index 51eae95..7f2d89b 100755
--- a/base/process.cc
+++ b/base/process.cc
@@ -51,7 +51,7 @@
 #include "base/mac_process.h"
 #endif  // OS_MACOSX
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #include <fcntl.h>
 #include <signal.h>
 #include <spawn.h>  // for posix_spawn().
@@ -120,7 +120,7 @@ bool Process::OpenBrowser(const string &url) {
   return ShellExecuteInSystemDir(L"open", wurl.c_str(), NULL, SW_SHOW);
 #endif
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   static const char kBrowserCommand[] = "/usr/bin/xdg-open";
   // xdg-open which uses kfmclient or gnome-open internally works both on KDE
   // and GNOME environments.
@@ -204,7 +204,7 @@ bool Process::SpawnProcess(const string &path,
   }
 #endif
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // Do not call posix_spawn() for obviously bad path.
   if (!S_ISREG(statbuf.st_mode)) {
     LOG(ERROR) << "Not a regular file: " << path;
@@ -399,7 +399,7 @@ bool Process::LaunchErrorMessageDialog(const string &error_type) {
   }
 #endif  // OS_WINDOWS
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   const char kMozcTool[] = "mozc_tool";
   const string arg = "--mode=error_message_dialog --error_type=" + error_type;
   size_t pid = 0;
diff --git a/base/run_level.cc b/base/run_level.cc
index 8b1fe47..cc4c58a 100755
--- a/base/run_level.cc
+++ b/base/run_level.cc
@@ -38,7 +38,7 @@
 #include <windows.h>
 #endif
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #include <unistd.h>
 #include <sys/types.h>
 #endif
diff --git a/base/thread.h b/base/thread.h
index 0397937..c2488e9 100755
--- a/base/thread.h
+++ b/base/thread.h
@@ -61,7 +61,8 @@
 
 // Andorid NDK and NaCl don't support TLS.
 #if defined(OS_LINUX) && !defined(OS_ANDROID) && \
-    !defined(__native_client__) && (defined(__GNUC__) || defined(__clang__))
+    !defined(__native_client__) && (defined(__GNUC__) || defined(__clang__)) || \
+	defined(OS_GNU_KFREEBSD)
 // GCC and Clang support TLS.
 #define TLS_KEYWORD __thread
 #define HAVE_TLS 1
diff --git a/base/util.cc b/base/util.cc
index 3b39cb6..846fcfb 100755
--- a/base/util.cc
+++ b/base/util.cc
@@ -1414,7 +1414,7 @@ class ClockImpl : public Util::ClockInterface {
     mach_timebase_info(&timebase_info);
     return static_cast<uint64>(
         1.0e9 * timebase_info.denom / timebase_info.numer);
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #if defined(HAVE_LIBRT)
     return 1000000000uLL;
 #else
@@ -1434,7 +1434,7 @@ class ClockImpl : public Util::ClockInterface {
     return static_cast<uint64>(timestamp.QuadPart);
 #elif defined(OS_MACOSX)
     return static_cast<uint64>(mach_absolute_time());
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #if defined(HAVE_LIBRT)
     struct timespec timestamp;
     if (-1 == clock_gettime(CLOCK_REALTIME, &timestamp)) {
@@ -2746,7 +2746,7 @@ string Util::GetServerDirectory() {
   return MacUtil::GetServerDirectory();
 #endif  // OS_MACOSX
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   return kMozcServerDirectory;
 #endif  // OS_LINUX
 }
@@ -2847,7 +2847,7 @@ bool GetCurrentSessionId(DWORD *session_id) {
 #endif  // OS_WINDOWS
 
 string Util::GetDesktopNameAsString() {
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   const char *display = getenv("DISPLAY");
   if (display == NULL) {
     return "";
@@ -3357,7 +3357,7 @@ bool Util::IsPlatformSupported() {
 #if defined(OS_MACOSX)
   // TODO(yukawa): support Mac.
   return true;
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // TODO(yukawa): support Linux.
   return true;
 #elif defined(OS_WINDOWS)
@@ -3793,6 +3793,9 @@ string Util::GetOSVersionString() {
 #elif defined(OS_LINUX)
   const string ret = "Linux";
   return ret;
+#elif defined(OS_GNU_KFREEBSD)
+  const string ret = "GNU/kFreeBSD";
+  return ret;
 #else
   const string ret = "Unknown";
   return ret;
@@ -3830,7 +3833,7 @@ uint64 Util::GetTotalPhysicalMemory() {
     return 0;
   }
   return total_memory;
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #if defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES)
   const long page_size = sysconf(_SC_PAGESIZE);
   const long number_of_phyisical_pages = sysconf(_SC_PHYS_PAGES);
@@ -3856,7 +3859,7 @@ void Util::PreloadMappedRegion(const void *begin,
   ::ZeroMemory(&system_info, sizeof(system_info));
   ::GetSystemInfo(&system_info);
   const size_t page_size = system_info.dwPageSize;
-#elif defined(OS_MACOSX) || defined(OS_LINUX)
+#elif defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #if defined(_SC_PAGESIZE)
   const size_t page_size = sysconf(_SC_PAGESIZE);
 #else
diff --git a/base/util_test.cc b/base/util_test.cc
index 11ae77f..3dc5a44 100755
--- a/base/util_test.cc
+++ b/base/util_test.cc
@@ -3626,7 +3626,7 @@ TEST(UtilTest, MacMaybeMLockTest) {
 TEST(UtilTest, LinuxMaybeMLockTest) {
   size_t data_len = 32;
   void *addr = malloc(data_len);
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #if defined(OS_ANDROID) || defined(__native_client__)
   EXPECT_EQ(-1, Util::MaybeMLock(addr, data_len));
   EXPECT_EQ(-1, Util::MaybeMUnlock(addr, data_len));
diff --git a/build_mozc.py b/build_mozc.py
index f584489..979598d 100755
--- a/build_mozc.py
+++ b/build_mozc.py
@@ -93,6 +93,14 @@ def GetMozcVersion():
   # TODO(matsuzakit): Caching might be better.
   return mozc_version.MozcVersion('%s/mozc_version.txt' % SRC_DIR)
 
+def IsFreeBSD():
+  """Returns true if the platform is FreeBSD."""
+  return os.name == 'posix' and os.uname()[0] == 'FreeBSD'
+
+def IsGNUkFreeBSD():
+  """Returns true if the platform is GNU/kFreeBSD."""
+  os.environ['GYP_DEFINES'] = 'OS=="GNU/kFreeBSD"'
+  return os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD'
 
 def GetColoredText(text, color):
   """Gets colored text for terminal."""
@@ -183,7 +191,7 @@ def GetBuildBaseName(options, target_platform):
     build_base = 'out_win'
   elif target_platform == 'Mac':
     build_base = 'out_mac'
-  elif target_platform == 'Linux' or target_platform == 'ChromeOS':
+  elif target_platform == 'Linux' or target_platform == 'ChromeOS' or target_platform == 'GNU/kFreeBSD':
     build_base = 'out_linux'
   elif target_platform == 'Android':
     build_base = 'out_android'
@@ -310,7 +318,7 @@ def GetGypFileNames(options):
   if IsWindows():
     gyp_file_names.extend(glob.glob('%s/win32/*/*.gyp' % SRC_DIR))
     gyp_file_names.extend(glob.glob('third_party/breakpad/*.gyp'))
-  elif IsLinux():
+  elif IsLinux() or IsGNUkFreeBSD():
     gyp_file_names.extend(glob.glob('%s/unix/*/*.gyp' % SRC_DIR))
     # Add ibus.gyp if ibus is installed.
     # Ubuntu 8.04 (Hardy) does not contain ibus package.
@@ -380,6 +388,7 @@ def AddCommonOptions(parser):
                     help='Specifies the base directory of the built binaries.')
   parser.add_option('--language', dest='language', default='japanese',
                     help='Specify the target language to build.')
+  parser.add_option('--os', dest='os', default='linux')
   return parser
 
 
@@ -394,6 +403,10 @@ def AddTargetPlatformOption(parser):
     default_target = 'Windows'
   elif IsMac():
     default_target = 'Mac'
+  elif IsFreeBSD():
+    default_target = 'FreeBSD'
+  elif IsGNUkFreeBSD():
+    default_target = 'GNU/kFreeBSD'
   parser.add_option('--target_platform', dest='target_platform',
                     default=default_target,
                     help=('Linux environment can build for Linux, Android  and '
@@ -566,7 +579,7 @@ def ExpandMetaTarget(meta_target_name):
   # Note that ChromeOS does not use this method.
   if target_platform == 'Android':
     targets = ['%s/android/android.gyp:apk']
-  elif target_platform == 'Linux':
+  elif target_platform == 'Linux' or  target_platform == 'Linux' :
     targets = ['%s/unix/ibus/ibus.gyp:ibus_mozc',
                '%s/server/server.gyp:mozc_server',
                '%s/renderer/renderer.gyp:mozc_renderer',
@@ -585,7 +598,7 @@ def ParseBuildOptions(args=None, values=None):
   """Parses command line options for the build command."""
   parser = optparse.OptionParser(usage='Usage: %prog build [options]')
   AddCommonOptions(parser)
-  if IsLinux():
+  if IsLinux() or IsGNUkFreeBSD():
     default_build_concurrency = GetNumberOfProcessors() * 2
     parser.add_option('--jobs', '-j', dest='jobs',
                       default=('%d' % default_build_concurrency),
@@ -605,7 +618,7 @@ def ParseRunTestsOptions(args=None, values=None):
   parser = optparse.OptionParser(
       usage='Usage: %prog runtests [options] [test_targets] [-- build options]')
   AddCommonOptions(parser)
-  if IsLinux():
+  if IsLinux() or IsGNUkFreeBSD():
     default_build_concurrency = GetNumberOfProcessors() * 2
     parser.add_option('--jobs', '-j', dest='jobs',
                       default=('%d' % default_build_concurrency),
@@ -734,6 +747,8 @@ def GypMain(options, unused_args):
     command_line.extend(['-D', 'wix_dir=%s' % options.wix_dir])
   else:
     command_line.extend(['-D', 'use_wix=NO'])
+  if options.os: 
+    command_line.extend(['-D', 'OS=%s' % options.os])
 
   command_line.extend(['-D', 'build_base=%s' %
                        GetBuildBaseName(options, version.GetTargetPlatform())])
@@ -766,7 +781,7 @@ def GypMain(options, unused_args):
 
   def SetCommandLineForFeature(option_name, windows=False, mac=False,
                                linux=False, chromeos=False, android=False,
-                               nacl=False):
+                               nacl=False, freebsd=False, gnu_kfreebsd=False):
     """Updates an option like '--enable_foober' and add a -D argument for gyp.
 
     This function ensures an option like '--enable_foober' exists and it has a
@@ -790,6 +805,10 @@ def GypMain(options, unused_args):
           option on Android platform.
       nacl: A boolean which replesents the default value of the target
           option on NaCl.
+      freebsd: A boolean which replesents the default value of the target
+          option on FreeBSD platform.
+      gnu_fkreebsd: A boolean which replesents the default value of the target
+          option on GNU/kFreeBSD platform.
 
     Raises:
       ValueError: An error occurred when 'option_name' is empty.
@@ -803,6 +822,7 @@ def GypMain(options, unused_args):
                        'Linux': linux,
                        'ChromeOS': chromeos,
                        'Android': android,
+                       'GNU/kFreeBSD': gnu_kfreebsd,
                        'NaCl': nacl}[options.target_platform]
     enable_option_name = 'enable_%s' % option_name
     enabled = options.ensure_value(enable_option_name, default_enabled)
@@ -861,7 +881,7 @@ def GypMain(options, unused_args):
   else:
     command_line.extend(['-D', 'use_zinnia=NO'])
 
-  if IsLinux():
+  if IsLinux() or IsGNUkFreeBSD():
     if '%s/unix/ibus/ibus.gyp' % SRC_DIR in gyp_file_names:
       command_line.extend(['-D', 'use_libibus=1'])
     if '%s/unix/scim/scim.gyp' % SRC_DIR in gyp_file_names:
@@ -886,7 +906,7 @@ def GypMain(options, unused_args):
   # command for pkg-config.  Here we catch the environment variable
   # and use the specified command instead of actual pkg-config
   # command.
-  if IsLinux():
+  if IsLinux() or IsFreeBSD() or IsGNUkFreeBSD():
     command_line.extend(['-D', 'pkg_config_command=%s' % GetPkgConfigCommand()])
   else:
     command_line.extend(['-D', 'pkg_config_command='])
@@ -1020,6 +1040,44 @@ def BuildOnMac(options, targets, original_directory_name):
               '-parallelizeTargets',
               'BUILD_WITH_GYP=1'])
 
+def BuildOnBSD(options, targets, unused_original_directory_name):
+  """Build the targets on *BSD."""
+  target_names = []
+  for target in targets:
+    (unused_gyp_file_name, target_name) = (
+        CanonicalTargetToGypFileAndTargetName(target))
+    target_names.append(target_name)
+
+  if os.uname()[0] == 'FreeBSD' :
+    make_command = os.getenv('BUILD_COMMAND', 'gmake')
+  else:
+    make_command = os.getenv('BUILD_COMMAND', 'make')
+  # flags for building in Chrome OS chroot environment
+  envvars = [
+      'CFLAGS',
+      'CXXFLAGS',
+      'CXX',
+      'CC',
+      'AR',
+      'AS',
+      'RANLIB',
+      'LD',
+  ]
+  for envvar in envvars:
+    if envvar in os.environ:
+      os.environ[envvar] = os.getenv(envvar)
+
+  # set output directory
+  os.environ['builddir_name'] = 'out_bsd'
+
+  build_args = ['-j%s' % options.jobs,
+                'MAKE_JOBS=%s' % options.jobs,
+                'BUILDTYPE=%s' % options.configuration]
+  build_args.append('builddir_name=%s' %
+                    GetBuildBaseName(options,
+                                     GetMozcVersion().GetTargetPlatform()))
+
+  RunOrDie([make_command] + build_args + target_names)
 
 def LocateMSBuildDir():
   """Locate the directory where msbuild.exe exists.
@@ -1171,6 +1229,8 @@ def BuildMain(options, targets, original_directory_name):
     BuildOnMac(options, targets, original_directory_name)
   elif IsLinux():
     BuildOnLinux(options, targets, original_directory_name)
+  elif IsFreeBSD() or IsGNUkFreeBSD():
+    BuildOnBSD(options, targets, original_directory_name)
   elif IsWindows():
     BuildOnWindows(options, targets, original_directory_name)
   else:
@@ -1323,7 +1383,7 @@ def CleanBuildFilesAndDirectories(options, unused_args):
     elif IsMac():
       directory_names.extend(glob.glob(os.path.join(gyp_directory_name,
                                                     '*.xcodeproj')))
-    elif IsLinux():
+    elif IsLinux() or IsFreeBSD() or IsGNUkFreeBSD():
       file_names.extend(glob.glob(os.path.join(gyp_directory_name,
                                                '*.target.mk')))
       file_names.extend(glob.glob(os.path.join(gyp_directory_name,
@@ -1350,6 +1410,10 @@ def CleanBuildFilesAndDirectories(options, unused_args):
     file_names.append('Makefile')
   elif IsWindows():
     file_names.append('third_party/breakpad/breakpad.gyp')
+    directory_names.append('out_win')
+  elif IsFreeBSD() or IsGNUkFreeBSD():
+    file_names.append('Makefile')
+    directory_names.append('out_bsd')
   # Remove files.
   for file_name in file_names:
     RemoveFile(file_name)
@@ -1376,7 +1440,6 @@ def ShowHelpAndExit():
   print 'See also the comment in the script for typical usage.'
   sys.exit(1)
 
-
 def main():
   logging.basicConfig(level=logging.INFO, format='%(message)s')
 
diff --git a/build_tools/mozc_version.py b/build_tools/mozc_version.py
index e8bbafd..6f38964 100755
--- a/build_tools/mozc_version.py
+++ b/build_tools/mozc_version.py
@@ -56,6 +56,13 @@ import os
 import re
 import sys
 
+def IsFreeBSD():
+  """Returns true if the platform is FreeBSD."""
+  return os.name == 'posix' and os.uname()[0] == 'FreeBSD'
+
+def IsGNUkFreeBSD():
+  """Returns true if the platform is GNU/kFreeBSD."""
+  return os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD'
 
 TARGET_PLATFORM_TO_DIGIT = {
     'Windows': '0',
@@ -64,6 +71,8 @@ TARGET_PLATFORM_TO_DIGIT = {
     'ChromeOS': '2',
     'Android': '3',
     'NaCl': '4',
+	'FreeBSD': '5',
+	'GNU/kFreeBSD': '6',
     }
 
 VERSION_PROPERTIES = [
diff --git a/chrome/skk/skk.gyp b/chrome/skk/skk.gyp
index 3b82e84..ec69cc1 100755
--- a/chrome/skk/skk.gyp
+++ b/chrome/skk/skk.gyp
@@ -42,7 +42,7 @@
     'configuration_nacl_i686': '<(CONFIGURATION_NAME)_NaCl_i686',
     'configuration_nacl_x86_64': '<(CONFIGURATION_NAME)_NaCl_x86-64',
     'conditions': [
-      ['OS=="linux"', {
+      ['OS=="linux" or OS=="gnu-kfreebsd"', {
         # We need to copy binaries for NaCl i686 and x86-64 into a single skk
         # directory across configurations.  The following variables must be
         # the same as <(PRODUCT_DIR) for each configuration.
diff --git a/client/client.cc b/client/client.cc
index 5cc62a2..5265601 100755
--- a/client/client.cc
+++ b/client/client.cc
@@ -933,7 +933,7 @@ bool Client::LaunchTool(const string &mode, const string &extra_arg) {
     return false;
   }
 
-#if defined(OS_WINDOWS) || defined(OS_LINUX)
+#if defined(OS_WINDOWS) || defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   string arg = "--mode=" + mode;
   if (!extra_arg.empty()) {
     arg += " ";
diff --git a/config/stats_config_util_test.cc b/config/stats_config_util_test.cc
index ed5ebd2..8be77d1 100755
--- a/config/stats_config_util_test.cc
+++ b/config/stats_config_util_test.cc
@@ -687,7 +687,7 @@ TEST_F(StatsConfigUtilTestWin, IsEnabled) {
 #endif  // OS_WINDOWS
 
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 TEST(StatsConfigUtilTestLinux, DefaultValueTest) {
   EXPECT_FALSE(mozc::StatsConfigUtil::IsEnabled());
 }
diff --git a/gui/base/locale_util.cc b/gui/base/locale_util.cc
index 3bc8e98..6c1ccb3 100755
--- a/gui/base/locale_util.cc
+++ b/gui/base/locale_util.cc
@@ -206,7 +206,7 @@ TranslationDataImpl::TranslationDataImpl()
   qApp->installEventFilter(&window_title_modifier_);
 #endif  // MOZC_SHOW_BUILD_NUMBER_ON_TITLE
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // Use system default messages.
   // Even if the locale is not English nor Japanese, load translation
   // file to translate common messages like "OK" and "Cancel".
diff --git a/gui/config_dialog/config_dialog.cc b/gui/config_dialog/config_dialog.cc
index d5ade5e..77b536b 100755
--- a/gui/config_dialog/config_dialog.cc
+++ b/gui/config_dialog/config_dialog.cc
@@ -81,7 +81,7 @@ ConfigDialog::ConfigDialog()
   miscAdministrationWidget->setVisible(false);
 #endif  // OS_MACOSX
 
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   miscDefaultIMEWidget->setVisible(false);
   miscAdministrationWidget->setVisible(false);
   miscStartupWidget->setVisible(false);
@@ -91,7 +91,7 @@ ConfigDialog::ConfigDialog()
   // disable logging options
   miscLoggingWidget->setVisible(false);
 
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // The last "misc" tab has no valid configs on Linux
   const int kMiscTabIndex = 6;
   configDialogTabWidget->removeTab(kMiscTabIndex);
@@ -320,7 +320,7 @@ ConfigDialog::ConfigDialog()
   dictionaryPreloadingAndUACLabel->setVisible(false);
 #endif  // OS_WINDOWS
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // On Linux, disable all fields for UsageStats
   usageStatsLabel->setEnabled(false);
   usageStatsLabel->setVisible(false);
@@ -436,7 +436,7 @@ bool ConfigDialog::Update() {
   }
 
 
-#if defined(OS_WINDOWS) || defined(OS_LINUX)
+#if defined(OS_WINDOWS) || defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   if (initial_preedit_method_ !=
       static_cast<int>(config.preedit_method()) ||
       initial_use_keyboard_to_change_preedit_method_ !=
diff --git a/gui/config_dialog/keybinding_editor.cc b/gui/config_dialog/keybinding_editor.cc
index 0644079..7d7728a 100755
--- a/gui/config_dialog/keybinding_editor.cc
+++ b/gui/config_dialog/keybinding_editor.cc
@@ -33,7 +33,7 @@
 #include <windows.h>
 #include <imm.h>
 #include <ime.h>
-#elif OS_LINUX
+#elif defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 #define XK_MISCELLANY
 #include <X11/keysymdef.h>
 #endif
@@ -121,7 +121,7 @@ const WinVirtualKeyEntry kWinVirtualKeyModifierNonRequiredTable[] = {
   { VK_DBE_DBCSCHAR, "Hankaku/Zenkaku" },        // Zenkaku/hankaku
   // { VK_KANJI, "Kanji" },  // Do not support Kanji
 };
-#elif OS_LINUX
+#elif defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
 struct LinuxVirtualKeyEntry {
   uint16 virtual_key;
   const char *mozc_key_name;
@@ -390,7 +390,7 @@ KeyBindingFilter::KeyState KeyBindingFilter::AddKey(
       return Encode(result);
     }
   }
-#elif OS_LINUX
+#elif defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   const uint16 virtual_key = key_event.nativeVirtualKey();
 
   // The XKB defines three types of logical key code: "xkb::Hiragana",
@@ -500,7 +500,7 @@ bool KeyBindingFilter::eventFilter(QObject *obj, QEvent *event) {
 KeyBindingEditor::KeyBindingEditor(QWidget *parent, QWidget *trigger_parent)
     : QDialog(parent), trigger_parent_(trigger_parent) {
   setupUi(this);
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // Workaround for the issue http://code.google.com/p/mozc/issues/detail?id=9
   // Seems that even after clicking the button for the keybinding dialog,
   // the edit is not raised. This might be a bug of setFocusProxy.
diff --git a/gui/config_dialog/keymap_editor.cc b/gui/config_dialog/keymap_editor.cc
index 6d33630..6285618 100755
--- a/gui/config_dialog/keymap_editor.cc
+++ b/gui/config_dialog/keymap_editor.cc
@@ -447,7 +447,7 @@ bool KeyMapEditorDialog::Update() {
   *keymap_table += invisible_keymap_table_;
 
   if (new_ime_switch_keymap != ime_switch_keymap_) {
-#if defined(OS_WINDOWS) || defined(OS_LINUX)
+#if defined(OS_WINDOWS) || defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
     QMessageBox::information(
         this,
         tr("Mozc settings"),
diff --git a/gui/dictionary_tool/dictionary_tool.cc b/gui/dictionary_tool/dictionary_tool.cc
index d47ce0c..608f57d 100755
--- a/gui/dictionary_tool/dictionary_tool.cc
+++ b/gui/dictionary_tool/dictionary_tool.cc
@@ -327,7 +327,7 @@ DictionaryTool::DictionaryTool(QWidget *parent)
   }
 
   // main window
-#ifndef OS_LINUX
+#if !defined(OS_LINUX) && !defined(OS_GNU_KFREEBSD) && !defined(OS_FREEBSD)
   // For some reason setCentralWidget crashes the dictionary_tool on Linux
   // TODO(taku): investigate the cause of the crashes
   setCentralWidget(splitter_);
diff --git a/gui/gui.gyp b/gui/gui.gyp
index fc05c5e..bc0abe1 100755
--- a/gui/gui.gyp
+++ b/gui/gui.gyp
@@ -387,7 +387,7 @@
             '../session/session_base.gyp:session_protocol',
           ],
         }],
-        ['use_libzinnia==1 and OS=="linux"', {
+        ['use_libzinnia==1 and (OS=="linux" or OS=="gnu-kfreebsd")', {
           'defines': [
             'USE_LIBZINNIA',
           ],
diff --git a/gui/qt_libraries.gypi b/gui/qt_libraries.gypi
index 8b4a80a..059d844 100755
--- a/gui/qt_libraries.gypi
+++ b/gui/qt_libraries.gypi
@@ -84,7 +84,7 @@
         '$(SDKROOT)/System/Library/Frameworks/Carbon.framework',
       ]
     }],
-    ['OS=="linux"', {
+    ['OS=="linux" or OS=="gnu-kfreebsd"', {
       'conditions': [
         ['qt_dir', {
           'libraries': [
diff --git a/gui/word_register_dialog/word_register_dialog.cc b/gui/word_register_dialog/word_register_dialog.cc
index 1310118..4e170cc 100755
--- a/gui/word_register_dialog/word_register_dialog.cc
+++ b/gui/word_register_dialog/word_register_dialog.cc
@@ -74,7 +74,7 @@ QString GetEnv(const char *envname) {
   }
   return "";
 #endif  // OS_WINDOWS
-#if defined(OS_MACOSX) || defined(OS_LINUX)
+#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   return ::getenv(envname);
 #endif  // OS_MACOSX or OS_LINUX
   // TODO(team): Support other platforms.
diff --git a/gui/zinnia.gyp b/gui/zinnia.gyp
index e4d323a..dc6d8a9 100755
--- a/gui/zinnia.gyp
+++ b/gui/zinnia.gyp
@@ -45,7 +45,7 @@
       'target_name': 'zinnia',
       'type': 'static_library',
       'conditions': [
-        ['OS=="linux"', {
+        ['OS=="linux" or OS=="gnu-kfreebsd"', {
           'conditions': [
             ['use_libzinnia==1', {
               'link_settings': {
diff --git a/gyp/common.gypi b/gyp/common.gypi
index ef8fb08..d40ac35 100755
--- a/gyp/common.gypi
+++ b/gyp/common.gypi
@@ -269,12 +269,12 @@
           # additional suffix except for Japanese so that multiple
           # converter processes can coexist. Note that Mozc on ChromeOS does
           # not use IPC so this kind of special treatment is not required.
-          ['language!="japanese" and target_platform=="Linux"', {
+          ['language!="japanese" and target_platform=="Linux" or target_platform=="GNU/kFreeBSD"', {
             'defines': [
               'MOZC_LANGUAGE_SUFFIX_FOR_LINUX="_<(language)"',
             ],
           }],
-          ['OS=="linux"', {
+          ['OS=="linux" or OS=="gnu-kfreebsd"', {
             'ldflags': [
               '<@(linux_ldflags)',
             ],
@@ -416,7 +416,7 @@
           },
         },
         'conditions': [
-          ['OS=="linux"', {
+          ['OS=="linux" or OS=="gnu-kfreebsd"', {
             'cflags': [
               '<@(debug_extra_cflags)',
             ],
@@ -454,7 +454,7 @@
           },
         },
         'conditions': [
-          ['OS=="linux"', {
+          ['OS=="linux" or OS=="gnu-kfreebsd"', {
             'cflags': [
               '<@(release_extra_cflags)',
             ],
@@ -760,6 +760,16 @@
           }],
         ],
       }],
+      ['OS=="gnu-kfreebsd"', {
+        'defines': [
+          'OS_GNU_KFREEBSD',
+        ],
+        'cflags': [
+          '<@(gcc_cflags)',
+          '-fPIC',
+          '-fno-exceptions',
+        ],
+      }],
       ['OS=="mac"', {
         'defines': [
           'OS_MACOSX',
diff --git a/handwriting/handwriting.gyp b/handwriting/handwriting.gyp
index 1538d43..b78e773 100755
--- a/handwriting/handwriting.gyp
+++ b/handwriting/handwriting.gyp
@@ -39,7 +39,7 @@
         '../base/base.gyp:base',
         '../gui/zinnia.gyp:zinnia',
       ],
-      'conditions': [['use_libzinnia==1 and OS=="linux"', {
+      'conditions': [['use_libzinnia==1 and (OS=="linux" or OS=="gnu-kfreebsd")', {
         'defines': [
           'USE_LIBZINNIA',
         ],
diff --git a/ipc/ipc_path_manager.cc b/ipc/ipc_path_manager.cc
index 86f4a0c..b000cda 100755
--- a/ipc/ipc_path_manager.cc
+++ b/ipc/ipc_path_manager.cc
@@ -284,7 +284,7 @@ bool IPCPathManager::GetPathName(string *ipc_name) const {
   *ipc_name = kIPCPrefix;
 #endif  // OS_WINDOWS
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // On Linux, use abstract namespace which is independent of the file system.
   (*ipc_name)[0] = '\0';
 #endif
@@ -377,7 +377,7 @@ bool IPCPathManager::IsValidServer(uint32 pid,
   }
 #endif
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   // load from /proc/<pid>/exe
   char proc[128];
   char filename[512];
@@ -397,7 +397,7 @@ bool IPCPathManager::IsValidServer(uint32 pid,
     return true;
   }
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
   if ((server_path + " (deleted)") == server_path_) {
     LOG(WARNING) << server_path << " on disk is modified";
     // If a user updates the server binary on disk during the server is running,
diff --git a/ipc/ipc_path_manager_test.cc b/ipc/ipc_path_manager_test.cc
index e1e2481..7b7e5c8 100755
--- a/ipc/ipc_path_manager_test.cc
+++ b/ipc/ipc_path_manager_test.cc
@@ -102,7 +102,7 @@ TEST_F(IPCPathManagerTest, IPCPathManagerTest) {
   EXPECT_FALSE(manager->GetServerProductVersion().empty());
   EXPECT_GT(manager->GetServerProcessId(), 0);
   EXPECT_EQ(t.path(), path);
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) 
   // On Linux, |path| should be abstract (see man unix(7) for details.)
   ASSERT_FALSE(path.empty());
   EXPECT_EQ('\0', path[0]);
diff --git a/ipc/unix_ipc.cc b/ipc/unix_ipc.cc
index 7b85039..4da8032 100755
--- a/ipc/unix_ipc.cc
+++ b/ipc/unix_ipc.cc
@@ -28,7 +28,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 // skip all if non-Linux or Android.
-#if defined(OS_LINUX) && !defined(OS_ANDROID)
+#if (defined(OS_LINUX) && !defined(OS_ANDROID)) || defined(OS_GNU_KFREEBSD)
 
 #include "ipc/ipc.h"
 
@@ -41,7 +41,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/un.h>
-#ifdef OS_MACOSX
+#if defined(OS_MACOSX) || defined(OS_FREEBSD)
 #include <sys/ucred.h>
 #endif
 #include <sys/wait.h>
@@ -124,7 +124,7 @@ bool IsWriteTimeout(int socket, int timeout) {
 bool IsPeerValid(int socket, pid_t *pid) {
   *pid = 0;
 
-#ifdef OS_MACOSX
+#if defined(OS_MACOSX) || defined(OS_FREEBSD)
   // If the OS is MAC, we should validate the peer by using LOCAL_PEERCRED.
   struct xucred peer_cred;
   socklen_t peer_cred_len = sizeof(struct xucred);
@@ -146,7 +146,7 @@ bool IsPeerValid(int socket, pid_t *pid) {
   *pid = 0;
 #endif
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX)
   // On ARM Linux, we do nothing and just return true since the platform
   // sometimes doesn't support the getsockopt(sock, SOL_SOCKET, SO_PEERCRED)
   // system call.
@@ -185,7 +185,7 @@ bool SendMessage(int socket,
       return false;
     }
     const ssize_t l = ::send(socket, buf, buf_length_left,
-#ifdef OS_MACOSX
+#if defined(OS_MACOSX) || defined(OS_FREEBSD)
                              SO_NOSIGPIPE
 #else
                              MSG_NOSIGNAL
diff --git a/languages/chewing/chewing.gyp b/languages/chewing/chewing.gyp
index e94e8dd..a5bfb3c 100755
--- a/languages/chewing/chewing.gyp
+++ b/languages/chewing/chewing.gyp
@@ -55,7 +55,7 @@
     },
   ],
   'conditions': [
-    ['OS=="linux"', {
+    ['OS=="linux" or OS=="gnu-kfreebsd"', {
       'targets': [
         {
           'target_name': 'ibus_mozc_chewing',
diff --git a/languages/hangul/hangul.gyp b/languages/hangul/hangul.gyp
index bd5ee6f..3cb36de 100755
--- a/languages/hangul/hangul.gyp
+++ b/languages/hangul/hangul.gyp
@@ -59,7 +59,7 @@
     },
   ],
   'conditions': [
-    ['OS=="linux"', {
+    ['OS=="linux" or OS=="gnu-kfreebsd"', {
       'targets': [
         {
           'target_name': 'ibus_mozc_hangul',
diff --git a/net/net.gyp b/net/net.gyp
index 717bdd7..a0bcb88 100755
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -61,7 +61,7 @@
                 },
               },
             }],
-            ['target_platform=="Linux"', {
+            ['target_platform=="Linux" or OS=="gnu-kfreebsd"', {
               # Enable libcurl
               'cflags': [
                 '<!@(<(pkg_config_command) --cflags libcurl)',
diff --git a/protobuf/genproto.gypi b/protobuf/genproto.gypi
index a0db8b8..d67f511 100755
--- a/protobuf/genproto.gypi
+++ b/protobuf/genproto.gypi
@@ -34,7 +34,7 @@
     'build_tools_dir%': '../build_tools',
   },
   'conditions': [
-    ['OS!="linux"', {
+    ['OS!="linux" and OS!="gnu-kfreebsd"', {
       'variables': {
         'protoc_command%': '<(relative_dir)/<(mozc_build_tools_dir)/protoc<(EXECUTABLE_SUFFIX)',
       },
diff --git a/protobuf/protobuf.gyp b/protobuf/protobuf.gyp
index 6998e9f..c3f66aa 100755
--- a/protobuf/protobuf.gyp
+++ b/protobuf/protobuf.gyp
@@ -117,7 +117,7 @@
       'type': 'static_library',
       'toolsets': ['host', 'target'],
       'conditions': [
-        ['OS=="linux"', {
+        ['OS=="linux" or OS=="gnu-kfreebsd"', {
           'conditions': [
             ['use_libprotobuf==1', {
               'link_settings': {
@@ -162,7 +162,7 @@
         '.',
       ],
       'conditions': [
-        ['OS=="linux"', {
+        ['OS=="linux" or OS=="gnu-kfreebsd"', {
           'conditions': [
             ['use_libprotobuf!=1', {
               'cflags': [
@@ -199,7 +199,7 @@
       },
       'conditions': [
         # use system-installed protoc on Linux
-        ['OS!="linux"', {
+        ['OS!="linux" and OS!="gnu-kfreebsd"', {
           'includes' : [
             '../gyp/install_build_tool.gypi',
           ],
diff --git a/session/session_converter_interface.h b/session/session_converter_interface.h
index 0c55421..66310be 100755
--- a/session/session_converter_interface.h
+++ b/session/session_converter_interface.h
@@ -56,7 +56,7 @@ struct OperationPreferences {
   bool use_cascading_window;
   string candidate_shortcuts;
   OperationPreferences() {
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
     // TODO(komatsu): Move this logic to the client code.
     use_cascading_window = false;
 #else
diff --git a/session/session_test.cc b/session/session_test.cc
index 13d574f..a94f31a 100755
--- a/session/session_test.cc
+++ b/session/session_test.cc
@@ -2343,7 +2343,7 @@ TEST_F(SessionTest, OutputAllCandidateWords) {
 
     EXPECT_EQ(0, output.all_candidate_words().focused_index());
     EXPECT_EQ(commands::CONVERSION, output.all_candidate_words().category());
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
     // Cascading window is not supported on Linux, so the size of
     // candidate words is different from other platform.
     // TODO(komatsu): Modify the client for Linux to explicitly change
@@ -2371,7 +2371,7 @@ TEST_F(SessionTest, OutputAllCandidateWords) {
 
     EXPECT_EQ(1, output.all_candidate_words().focused_index());
     EXPECT_EQ(commands::CONVERSION, output.all_candidate_words().category());
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD)
     // Cascading window is not supported on Linux, so the size of
     // candidate words is different from other platform.
     // TODO(komatsu): Modify the client for Linux to explicitly change
-- 
1.7.10