-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
169 lines (135 loc) · 4.59 KB
/
makefile
File metadata and controls
169 lines (135 loc) · 4.59 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
# Copyright 2024 v66v
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SRC_DIR ?= src
TYPE ?= release
BUILDDIRBASE := build/
BUILDDIR := $(BUILDDIRBASE)$(TYPE)
DESTDIR ?= $(CURDIR)/$(BUILDDIR)
export DESTDIR
INC_DIRS = $(SRC_DIR)/
INCS := $(addprefix -I,$(INC_DIRS))
NOTPATH := -not -path "$(SRC_DIR)/extra/*"
SRC_FILES := $(shell find $(SRC_DIR)/ $(NOTPATH) -name "*.c")
ifdef EXTRAS
export EXTRAS
HDR_FILES := $(shell find $(SRC_DIR)/ -name "*.h")
else
HDR_FILES := $(shell find $(SRC_DIR)/ $(NOTPATH) -name "*.h")
endif
HDR_DIR := $(BUILDDIR)/include/std
HDRS := $(HDR_FILES:$(SRC_DIR)/%=$(HDR_DIR)/%)
OBJS_DIR = $(BUILDDIR)/objects
OBJS := $(SRC_FILES:$(SRC_DIR)/%.c=$(OBJS_DIR)/%.lo)
ifdef EXTRAS
FONTCONFIG_SRC_FILES := $(shell find $(SRC_DIR)/extra/fontconfig -name "*.c")
FONTCONFIG_OBJS := $(FONTCONFIG_SRC_FILES:$(SRC_DIR)/%.c=$(OBJS_DIR)/%.lo)
else
FONTCONFIG_SRC_FILES :=
FONTCONFIG_OBJS :=
endif
DEPS := $(OBJS:.lo=.d) $(FONTCONFIG_OBJS:.lo=.d)
-include $(DEPS)
FONTCONFIG_CFLAGS := $(shell pkg-config --cflags fontconfig)
PKGCONFIGS_CFLAGS :=
PKGCONFIGS_LIBS :=
ifneq ($(PKGCONFIGS_CFLAGS),)
PKGCONFIG_CFLAGS = $(shell pkg-config --cflags $(PKGCONFIGS_CFLAGS))
endif
ifneq ($(PKGCONFIGS_LIBS),)
PKGCONFIG_LIBS = $(shell pkg-config --libs $(PKGCONFIGS_LIBS))
endif
LIB_NAMES :=
LIBS := $(addprefix -l,$(LIB_NAMES))
LIBS += $(PKGCONFIG_LIBS)
CFLAGS = -MMD -MP -std=gnu11
CFLAGS += $(PKGCONFIG_CFLAGS)
ifeq ($(TYPE), debug)
CFLAGS += -O2 -DDEBUG -ggdb -Wall -Wextra -Wswitch-enum -Wswitch-default
else
CFLAGS += -O3
endif
CC := gcc
LIBTOOL := libtool
LIBTOOLFLAGS := --silent
LIBTOOL_TYPE := # -static or -shared
LIBTOOL_CFLAGS := -version-info 1:1:0
LIB_NAME := std
TARGET_LIBS := libstd
ifdef EXTRAS
TARGET_LIBS += extra/libstd-fontconfig
endif
LIBNS := $(TARGET_LIBS:%=$(BUILDDIR)/lib/%.la)
.DEFAULT_GOAL := all
all: build
build: build_info dirs hdrs $(LIBNS) makefile
check:
@$(MAKE) -sC tests
hdrs: $(HDRS)
$(HDR_DIR)/%.h: $(SRC_DIR)/%.h
@cp $(SRC_DIR)/$*.h $(HDR_DIR)/$*.h
$(BUILDDIR)/lib/libstd.la: $(OBJS)
$(info [CC] Linking object files [libstd])
@$(LIBTOOL) $(LIBTOOLFLAGS) --tag=CC --mode=link $(CC) $(LIBTOOL_TYPE) \
$(LIBTOOL_CFLAGS) $(LIBS) -o $(OBJS_DIR)/libstd.la -rpath $(DESTDIR)/lib $^
@$(LIBTOOL) $(LIBTOOLFLAGS) --mode=install install -c \
$(OBJS_DIR)/libstd.la $(DESTDIR)/lib/libstd.la
$(BUILDDIR)/lib/extra/libstd-fontconfig.la: $(FONTCONFIG_OBJS)
$(info [CC] Linking object files [libstd-fontconfig])
@$(LIBTOOL) $(LIBTOOLFLAGS) --tag=CC --mode=link $(CC) $(LIBTOOL_TYPE) \
$(LIBTOOL_CFLAGS) $(FONTCONFIG_CFLAGS) \
-o $(OBJS_DIR)/libstd-fontconfig.la -rpath $(DESTDIR)/lib/extra $^
@$(LIBTOOL) $(LIBTOOLFLAGS) --mode=install install -c \
$(OBJS_DIR)/libstd-fontconfig.la $(DESTDIR)/lib/extra/libstd-fontconfig.la
$(OBJS_DIR)/%.lo: $(SRC_DIR)/%.c makefile
$(info [CC] $<)
@$(LIBTOOL) $(LIBTOOLFLAGS) --tag=CC --mode=compile $(CC) $(CFLAGS) $(INCS) -o $@ -c $<
install: $(DESTDIR)/lib/extra/ install_info build
ifneq ($(BUILDDIR), $(DESTDIR))
@cp -r $(BUILDDIR)/lib/ $(DESTDIR)/
@cp -r $(BUILDDIR)/include/ $(DESTDIR)/
else
$(info [WRN] BUILDDIR($(BUILDDIR)) == DESTDIR($(DESTDIR)))
endif
dirs: $(dir $(LIBNS)) $(dir $(OBJS)) $(dir $(HDRS))
.PRECIOUS: $(BUILDDIR)/. $(BUILDDIR)/%/. $(DESTDIR)/. $(DESTDIR)/%/.
$(BUILDDIR)/:
$(info [INFO] Creating directory [$@])
@mkdir -p $@
$(DESTDIR)/:
$(info [INFO] Creating directory [$@])
@mkdir -p $@
$(DESTDIR)/%/:
$(info [INFO] Creating directory [$@])
@mkdir -p $@
$(BUILDDIR)/%/:
$(info [INFO] Creating directory [$@])
@mkdir -p $@
.PHONY: clean ccls build_info install_info
build_info:
ifeq ($(TYPE), debug)
$(info [INFO] Compiling In Debug Mode [$(BUILDDIR)/lib/$(LIB_NAME)])
else
$(info [INFO] Building library [$(BUILDDIR)/lib/$(LIB_NAME)])
endif
install_info:
$(info [INFO] Installing Library [$(DESTDIR)/lib/$(LIB_NAME)])
clean:
$(info [INFO] Cleaning [$(notdir $(CURDIR))])
@rm -rf $(BUILDDIRBASE)/
@$(MAKE) -sC tests clean
ccls:
$(info [INFO] Creating .ccls file)
@printf "%s\\n" $(CC) $(subst ' ','\n',$(LIBS)) $(CFLAGS) \
$(subst ' ','\n',$(INCS)) $(subst ' ','\n',$(FONTCONFIG_CFLAGS)) \
-I$(subst :, -I,$(C_INCLUDE_PATH)) > .ccls