aboutsummaryrefslogtreecommitdiff
path: root/multimedia/vdr/files/patch-vdr-1.7.28_FreeBSD
blob: 583db5ab79e417531e50727daa93c479e294fa74 (plain) (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
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
Index: Make.config.template
@@ -8,6 +8,11 @@
 #
 # $Id: Make.config.template 2.8 2012/03/20 11:20:13 kls Exp $
 
+OSTYPE   ?= $(shell uname -s)
+ifeq ($(OSTYPE),FreeBSD)
+FREEBSD=1
+endif
+
 ### The C compiler and options:
 
 CC       = gcc
@@ -28,11 +33,22 @@ PREFIX   = $(DESTDIR)/usr/local
 MANDIR   = $(PREFIX)/man
 BINDIR   = $(PREFIX)/bin
 
+ifdef FREEBSD
+# you have to set DVBDIR to a valid path!!!
+# you will need extra patches for DVBDIR!!!
+#DVBDIR   = /usr/local/include
+LOCDIR       = $(PREFIX)/share/locale
+PLUGINDIR    = ./PLUGINS
+PLUGINLIBDIR = $(PREFIX)/lib/vdr
+VIDEODIR     = /video
+CONFDIR      = $(PREFIX)/etc/vdr
+else
 LOCDIR       = ./locale
 PLUGINDIR    = ./PLUGINS
 PLUGINLIBDIR = $(PLUGINDIR)/lib
 VIDEODIR     = /video
 CONFDIR      = $(VIDEODIR)
+endif
 
 ### The remote control:
 
@@ -46,3 +62,7 @@ LIRC_DEVICE = /var/run/lirc/lircd
 ifdef DVBDIR
 INCLUDES += -I$(DVBDIR)/include
 endif
+
+ifdef FREEBSD
+INCLUDES += -I$(VDRDIR)/include -I/usr/local/include
+endif
Index: Makefile
@@ -8,6 +8,11 @@
 
 .DELETE_ON_ERROR:
 
+OSTYPE   ?= $(shell uname -s)
+ifeq ($(OSTYPE),FreeBSD)
+FREEBSD=1
+endif
+
 CC       ?= gcc
 CFLAGS   ?= -g -O3 -Wall
 
@@ -21,7 +26,11 @@ MANDIR  ?= $(PREFIX)/share/man
 BINDIR  ?= $(PREFIX)/bin
 INCDIR  ?= $(PREFIX)/include
 LOCDIR  ?= ./locale
+ifdef FREEBSD
+LIBS     = -ljpeg -lpthread -lrt -lutil -lintl -liconv $(shell pkg-config --libs freetype2 fontconfig)
+else
 LIBS     = -ljpeg -lpthread -ldl -lcap -lrt $(shell pkg-config --libs freetype2 fontconfig)
+endif
 INCLUDES ?= $(shell pkg-config --cflags freetype2 fontconfig)
 
 PLUGINDIR= ./PLUGINS
@@ -150,7 +159,11 @@ i18n: $(I18Nmsgs)
 
 install-i18n:
 	@mkdir -p $(DESTDIR)$(LOCDIR)
+ifdef FREEBSD
+	@(cd $(LOCALEDIR); cp -R * $(DESTDIR)$(LOCDIR))
+else
 	@(cd $(LOCALEDIR); cp -r --parents * $(DESTDIR)$(LOCDIR))
+endif
 
 # The 'include' directory (for plugins):
 
@@ -189,7 +202,11 @@ install: install-bin install-conf instal
 
 install-bin: vdr
 	@mkdir -p $(DESTDIR)$(BINDIR)
+ifdef FREEBSD
+	@cp -f vdr svdrpsend $(DESTDIR)$(BINDIR)
+else
 	@cp --remove-destination vdr svdrpsend $(DESTDIR)$(BINDIR)
+endif
 
 # Configuration files:
 
@@ -212,13 +229,18 @@ install-doc:
 
 install-plugins: plugins
 	@mkdir -p $(DESTDIR)$(PLUGINLIBDIR)
+ifdef FREEBSD
+	@cp -f $(PLUGINDIR)/lib/lib*-*.so.$(APIVERSION) $(DESTDIR)$(PLUGINLIBDIR)
+else
 	@cp --remove-destination $(PLUGINDIR)/lib/lib*-*.so.$(APIVERSION) $(DESTDIR)$(PLUGINLIBDIR)
+endif
 
 # Includes:
 
 install-includes: include-dir
 	@mkdir -p $(DESTDIR)$(INCDIR)
 	@cp -pLR include/vdr include/libsi $(DESTDIR)$(INCDIR)
+	@cp Make.config Make.global $(DESTDIR)$(INCDIR)/vdr
 
 # pkg-config file:
 
Index: channels.c
@@ -29,7 +29,12 @@ tChannelID tChannelID::FromString(const 
   int tid;
   int sid;
   int rid = 0;
+#ifdef __FreeBSD__
+  sourcebuf = MALLOC(char, 10);
+  int fields = sscanf(s, "%9[^-]-%d-%d-%d-%d", sourcebuf, &nid, &tid, &sid, &rid);
+#else
   int fields = sscanf(s, "%a[^-]-%d-%d-%d-%d", &sourcebuf, &nid, &tid, &sid, &rid);
+#endif
   if (fields == 4 || fields == 5) {
      int source = cSource::FromString(sourcebuf);
      free(sourcebuf);
@@ -554,7 +559,18 @@ bool cChannel::Parse(const char *s)
      char *apidbuf = NULL;
      char *tpidbuf = NULL;
      char *caidbuf = NULL;
+#ifdef __FreeBSD__
+     namebuf = MALLOC(char, 256);
+     sourcebuf = MALLOC(char, 10);
+     parambuf = MALLOC(char, 256);
+     vpidbuf = MALLOC(char, 256);
+     apidbuf = MALLOC(char, 256);
+     tpidbuf = MALLOC(char, 256);
+     caidbuf = MALLOC(char, 256);
+     int fields = sscanf(s, "%255[^:]:%d :%255[^:]:%255[^:] :%d :%255[^:]:%255[^:]:%255[^:]:%255[^:]:%d :%d :%d :%d ", namebuf, &frequency, parambuf, sourcebuf, &srate, vpidbuf, apidbuf, tpidbuf, caidbuf, &sid, &nid, &tid, &rid);
+#else
      int fields = sscanf(s, "%a[^:]:%d :%a[^:]:%a[^:] :%d :%a[^:]:%a[^:]:%a[^:]:%a[^:]:%d :%d :%d :%d ", &namebuf, &frequency, &parambuf, &sourcebuf, &srate, &vpidbuf, &apidbuf, &tpidbuf, &caidbuf, &sid, &nid, &tid, &rid);
+#endif
      if (fields >= 9) {
         if (fields == 9) {
            // allow reading of old format
Index: ci.c
===================================================================
RCS file: /progs/network/ccvs/vdr/ci.c,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- ci.c	2010/02/17 10:14:44	1.1.1.2
+++ ci.c	2010/02/17 10:46:55	1.3
@@ -10,7 +10,11 @@
 #include "ci.h"
 #include <ctype.h>
 #include <linux/dvb/ca.h>
+#ifdef __FreeBSD__
+#include <stdlib.h>
+#else
 #include <malloc.h>
+#endif
 #include <netinet/in.h>
 #include <poll.h>
 #include <string.h>
Index: config.c
===================================================================
RCS file: /progs/network/ccvs/vdr/config.c,v
retrieving revision 1.1.1.4
retrieving revision 1.4
diff -u -r1.1.1.4 -r1.4
--- config.c	2010/06/07 09:07:28	1.1.1.4
+++ config.c	2010/06/07 09:12:57	1.4
@@ -10,6 +10,9 @@
 #include "config.h"
 #include <ctype.h>
 #include <stdlib.h>
+#ifdef __FreeBSD__
+#include <netinet/in.h>
+#endif
 #include "device.h"
 #include "i18n.h"
 #include "interface.h"
Index: diseqc.c
@@ -114,7 +114,14 @@ bool cDiseqc::Parse(const char *s)
      return true;
   bool result = false;
   char *sourcebuf = NULL;
+#ifdef __FreeBSD__
+  sourcebuf = MALLOC(char, 10);
+  if (commands == NULL)
+      commands = MALLOC(char, 256);
+  int fields = sscanf(s, "%9[^ ] %d %c %d %255[^\n]", sourcebuf, &slof, &polarization, &lof, commands);
+#else
   int fields = sscanf(s, "%a[^ ] %d %c %d %a[^\n]", &sourcebuf, &slof, &polarization, &lof, &commands);
+#endif
   if (fields == 4)
      commands = NULL; //XXX Apparently sscanf() doesn't work correctly if the last %a argument results in an empty string
   if (4 <= fields && fields <= 5) {
Index: eit.c
===================================================================
RCS file: /progs/network/ccvs/vdr/eit.c,v
retrieving revision 1.1.1.3
retrieving revision 1.5
diff -u -r1.1.1.3 -r1.5
--- eit.c	2010/06/07 09:07:27	1.1.1.3
+++ eit.c	2010/06/07 09:12:57	1.5
@@ -339,10 +339,15 @@
   if (diff > 2) {
      mutex.Lock();
      if (abs(diff - lastDiff) < 3) {
+#ifdef __FreeBSD__
+        isyslog("system time would have changed from %s (%ld) to %s (%ld)", *TimeToString(loctim), loctim, *TimeToString(sattim), sattim);
+        esyslog("stime() not available on FreeBSD, maybe use adjtime()?");
+#else
         if (stime(&sattim) == 0)
            isyslog("system time changed from %s (%ld) to %s (%ld)", *TimeToString(loctim), loctim, *TimeToString(sattim), sattim);
         else
            esyslog("ERROR while setting system time: %m");
+#endif
         }
      lastDiff = diff;
      mutex.Unlock();
Index: epg.c
===================================================================
RCS file: /progs/network/ccvs/vdr/epg.c,v
retrieving revision 1.1.1.3
retrieving revision 1.5
diff -u -r1.1.1.3 -r1.5
--- epg.c	2010/03/01 09:42:48	1.1.1.3
+++ epg.c	2010/03/01 09:58:06	1.5
@@ -31,7 +31,13 @@
 bool tComponent::FromString(const char *s)
 {
   unsigned int Stream, Type;
+#ifdef __FreeBSD__
+  if (description == NULL)
+	description = MALLOC(char, 256);
+  int n = sscanf(s, "%X %02X %7s %255[^\n]", &Stream, &Type, language, description); // 7 = MAXLANGCODE2 - 1
+#else
   int n = sscanf(s, "%X %02X %7s %a[^\n]", &Stream, &Type, language, &description); // 7 = MAXLANGCODE2 - 1
+#endif
   if (n != 4 || isempty(description)) {
      free(description);
      description = NULL;
Index: font.c
===================================================================
RCS file: /progs/network/ccvs/vdr/font.c,v
retrieving revision 1.1.1.3
retrieving revision 1.5
diff -u -r1.1.1.3 -r1.5
--- font.c	2010/10/19 20:28:48	1.1.1.3
+++ font.c	2010/10/19 20:32:58	1.5
@@ -383,7 +383,11 @@
 {
   if (!FontNames->Size()) {
      FcInit();
+#ifdef __FreeBSD__
+     FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, (char *)NULL);
+#else
      FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
+#endif
      FcPattern *pat = FcPatternCreate();
      FcPatternAddBool(pat, FC_SCALABLE, FcTrue);
      if (Monospaced)
Index: i18n.h
===================================================================
RCS file: /progs/network/ccvs/vdr/i18n.h,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- i18n.h	2010/02/17 10:14:45	1.1.1.2
+++ i18n.h	2010/02/17 10:46:55	1.3
@@ -48,7 +48,11 @@
    ///< have an actual locale installed. The rest are just dummy entries
    ///< to allow having three letter language codes for other languages
    ///< that have no actual locale on this system.
+#ifdef __FreeBSD__
+const char *I18nTranslate(const char *s, const char *Plugin = NULL) __format_arg(1);
+#else
 const char *I18nTranslate(const char *s, const char *Plugin = NULL) __attribute_format_arg__(1);
+#endif
    ///< Translates the given string (with optional Plugin context) into
    ///< the current language. If no translation is available, the original
    ///< string will be returned.
Index: menu.c
===================================================================
RCS file: /progs/network/ccvs/vdr/menu.c,v
retrieving revision 1.1.1.6
retrieving revision 1.7
diff -u -r1.1.1.6 -r1.7
Index: menuitems.c
===================================================================
RCS file: /progs/network/ccvs/vdr/menuitems.c,v
retrieving revision 1.1.1.4
retrieving revision 1.5
diff -u -r1.1.1.4 -r1.5
--- menuitems.c	2010/06/07 09:07:27	1.1.1.4
+++ menuitems.c	2010/06/07 09:12:57	1.5
@@ -838,7 +838,11 @@
      struct tm tm_r;
      localtime_r(value, &tm_r);
      strftime(buf, DATEBUFFERSIZE, "%Y-%m-%d ", &tm_r);
+#ifdef __FreeBSD__
+     strcat(buf, WeekDayNameReal(tm_r.tm_wday));
+#else
      strcat(buf, WeekDayName(tm_r.tm_wday));
+#endif
      }
   else
      *buf = 0;
Index: pat.c
===================================================================
RCS file: /progs/network/ccvs/vdr/pat.c,v
retrieving revision 1.1.1.5
retrieving revision 1.6
diff -u -r1.1.1.5 -r1.6
--- pat.c	2010/10/19 20:28:48	1.1.1.5
+++ pat.c	2010/10/19 20:32:58	1.6
@@ -8,7 +8,11 @@
  */
 
 #include "pat.h"
+#ifdef __FreeBSD__
+#include <stdlib.h>
+#else
 #include <malloc.h>
+#endif
 #include "channels.h"
 #include "libsi/section.h"
 #include "libsi/descriptor.h"
Index: recording.c
===================================================================
RCS file: /progs/network/ccvs/vdr/recording.c,v
retrieving revision 1.1.1.3
retrieving revision 1.5
diff -u -r1.1.1.3 -r1.5
--- recording.c	2010/03/16 15:18:58	1.1.1.3
+++ recording.c	2010/03/16 15:21:05	1.5
@@ -1825,7 +1829,11 @@
          // Search for a PAT packet from the end of the file:
          cPatPmtParser PatPmtParser;
          sprintf(pFileNumber, RECORDFILESUFFIXTS, Number);
+#ifdef __FreeBSD__
+         int fd = open(fileName, O_RDONLY, DEFFILEMODE);
+#else
          int fd = open(fileName, O_RDONLY | O_LARGEFILE, DEFFILEMODE);
+#endif
          if (fd >= 0) {
             off_t pos = lseek(fd, -TS_SIZE, SEEK_END);
             while (pos >= 0) {
@@ -1866,14 +1874,22 @@
      int BlockingFlag = blocking ? 0 : O_NONBLOCK;
      if (record) {
         dsyslog("recording to '%s'", fileName);
+#ifdef __FreeBSD__
+        file = OpenVideoFile(fileName, O_RDWR | O_CREAT | BlockingFlag);
+#else
         file = OpenVideoFile(fileName, O_RDWR | O_CREAT | O_LARGEFILE | BlockingFlag);
+#endif
         if (!file)
            LOG_ERROR_STR(fileName);
         }
      else {
         if (access(fileName, R_OK) == 0) {
            dsyslog("playing '%s'", fileName);
+#ifdef __FreeBSD__
+           file = cUnbufferedFile::Create(fileName, O_RDONLY | BlockingFlag);
+#else
            file = cUnbufferedFile::Create(fileName, O_RDONLY | O_LARGEFILE | BlockingFlag);
+#endif
            if (!file)
               LOG_ERROR_STR(fileName);
            }
Index: skins.c
===================================================================
RCS file: /progs/network/ccvs/vdr/skins.c,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- skins.c	2010/02/17 10:14:45	1.1.1.2
+++ skins.c	2010/02/17 10:46:55	1.3
@@ -11,6 +11,20 @@
 #include "interface.h"
 #include "status.h"
 
+#if defined(__FreeBSD__) && __FreeBSD_version < 1000029
+/* XXX Implement strchrnul for FreeBSD. */
+static char *
+strchrnul (const char *s, int c_in)
+{
+  char c = c_in;
+  while (*s && (*s != c))
+    s++;
+
+  return (char *) s;
+}
+#endif
+
+
 // --- cSkinQueuedMessage ----------------------------------------------------
 
 class cSkinQueuedMessage : public cListObject {
Index: sources.c
===================================================================
RCS file: /progs/network/ccvs/vdr/sources.c,v
retrieving revision 1.1.1.4
retrieving revision 1.5
diff -u -r1.1.1.4 -r1.5
--- sources.c	2010/03/16 15:18:58	1.1.1.4
+++ sources.c	2010/03/16 15:21:05	1.5
@@ -31,7 +31,14 @@
 bool cSource::Parse(const char *s)
 {
   char *codeBuf = NULL;
+#ifdef __FreeBSD__
+  codeBuf = MALLOC(char, 10);
+  if (description == NULL)
+	description = MALLOC(char, 256);
+  if (2 == sscanf(s, "%9[^ ] %255[^\n]", codeBuf, description))
+#else
   if (2 == sscanf(s, "%a[^ ] %a[^\n]", &codeBuf, &description))
+#endif
      code = FromString(codeBuf);
   free(codeBuf);
   return code != stNone && description && *description;
Index: svdrp.c
@@ -40,6 +40,12 @@
 #include "tools.h"
 #include "videodir.h"
 
+/* FreeBSD has it's own version of isnumber(),
+   but VDR's version is incompatible */
+#ifdef __FreeBSD__
+#undef isnumber
+#endif
+
 // --- cSocket ---------------------------------------------------------------
 
 cSocket::cSocket(int Port, int Queue)
@@ -124,6 +130,23 @@ int cSocket::Accept(void)
         }
      else if (errno != EINTR && errno != EAGAIN)
         LOG_ERROR;
+#ifdef __FreeBSD__
+     // Linux' accept() doesn't inherit O_NONBLOCK... (this fixes
+     // cSVDRP::Send() failing due to EAGAIN when vdradmin-am downloads EPG.)
+     if (newsock >= 0) {
+        // make it blocking:
+        int oldflags = fcntl(newsock, F_GETFL, 0);
+        if (oldflags < 0) {
+           LOG_ERROR;
+           return -1;
+           }
+        oldflags &= ~O_NONBLOCK;
+        if (fcntl(newsock, F_SETFL, oldflags) < 0) {
+           LOG_ERROR;
+           return -1;
+           }
+        }
+#endif
      return newsock;
      }
   return -1;
Index: themes.c
===================================================================
RCS file: /progs/network/ccvs/vdr/themes.c,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- themes.c	2010/02/17 10:14:44	1.1.1.2
+++ themes.c	2010/02/17 10:46:55	1.3
@@ -47,7 +47,11 @@
                     // FileName is ok
                     if (SetName) {
                        free(name);
+#ifdef __FreeBSD__
+                       name = (char *)strndup(n, e - n);
+#else
                        name = strndup(n, e - n);
+#endif
                        }
                     }
                  else
Index: thread.c
===================================================================
RCS file: /progs/network/ccvs/vdr/thread.c,v
retrieving revision 1.1.1.2
retrieving revision 1.6
diff -u -r1.1.1.2 -r1.6
--- thread.c	2010/02/17 10:14:45	1.1.1.2
+++ thread.c	2010/02/24 08:41:13	1.6
@@ -9,15 +9,22 @@
 
 #include "thread.h"
 #include <errno.h>
+#ifdef __FreeBSD__
+#include <pthread_np.h>
+#include <stdlib.h>
+#else
 #include <linux/unistd.h>
 #include <malloc.h>
+#endif
 #include <stdarg.h>
 #include <stdlib.h>
 #include <sys/resource.h>
 #include <sys/syscall.h>
 #include <sys/time.h>
 #include <sys/wait.h>
+#ifndef __FreeBSD__
 #include <sys/prctl.h>
+#endif
 #include <unistd.h>
 #include "tools.h"
 
@@ -143,7 +150,9 @@
 {
   pthread_rwlockattr_t attr;
   pthread_rwlockattr_init(&attr);
+#ifndef __FreeBSD__
   pthread_rwlockattr_setkind_np(&attr, PreferWriter ? PTHREAD_RWLOCK_PREFER_WRITER_NP : PTHREAD_RWLOCK_PREFER_READER_NP);
+#endif
   pthread_rwlock_init(&rwlock, &attr);
 }
 
@@ -179,7 +188,11 @@
   locked = 0;
   pthread_mutexattr_t attr;
   pthread_mutexattr_init(&attr);
+#ifdef __FreeBSD__
+  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
+#else
   pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP);
+#endif
   pthread_mutex_init(&mutex, &attr);
 }
 
@@ -228,8 +241,12 @@
 
 void cThread::SetIOPriority(int Priority)
 {
+#ifdef __FreeBSD__
+  esyslog("ERROR: syscall(SYS_ioprio_set ...) unsupported on FreeBSD");
+#else
   if (syscall(SYS_ioprio_set, 1, 0, (Priority & 0xff) | (2 << 13)) < 0) // best effort class
      LOG_ERROR;
+#endif
 }
 
 void cThread::SetDescription(const char *Description, ...)
@@ -335,7 +352,11 @@
 
 tThreadId cThread::ThreadId(void)
 {
+#ifdef __FreeBSD__
+  return reinterpret_cast<long>(::pthread_self());
+#else
   return syscall(__NR_gettid);
+#endif
 }
 
 void cThread::SetMainThreadId(void)
@@ -461,7 +482,11 @@
         int MaxPossibleFileDescriptors = getdtablesize();
         for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++)
             close(i); //close all dup'ed filedescriptors
+#ifdef __FreeBSD__
+        if (execl("/bin/sh", "sh", "-c", Command, (char *)NULL) == -1) {
+#else
         if (execl("/bin/sh", "sh", "-c", Command, NULL) == -1) {
+#endif
            LOG_ERROR_STR(Command);
            close(fd[1 - iopipe]);
            _exit(-1);
@@ -544,7 +569,11 @@
      int MaxPossibleFileDescriptors = getdtablesize();
      for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++)
          close(i); //close all dup'ed filedescriptors
+#ifdef __FreeBSD__
+     if (execl("/bin/sh", "sh", "-c", Command, (char *)NULL) == -1) {
+#else
      if (execl("/bin/sh", "sh", "-c", Command, NULL) == -1) {
+#endif
         LOG_ERROR_STR(Command);
         _exit(-1);
         }
Index: thread.h
===================================================================
RCS file: /progs/network/ccvs/vdr/thread.h,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- thread.h	2010/02/17 10:14:44	1.1.1.2
+++ thread.h	2010/02/17 10:46:55	1.3
@@ -13,6 +13,9 @@
 #include <pthread.h>
 #include <stdio.h>
 #include <sys/types.h>
+#ifdef __FreeBSD__
+#include <signal.h>
+#endif
 
 class cCondWait {
 private:
Index: timers.c
===================================================================
RCS file: /progs/network/ccvs/vdr/timers.c,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- timers.c	2010/02/17 10:14:45	1.1.1.2
+++ timers.c	2010/02/17 10:46:55	1.3
@@ -23,6 +23,12 @@
 // format characters in order to allow any number of blanks after a numeric
 // value!
 
+/* FreeBSD has it's own version of isnumber(),
+   but VDR's version is incompatible */
+#ifdef __FreeBSD__
+#undef isnumber
+#endif
+
 // --- cTimer ----------------------------------------------------------------
 
 cTimer::cTimer(bool Instant, bool Pause, cChannel *Channel)
@@ -292,7 +298,15 @@
      s = s2;
      }
   bool result = false;
+#ifdef __FreeBSD__
+  channelbuffer = MALLOC(char, 256);
+  daybuffer = MALLOC(char, 256);
+  filebuffer = MALLOC(char, 256);
+  aux = MALLOC(char, 256);
+  if (8 <= sscanf(s, "%u :%255[^:]:%255[^:]:%d :%d :%d :%d :%255[^:\n]:%255[^\n]", &flags, channelbuffer, daybuffer, &start, &stop, &priority, &lifetime, filebuffer, aux)) {
+#else
   if (8 <= sscanf(s, "%u :%a[^:]:%a[^:]:%d :%d :%d :%d :%a[^:\n]:%a[^\n]", &flags, &channelbuffer, &daybuffer, &start, &stop, &priority, &lifetime, &filebuffer, &aux)) {
+#endif
      ClrFlags(tfRecording);
      if (aux && !*skipspace(aux)) {
         free(aux);
Index: tools.c
===================================================================
RCS file: /progs/network/ccvs/vdr/tools.c,v
retrieving revision 1.1.1.5
retrieving revision 1.8
diff -u -r1.1.1.5 -r1.8
--- tools.c	2010/10/19 20:28:48	1.1.1.5
+++ tools.c	2010/10/19 20:32:58	1.8
@@ -21,13 +21,24 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <sys/time.h>
+#ifdef __FreeBSD__
+#include <sys/param.h>
+#include <sys/mount.h>
+#else
 #include <sys/vfs.h>
+#endif
 #include <time.h>
 #include <unistd.h>
 #include <utime.h>
 #include "i18n.h"
 #include "thread.h"
 
+/* FreeBSD has it's own version of isnumber(),
+   but VDR's version is incompatible */
+#ifdef __FreeBSD__
+#undef isnumber
+#endif
+
 int SysLogLevel = 3;
 
 #define MAXSYSLOGBUF 256
@@ -493,6 +504,18 @@
 {
   if (!FileName)
      return NULL;
+#ifdef __FreeBSD__
+  char *resolved_path = NULL;
+  resolved_path = MALLOC(char, PATH_MAX+1);
+  if (realpath(FileName, resolved_path) == NULL)
+  {
+        if (errno != ENOENT) // some other error occurred
+           LOG_ERROR_STR(FileName);
+        else // file doesn't exist
+           resolved_path = strdup(FileName);
+  }
+  return resolved_path;
+#else
   char *TargetName = canonicalize_file_name(FileName);
   if (!TargetName) {
      if (errno == ENOENT) // file doesn't exist
@@ -501,6 +524,7 @@
         LOG_ERROR_STR(FileName);
      }
   return TargetName;
+#endif
 }
 
 bool SpinUpDisk(const char *FileName)
@@ -517,7 +541,11 @@
          int f = open(buf, O_WRONLY | O_CREAT, DEFFILEMODE);
          // O_SYNC doesn't work on all file systems
          if (f >= 0) {
+#ifdef __FreeBSD__
+            if (fsync(f) < 0)
+#else
             if (fdatasync(f) < 0)
+#endif
                LOG_ERROR_STR(*buf);
             close(f);
             remove(buf);
@@ -920,7 +952,11 @@
   return cString(buffer, true);
 }
 
+#ifdef __FreeBSD__
+cString WeekDayNameReal(int WeekDay)
+#else
 cString WeekDayName(int WeekDay)
+#endif
 {
   char buffer[16];
   WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with Monday==0!
@@ -938,10 +974,18 @@
 cString WeekDayName(time_t t)
 {
   struct tm tm_r;
+#ifdef __FreeBSD__
+  return WeekDayNameReal(localtime_r(&t, &tm_r)->tm_wday);
+#else
   return WeekDayName(localtime_r(&t, &tm_r)->tm_wday);
+#endif
 }
 
+#ifdef __FreeBSD__
+cString WeekDayNameFullReal(int WeekDay)
+#else
 cString WeekDayNameFull(int WeekDay)
+#endif
 {
   WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with Monday==0!
   switch (WeekDay) {
@@ -959,7 +1003,11 @@
 cString WeekDayNameFull(time_t t)
 {
   struct tm tm_r;
+#ifdef __FreeBSD__
+  return WeekDayNameFullReal(localtime_r(&t, &tm_r)->tm_wday);
+#else
   return WeekDayNameFull(localtime_r(&t, &tm_r)->tm_wday);
+#endif
 }
 
 cString DayDateTime(time_t t)
@@ -969,7 +1017,11 @@
      time(&t);
   struct tm tm_r;
   tm *tm = localtime_r(&t, &tm_r);
+#ifdef __FreeBSD__
+  snprintf(buffer, sizeof(buffer), "%s %02d.%02d. %02d:%02d", *WeekDayNameReal(tm->tm_wday), tm->tm_mday, tm->tm_mon + 1, tm->tm_hour, tm->tm_min);
+#else
   snprintf(buffer, sizeof(buffer), "%s %02d.%02d. %02d:%02d", *WeekDayName(tm->tm_wday), tm->tm_mday, tm->tm_mon + 1, tm->tm_hour, tm->tm_min);
+#endif
   return buffer;
 }
 
@@ -988,7 +1040,11 @@
   char buf[32];
   struct tm tm_r;
   tm *tm = localtime_r(&t, &tm_r);
+#ifdef __FreeBSD__
+  char *p = stpcpy(buf, WeekDayNameReal(tm->tm_wday));
+#else
   char *p = stpcpy(buf, WeekDayName(tm->tm_wday));
+#endif
   *p++ = ' ';
   strftime(p, sizeof(buf) - (p - buf), "%d.%m.%Y", tm);
   return buf;
@@ -1315,7 +1371,11 @@
      if (!IsOpen()) {
         f = FileDes;
         if (f >= 0) {
+#ifdef __FreeBSD__
+           if ((uint)f < FD_SETSIZE) {
+#else
            if (f < FD_SETSIZE) {
+#endif
               if (f >= maxFiles)
                  maxFiles = f + 1;
               if (!files[f])
@@ -1356,7 +1416,11 @@
       if (files[i])
          FD_SET(i, &set);
       }
+#ifdef __FreeBSD__
+  if (0 <= FileDes && (uint)FileDes < FD_SETSIZE && !files[FileDes])
+#else
   if (0 <= FileDes && FileDes < FD_SETSIZE && !files[FileDes])
+#endif
      FD_SET(FileDes, &set); // in case we come in with an arbitrary descriptor
   if (TimeoutMs == 0)
      TimeoutMs = 10; // load gets too heavy with 0
@@ -1451,7 +1515,9 @@
 
 // --- cUnbufferedFile -------------------------------------------------------
 
+#ifndef __FreeBSD__
 #define USE_FADVISE
+#endif
 
 #define WRITE_BUFFER KILOBYTE(800)
 
@@ -1512,11 +1578,13 @@
   readahead = ra;
 }
 
+#ifdef USE_FADVISE
 int cUnbufferedFile::FadviseDrop(off_t Offset, off_t Len)
 {
   // rounding up the window to make sure that not PAGE_SIZE-aligned data gets freed.
   return posix_fadvise(fd, Offset - (FADVGRAN - 1), Len + (FADVGRAN - 1) * 2, POSIX_FADV_DONTNEED);
 }
+#endif
 
 off_t cUnbufferedFile::Seek(off_t Offset, int Whence)
 {
Index: tools.h
@@ -27,6 +27,12 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#ifdef __FreeBSD__
+#include <sys/param.h>
+typedef int (*__compar_fn_t) (__const void *, __const void *);
+#undef isnumber
+#endif
+
 typedef unsigned char uchar;
 
 extern int SysLogLevel;
@@ -227,12 +233,20 @@ bool SpinUpDisk(const char *FileName);
 void TouchFile(const char *FileName);
 time_t LastModifiedTime(const char *FileName);
 off_t FileSize(const char *FileName); ///< returns the size of the given file, or -1 in case of an error (e.g. if the file doesn't exist)
+#ifdef __FreeBSD__
+cString WeekDayNameReal(int WeekDay);
+#else
 cString WeekDayName(int WeekDay);
+#endif
     ///< Converts the given WeekDay (0=Sunday, 1=Monday, ...) to a three letter
     ///< day name.
 cString WeekDayName(time_t t);
     ///< Converts the week day of the given time to a three letter day name.
+#ifdef __FreeBSD__
+cString WeekDayNameFullReal(int WeekDay);
+#else
 cString WeekDayNameFull(int WeekDay);
+#endif
     ///< Converts the given WeekDay (0=Sunday, 1=Monday, ...) to a full
     ///< day name.
 cString WeekDayNameFull(time_t t);
Index: vdr.c
--- vdr.c
+++ vdr.c
@@ -32,8 +32,13 @@
 #include <pwd.h>
 #include <signal.h>
 #include <stdlib.h>
+#ifndef __FreeBSD__
 #include <sys/capability.h>
 #include <sys/prctl.h>
+#else
+#include <sys/types.h>
+#include <login_cap.h>
+#endif
 #include <termios.h>
 #include <unistd.h>
 #include "audio.h"
@@ -107,12 +112,15 @@ static bool SetUser(const char *UserName
         fprintf(stderr, "vdr: cannot set user id %u: %s\n", (unsigned int)user->pw_uid, strerror(errno));
         return false;
         }
+#ifndef __FreeBSD__
      if (UserDump && prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0)
         fprintf(stderr, "vdr: warning - cannot set dumpable: %s\n", strerror(errno));
+#endif
      }
   return true;
 }
 
+#ifndef __FreeBSD__
 static bool DropCaps(void)
 {
   // drop all capabilities except selected ones
@@ -139,6 +147,7 @@ static bool SetKeepCaps(bool On)
      }
   return true;
 }
+#endif
 
 static void SignalHandler(int signum)
 {
@@ -400,14 +409,18 @@ int main(int argc, char *argv[])
   if (VdrUser && geteuid() == 0) {
      StartedAsRoot = true;
      if (strcmp(VdrUser, "root")) {
+#ifndef __FreeBSD__
         if (!SetKeepCaps(true))
            return 2;
+#endif
         if (!SetUser(VdrUser, UserDump))
            return 2;
+#ifndef __FreeBSD__
         if (!SetKeepCaps(false))
            return 2;
         if (!DropCaps())
            return 2;
+#endif
         }
      }
 
@@ -556,6 +569,25 @@ int main(int argc, char *argv[])
            CodeSet++; // skip the dot
         }
      }
+#ifdef __FreeBSD__
+  // If we are started without a locale query login.conf(5) for
+  // a lang setting
+
+  if (!CodeSet || !strcmp(CodeSet, "US-ASCII")) {
+     struct passwd *User = getpwnam(VdrUser);
+     login_cap_t *Lc = login_getuserclass(User);
+     if (!Lc)
+        Lc = login_getpwclass(User);
+     if (Lc) {
+        const char *Lang = login_getcapstr(Lc, "lang", NULL, NULL);
+        if (Lang && setlocale(LC_CTYPE, Lang)) {
+           CodeSet = nl_langinfo(CODESET);
+           setenv("LANG", Lang, 1);
+           }
+        login_close(Lc);
+        }
+     }
+#endif
   if (CodeSet) {
      bool known = SI::SetSystemCharacterTable(CodeSet);
      isyslog("codeset is '%s' - %s", CodeSet, known ? "known" : "unknown");
Index: PLUGINS/src/svdrpdemo/svdrpdemo.c
===================================================================
RCS file: /progs/network/ccvs/vdr/PLUGINS/src/svdrpdemo/svdrpdemo.c,v
retrieving revision 1.1.1.2
retrieving revision 1.4
diff -u -r1.1.1.2 -r1.4
Index: libsi/headers.h
===================================================================
RCS file: /progs/network/ccvs/vdr/libsi/headers.h,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -u -r1.1.1.2 -r1.3
--- libsi/headers.h	2010/02/17 10:14:45	1.1.1.2
+++ libsi/headers.h	2010/02/17 10:46:56	1.3
@@ -17,7 +17,11 @@
 #ifndef LIBSI_HEADERS_H
 #define LIBSI_HEADERS_H
 
+#ifdef __FreeBSD__
+#include <sys/endian.h>
+#else
 #include <endian.h>
+#endif
 
 namespace SI {
 
Index: libsi/si.c
===================================================================
RCS file: /progs/network/ccvs/vdr/libsi/si.c,v
retrieving revision 1.1.1.4
retrieving revision 1.7
diff -u -r1.1.1.4 -r1.7
--- libsi/si.c	2010/03/01 09:42:49	1.1.1.4
+++ libsi/si.c	2010/03/01 09:58:08	1.7
@@ -13,7 +13,9 @@
 #include "si.h"
 #include <errno.h>
 #include <iconv.h>
+#ifndef __FreeBSD__
 #include <malloc.h>
+#endif
 #include <stdlib.h> // for broadcaster stupidity workaround
 #include <string.h>
 #include "descriptor.h"
--- PLUGINS/src/dvbsddevice/Makefile.orig
+++ PLUGINS/src/dvbsddevice/Makefile
@@ -45,7 +45,7 @@ PACKAGE = vdr-$(ARCHIVE)
 
 ### Includes and Defines (add further entries here):
 
-INCLUDES += -I$(VDRDIR)/include
+INCLUDES = -I$(VDRDIR)/include -I${LOCALBASE}/include
 
 DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
 
@@ -100,7 +100,11 @@ i18n: $(I18Nmsgs) $(I18Npot)
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: $(I18Npo) clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/hello/Makefile.orig
+++ PLUGINS/src/hello/Makefile
@@ -45,7 +45,7 @@ PACKAGE = vdr-$(ARCHIVE)
 
 ### Includes and Defines (add further entries here):
 
-INCLUDES += -I$(VDRDIR)/include
+INCLUDES = -I$(VDRDIR)/include -I${LOCALBASE}/include
 
 DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
 
@@ -100,7 +100,11 @@ i18n: $(I18Nmsgs)
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: $(I18Npo) clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/osddemo/Makefile.orig
+++ PLUGINS/src/osddemo/Makefile
@@ -43,7 +43,7 @@ PACKAGE = vdr-$(ARCHIVE)
 
 ### Includes and Defines (add further entries here):
 
-INCLUDES += -I$(VDRDIR)/include
+INCLUDES = -I$(VDRDIR)/include -I${LOCALBASE}/include
 
 DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
 
@@ -73,7 +73,11 @@ $(DEPFILE): Makefile
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/pictures/Makefile.orig
+++ PLUGINS/src/pictures/Makefile
@@ -45,7 +45,7 @@ PACKAGE = vdr-$(ARCHIVE)
 
 ### Includes and Defines (add further entries here):
 
-INCLUDES += -I$(VDRDIR)/include
+INCLUDES = -I$(VDRDIR)/include -I${LOCALBASE}/include
 
 DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
 
@@ -100,7 +100,11 @@ i18n: $(I18Nmsgs) $(I18Npot)
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: $(I18Npo) clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/servicedemo/Makefile.orig
+++ PLUGINS/src/servicedemo/Makefile
@@ -45,7 +45,7 @@ PACKAGE = vdr-$(ARCHIVE)
 
 ### Includes and Defines (add further entries here):
 
-INCLUDES += -I$(VDRDIR)/include
+INCLUDES = -I$(VDRDIR)/include -I${LOCALBASE}/include
 
 DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
 
@@ -75,11 +75,19 @@ $(DEPFILE): Makefile
 
 libvdr-$(PLUGIN1).so: $(PLUGIN1).o
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(PLUGIN1).o -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 libvdr-$(PLUGIN2).so: $(PLUGIN2).o
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(PLUGIN2).o -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/skincurses/Makefile.orig
+++ PLUGINS/src/skincurses/Makefile
@@ -45,7 +45,7 @@ PACKAGE = vdr-$(ARCHIVE)
 
 ### Includes and Defines (add further entries here):
 
-INCLUDES += -I$(VDRDIR)/include
+INCLUDES = -I$(VDRDIR)/include -I${LOCALBASE}/include
 
 DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
 
@@ -100,7 +100,11 @@ i18n: $(I18Nmsgs) $(I18Npot)
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -lncursesw -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: $(I18Npo) clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/status/Makefile.orig
+++ PLUGINS/src/status/Makefile
@@ -43,7 +43,7 @@ PACKAGE = vdr-$(ARCHIVE)
 
 ### Includes and Defines (add further entries here):
 
-INCLUDES += -I$(VDRDIR)/include
+INCLUDES = -I$(VDRDIR)/include -I${LOCALBASE}/include
 
 DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
 
@@ -73,7 +73,11 @@ $(DEPFILE): Makefile
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/svdrpdemo/Makefile.orig
+++ PLUGINS/src/svdrpdemo/Makefile
@@ -43,7 +43,7 @@ PACKAGE = vdr-$(ARCHIVE)
 
 ### Includes and Defines (add further entries here):
 
-INCLUDES += -I$(VDRDIR)/include
+INCLUDES = -I$(VDRDIR)/include -I${LOCALBASE}/include
 
 DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
 
@@ -73,7 +73,11 @@ $(DEPFILE): Makefile
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@
-	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
+ 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/epgtableid0/Makefile.orig
+++ PLUGINS/src/epgtableid0/Makefile
@@ -100,7 +100,11 @@ i18n: $(I18Nmsgs) $(I18Npot)
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: $(I18Npo) clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)
--- PLUGINS/src/rcu/Makefile.orig
+++ PLUGINS/src/rcu/Makefile
@@ -100,7 +100,11 @@ i18n: $(I18Nmsgs) $(I18Npot)
 
 libvdr-$(PLUGIN).so: $(OBJS)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@
+ifdef FREEBSD
+	@cp -f $@ $(LIBDIR)/$@.$(APIVERSION)
+else
 	@cp --remove-destination $@ $(LIBDIR)/$@.$(APIVERSION)
+endif
 
 dist: $(I18Npo) clean
 	@-rm -rf $(TMPDIR)/$(ARCHIVE)