-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathconfigure.ac
More file actions
182 lines (154 loc) · 5.63 KB
/
Copy pathconfigure.ac
File metadata and controls
182 lines (154 loc) · 5.63 KB
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
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])
AC_INIT([fastrpc], [0.0.1])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE(1.10 foreign subdir-objects)
LT_INIT(disable-static)
AS_CASE([$host],
[*-linux-android], [
compile_for_android=yes
], [
compile_for_android=no
]
)
AM_CONDITIONAL([ANDROID_CC],
[test "$compile_for_android" = yes])
# Add shared object versioning
m4_define([LT_MAJOR], [1])
m4_define([LT_MINOR], [0])
m4_define([LT_PATCH], [0])
AC_SUBST([LT_VERSION], LT_MAJOR.LT_MINOR)
AC_SUBST([LT_VERSION_NUMBER], LT_MAJOR:LT_MINOR:LT_PATCH)
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AM_PROG_CC_C_O
# Checks for libraries.
# Enable pkg-config
PKG_PROG_PKG_CONFIG
# Configure systemd unit directory option (--with-systemdsystemunitdir)
AC_ARG_WITH([systemdsystemunitdir],
[AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
[Directory for systemd service files (default: /lib/systemd/system)])],
[systemdsystemunitdir="$withval"],
[PKG_CHECK_VAR([systemdsystemunitdir], [systemd], [systemdsystemunitdir], [], [systemdsystemunitdir="/lib/systemd/system"])])
AC_MSG_NOTICE([systemd unit directory: $systemdsystemunitdir])
AC_SUBST([systemdsystemunitdir])
# Configure udev rules directory option (--with-udevrulesdir)
AC_ARG_WITH([udevrulesdir],
[AS_HELP_STRING([--with-udevrulesdir=DIR],
[Directory for udev rules files (default: /lib/udev/rules.d)])],
[udevrulesdir="$withval"],
[PKG_CHECK_VAR([udevdir], [udev], [udevdir], [udevrulesdir="${udevdir}/rules.d"], [udevrulesdir="/lib/udev/rules.d"])])
AC_MSG_NOTICE([udev rules directory: $udevrulesdir])
AC_SUBST([udevrulesdir])
# Configure sysusers directory option (--with-sysusersdir)
AC_ARG_WITH([sysusersdir],
[AS_HELP_STRING([--with-sysusersdir=DIR],
[Directory for systemd sysusers files (default: /usr/lib/sysusers.d)])],
[sysusersdir="$withval"],
[PKG_CHECK_VAR([sysusersdir], [systemd], [sysusersdir], [], [sysusersdir="/usr/lib/sysusers.d"])])
AC_MSG_NOTICE([sysusers directory: $sysusersdir])
AC_SUBST([sysusersdir])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
# Check for libyaml only if not Android
AS_IF([test "$compile_for_android" = no], [
PKG_CHECK_MODULES([YAML], [yaml-0.1], [],
[AC_MSG_ERROR([libyaml (yaml-0.1) is required but not found.])])
AC_SUBST(YAML_CFLAGS)
AC_SUBST(YAML_LIBS)
])
# Check for libbsd only if not Android (provides strlcpy, strlcat, etc.)
AS_IF([test "$compile_for_android" = no], [
PKG_CHECK_MODULES([BSD], [libbsd-overlay], [],
[AC_MSG_ERROR([libbsd (libbsd-overlay) is required but not found.])])
AC_SUBST(BSD_CFLAGS)
AC_SUBST(BSD_LIBS)
])
# Configure config base path option (--with-config-base-dir)
AC_ARG_WITH([config-base-dir],
[AS_HELP_STRING([--with-config-base-dir=PATH],
[Base directory for config files (default: /usr/share/qcom)])],
[config_base_dir="$withval"],
[config_base_dir="/usr/share/qcom/"])
AC_MSG_NOTICE([Config base path: $config_base_dir])
AC_SUBST([CONFIG_BASE_DIR], ["$config_base_dir"])
# Enable stricter compiler flags
# These are based on Debian's dpkg-buildflags defaults for compatibility with
# distro builds and to catch issues during development
AC_ARG_ENABLE([stricter],
[AS_HELP_STRING([--enable-stricter],
[Enable stricter compiler flags (warnings, stack protection, fortify source, RELRO)])],
[enable_stricter=$enableval],
[enable_stricter=no])
# Helper macro to test if compiler accepts a flag
AC_DEFUN([CC_CHECK_FLAG], [
AC_MSG_CHECKING([if $CC supports $1])
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $1"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes]); $2],
[AC_MSG_RESULT([no]); $3])
CFLAGS="$saved_CFLAGS"
])
# Helper macro to test if linker accepts a flag
AC_DEFUN([LD_CHECK_FLAG], [
AC_MSG_CHECKING([if linker supports $1])
saved_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $1"
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes]); $2],
[AC_MSG_RESULT([no]); $3])
LDFLAGS="$saved_LDFLAGS"
])
# Set up hardening flags
STRICTER_CFLAGS=""
STRICTER_CPPFLAGS=""
STRICTER_LDFLAGS=""
AS_IF([test "x$enable_stricter" = "xyes"], [
# Format string security warnings
STRICTER_CFLAGS="-Wformat -Werror=format-security -Werror=implicit-function-declaration"
# Stack protection
CC_CHECK_FLAG([-fstack-protector-strong],
[STRICTER_CFLAGS="$STRICTER_CFLAGS -fstack-protector-strong"])
CC_CHECK_FLAG([-fstack-clash-protection],
[STRICTER_CFLAGS="$STRICTER_CFLAGS -fstack-clash-protection"])
# Architecture-specific hardening
AS_CASE([$host_cpu],
[aarch64], [
CC_CHECK_FLAG([-mbranch-protection=standard],
[STRICTER_CFLAGS="$STRICTER_CFLAGS -mbranch-protection=standard"])
],
[]
)
# FORTIFY_SOURCE and reproducible builds
STRICTER_CPPFLAGS="-D_FORTIFY_SOURCE=2 -Wdate-time"
# RELRO - read-only relocations
LD_CHECK_FLAG([-Wl,-z,relro],
[STRICTER_LDFLAGS="-Wl,-z,relro"])
AC_MSG_NOTICE([Stricter compiler flags enabled)])
AC_MSG_NOTICE([ STRICTER_CFLAGS: $STRICTER_CFLAGS])
AC_MSG_NOTICE([ STRICTER_CPPFLAGS: $STRICTER_CPPFLAGS])
AC_MSG_NOTICE([ STRICTER_LDFLAGS: $STRICTER_LDFLAGS])
], [
AC_MSG_NOTICE([Stricter compiler flags disabled (use --enable-stricter to enable)])
])
AC_SUBST([STRICTER_CFLAGS])
AC_SUBST([STRICTER_CPPFLAGS])
AC_SUBST([STRICTER_LDFLAGS])
AC_CONFIG_FILES([
Makefile
inc/Makefile
src/Makefile
test/Makefile
files/Makefile
Docs/manpages/Makefile
])
AC_OUTPUT