config.mk 3.34 KB
Newer Older
Philippe Gerum's avatar
Philippe Gerum committed
1
2
3
# SPDX-License-Identifier: MIT

ARCH		?= $(shell uname -m | sed	\
4
		-e s/arm.*/arm/			\
Philippe Gerum's avatar
Philippe Gerum committed
5
6
		-e s/aarch64.*/arm64/		\
		-e s/x86_64/x86/ )
Philippe Gerum's avatar
Philippe Gerum committed
7
8
CROSS_COMPILE	?=
CC		= $(CROSS_COMPILE)gcc
Philippe Gerum's avatar
Philippe Gerum committed
9
CXX		= $(CROSS_COMPILE)g++
Philippe Gerum's avatar
Philippe Gerum committed
10
11
12
LD		= $(CROSS_COMPILE)ld
AR		= $(CROSS_COMPILE)ar
UAPI		?= /usr/include
13
DESTDIR		?= /usr/evl
Philippe Gerum's avatar
Philippe Gerum committed
14
15
16
17
18
19
20
21
22
23

INSTALL		?= install
INSTALL_PROGRAM	?= $(INSTALL)
INSTALL_DATA	?= $(INSTALL) -m 644

CP		:= cp
CPIO		:= cpio
RM		:= rm
LN_S		:= ln -sf
MKDIR_P		:= mkdir -p
24
RMDIR_SAFE	:= rmdir --ignore-fail-on-non-empty
Philippe Gerum's avatar
Philippe Gerum committed
25
26
27
28

libdir		?= lib
includedir	?= include
bindir		?= bin
29
testdir		?= tests
30
libexecdir	?= libexec
31
tbitsdir	?= tidbits
Philippe Gerum's avatar
Philippe Gerum committed
32

33
export ARCH CROSS_COMPILE CC CXX LD AR UAPI CFLAGS LDFLAGS DESTDIR
Philippe Gerum's avatar
Philippe Gerum committed
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

MAKEFLAGS += -rR

ifneq ("$(origin O)", "command line")
  O_DIR = $(CURDIR)
else
  O_DIR := $(shell $(MKDIR_P) $(O) && cd $(O) && /bin/pwd)
endif

ifneq ("$(origin V)", "command line")
  V = 0
endif

ifeq ($(V),1)
  Q =
else
  Q = @
  MAKEFLAGS += --no-print-directory
endif

ifeq ($(D),1)
  DEBUG_CPPFLAGS=
  DEBUG_CFLAGS=-g -O0
else
  DEBUG_CPPFLAGS=-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
  DEBUG_CFLAGS=-O2
endif

BASE_CPPFLAGS := -D_GNU_SOURCE -D_REENTRANT $(DEBUG_CPPFLAGS)

64
65
66
67
68
69
70
GCCVER_GTE_7 := $(shell expr `${CC} -dumpversion | cut -f1 -d.` \>= 7)
ifeq "$(GCCVER_GTE_7)" "1"
	WSHADOW_FLAG="-Wshadow=local"
else
	WSHADOW_FLAG=
endif

71
BASE_CFLAGS :=	-pipe -fstrict-aliasing	 					\
Philippe Gerum's avatar
Philippe Gerum committed
72
		-Wall -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long	\
73
		-Wno-unused-parameter ${WSHADOW_FLAG} -Werror $(DEBUG_CFLAGS)
Philippe Gerum's avatar
Philippe Gerum committed
74

Philippe Gerum's avatar
Philippe Gerum committed
75
BASE_CXXFLAGS := -pipe -fstrict-aliasing -Wall -Wno-long-long	\
76
		-Wno-unused-parameter ${WSHADOW_FLAG} -Werror $(DEBUG_CFLAGS)
Philippe Gerum's avatar
Philippe Gerum committed
77

Philippe Gerum's avatar
Philippe Gerum committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Easy way to hide commas in args from $(call ...) invocations
comma := ,

ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
  quiet=y
endif

terse-echo = @$(if $(Q),echo "	$(1)	$(2)";)
define run-cmd
	$(if $(quiet),,$(call terse-echo,$(1),$(2)))
	$(Q)$(3)
endef
define run-cc
	@$(MKDIR_P) $(dir $(2))
	$(call run-cmd,$(1),$(notdir $(2)),$(3))
endef
cc-pic-cmd = $(call run-cc,CC-PIC,$(1),$(2))
cc-cmd = $(call run-cc,CC,$(1),$(2))
dep-cmd = $(call run-cc,DEP,$(1),$(2))
ccld-cmd = $(call run-cc,CCLD,$(1),$(2))
Philippe Gerum's avatar
Philippe Gerum committed
98
cxxld-cmd = $(call run-cc,CXXLD,$(1),$(2))
Philippe Gerum's avatar
Philippe Gerum committed
99
100
ld-cmd = $(call run-cmd,LD,$(notdir $(1)),$(2))
ar-cmd = $(call run-cmd,AR,$(notdir $(1)),$(2) $(if $(Q),2>/dev/null))
101
inst-cmd = $(call run-cmd,INST,$(notdir $(1)),$(2))
Philippe Gerum's avatar
Philippe Gerum committed
102

103
MAIN_GOALS := all clean clobber mrproper install install_all
104

105
106
107
108
109
_all:

# Default target when no goal was given on the command line
_all: all

110
111
112
$(TARGETS):
	$(Q)$(MAKE) -C $@ O=$(O_DIR)/$@ V=$(V)

Philippe Gerum's avatar
Philippe Gerum committed
113
114
$(O_DIR)/%.d: %.c
	$(call dep-cmd,$@,@$(CC) -MM $(CFLAGS) $< | sed 's$(comma)\($*\)\.o[ :]*$(comma)$(O_DIR)/\1.o $@: $(comma)g' > $@ || rm -f $@)
115

116
117
118
$(O_DIR)/%.d: %.cc
	$(call dep-cmd,$@,@$(CXX) -MM $(CXXFLAGS) $< | sed 's$(comma)\($*\)\.o[ :]*$(comma)$(O_DIR)/\1.o $@: $(comma)g' > $@ || rm -f $@)

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
define MAKEFLY =
# Automatically generated: do not edit

MAKEARGS := O=$(O_DIR) -C $(CURDIR) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) UAPI=$(UAPI) DESTDIR=$(DESTDIR)

$$(filter-out sub-make, $$(MAKECMDGOALS)): sub-make
	@:

sub-make:
	$$(MAKE) $$(MAKEARGS) $$(MAKECMDGOALS)
endef

# CURDIR is the source directory
export MAKEFLY
output-Makefile:
ifneq ($(O_DIR), $(CURDIR))
	@if test \! -e $(O_DIR)/Makefile || grep -q Automatically $(O_DIR)/Makefile; then \
		echo "$$MAKEFLY" > $(O_DIR)/Makefile; \
	fi
endif

140
141
142
FORCE:

.PHONY: _all $(MAIN_GOALS) output-Makefile FORCE