1 ########################################################################
2 # Copyright (C) 2021, 2022 Alejandro Colomar <alx.manpages@gmail.com>
3 # SPDX-License-Identifier: GPL-2.0 OR LGPL-2.0
4 ########################################################################
7 ifndef MAKEFILE_BUILD_SRC_INCLUDED
8 MAKEFILE_BUILD_SRC_INCLUDED
:= 1
11 include $(srcdir)/lib
/build.mk
12 include $(srcdir)/lib
/cmd.mk
13 include $(srcdir)/lib
/lint.mk
14 include $(srcdir)/lib
/src.mk
17 PKG-CONFIG_LIBS
:= libbsd-overlay
20 DEFAULT_CPPFLAGS
:= $(shell $(PKG-CONFIG
) --cflags $(PKG-CONFIG_LIBS
))
22 CPPFLAGS
:= $(DEFAULT_CPPFLAGS
) $(EXTRA_CPPFLAGS
)
24 DEFAULT_CFLAGS
:= -std
=gnu17
25 DEFAULT_CFLAGS
+= -Wall
26 DEFAULT_CFLAGS
+= -Wextra
27 DEFAULT_CFLAGS
+= -Wstrict-prototypes
28 DEFAULT_CFLAGS
+= -Werror
29 DEFAULT_CFLAGS
+= -Wno-error
=unused-parameter
30 DEFAULT_CFLAGS
+= -Wno-error
=sign-compare
31 DEFAULT_CFLAGS
+= -Wno-error
=format
32 DEFAULT_CFLAGS
+= -Wno-error
=uninitialized
34 CFLAGS
:= $(DEFAULT_CFLAGS
) $(EXTRA_CFLAGS
)
36 DEFAULT_LDFLAGS
:= -Wl
,--as-needed
37 DEFAULT_LDFLAGS
+= -Wl
,--no-allow-shlib-undefined
38 DEFAULT_LDFLAGS
+= -Wl
,--no-copy-dt-needed-entries
39 DEFAULT_LDFLAGS
+= -Wl
,--no-undefined
40 DEFAULT_LDFLAGS
+= $(shell $(PKG-CONFIG
) --libs-only-L
$(PKG-CONFIG_LIBS
))
41 DEFAULT_LDFLAGS
+= $(shell $(PKG-CONFIG
) --libs-only-other
$(PKG-CONFIG_LIBS
))
43 LDFLAGS
:= $(DEFAULT_LDFLAGS
) $(EXTRA_LDFLAGS
)
46 DEFAULT_LDLIBS
+= $(shell $(PKG-CONFIG
) --libs-only-l
$(PKG-CONFIG_LIBS
))
48 LDLIBS
:= $(DEFAULT_LDLIBS
) $(EXTRA_LDLIBS
)
56 _SRCPAGEDIRS
:= $(patsubst $(MANDIR
)/%,$(_SRCDIR
)/%.d
,$(LINTMAN
))
58 _UNITS_src_src
:= $(patsubst $(MANDIR
)/%,$(_SRCDIR
)/%,$(shell \
59 $(FIND
) $(MANDIR
)/man
*/ -type f \
60 |
$(GREP
) '$(MANEXT)$$' \
61 |
$(XARGS
) $(GREP
) -l
'^\.TH ' \
64 $(SED
) -n
"s,^\... SRC BEGIN (\(.*.[ch]\))$$,$$m.d/\1,p"; \
67 _UNITS_src_h
:= $(filter %.h
,$(_UNITS_src_src
))
68 _UNITS_src_c
:= $(filter %.c
,$(_UNITS_src_src
))
69 _UNITS_src_o
:= $(patsubst %.c
,%.o
,$(_UNITS_src_c
))
70 _UNITS_src_bin
:= $(patsubst %.c
,%,$(_UNITS_src_c
))
73 $(_SRCPAGEDIRS
): $(_SRCDIR
)/%.d
: $(MANDIR
)/% |
$$(@D
)/.
78 $(_UNITS_src_src
): $$(patsubst $(_SRCDIR
)/%.d
,$(MANDIR
)/%,$$(@D
)) |
$$(@D
)
79 $(_UNITS_src_c
): $$(filter $$(@D
)/%.h
,$(_UNITS_src_h
))
84 -e
'/^\.TH/,/^\.SH/{/^\.SH/!p}' \
85 -e
'/^\.SH EXAMPLES/p' \
86 -e
"/^\... SRC BEGIN ($(@F))$$/,/^\... SRC END$$/p" \
87 |
$(MAN
) -P cat
-l
- \
92 $(_UNITS_src_o
): $(_SRCDIR
)/%.o
: $(_SRCDIR
)/%.c
94 $(CC
) -c
$(CPPFLAGS
) $(CFLAGS
) -o
$@
$<
96 $(_UNITS_src_bin
): $(_SRCDIR
)/%: $(_SRCDIR
)/%.o
98 $(LD
) $(LDFLAGS
) -o
$@
$< $(LDLIBS
)
102 build-src-c
: $(_UNITS_src_c
) | builddirs-src
106 build-src-cc
: $(_UNITS_src_o
)
110 build-src-ld
: $(_UNITS_src_bin
)
113 .PHONY
: builddirs-src
114 builddirs-src
: $(_SRCDIRS
)
118 build-src
: build-src-ld
121 endif # MAKEFILE_BUILD_SRC_INCLUDED