File: configure

package info (click to toggle)
miniupnpd 2.3.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,040 kB
  • sloc: ansic: 28,571; sh: 2,024; makefile: 164
file content (1124 lines) | stat: -rwxr-xr-x 37,106 bytes parent folder | download
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
#! /bin/sh
# $Id: configure,v 1.136 2025/04/21 22:56:48 nanard Exp $
# vim: tabstop=4 shiftwidth=4 noexpandtab
#
# miniupnp daemon
# http://miniupnp.free.fr or https://miniupnp.tuxfamily.org/
# (c) 2006-2025 Thomas Bernard
# This software is subject to the conditions detailed in the
# LICENCE file provided within the distribution

# default to UPnP Device Architecture (UDA) v1.1
# some control points do not like UDA v2.0
UPNP_VERSION_MAJOR=1
UPNP_VERSION_MINOR=1

# input environment variables :
# IPV6, IGD2, STRICT, DEBUG, LEASFILE, VENDORCFG, PCP_PEER,
# PORTINUSE, REGEX, DISABLEPPPCONN, FW, IPTABLESPATH,
# PKG_CONFIG, NO_BACKGROUND_NO_PIDFILE, DYNAMIC_OS_VERSION
# OS_NAME, OS_VERSION, OS_MACHINE, V6SOCKETS_ARE_V6ONLY
# USE_LIBPFCTL, HTTPS, HTTPS_CERTFILE, HTTPS_KEYFILE

if [ -z "$DYNAMIC_OS_VERSION" ] ; then
  DYNAMIC_OS_VERSION=1
fi
if [ -z "$HTTPS_CERTFILE" ] ; then
  HTTPS_CERTFILE=/etc/miniupnpd/certificate.pem
fi
if [ -z "$HTTPS_KEYFILE" ] ; then
  HTTPS_KEYFILE=/etc/miniupnpd/private-key.pem
fi

TESTS=1

for argv; do
case "$argv" in
	--disable-tests) TESTS=0 ;;
	--ipv6) IPV6=1 ;;
	--igd2) IGD2=1 ;;
	--strict) STRICT=1 ;;
	--debug) DEBUG=1 ;;
	--leasefile) LEASEFILE=1 ;;
	--vendorcfg) VENDORCFG=1 ;;
	--pcp-peer) PCP_PEER=1 ;;
	--portinuse) PORTINUSE=1 ;;
	--regex) REGEX=1 ;;
	--https) HTTPS=1 ;;
	--https-cert=*)
		HTTPS_CERTFILE=$(echo $argv | cut -d= -f2) ;;
	--https-key=*)
		HTTPS_KEYFILE=$(echo $argv | cut -d= -f2) ;;
	--uda-version=*)
		UPNP_VERSION=$(echo $argv | cut -d= -f2)
		UPNP_VERSION_MAJOR=$(echo $UPNP_VERSION | cut -s -d. -f1)
		UPNP_VERSION_MINOR=$(echo $UPNP_VERSION | cut -s -d. -f2)
		echo "Setting UPnP version major=$UPNP_VERSION_MAJOR minor=$UPNP_VERSION_MINOR"
		if [ -z "$UPNP_VERSION_MAJOR" ] || [ -z "$UPNP_VERSION_MINOR" ] ; then
			echo "UPnP Version invalid in option $argv"
			exit 1
		fi ;;
	--disable-pppconn) DISABLEPPPCONN=1 ;;
	--disable-fork) NO_BACKGROUND_NO_PIDFILE=1 ;;
	--systemd) SYSTEMD=1 ;;
	--firewall=*)
	    FW=$(echo $argv | cut -d= -f2) ;;
	--libpfctl) USE_LIBPFCTL=1 ;;
	--iptablespath=*)
		IPTABLESPATH=$(echo $argv | cut -d= -f2) ;;
	--getifaddrs) GETIFADDRS=1 ;;
	--v6sockets-v6only) V6SOCKETS_ARE_V6ONLY=1 ;;
	--host-os=*)
		OS_NAME=$(echo $argv | cut -d= -f2) ;;
	--host-os-version=*)
		OS_VERSION=$(echo $argv | cut -d= -f2) ;;
	--host-machine=*)
		OS_MACHINE=$(echo $argv | cut -d= -f2) ;;
	--help|-h)
		echo "Usage: $0 [options]"
		echo " --help                Show this help"
		echo " --ipv6                Enable IPv6"
		echo " --igd2                Build an IGDv2 instead of an IGDv1"
		echo " --strict              Stricter compliance with UPnP specifications"
		echo " --debug               #define DEBUG 1"
		echo " --leasefile           Enable lease file"
		echo " --vendorcfg           Enable configuration of manufacturer info"
		echo " --pcp-peer            Enable PCP PEER operation"
		echo " --portinuse           Enable port in use check"
		echo " --regex               Enable description regex filter"
		echo " --https               Enable HTTPS support (for IGDv2)"
		echo " --https-cert=/path    Path to the HTTPS certificate (default to ${HTTPS_CERTFILE})"
		echo " --https-key=/path     Path to the HTTPS private key (default to ${HTTPS_KEYFILE})"
		echo " --uda-version=x.x     Set advertised UPnP version (default to ${UPNP_VERSION_MAJOR}.${UPNP_VERSION_MINOR})"
		echo " --disable-pppconn     Disable WANPPPConnection"
		echo " --firewall=<name>     Force firewall type (nftables, iptables, pf, ipf, ipfw)"
		echo " --libpfctl            Use libpfctl"
		echo " --iptablespath=/path  Use a specific version of iptables"
		echo " --disable-fork        Do not go to background and do not write pid file"
		echo " --systemd             Include support for systemd process management"
		echo " --getifaddrs          Force use getifaddrs() to obtain interface addresses"
		echo " --v6sockets-v6only    v6 sockets don't do v4, ie sysctl net.inet6.ip6.v6only=1"
		echo " --host-os=<name>      For cross build. result of uname -s on the host machine"
		echo " --host-os-version=x.x For cross build. result of uname -r on the host machine"
		echo " --host-machine=<arch> For cross build. result of uname -m on the host machine"
		echo " --disable-tests       Do not build tests"
		exit 1
		;;
	*)
		echo "Option not recognized: $argv"
		echo "Use -h option to display help"
		exit 1
		;;
esac
done

echo $* > .configure.cache
BASEDIR=`dirname "$0"`
RM="rm -f"
MV="mv"

CONFIGFILE=`mktemp tmp.config.h.XXXXXXXXXX`
CONFIGFILE_FINAL="config.h"
CONFIGMACRO="CONFIG_H_INCLUDED"
if [ -z "$PKG_CONFIG" ] ; then
	PKG_CONFIG=`command -v pkg-config`
fi

pkg_config_write ()
{
	key="$1"; shift
	value="$("${PKG_CONFIG}" "$@")"
	if [ -n "$value" ]; then
		printf "%s += %s\n" "$key" "$value"
	fi
}

# Outputs CFLAGS / LDFLAGS / LDLIBS to CONFIG_MK if needed
pkg_detect ()
{
	if [ -z "${PKG_CONFIG}" ]; then
		return 1
	fi

	libs=
	check_args=
	preamble=
	ok=1
	for arg in "$@"; do
		if echo "${arg}" | grep -q '^-'; then
			check_args="${check_args} ${arg}"
		else
			libs="${libs} ${arg}"
			if [ -z "${check_args}" ]; then
				check_args="--exists"
			fi
			if "${PKG_CONFIG}" ${check_args} "${arg}"; then
				version="$("${PKG_CONFIG}" --modversion "${arg}")"
				eval "$(echo "${arg}" | tr -dc 'a-zA-Z0-9' | tr 'a-z' 'A-Z')_VERSION='${version}'"

				info="found ${arg} version ${version}"
				echo "${info}"
				preamble="$(printf "%s\n# %s\n" "${preamble}" "${info}")"
			else
				echo "${arg} not found"
				ok=
			fi
			check_args=
		fi
	done

	if [ -z "$ok" ]; then
		return 1
	fi

	{
		printf "%s\n" "${preamble}"
		pkg_config_write CFLAGS --cflags ${libs}
		pkg_config_write LDFLAGS --libs-only-L --libs-only-other ${libs}
		pkg_config_write LDLIBS --libs-only-l ${libs}
	} >> "${CONFIG_MK}"
}

MINIUPNPD_DATE=`date +"%Y%m%d"`
if [ -n "$SOURCE_DATE_EPOCH" ]; then
	if date --version 2>&1 | grep -q GNU; then
		MINIUPNPD_DATE=`date --utc --date="@$SOURCE_DATE_EPOCH" +"%Y%m%d"`
	else
		MINIUPNPD_DATE=`TZ=UTC date -j -f %s $SOURCE_DATE_EPOCH +%Y%m%d`
	fi
fi

# Facility to syslog
LOG_MINIUPNPD="LOG_DAEMON"

# Makefile to use
MAKEFILE=

if [ -z "$OS_NAME" ] ; then
# detecting the OS name and version
OS_NAME=`uname -s`
OS_VERSION=`uname -r`
OS_MACHINE=`uname -m`

# pfSense special case
if [ -f /etc/platform ]; then
	if [ `cat /etc/platform` = "pfSense" ]; then
		OS_NAME=pfSense
		OS_VERSION=`cat /etc/version`
	fi
fi

# OpenWrt special case
if [ -f ./os.openwrt ]; then
	OS_NAME=OpenWrt
	OS_VERSION=$(cat ./os.openwrt)
fi

# AstLinux special case
if [ -f ./os.astlinux ]; then
	OS_NAME=AstLinux
	OS_VERSION=$(cat ./os.astlinux)
fi

# Tomato USB special case
if [ -f ../shared/tomato_version ]; then
	OS_NAME=Tomato
	TOMATO_VER=`cat ../shared/tomato_version | cut -d' ' -f2,3`
	OS_VERSION="Tomato $TOMATO_VER"
fi

# OpenEmbedded special case
if [ -f ./os.openembedded ]; then
	OS_NAME=OpenEmbedded
	OS_VERSION=$(cat ./os.openembedded)
fi

else
CROSSBUILD=1
if [ -z "$OS_VERSION" ] || [ -z "$OS_MACHINE" ] ; then
	echo "OS_NAME set to \"$OS_NAME\"."
	echo "Please also set OS_VERSION/--host-os-version and OS_MACHINE/--host-machine"
	exit 1
fi
fi

${RM} ${CONFIGFILE}

echo "/* MiniUPnP Project" >> ${CONFIGFILE}
echo " * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
echo " * (c) 2006-2025 Thomas Bernard" >> ${CONFIGFILE}
echo " * Generated by $0 on `date`" >> ${CONFIGFILE}
echo " * `uname -a`" >> ${CONFIGFILE}
if [ -z "$*" ] ; then
	echo " * using no command line option */" >> ${CONFIGFILE}
else
	echo " * using command line options $* */" >> ${CONFIGFILE}
fi
echo "#ifndef $CONFIGMACRO" >> ${CONFIGFILE}
echo "#define $CONFIGMACRO" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}
echo "#include <inttypes.h>" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}
echo "#define MINIUPNPD_VERSION \"`cat ${BASEDIR}/VERSION`\"" >> ${CONFIGFILE}
echo "#define MINIUPNPD_DATE	\"$MINIUPNPD_DATE\"" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

if [ -n "$DEBUG" ] ; then
	echo "#define DEBUG 1" >> ${CONFIGFILE}
	echo "" >> ${CONFIGFILE}
fi

cat >> ${CONFIGFILE} <<EOF
#ifndef XSTR
#define XSTR(s) STR(s)
#define STR(s) #s
#endif /* XSTR */
EOF

echo "" >> ${CONFIGFILE}
cat >> ${CONFIGFILE} <<EOF
/* UPnP version reported in XML descriptions
 * 1.0 / 1.1 / 2.0 depending on which UDA (UPnP Device Architecture) Version */
#define UPNP_VERSION_MAJOR	${UPNP_VERSION_MAJOR}
#define UPNP_VERSION_MINOR	${UPNP_VERSION_MINOR}
#define UPNP_VERSION_MAJOR_STR	XSTR(UPNP_VERSION_MAJOR)
#define UPNP_VERSION_MINOR_STR	XSTR(UPNP_VERSION_MINOR)
EOF
echo "" >> ${CONFIGFILE}

# OS Specific stuff
OS_FAMILY="$OS_NAME"
case $OS_NAME in
	OpenBSD)
		MAKEFILE=Makefile.bsd
		MAJORVER=`echo $OS_VERSION | cut -d. -f1`
		MINORVER=`echo $OS_VERSION | cut -d. -f2`
		#echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
		# The pledge() system call first appeared in OpenBSD 5.9.
		if [ \( $MAJORVER -ge 6 \) -o \( $MAJORVER -eq 5 -a $MINORVER -ge 9 \) ]; then
			# as of writing (OpenBSD 6.7) DIOCGETRULES is not included in the
			# operations allowed by the "pf" pledge.
			echo "/*#define HAS_PLEDGE*/" >> ${CONFIGFILE}
		fi
		# rtableid was introduced in OpenBSD 4.0
		if [ $MAJORVER -ge 4 ]; then
			echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
		fi
		# from the 3.8 version, packets and bytes counters are double : in/out
		if [ \( $MAJORVER -ge 4 \) -o \( $MAJORVER -eq 3 -a $MINORVER -ge 8 \) ]; then
			echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
		fi
		# from the 4.7 version, new pf
		if [ \( $MAJORVER -ge 5 \) -o \( $MAJORVER -eq 4 -a $MINORVER -ge 7 \) ]; then
			echo "#define PF_NEWSTYLE" >> ${CONFIGFILE}
		fi
		# onrdomain was introduced in OpenBSD 5.0
		if [ $MAJORVER -ge 5 ]; then
			echo "#define PFRULE_HAS_ONRDOMAIN" >> ${CONFIGFILE}
		fi
		# before OpenBSD 5.5 inpt_queue was CIRCLEQ
		if [ $MAJORVER -lt 5 ] || [ $MAJORVER -eq 5 -a $MINORVER -lt 5 ]; then
			echo "#define INPT_QUEUE_IS_CIRCLEQ" >> ${CONFIGFILE}
		fi
		FW=pf
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		OS_URL=https://www.openbsd.org/
		# net.inet6.ip6.v6only has been removed in recent OpenBSD versions
		# Default to 1 in that case
		if [ "$CROSSBUILD" != "1" ] && [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then
			if sysctl net.inet6.ip6 | grep net.inet6.ip6.v6only ; then
				V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only`
			else
				V6SOCKETS_ARE_V6ONLY=1
			fi
		fi
		;;
	FreeBSD | GNU/kFreeBSD)
		MAKEFILE=Makefile.bsd
		if [ "$CROSSBUILD" != "1" ] ; then
			VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
			if [ $VER -ge 700049 ]; then
				echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
			fi
			if [ $VER -ge 1500000 ]; then
				USE_LIBPFCTL=1
			fi
		else
			VER=`echo $OS_VERSION | cut -d. -f1`
			if [ $VER -ge 7 ]; then
				echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
			fi
			if [ $VER -ge 15 ]; then
				USE_LIBPFCTL=1
			fi
		fi
		HAVE_IP_MREQN=1
		# new way to see which one to use PF or IPF.
		# see https://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
		if [ "$CROSSBUILD" != "1" ] && [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/defaults/rc.conf ] ; then
			# source file with handy subroutines like checkyesno
			. /etc/rc.subr
			# source config file so we can probe vars
			. /etc/defaults/rc.conf
			if [ -f /etc/rc.conf ] ; then
				. /etc/rc.conf
			fi
			if checkyesno ipfilter_enable; then
				echo "Using ipf"
				FW=ipf
			elif checkyesno pf_enable; then
				echo "Using pf"
				FW=pf
			elif checkyesno firewall_enable; then
				echo "Using ifpw"
				FW=ipfw
			fi
		fi
		if [ -z $FW ] ; then
			echo "Could not detect usage of ipf, pf, ipfw. Compiling for pf by default"
			FW=pf
		fi
		if [ "$FW" = "ipfw" ] ; then
			echo "!!! ipfw is known to not work with FreeBSD, please contribute !!!"
			echo "!!! see https://github.com/miniupnp/miniupnp/issues/596       !!!"
		fi
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		OS_URL=https://www.freebsd.org/
		if [ "$CROSSBUILD" != "1" ] && [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then
			V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only`
		fi
		;;
	pfSense)
		OS_FAMILY=FreeBSD
		MAKEFILE=Makefile.bsd
		# we need to detect if PFRULE_INOUT_COUNTS macro is needed
		FW=pf
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		OS_URL=https://www.pfsense.com/
		if [ "$CROSSBUILD" != "1" ] && [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then
			V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only`
		fi
		;;
	NetBSD)
		MAKEFILE=Makefile.bsd
		if [ "$CROSSBUILD" != "1" ] && [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
			# source file with handy subroutines like checkyesno
			. /etc/rc.subr
			# source config file so we can probe vars
			. /etc/rc.conf
			if checkyesno pf; then
				FW=pf
			elif checkyesno ipfilter; then
				FW=ipf
			fi
		fi
		if [ -z $FW ] ; then
			echo "Could not detect ipf nor pf, defaulting to pf."
			FW=pf
		fi
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		OS_URL=https://www.netbsd.org/
		;;
	DragonFly)
		OS_FAMILY=DragonFlyBSD
		MAKEFILE=Makefile.bsd
		if [ "$CROSSBUILD" != "1" ] && [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
			# source file with handy subroutines like checkyesno
			. /etc/rc.subr
			# source config file so we can probe vars
			. /etc/rc.conf
			if checkyesno pf; then
				FW=pf
			elif checkyesno ipfilter; then
				FW=ipf
			fi
		fi
		if [ -z $FW ] ; then
			echo "Could not detect ipf nor pf, defaulting to pf."
			FW=pf
		fi
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		# PFRULE_INOUT_COUNTS should be set for DragonFly > 2.8
		# version detection is not yet added to this script.
		echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
		# net.inet6.ip6.v6only has been on by default for many years
		# and this sysctl node has been removed
		V6SOCKETS_ARE_V6ONLY=1
		OS_URL=https://www.dragonflybsd.org/
		;;
	SunOS)
		OS_FAMILY=BSD
		MAKEFILE=Makefile.bsd
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		FW=ipf
		echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
		echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
		# solaris 10 does not define u_int64_t ?
		# but it does define uint64_t
		echo "typedef uint64_t u_int64_t;" >> ${CONFIGFILE}
		OS_URL=https://www.oracle.com/solaris/
		;;
	Linux)
		OS_URL=https://www.kernel.org/
		KERNVERA=`echo $OS_VERSION | awk -F. '{print $1}'`
		KERNVERB=`echo $OS_VERSION | awk -F. '{print $2}'`
		KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
		KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
		#echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
		# from the 2.4 version, struct ip_mreqn instead of struct ip_mreq
		if [ \( $KERNVERA -ge 3 \) -o \( $KERNVERA -eq 2 -a $KERNVERB -ge 4 \) ]; then
			HAVE_IP_MREQN=1
		fi
		if [ "$CROSSBUILD" != "1" ] ; then
			# Debian GNU/Linux special case
			if [ -f /etc/debian_version ]; then
				OS_NAME=Debian
				OS_VERSION=`cat /etc/debian_version`
				OS_URL=https://www.debian.org/
			fi
			# same thing for Gentoo linux
			if  [ -f /etc/gentoo-release ]; then
				OS_NAME=Gentoo
				OS_VERSION=`cat /etc/gentoo-release`
				OS_URL=https://www.gentoo.org/
			fi
			# ClearOS special case
			if [ -f /etc/clearos-release ]; then
				OS_NAME=ClearOS
				OS_VERSION=`grep ^base_version /etc/product | awk '{ print $3 }'`
				OS_URL=https://www.clearos.com/
			fi
			# use lsb_release (Linux Standard Base) when available
			LSB_RELEASE=`command -v lsb_release`
			if [ 0 -eq $? ]; then
				OS_NAME=`${LSB_RELEASE} -i -s`
				OS_VERSION=`${LSB_RELEASE} -r -s`
				case $OS_NAME in
					Chimera)
						OS_URL=https://chimera-linux.org/
						OS_VERSION=`uname -r`
						;;
					Debian)
						OS_URL=https://www.debian.org/
						OS_VERSION=`${LSB_RELEASE} -c -s`
						;;
					Ubuntu)
						OS_URL=https://ubuntu.com/
						OS_VERSION=`${LSB_RELEASE} -c -s`
						;;
					Gentoo)
						OS_URL=https://www.gentoo.org/
						;;
					arch)
						OS_URL=https://archlinux.org/
						OS_VERSION=`uname -r`
						;;
				esac
			fi
		fi
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		if [ "$CROSSBUILD" != "1" ] ; then
			if [ -z ${FW} ]; then
				# test the current environment to determine which to use
				# Would be better to check for actual presence of nftable rules, but that requires root privileges
				if [ -x "$(command -v nft)" ]; then
					FW=nftables
				else
					FW=iptables
				fi
			fi
			if [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then
			V6SOCKETS_ARE_V6ONLY=`$(find /sbin /bin /usr/sbin /usr/bin -name sysctl) -n net.ipv6.bindv6only`
			fi
		fi
		;;
	OpenWrt)
		OS_FAMILY=Linux
		OS_URL=https://www.openwrt.org/
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		GETIFADDRS=1
		;;
	OpenEmbedded)
		OS_FAMILY=Linux
		OS_URL=https://www.openembedded.org/
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		FW=iptables
		;;
	AstLinux)
		OS_FAMILY=Linux
		OS_URL=https://www.astlinux-project.org/
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		FW=iptables
		;;
	Tomato)
		OS_FAMILY=Linux
		OS_NAME=UPnP
		OS_URL=http://tomatousb.org/
		echo "" >> ${CONFIGFILE}
		echo "#ifndef TOMATO" >> ${CONFIGFILE}
		echo "#define TOMATO" >> ${CONFIGFILE}
		echo "#endif" >> ${CONFIGFILE}
		echo "" >> ${CONFIGFILE}
		echo "#ifdef LINUX26" >> ${CONFIGFILE}
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		echo "#endif" >> ${CONFIGFILE}
		echo "#ifdef TCONFIG_IPV6" >> ${CONFIGFILE}
		echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
		echo "#endif" >> ${CONFIGFILE}
		FW=iptables
		;;
	Darwin)
		MAKEFILE=Makefile.macosx
		MAJORVER=`echo $OS_VERSION | cut -d. -f1`
		echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
		# OS X switched to pf since 10.7 Lion (Darwin 11.0)
		if [ $MAJORVER -ge 11 ] ; then
			FW=pf
			echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
		else
			FW=ipfw
		fi
		OS_URL=https://developer.apple.com/macos/
		;;
	*)
		echo "Unknown OS : $OS_NAME"
		echo "Supported OS_NAME / --host-os values : "
		# find all the cases in this "case $OS_NAME in" statement :
		awk '/# OS Specific stuff/{if(b>0){b=0}else{b=NR}} (b>0&&NR>b){print}' "$0" | grep '^	[^\(]*)$' | grep -v '*)' | tr ')|' " \n" | tr -d '\t ' | sort | tr "\n" " " ; echo ""
		echo "Please contact the author at https://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/."
		exit 1
		;;
esac

if [ "$OS_FAMILY" = "Linux" ] ; then
	CONFIG_MK=`mktemp tmp.config.mk.XXXXXXXXXX`
	CONFIG_MK_FINAL="config.mk"
	${RM} ${CONFIG_MK}
	echo "# generated by $0 on `date`" > ${CONFIG_MK}
	echo "SRCDIR = ${BASEDIR}" >> ${CONFIG_MK}
	echo "CPPFLAGS += -I." >> ${CONFIG_MK}
	echo "TESTS = ${TESTS}" >> ${CONFIG_MK}
fi

case $FW in
	pf)
		echo "#define USE_PF 1" >> ${CONFIGFILE}
		if [ "$USE_LIBPFCTL" = "1" ] ; then
			echo "#define USE_LIBPFCTL 1" >> ${CONFIGFILE}
		fi
		;;
	ipf)
		echo "#define USE_IPF 1" >> ${CONFIGFILE}
		;;
	ipfw)
		echo "#define USE_IPFW 1" >> ${CONFIGFILE}
		;;
	iptables)
		if ! [ "$OS_FAMILY" = "Linux" ] ; then
			echo "Error: --firewall=$FW is only available on Linux"
			exit 1
		fi

		MAKEFILE=Makefile.linux
		echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
		echo "#define USE_IPTABLES  1" >> ${CONFIGFILE}
		if [ "$PKG_CONFIG" ] ; then
			if pkg_detect --atleast-version=1.4.3 libiptc; then
				IPTABLES_143=1
			elif pkg_detect libiptc; then
				:
			else
				echo "Warning: no libiptc pkg-config found"
			fi
			if pkg_detect --atleast-version=1.0.2 libnetfilter_conntrack \
			              --atleast-version=1.0.3 libmnl; then
				echo "CPPFLAGS += -DUSE_NFCT" >> ${CONFIG_MK}
			fi
		elif [ "$IPTABLESPATH" ] ; then
			echo "CPPFLAGS += -I${IPTABLESPATH}/include/" >> ${CONFIG_MK}
			echo "LDFLAGS += -L${IPTABLESPATH}/libiptc/" >> ${CONFIG_MK}
			if [ "$OS_NAME" != "OpenWrt" ]; then
				IPTABLESVERSION=`grep "\#define VERSION" ${IPTABLESPATH}/config.h | tr -d \" |cut -d" " -f3`
				echo "detected libiptc version $IPTABLESVERSION"
				echo "# detected libiptc version $IPTABLESVERSION" >> ${CONFIG_MK}
				IPTVER1=`echo $IPTABLESVERSION | cut -d. -f1`
				IPTVER2=`echo $IPTABLESVERSION | cut -d. -f2`
				IPTVER3=`echo $IPTABLESVERSION | cut -d. -f3`
				if [ $IPTVER1 -gt 1 ] || \
				   [ \( $IPTVER1 -eq 1 \) -a \( \( $IPTVER2 -gt 4 \) \
				     -o \( \( $IPTVER2 -eq 4 \) -a \( $IPTVER3 -ge 3 \) \) \) ] ; then
					IPTABLES_143=1
				fi
				if [ "$IPTABLES_143" = "1" ] ; then
					echo "LDLIBS += ${IPTABLESPATH}/libiptc/.libs/libip4tc.o" >> ${CONFIG_MK}
				else
					echo "LDLIBS += ${IPTABLESPATH}/libiptc/libiptc.a" >> ${CONFIG_MK}
				fi
			else
				# OpenWrt
				# check for system-wide iptables files. Test if iptables version >= 1.4.3
				# the following test has to be verified :
				if test -f /usr/include/iptables/internal.h && \
				   grep -q "\#define IPTABLES_VERSION" /usr/include/iptables/internal.h ; then
					IPTABLES_143=1
					echo "LDLIBS += -liptc" >> ${CONFIG_MK}
				fi
				arch=`echo $OS_MACHINE | grep -q x86_64 && echo 64`
				if test -f /usr/lib${arch}/libiptc.a ; then
					echo "LDLIBS += -liptc /usr/lib${arch}/libiptc.a" >> ${CONFIG_MK}
				fi
			fi
		else
			# IPTABLESPATH not defined and no pkg-config
			echo "WARNING: no pkg-config and IPTABLESPATH not defined. checking /usr/include/xtables.h"
			# since 1.4.16, XTABLES_VERSION_CODE has been moved to xtables-version.h
			if test -f /usr/include/xtables-version.h || \
			   test -f /usr/include/xtables.h && \
			   grep -q "XTABLES_VERSION_CODE" /usr/include/xtables.h ; then
				IPTABLES_143=1
				echo "LDLIBS += -liptc" >> ${CONFIG_MK}
				if test -f /lib/libip4tc.so ; then
					echo "LDLIBS += -lip4tc" >> ${CONFIG_MK}
				fi
				if test -f /lib/libip6tc.so ; then
					echo "LDLIBS += -lip6tc" >> ${CONFIG_MK}
				fi
			fi
		fi
		echo "/* when IPTABLES_143 is defined, miniupnpd uses the new API" >> ${CONFIGFILE}
		echo " * from libiptc 1.4.3+ */ " >> ${CONFIGFILE}
		if [ "$IPTABLES_143" = "1" ] ; then
			echo "#define IPTABLES_143" >> ${CONFIGFILE}
		else
			echo "#undef IPTABLES_143" >> ${CONFIGFILE}
		fi
		;;
	nftables)
		if ! [ "$OS_FAMILY" = "Linux" ] ; then
			echo "Error: --firewall=$FW is only available on Linux"
			exit 1
		fi

		MAKEFILE=Makefile.linux_nft
		echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
		echo "#define USE_NFTABLES  1" >> ${CONFIGFILE}
		if pkg_detect libnftnl libmnl; then
			:
		else
			echo "Warning: no libnftnl or libmnl pkg-config found"
		fi
		;;
	*)
		echo "Unknown Firewall/packet filtering software [$FW]"
		echo "Please contact the author at http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/."
		exit 1
		;;
esac

if [ "$MAKEFILE" = "Makefile.linux" ] || [ "$MAKEFILE" = "Makefile.linux_nft" ] || [ "$MAKEFILE" = "Makefile.macosx" ] ; then
	DEFAULT_CONFIG=/etc/miniupnpd/miniupnpd.conf
else
	DEFAULT_CONFIG=/etc/miniupnpd.conf
fi

if [ "$MAKEFILE" = "Makefile.bsd" ] || [ "$OS_NAME" = "Darwin" ] || [ "$OS_NAME" = "SunOS" ] ; then
	CONFIG_MK=bsdmake.inc
	echo "# generated by $0 on `date`" > bsdmake.inc
	echo "OSNAME = ${OS_NAME}" >> bsdmake.inc
	echo "ARCH = ${OS_MACHINE}" >> bsdmake.inc
	echo "FWNAME = $FW" >> bsdmake.inc
	echo "SRCDIR = ${BASEDIR}" >> bsdmake.inc
	echo "CPPFLAGS += -I." >> bsdmake.inc
	if [ "$USE_LIBPFCTL" = "1" ] ; then
		echo "CPPFLAGS += -I/usr/local/include/" >> bsdmake.inc
		echo "LDFLAGS += -L/usr/local/lib" >> bsdmake.inc
		echo "LIBS += -lpfctl" >> bsdmake.inc
	fi
fi
if [ "$MAKEFILE" ] ; then
	cp "${BASEDIR}/${MAKEFILE}" Makefile && echo "${BASEDIR}/${MAKEFILE} -> Makefile"
fi

# discover systemd
if [ "$OS_FAMILY" = "Linux" ] && [ -n "$SYSTEMD" ] && [ "$SYSTEMD" -eq 1 ] ; then
	if pkg_detect libsystemd; then
		:
	else
		echo "Warning: libsystemd not found"
	fi
fi

# libcap variants
case $OS_FAMILY in
	Linux)
		if [ "$PKG_CONFIG" ] ; then
			if pkg_detect libcap-ng; then
				echo "#define HAS_LIBCAP_NG" >> ${CONFIGFILE}
			elif pkg_detect libcap; then
				echo "#define HAS_LIBCAP" >> ${CONFIGFILE}
			fi
		else
			echo "WARNING: no pkg-config, cannot detect libcap/libcap-ng"
		fi
		;;
esac

# UUID API
case $OS_FAMILY in
	Linux)
		if pkg_detect uuid; then
			echo "#define LIB_UUID" >> ${CONFIGFILE}
		else
			echo "Warning: uuid pkg-config not found"
		fi
		;;
	*)
		if grep uuid_create /usr/include/uuid.h > /dev/null 2>&1 ; then
			echo "#define BSD_UUID" >> ${CONFIGFILE}
		fi
		if grep uuid_generate /usr/include/uuid/uuid.h > /dev/null 2>&1 ; then
			echo "#define LIB_UUID" >> ${CONFIGFILE}
		fi
		;;
esac

# OpenSSL : only with IGDv2 enabled
if [ -n "$HTTPS" ] && [ -n "$IGD2" ] ; then
	case $OS_FAMILY in
		Linux)
			if pkg_detect openssl; then
				:
			else
				echo "Warning: openssl pkg-config not found!"
			fi
		;;
		*BSD)
			echo "LIBS += -lssl -lcrypto" >> bsdmake.inc
		;;
	esac
fi

# UUID binary
if [ "$OS_NAME" = "OpenWrt" ]; then
	UUIDBINDIR="${STAGING_DIR_HOST}/bin/"
fi
# genuuid uses the uuidgen CLI tool which is part of libuuid
# from the e2fsprogs
# 'cat /proc/sys/kernel/random/uuid' could be also used
for bin in genuuid uuidgen uuid; do
	UUIDBIN="$(command -v "${UUIDBINDIR}${bin}" 2>/dev/null)" && break
done
if [ -n "${UUIDBIN}" ]; then
	echo "UUIDBIN = ${UUIDBIN}" >> ${CONFIG_MK}
elif [ -f /proc/sys/kernel/random/uuid ] ; then
	echo "UUIDBIN = cat /proc/sys/kernel/random/uuid" >> ${CONFIG_MK}
else
	echo "Warning: genuuid/uuidgen/uuid not found!"
fi

# set V6SOCKETS_ARE_V6ONLY to 0 if it was not set above
if [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then
	V6SOCKETS_ARE_V6ONLY=0
fi

echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] [$OS_MACHINE] with [$FW] firewall software."
echo "Please edit config.h for more compilation options."

# define SUPPORT_REMOTEHOST if the FW related code really supports setting
# a RemoteHost
if [ \( "$FW" = "nftables" \) -o \( "$FW" = "iptables" \) -o \( "$FW" = "pf" \) -o \( "$FW" = "ipfw" \) ] ; then
	echo "#define SUPPORT_REMOTEHOST" >> ${CONFIGFILE}
fi

echo "/* Enable IGD2 \"Port Triggering\" as defined in Section 2.5.16" >> ${CONFIGFILE}
echo " * figure 2.2 in UPnP-gw-WANIPConnection-v2-Service.pdf */" >> ${CONFIGFILE}
echo "#define ENABLE_PORT_TRIGGERING" >> ${CONFIGFILE}

echo "" >> ${CONFIGFILE}
if [ $DYNAMIC_OS_VERSION -ne 0 ] ; then
  OS_VERSION="%s"
  echo "#define DYNAMIC_OS_VERSION 1" >> ${CONFIGFILE}
fi
echo "#define OS_NAME		\"$OS_NAME\"" >> ${CONFIGFILE}
if [ -z "$OS_VERSION" ] ; then
  echo "#define OS_VERSION	\"$OS_NAME\"" >> ${CONFIGFILE}
else
  echo "#define OS_VERSION	\"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
fi
echo "#define OS_URL		\"${OS_URL}\"" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
echo "#define LOG_MINIUPNPD		 ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Comment the following line to disable PCP operations */" >> ${CONFIGFILE}
echo "#define ENABLE_PCP" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "#ifdef ENABLE_PCP" >> ${CONFIGFILE}
if [ -n "$PCP_PEER" ]; then
echo "/* Comment the following line to disable PCP PEER operation */" >> ${CONFIGFILE}
echo "#define PCP_PEER" >> ${CONFIGFILE}
else
echo "/* Uncomment the following line to enable PCP PEER operation */" >> ${CONFIGFILE}
echo "/*#define PCP_PEER*/" >> ${CONFIGFILE}
fi
echo "#ifdef PCP_PEER" >> ${CONFIGFILE}
echo "/*#define PCP_FLOWP*/" >> ${CONFIGFILE}
echo "#endif /*PCP_PEER*/" >> ${CONFIGFILE}
echo "/*#define PCP_SADSCP*/" >> ${CONFIGFILE}
echo "#endif /*ENABLE_PCP*/" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
echo " * filter rules with pf */" >> ${CONFIGFILE}
echo "/*#define PF_ENABLE_FILTER_RULES*/">> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to set dst address in rdr rules with pf." >> ${CONFIGFILE}
echo " * It is disabled by default because of" >> ${CONFIGFILE}
echo " * https://github.com/miniupnp/miniupnp/issues/433 */" >> ${CONFIGFILE}
echo "/*#define PF_SET_DST_ADDR*/">> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
echo " * the getifstats() function */" >> ${CONFIGFILE}
echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
echo "/* note : That is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
echo "/* Dynamic external ip adresses are not supported when this option is enabled." >> ${CONFIGFILE}
echo " * Also note that you would need to configure your .conf file accordingly. */" >> ${CONFIGFILE}
echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
echo " * of BSD daemon() */" >> ${CONFIGFILE}
echo "#define USE_DAEMON" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
if [ -n "$LEASEFILE" ] ; then
	echo "#define ENABLE_LEASEFILE" >> ${CONFIGFILE}
else
	echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
fi
echo "/* Uncomment the following line to store remaining time in lease file */" >> ${CONFIGFILE}
echo "/*#define LEASEFILE_USE_REMAINING_TIME*/" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to enable port in use check */" >> ${CONFIGFILE}
if [ -n "$PORTINUSE" ]; then
	echo "#define CHECK_PORTINUSE" >> ${CONFIGFILE}
else
	echo "/*#define CHECK_PORTINUSE*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to enable description regex filter */" >> ${CONFIGFILE}
if [ -n "$REGEX" ]; then
	echo "#define ENABLE_REGEX" >> ${CONFIGFILE}
else
	echo "/*#define ENABLE_REGEX*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
echo " * option. */" >> ${CONFIGFILE}
echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* define ADVERTISE_WANPPPCONN to allow buggy Control Point to use" >> ${CONFIGFILE}
echo " * WANPPPConnection instead of WANIPConnection. */" >>  ${CONFIGFILE}
if [ -n "$STRICT" ] || [ -n "$DISABLEPPPCONN" ] ; then
	echo "/*#define ADVERTISE_WANPPPCONN*/" >> ${CONFIGFILE}
else
	echo "#define ADVERTISE_WANPPPCONN" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

echo "/* Enable IP v6 support */" >> ${CONFIGFILE}
if [ -n "$IPV6" ]; then
	echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
else
	echo "/*#define ENABLE_IPV6*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

echo "/* Define V6SOCKETS_ARE_V6ONLY if AF_INET6 sockets are restricted" >> ${CONFIGFILE}
echo " * to IPv6 communications only. */" >> ${CONFIGFILE}
if [ $V6SOCKETS_ARE_V6ONLY -eq 1 ] ; then
	echo "#define V6SOCKETS_ARE_V6ONLY" >> ${CONFIGFILE}
else
	echo "/*#define V6SOCKETS_ARE_V6ONLY*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

if [ -n "$HAVE_IP_MREQN" ]; then
	echo "#define HAVE_IP_MREQN" >> ${CONFIGFILE}
	echo "" >> ${CONFIGFILE}
fi

echo "/* Enable the support of IGD v2 specification." >> ${CONFIGFILE}
echo " * This is not fully tested yet and can cause incompatibilities with some" >> ${CONFIGFILE}
echo " * control points, so enable with care. */" >> ${CONFIGFILE}
if [ -n "$IGD2" ]; then
	echo "#define IGD_V2" >> ${CONFIGFILE}
else
	echo "/*#define IGD_V2*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

echo "#ifdef IGD_V2" >> ${CONFIGFILE}
echo "/* Enable DeviceProtection service (IGDv2) - incomplete implementation */" >> ${CONFIGFILE}
echo "/*#define ENABLE_DP_SERVICE*/" >> ${CONFIGFILE}
if [ -n "$HTTPS" ]; then
	echo "#define ENABLE_HTTPS" >> ${CONFIGFILE}
	echo "#define HTTPS_CERTFILE \"${HTTPS_CERTFILE}\"" >> ${CONFIGFILE}
	echo "#define HTTPS_KEYFILE \"${HTTPS_KEYFILE}\"" >> ${CONFIGFILE}
else
	echo "/*#define ENABLE_HTTPS*/" >> ${CONFIGFILE}
	echo "/*#define HTTPS_CERTFILE \"${HTTPS_CERTFILE}\"*/" >> ${CONFIGFILE}
	echo "/*#define HTTPS_KEYFILE \"${HTTPS_KEYFILE}\"*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}
echo "/* Enable WANIPv6FirewallControl service (IGDv2). needs IPv6 */" >> ${CONFIGFILE}
echo "#ifdef ENABLE_IPV6" >> ${CONFIGFILE}
echo "#define ENABLE_6FC_SERVICE" >> ${CONFIGFILE}
echo "#endif /* ENABLE_IPV6 */" >> ${CONFIGFILE}
echo "#endif /* IGD_V2 */" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* UPnP Events support. Working well enough to be enabled by default." >> ${CONFIGFILE}
echo " * It can be disabled to save a few bytes. */" >> ${CONFIGFILE}
echo "#define ENABLE_EVENTS" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* include interface name in pf, ipf and nftables rules */" >> ${CONFIGFILE}
echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Experimental NFQUEUE support. */" >> ${CONFIGFILE}
echo "/*#define ENABLE_NFQUEUE*/" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Enable to make MiniUPnPd more strict about UPnP conformance" >> ${CONFIGFILE}
echo " * and the messages it receives from control points */" >> ${CONFIGFILE}
if [ -n "$STRICT" ] ; then
	echo "#define UPNP_STRICT" >> ${CONFIGFILE}
else
	echo "/*#define UPNP_STRICT*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

echo "/* If SSDP_RESPOND_SAME_VERSION is defined, the M-SEARCH response" >> ${CONFIGFILE}
echo " * include the same device version as was contained in the search" >> ${CONFIGFILE}
echo " * request. It conforms to UPnP DA v1.1 */" >> ${CONFIGFILE}
echo "#define SSDP_RESPOND_SAME_VERSION" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Add the optional Date: header in all HTTP responses */" >> ${CONFIGFILE}
if [ -n "$STRICT" ] ; then
	echo "#define ENABLE_HTTP_DATE" >> ${CONFIGFILE}
else
	echo "/*#define ENABLE_HTTP_DATE*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

echo "/* Wait a little before answering M-SEARCH request */" >> ${CONFIGFILE}
if [ -n "$STRICT" ] ; then
	echo "#define DELAY_MSEARCH_RESPONSE" >> ${CONFIGFILE}
else
	echo "/*#define DELAY_MSEARCH_RESPONSE*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

echo "/* disable reading and parsing of config file (miniupnpd.conf) */" >> ${CONFIGFILE}
echo "/*#define DISABLE_CONFIG_FILE*/" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "#define DEFAULT_CONFIG \"${DEFAULT_CONFIG}\"" >> ${CONFIGFILE}
echo "" >> ${CONFIGFILE}

echo "/* Uncomment the following line to configure all manufacturer infos through miniupnpd.conf */" >> ${CONFIGFILE}
if [ -n "$VENDORCFG" ] ; then
	echo "#define ENABLE_MANUFACTURER_INFO_CONFIGURATION" >> ${CONFIGFILE}
else
	echo "/*#define ENABLE_MANUFACTURER_INFO_CONFIGURATION*/" >> ${CONFIGFILE}
fi
echo "" >> ${CONFIGFILE}

cat >> ${CONFIGFILE} <<EOF
#if defined(ENABLE_6FC_SERVICE) || (defined(ENABLE_PCP) && defined(ENABLE_IPV6))
#define ENABLE_UPNPPINHOLE
#endif

EOF

cat >> ${CONFIGFILE} <<EOF
/* Uncomment the following line if your device does not have a proper clock
 * BOOTID.UPNP.ORG can be set with command line */
#define USE_TIME_AS_BOOTID

EOF

cat >> ${CONFIGFILE} <<EOF
/* With the following macro defined, a random string is prepended to all URLs */
/*#define RANDOMIZE_URLS*/

/* maximum length of SSDP packets we are generating
 * (reception is done in a 1500byte buffer) */
#define SSDP_PACKET_MAX_LEN 1024

EOF

echo "/* disable forking to the background and writing the pid file */" >> ${CONFIGFILE}
if [ -n "$NO_BACKGROUND_NO_PIDFILE" ] && [ $NO_BACKGROUND_NO_PIDFILE -eq 1 ] ; then
	echo "#define NO_BACKGROUND_NO_PIDFILE" >> ${CONFIGFILE}
else
	echo "/*#define NO_BACKGROUND_NO_PIDFILE*/" >> ${CONFIGFILE}
fi

echo "/* support systemd process management (use sd_notify() instead of daemonization) */" >> ${CONFIGFILE}
if [ -n "$SYSTEMD" ] && [ $SYSTEMD -eq 1 ] ; then
	echo "#define USE_SYSTEMD" >> ${CONFIGFILE}
	echo "USE_SYSTEMD = 1" >> ${CONFIG_MK}
else
	echo "/*#define USE_SYSTEMD*/" >> ${CONFIGFILE}
fi

echo "/* Whether to use getifaddrs() to determine interface addresses */" >> ${CONFIGFILE}
if [ -n "$GETIFADDRS" ] && [ $GETIFADDRS -eq 1 ] ; then
	echo "#define USE_GETIFADDRS" >> ${CONFIGFILE}
else
	echo "/*#define USE_GETIFADDRS*/" >> ${CONFIGFILE}
fi

echo "/* uncomment if your libc is too old to include strndup() */" >> ${CONFIGFILE}
echo "/*#define NO_STRNDUP */" >> ${CONFIGFILE}

echo "" >> ${CONFIGFILE}
echo "#endif /* ${CONFIGMACRO} */" >> ${CONFIGFILE}

${MV} ${CONFIGFILE} ${CONFIGFILE_FINAL}
if [ -f "${CONFIG_MK}" ] && [ -n "${CONFIG_MK_FINAL}" ] ; then
	${MV} ${CONFIG_MK} ${CONFIG_MK_FINAL}
fi

exit 0