summaryrefslogtreecommitdiff
path: root/Makefile.common
blob: 964357a157e5756638328162aeb79b688f3d7869 (plain)
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
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
SERENITY_BASE_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))

CXX_STANDARD_FLAGS = -std=c++2a
CXX_WARNING_FLAGS = -Werror -Wextra -Wall -Wno-nonnull-compare -Wno-deprecated-copy -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-expansion-to-defined
CXX_FLAVOR_FLAGS = -fno-exceptions -fno-rtti -fstack-protector
#CXX_SUGGEST_FLAGS = -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override #-Wsuggest-attribute=noreturn 

C_STANDARD_FLAGS =
C_WARNING_FLAGS = -Werror -Wextra -Wall -Wno-nonnull-compare -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-expansion-to-defined
C_FLAVOR_FLAGS = -fstack-protector

ARCH_FLAGS =
OPTIMIZATION_FLAGS = -Os

INCLUDE_FLAGS += \
    -I. \
    -I$(SERENITY_BASE_DIR)/DevTools \
    -I$(SERENITY_BASE_DIR) \
    -I$(SERENITY_BASE_DIR)/Libraries \
    -I$(SERENITY_BASE_DIR)/Servers

VERBOSE = 0

ifneq ($(USE_HOST_CXX),)
    UNAME_S := $(shell uname -s)
    ifeq ($(UNAME_S),OpenBSD)
        HOST_CXX ?= clang++
    endif

    ifeq '' '$(findstring clang++,$(CXX))'
        C_WARNING_FLAGS += -Wno-unknown-warning-option
        CXX_WARNING_FLAGS += -Wno-unknown-warning-option
    endif
    ifeq ($(HOST_CXX),)
        CXX = $(PRE_CXX) g++
    else
        CXX = $(HOST_CXX)
    endif
    AS = as
    LINK = ld
    OBJ_SUFFIX ?= .host
    ARCH = $(shell arch -s)
else
    TOOLCHAIN_PATH = $(SERENITY_BASE_DIR)/Toolchain/Local/bin
    CXX = $(PRE_CXX) $(TOOLCHAIN_PATH)/i686-pc-serenity-g++
    CC = $(PRE_CC) $(TOOLCHAIN_PATH)/i686-pc-serenity-gcc
    AS = $(TOOLCHAIN_PATH)/i686-pc-serenity-as
    LINK = $(TOOLCHAIN_PATH)/i686-pc-serenity-ld
    RANLIB = $(TOOLCHAIN_PATH)/i686-pc-serenity-ranlib
    AR = $(TOOLCHAIN_PATH)/i686-pc-serenity-ar
    ARCH = i386

    DEFINES += -DDEBUG

    INCLUDE_FLAGS += \
    	-I$(SERENITY_BASE_DIR)/Libraries/LibC \
    	-I$(SERENITY_BASE_DIR)/Libraries/LibM \
    	-I$(SERENITY_BASE_DIR)/Libraries/LibPthread

    ifdef KERNEL
        DEFINES += -DKERNEL
    else ifdef BOOTSTRAPPER
        DEFINES += -DBOOTSTRAPPER
    else
        # everything else gets -lc -lm
        LIB_DEPS := C M $(LIB_DEPS)
    endif

    # turn "LIB_DEPS=C Core Thread" into "-lc -lcore -lthread -L.../LibC ..."
    LDFLAGS += $(foreach lib,$(LIB_DEPS),\
        -l$(shell echo $(lib) | tr A-Z a-z))
    LDFLAGS += $(foreach lib,$(LIB_DEPS),\
        -L$(SERENITY_BASE_DIR)/Libraries/Lib$(lib))

    STATIC_LIB_DEPS = $(foreach lib,$(LIB_DEPS),\
        $(SERENITY_BASE_DIR)/Libraries/Lib$(lib)/lib$(shell echo $(lib) | tr A-Z a-z).a)

    OBJ_SUFFIX ?=
endif

#CXX = clang $(CLANG_FLAGS)
#CLANG_FLAGS = -Wconsumed -m32 -ffreestanding -march=i686

CXXFLAGS = -MMD -MP $(CXX_WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(CXX_FLAVOR_FLAGS) $(ARCH_FLAGS) $(CXX_STANDARD_FLAGS) $(CXX_SUGGEST_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) $(SUBPROJECT_CXXFLAGS)
CFLAGS = -MMD -MP $(C_FLAVOR_FLAGS) $(ARCH_FLAGS) $(C_STANDARD_FLAGS) $(C_SUGGEST_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) $(SUBPROJECT_CXXFLAGS)

DEFINES += -DSANITIZE_PTRS

SUFFIXED_OBJS = $(patsubst %.o,%$(OBJ_SUFFIX).o,$(OBJS))

ifeq ($(VERBOSE),1)
    QUIET =
else
    QUIET = @
endif

-include $(SUFFIXED_OBJS:%.o=%.d)

.SUFFIXES:

%$(OBJ_SUFFIX).o: %.cpp $(EXTRA_SOURCES)
	@echo "$(notdir $(CURDIR)): C++ $@"
	$(QUIET) $(CXX) $(CXXFLAGS) -o $@ -c $<

%$(OBJ_SUFFIX).o: %.c
	@echo "$(notdir $(CURDIR)): C $@"
	$(QUIET) $(CC) $(CFLAGS) -o $@ -c $<

%.ao: %.S
	@echo "$(notdir $(CURDIR)): AS $@"
	$(QUIET) $(AS) -o $@ $<

$(PROGRAM): $(STATIC_LIB_DEPS) $(SUFFIXED_OBJS) $(EXTRA_OBJS)
	@echo "$(notdir $(CURDIR)): LINK $(PROGRAM)"
	$(QUIET) $(CXX) -o $(PROGRAM) $(EXTRA_OBJS) $(SUFFIXED_OBJS) $(LDFLAGS)

$(LIBRARY): $(SUFFIXED_OBJS) $(EXTRA_OBJS)
	@echo "$(notdir $(CURDIR)): LIB $@"
	$(QUIET) $(AR) rcs $@ $(OBJS) $(EXTRA_OBJS) $(LIBS)
	$(POST_LIBRARY_BUILD)

#.PHONY: $(STATIC_LIB_DEPS)
$(STATIC_LIB_DEPS):
	@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

IPCCOMPILER = $(SERENITY_BASE_DIR)/DevTools/IPCCompiler/IPCCompiler
IPCCOMPILER: $(IPCCOMPILER)
$(IPCCOMPILER):
	@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

FORMCOMPILER = $(SERENITY_BASE_DIR)/DevTools/FormCompiler/FormCompiler
FORMCOMPILER: $(FORMCOMPILER)
$(FORMCOMPILER):
	@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

.DEFAULT_GOAL := all

all: $(PROGRAM) $(LIBRARY)

EXTRA_CLEAN ?=

clean:
	@echo "$(notdir $(CURDIR)): CLEAN"
	$(QUIET) rm -f $(PROGRAM) $(LIBRARY) $(SUFFIXED_OBJS) $(EXTRA_OBJS) $(patsubst %.o,%.d,$(SUFFIXED_OBJS) $(EXTRA_OBJS)) $(EXTRA_CLEAN)

install:

.DELETE_ON_ERROR:

.PHONY: all clean install