forked from netsurf-browser/libcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGNUmakefile
More file actions
89 lines (74 loc) · 3.26 KB
/
Copy pathGNUmakefile
File metadata and controls
89 lines (74 loc) · 3.26 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
# Self-contained GNU makefile for libcss.
#
# GNU make prefers GNUmakefile over the upstream netsurf-buildsystem Makefile,
# so plain `make` here builds libcss without that buildsystem. This file is
# deliberately standalone — it touches nothing else in the tree and writes all
# output under build-gnu/ (already covered by the build-* .gitignore) — so the
# commit that adds it can be rebased cleanly onto upstream. `make -f Makefile`
# still drives the original buildsystem.
#
# It builds a static archive: build-gnu/libcss.a
#
# libcss depends on libparserutils and libwapcaplet for headers. They default
# to sibling git checkouts (../libparserutils, ../libwapcaplet) and otherwise
# fall back to pkg-config. Override explicitly with:
# make PARSERUTILS=/path/to/libparserutils WAPCAPLET=/path/to/libwapcaplet
CC ?= cc
AR ?= ar
BUILDDIR := build-gnu
LIB := $(BUILDDIR)/libcss.a
all: $(LIB)
# --- Dependency headers ------------------------------------------------------
PARSERUTILS ?= $(wildcard ../libparserutils)
WAPCAPLET ?= $(wildcard ../libwapcaplet)
DEP_CFLAGS :=
ifneq ($(PARSERUTILS),)
DEP_CFLAGS += -I$(PARSERUTILS)/include
else
DEP_CFLAGS += $(shell pkg-config --cflags libparserutils 2>/dev/null)
endif
ifneq ($(WAPCAPLET),)
DEP_CFLAGS += -I$(WAPCAPLET)/include
else
DEP_CFLAGS += $(shell pkg-config --cflags libwapcaplet 2>/dev/null)
endif
# _ALIGNED / STMTEXPR are the struct-attribute macros the netsurf buildsystem
# supplies (see buildsystem/makefiles/Makefile.gcc); the sources expect them.
CFLAGS := -std=c99 -O2 -g \
-D_BSD_SOURCE -D_DEFAULT_SOURCE \
-D_ALIGNED="__attribute__((aligned))" -DSTMTEXPR=1 \
-Iinclude -Isrc $(DEP_CFLAGS)
# --- Ordinary sources --------------------------------------------------------
# Everything under src/ except the parser-generator tool (it has its own
# main()) and any in-tree autogenerated_*.c (we generate our own copies below).
SRCS := $(shell find src -name '*.c' \
! -name 'css_property_parser_gen.c' ! -name 'autogenerated_*.c')
OBJS := $(patsubst src/%.c,$(BUILDDIR)/%.o,$(SRCS))
# --- Generated longhand property parsers -------------------------------------
# css_property_parser_gen.c is a build-time tool that emits one
# autogenerated_<prop>.c per property listed in properties.gen.
PROPGEN := src/parse/properties/properties.gen
AUTOPROPS := $(shell perl -ne 'next if /^\#/; print "$$1 " if /^([^:]+):/' $(PROPGEN))
AUTOOBJS := $(patsubst %,$(BUILDDIR)/gen/autogenerated_%.o,$(AUTOPROPS))
OBJS += $(AUTOOBJS)
$(LIB): $(OBJS)
@mkdir -p $(dir $@)
$(AR) cr $@ $^
$(BUILDDIR)/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -MMD -MP -MF $(@:.o=.d) -c -o $@ $<
$(BUILDDIR)/gen_parser: src/parse/properties/css_property_parser_gen.c
@mkdir -p $(dir $@)
$(CC) -O2 -o $@ $<
.SECONDARY: $(AUTOOBJS:.o=.c)
$(BUILDDIR)/gen/autogenerated_%.c: $(PROPGEN) $(BUILDDIR)/gen_parser
@mkdir -p $(dir $@)
$(BUILDDIR)/gen_parser -o $@ "$$(grep '^$*:' $(PROPGEN))"
$(BUILDDIR)/gen/%.o: $(BUILDDIR)/gen/%.c
$(CC) $(CFLAGS) -MMD -MP -MF $(@:.o=.d) -c -o $@ $<
clean:
rm -rf $(BUILDDIR)
.PHONY: all clean
# Include only dep files that already exist, so make never tries to *build* a
# .d (which would misfire the autogenerated_%.c pattern into phantom targets).
-include $(shell find $(BUILDDIR) -name '*.d' 2>/dev/null)