Codebase list mozc / deb4d66 debian / patches / support-kfreebsd.patch
deb4d66

Tree @deb4d66 (Download .tar.gz)

support-kfreebsd.patch @deb4d66raw · 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
diff --git a/base/cpu_stats.cc b/base/cpu_stats.cc
index ef7ee3d..59094d9 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) || defined(OS_FREEBSD)
   // 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) || defined(OS_FREEBSD)
   // 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) || defined(OS_FREEBSD)
   // Not implemented
   return 1;
 #endif  // OS_LINUX
diff --git a/base/flags.h b/base/flags.h
index 18b9c58..fdb210d 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 79976b2..568395c 100755
--- a/base/iconv.cc
+++ b/base/iconv.cc
@@ -52,7 +52,11 @@ void 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;
     }
diff --git a/base/logging.cc b/base/logging.cc
index 6acf323..4a3e094 100755
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -212,7 +212,7 @@ string Logging::GetLogMessageHeader() {
   char buf[512];
   snprintf(buf, sizeof(buf),
            "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d %u "
-#ifndef OS_LINUX  // = OS_WINDOWS or OS_MACOSX
+#if !defined(OS_LINUX) && !defined(OS_GNU_KFREEBSD) && !defined(OS_FREEBSD)  // = OS_WINDOWS or OS_MACOSX
            "%u",
 #else
            "%lu",
diff --git a/base/mutex.cc b/base/mutex.cc
index 433d954..2b3b01a 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) || defined(OS_FREEBSD)
+// 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 5af82b9..07e280b 100755
--- a/base/mutex.h
+++ b/base/mutex.h
@@ -86,10 +86,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 cf0b422..61a381f 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) || defined(OS_FREEBSD)
 typedef PlainPasswordManager DefaultPasswordManager;
 #endif
 
diff --git a/base/process.cc b/base/process.cc
index c230b31..2d5859a 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) || defined(OS_FREEBSD)
 #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) || defined(OS_FREEBSD)
   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) || defined(OS_FREEBSD)
   // 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) || defined(OS_FREEBSD)
   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 cd7a42b..b82354b 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) || defined(OS_FREEBSD)
 #include <unistd.h>
 #include <sys/types.h>
 #endif
diff --git a/base/stopwatch.cc b/base/stopwatch.cc
index 15afad3..8ff2e29 100755
--- a/base/stopwatch.cc
+++ b/base/stopwatch.cc
@@ -39,7 +39,7 @@
 #include <unistd.h>
 #endif  // OS_MACOSX
 
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
 #include <sys/time.h>
 #endif  // OS_LINUX
 
@@ -65,7 +65,7 @@ int64 Stopwatch::GetFrequency() {
   return static_cast<int64>(1.0e9 * timebase_info.denom / timebase_info.numer);
 #endif  // OS_MACOSX
 
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   return 1000000000LL;
 #endif  // OS_LINUX
 }
@@ -83,7 +83,7 @@ int64 Stopwatch::GetTimestamp() {
   return static_cast<int64>(mach_absolute_time());
 #endif  // OS_MACOSX
 
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   struct timespec timestamp;
   if (-1 == clock_gettime(CLOCK_REALTIME, &timestamp)) {
     return 0;
diff --git a/base/thread.h b/base/thread.h
index 681c3f6..e1d9ecf 100755
--- a/base/thread.h
+++ b/base/thread.h
@@ -58,10 +58,10 @@
 #endif // OS_WINDOWS
 
 // Use GCC's keyword on Linux.
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
 #define TLS_KEYWORD __thread
 #define HAVE_TLS 1
-#endif  // OS_LINUX
+#endif  // OS_LINUX || OS_GNU_KFREEBSD || OS_FREEBSD
 
 
 // OSX doesn't support Thread Local Storage.
diff --git a/base/util.cc b/base/util.cc
index 484cd63..d44e002 100755
--- a/base/util.cc
+++ b/base/util.cc
@@ -2592,7 +2592,7 @@ string Util::GetServerDirectory() {
   return MacUtil::GetServerDirectory();
 #endif  // OS_MACOSX
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   return "/usr/lib/mozc";
 #endif  // OS_LINUX
 }
@@ -2671,7 +2671,7 @@ string GetObjectNameAsString(HANDLE handle) {
 #endif
 
 string Util::GetDesktopNameAsString() {
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   const char *display = getenv("DISPLAY");
   if (display == NULL) {
     return "";
@@ -3167,7 +3167,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) || defined(OS_FREEBSD)
   // TODO(yukawa): support Linux.
   return true;
 #elif defined(OS_WINDOWS)
@@ -3587,18 +3587,19 @@ string Util::GetOSVersionString() {
   } else {
     LOG(WARNING) << "GetVersionEx failed";
   }
-  return ret;
 #elif defined(OS_MACOSX)
   const string ret = "MacOSX " + MacUtil::GetOSVersionString();
   // TODO(toshiyuki): get more specific info
-  return ret;
 #elif defined(OS_LINUX)
   const string ret = "Linux";
-  return ret;
+#elif defined(OS_GNU_KFREEBSD)
+  const string ret = "GNU/kFreeBSD";
+#elif defined(OS_FREEBSD)
+  const string ret = "FreeBSD";
 #else
   const string ret = "Unknown";
-  return ret;
 #endif
+  return ret;
 }
 
 void Util::DisableIME() {
@@ -3632,7 +3633,7 @@ uint64 Util::GetTotalPhysicalMemory() {
     return 0;
   }
   return total_memory;
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
 #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);
@@ -3658,7 +3659,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) || defined(OS_FREEBSD)
 #if defined(_SC_PAGESIZE)
   const size_t page_size = sysconf(_SC_PAGESIZE);
 #else
diff --git a/build_mozc.py b/build_mozc.py
index a08f8c5..5adcbfa 100755
--- a/build_mozc.py
+++ b/build_mozc.py
@@ -72,6 +72,14 @@ def IsLinux():
   """Returns true if the platform is Linux."""
   return os.name == 'posix' and os.uname()[0] == 'Linux'
 
+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'
 
 # TODO(yukawa): Move this function to util.py (b/2715400)
 def GetNumberOfProcessors():
@@ -87,7 +95,7 @@ def GetNumberOfProcessors():
     commands = ['sysctl', '-n', 'hw.ncpu']
     process = subprocess.Popen(commands, stdout=subprocess.PIPE)
     return int(process.communicate()[0])
-  elif IsLinux():
+  elif IsLinux() or IsFreeBSD() or IsGNUkFreeBSD():
     # Count the number of 'vendor_id' in /proc/cpuinfo, assuming that
     # each line corresponds to one logical CPU.
     cpuinfo = open('/proc/cpuinfo', 'r')
@@ -114,6 +122,8 @@ def GetBuildBaseName(options):
     # On Linux, seems there is no way to specify the build_base directory
     # inside common.gypi
     build_base = 'out_linux'
+  elif IsFreeBSD() or IsGNUkFreeBSD():
+    build_base = 'out_bsd'
   else:
     logging.error('Unsupported platform: %s', os.name)
 
@@ -205,7 +215,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 IsFreeBSD() 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.
@@ -362,6 +372,7 @@ def AddCommonOptions(parser):
                     help='If you want ChromeOS build, specify "ChromeOS"')
   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
 
 
@@ -459,7 +470,7 @@ def ExpandMetaTarget(meta_target_name, target_platform):
     targets = ['%s/unix/ibus/ibus.gyp:ibus_mozc',
                '%s/server/server.gyp:mozc_server',
                '%s/gui/gui.gyp:mozc_tool']
-  elif IsLinux():
+  elif IsLinux() or IsFreeBSD() or IsGNUkFreeBSD():
     targets = ['%s/unix/ibus/ibus.gyp:ibus_mozc',
                '%s/server/server.gyp:mozc_server',
                '%s/gui/gui.gyp:mozc_tool']
@@ -579,6 +590,9 @@ def GypMain(options, unused_args):
   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)])
 
 
@@ -616,7 +630,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='])
@@ -714,6 +728,42 @@ def BuildOnLinux(options, targets, unused_original_directory_name):
 
   RunOrDie([make_command] + build_args + target_names)
 
+def BuildOnBSD(options, targets):
+  """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, 'BUILDTYPE=%s' % options.configuration]
+  if options.build_base:
+    build_args.append('builddir_name=%s' % options.build_base)
+
+  RunOrDie([make_command] + build_args + target_names)
 
 def CheckFileOrDie(file_name):
   """Check the file exists or dies if not."""
@@ -877,6 +927,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)
   elif IsWindows():
     BuildOnWindows(options, targets, original_directory_name)
   else:
@@ -1000,7 +1052,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,
@@ -1019,6 +1071,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)
@@ -1045,7 +1101,6 @@ def ShowHelpAndExit():
   print 'See also the comment in the script for typical usage.'
   sys.exit(1)
 
-
 def main():
   if len(sys.argv) < 2:
     ShowHelpAndExit()
diff --git a/build_tools/mozc_version.py b/build_tools/mozc_version.py
index 04d644b..b3ed870 100755
--- a/build_tools/mozc_version.py
+++ b/build_tools/mozc_version.py
@@ -58,6 +58,13 @@ def IsLinux():
   """Returns true if the platform is Linux."""
   return os.name == 'posix' and os.uname()[0] == 'Linux'
 
+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'
 
 def CalculateRevisionForPlatform(revision, target_platform):
   """Returns the revision for the current platform."""
@@ -76,6 +83,10 @@ def CalculateRevisionForPlatform(revision, target_platform):
     last_digit = '1'
   elif IsLinux():
     last_digit = '2'
+  elif IsFreeBSD():
+    last_digit = '3'
+  elif IsGNUkFreeBSD():
+    last_digit = '4'
   if last_digit:
     return revision[0:-1] + last_digit
 
diff --git a/config/stats_config_util_test.cc b/config/stats_config_util_test.cc
index a49dd08..61fda2e 100755
--- a/config/stats_config_util_test.cc
+++ b/config/stats_config_util_test.cc
@@ -690,7 +690,7 @@ TEST_F(StatsConfigUtilTestWin, IsEnabled) {
 #else  // CHANNEL_DEV
 #endif  // CHANNEL_DEV
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
 TEST(StatsConfigUtilTestLinux, DefaultValueTest) {
   EXPECT_FALSE(mozc::StatsConfigUtil::IsEnabled());
 }
diff --git a/gui/base/locale_util.cc b/gui/base/locale_util.cc
index 827fd28..52c881b 100755
--- a/gui/base/locale_util.cc
+++ b/gui/base/locale_util.cc
@@ -198,7 +198,7 @@ TranslationDataImpl::TranslationDataImpl()
   qApp->installEventFilter(&window_title_modifier_);
 #endif
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   // 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 5aee977..4df1942 100755
--- a/gui/config_dialog/config_dialog.cc
+++ b/gui/config_dialog/config_dialog.cc
@@ -73,11 +73,11 @@ ConfigDialog::ConfigDialog()
   verboseLevelLabel->setVisible(false);
   verboseLevelComboBox->setVisible(false);
 
-#if defined(OS_MACOSX) || defined(OS_LINUX)
+#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   // The last "misc" tab has no valid configs on Mac and Linux
   const int kMiscTabIndex = 6;
   configDialogTabWidget->removeTab(kMiscTabIndex);
-#endif  // OS_MACOSX || OS_LINUX
+#endif // OS_MACOSX || OS_LINUX || OS_GNU_KFREEBSD || OS_FREEBSD
 #endif  // NO_LOGGING
 
 #if !defined(GOOGLE_JAPANESE_INPUT_BUILD)
@@ -277,7 +277,7 @@ ConfigDialog::ConfigDialog()
   dictionaryPreloadingAndUACLabel->setVisible(false);
 #endif  // OS_WINDOWS
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   // On Linux, disable all fields for UsageStats
   usageStatsLabel->setEnabled(false);
   usageStatsLabel->setVisible(false);
@@ -364,7 +364,7 @@ bool ConfigDialog::Update() {
   }
 
 
-#if defined(OS_WINDOWS) || defined(OS_LINUX)
+#if defined(OS_WINDOWS) || defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   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 c17efc6..1239316 100755
--- a/gui/config_dialog/keybinding_editor.cc
+++ b/gui/config_dialog/keybinding_editor.cc
@@ -443,7 +443,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) || defined(OS_FREEBSD)
   // 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 5bc096d..c3b45d3 100755
--- a/gui/config_dialog/keymap_editor.cc
+++ b/gui/config_dialog/keymap_editor.cc
@@ -94,7 +94,7 @@ class KeyMapValidator {
     invisible_commands_.insert(kReportBugCommand);
     // Old command name.
     invisible_commands_.insert(kEditInsertCommand);
-#if defined(OS_MACOSX) || defined(OS_LINUX)
+#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
     // On Mac/Linux, we cannot customize keybindings for IME ON/OFF
     // So we do not show them.
     // TODO(toshiyuki): remove them after implimenting IME ON/OFF for Mac
@@ -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) || defined(OS_FREEBSD)
     QMessageBox::information(
         this,
         tr("Mozc settings"),
diff --git a/gui/dictionary_tool/dictionary_tool.cc b/gui/dictionary_tool/dictionary_tool.cc
index b66f13e..20c3461 100755
--- a/gui/dictionary_tool/dictionary_tool.cc
+++ b/gui/dictionary_tool/dictionary_tool.cc
@@ -317,7 +317,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 37e4e44..bef1334 100755
--- a/gui/gui.gyp
+++ b/gui/gui.gyp
@@ -378,7 +378,7 @@
       'includes': [
         'qt_libraries.gypi',
       ],
-      'conditions': [['use_libzinnia==1 and OS=="linux"', {
+      'conditions': [['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 b406bc6..b564c1c 100755
--- a/gui/qt_libraries.gypi
+++ b/gui/qt_libraries.gypi
@@ -86,7 +86,7 @@
         '$(SDKROOT)/System/Library/Frameworks/Carbon.framework',
       ]
     }],
-    ['OS=="linux"', {
+    ['OS=="linux" or OS=="gnu-kfreebsd"', {
       'conditions': [
         ['qt_dir', {
           'libraries': [
diff --git a/gui/zinnia.gyp b/gui/zinnia.gyp
index b4cd01c..481b280 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 551f8bd..c0e0a5f 100755
--- a/gyp/common.gypi
+++ b/gyp/common.gypi
@@ -238,7 +238,7 @@
           },
         },
         'conditions': [
-          ['OS=="linux"', {
+          ['OS=="linux" or OS=="gnu-kfreebsd"', {
             'cflags': [
               '<@(debug_extra_cflags)',
             ],
@@ -277,7 +277,7 @@
           },
         },
         'conditions': [
-          ['OS=="linux"', {
+          ['OS=="linux" or OS=="gnu-kfreebsd"', {
             'cflags': [
               '<@(release_extra_cflags)',
             ],
@@ -532,6 +532,51 @@
           }],
         ],
       }],
+      ['OS=="freebsd"', {
+        'defines': [
+          'OS_FREEBSD',
+        ],
+        'cflags': [
+          '<@(gcc_cflags)',
+          '-fPIC',
+          '-fno-exceptions',
+        ],
+        'libraries': [
+          '-lcurl',
+          '-lcrypto',
+          '-lpthread',
+          '-lrt',
+          '-lssl',
+          '-lz',
+          '<@(extra_linux_libs)',
+        ],
+        'conditions': [
+          ['chromeos==1', {
+            'defines': [
+              'OS_CHROMEOS',
+            ],
+          }],
+        ],
+      }],
+      ['OS=="gnu-kfreebsd"', {
+        'defines': [
+          'OS_GNU_KFREEBSD',
+        ],
+        'cflags': [
+          '<@(gcc_cflags)',
+          '-fPIC',
+          '-fno-exceptions',
+        ],
+        'libraries': [
+          '-lcurl',
+          '-lcrypto',
+          '-lpthread',
+          '-lrt',
+          '-lssl',
+          '-lz',
+          '<@(extra_linux_libs)',
+        ],
+      }],
       ['OS=="mac"', {
         'defines': [
           'OS_MACOSX',
@@ -586,7 +631,7 @@
           # Linux gyp (into scons) doesn't like target_conditions?
           # TODO(team): track down why 'target_conditions' doesn't work
           # on Linux gyp into scons like it does on Mac gyp into xcodeproj.
-          ['OS=="linux"', {
+          ['OS=="linux" or OS=="gnu-kfreebsd"', {
             'cflags': [ '-ftest-coverage',
                         '-fprofile-arcs' ],
             'link_settings': { 'libraries': [ '-lgcov' ] },
diff --git a/ipc/ipc_path_manager.cc b/ipc/ipc_path_manager.cc
index db5b5d7..ab4091b 100755
--- a/ipc/ipc_path_manager.cc
+++ b/ipc/ipc_path_manager.cc
@@ -274,7 +274,7 @@ bool IPCPathManager::GetPathName(string *ipc_name) {
   *ipc_name = kIPCPrefix;
 #endif  // OS_WINDOWS
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   // On Linux, use abstract namespace which is independent of the file system.
   (*ipc_name)[0] = '\0';
 #endif
@@ -367,7 +367,7 @@ bool IPCPathManager::IsValidServer(uint32 pid,
   }
 #endif
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   // load from /proc/<pid>/exe
   char proc[128];
   char filename[512];
@@ -387,7 +387,7 @@ bool IPCPathManager::IsValidServer(uint32 pid,
     return true;
   }
 
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_GNU_KFREEBSD) || defined(OS_FREEBSD)
   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 82cea4a..4b24fb8 100755
--- a/ipc/ipc_path_manager_test.cc
+++ b/ipc/ipc_path_manager_test.cc
@@ -108,7 +108,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)
   // 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 3085320..37ff133 100755
--- a/ipc/unix_ipc.cc
+++ b/ipc/unix_ipc.cc
@@ -28,7 +28,8 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 // skip all if Windows
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_MACOSX) ||\
+	defined(OS_FREEBSD) || defined(OS_GNU_KFREEBSD)
 
 #include "ipc/ipc.h"
 
@@ -41,7 +42,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 +125,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 +147,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 +186,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
@@ -524,4 +525,5 @@ void IPCServer::Loop() {
 
 };  // namespace mozc
 
-#endif  // OS_LINUX
+#endif // defined(OS_LINUX) || defined(OS_MACOSX) ||
+     //	defined(OS_FREEBSD) || defined(OS_GNU_KFREEBSD)
diff --git a/protobuf/genproto.gypi b/protobuf/genproto.gypi
index 38d8eef..b821e7c 100755
--- a/protobuf/genproto.gypi
+++ b/protobuf/genproto.gypi
@@ -39,7 +39,7 @@
         '<(protobuf_dir)/protobuf.gyp:install_protoc',
       ],
     }],
-    ['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 6072864..a619ddc 100755
--- a/protobuf/protobuf.gyp
+++ b/protobuf/protobuf.gyp
@@ -116,7 +116,7 @@
       'target_name': 'protobuf',
       'type': 'static_library',
       'conditions': [
-        ['OS=="linux"', {
+        ['OS=="linux" or OS=="gnu-kfreebsd"', {
           'conditions': [
             ['use_libprotobuf==1', {
               'link_settings': {
@@ -196,7 +196,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 be5bf45..c6cc2d0 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) || defined(OS_FREEBSD)
     // 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 ff8fece..1153dff 100755
--- a/session/session_test.cc
+++ b/session/session_test.cc
@@ -2089,7 +2089,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
@@ -2117,7 +2117,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
diff --git a/testing/testing.gyp b/testing/testing.gyp
index 58d1cf3..34a59d6 100755
--- a/testing/testing.gyp
+++ b/testing/testing.gyp
@@ -53,7 +53,7 @@
         '../base/base.gyp:base',
       ],
       'conditions': [
-        ['OS!="linux"', {
+        ['OS!="linux" and OS!="gnu-kfreebsd"', {
           'dependencies': [
             'testing',
           ],