Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
167 lines (137 loc) · 5.38 KB
/
Copy pathMakefile
File metadata and controls
167 lines (137 loc) · 5.38 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
# Compiler and flags
CC ?= gcc
CFLAGS = -W -Wall -finline-functions -fPIC -std=gnu99 -Wno-unused-result -O3
CLIB = -lpthread -lz -lm
CF_OPTIMIZE = 1
SRC_DIR = src
INCLUDE = include
OS := $(shell uname)
ifeq ($(OS), Darwin)
CFLAGS += -Wno-unused-function
else
CLIB += -lrt
endif
# Program name
PROG = yame
# Static library for downstream linkers (e.g. MethScope2): all objects except
# the CLI dispatcher (src/main.o), which carries the lone int main().
LIB = libyame.a
# HTSlib
LHTSLIB_DIR = htslib
LHTSLIB = $(LHTSLIB_DIR)/libhts.a
SOURCES := $(wildcard $(SRC_DIR)/*.c)
OBJECTS := $(SOURCES:$(SRC_DIR)/%.c=$(SRC_DIR)/%.o)
CFLAGS += -I$(SRC_DIR) -I$(LHTSLIB_DIR)
# libcurl, for `yame fetch` and the shared asset store (src/assets.c).
#
# A DEPENDENCY, not a bonus. It used to be detected and silently dropped, so a
# build environment without it produced a yame that looked complete and told
# nobody: `yame fetch` -- and with it the catalogue browser, `summary -b`, and
# resolving -R / -m against the store -- reported itself unavailable at run
# time, on a binary already shipped. A packager cannot notice what the build
# never mentioned, so a missing libcurl now stops the build and says what to
# do about it.
#
# Building without it stays possible, but only on purpose:
#
# make CURL=0 no libcurl; fetching is compiled out
# make CURL=/path/to/curl-config a specific one, if it is not on PATH
# make CURL_LIBS="$(curl-config --libs)" CURL_CFLAGS="$(curl-config --cflags)"
# spell it out, for a cross build where the
# host's curl-config cannot be run
#
# libyame.a carries objects only, so a downstream link must still add -lcurl
# itself -- kycg and sesame-cli already do.
CURL ?= auto
ifeq ($(CURL),auto)
CURL_CFLAGS := $(shell curl-config --cflags 2>/dev/null)
CURL_LIBS := $(shell curl-config --libs 2>/dev/null)
else ifeq ($(CURL),0)
CURL_CFLAGS :=
CURL_LIBS :=
else
CURL_CFLAGS := $(shell $(CURL) --cflags 2>/dev/null)
CURL_LIBS := $(shell $(CURL) --libs 2>/dev/null)
endif
ifneq ($(CURL_LIBS),)
CFLAGS += -DYAME_HAVE_CURL $(CURL_CFLAGS)
CLIB += $(CURL_LIBS)
else ifneq ($(CURL),0)
# Not while merely tidying up: `make clean` must work anywhere.
ifeq ($(filter clean,$(MAKECMDGOALS)),)
$(error libcurl not found: no curl-config on PATH. \
yame fetch needs it. Install libcurl development files (conda: add \
`libcurl` to the recipe host deps; Debian: libcurl4-openssl-dev; \
RHEL: libcurl-devel), or point at one with `make CURL=/path/to/curl-config`, \
or build deliberately without fetching using `make CURL=0`)
endif
endif
.PHONY: all build debug clean lib test docs docs-check
all: build
## Command-level tests against the built binary. Self-contained: every test
## packs its own fixtures from inline text, so this needs no network and no
## data store, and conda-recipe/build.sh runs it on every platform it builds.
test: $(PROG)
bash test/run.sh
# docs/index.html's Catalogue and Reference tabs are generated: the first
# from tools/registry/files.tsv, the second from every command's -h in THIS
# binary (docs/build_docs.py). `make docs` writes them; `make docs-check`
# fails when the page is behind either source.
docs: $(PROG)
@python3 docs/build_docs.py
docs-check: $(PROG)
@python3 docs/build_docs.py --check
build: exportcf $(PROG) yame-config
# Build just the static library (used by MethScope2).
lib: exportcf $(LIB) yame-config
# What a downstream tool should compile and link against. Generated so the
# answer reflects this build -- in particular whether libcurl was found and
# which one -- instead of each consumer hardcoding its own guess.
yame-config: yame-config.in Makefile src/yame_version.h
@sed -e 's|@PREFIX@|$(CURDIR)|g' \
-e 's|@VERSION@|$(shell sed -n 's/.*YAME_VERSION "\(.*\)".*/\1/p' src/yame_version.h)|g' \
-e 's|@CURL_CFLAGS@|$(CURL_CFLAGS)|g' \
-e 's|@CURL_LIBS@|$(CURL_LIBS)|g' \
-e 's|@CLIB@|$(CLIB)|g' \
yame-config.in > $@
@chmod +x $@
exportcf:
$(eval export CF_OPTIMIZE)
debug: CF_OPTIMIZE := 0
debug: CFLAGS += -g
debug: CFLAGS := $(filter-out -O3,$(CFLAGS))
debug: build
#####################
##### libraries #####
#####################
$(LHTSLIB) :
$(MAKE) -C $(LHTSLIB_DIR) libhts.a
###################
### compilation ###
###################
# Compile each .c in src/ into a .o in src/.
#
# -MMD -MP writes a .d beside each .o listing the headers that .c actually
# included; the -include below feeds those back to make. Without it a header
# change rebuilt nothing, so editing yame_version.h and running make produced
# a binary still reporting the previous version, and regenerating registry.h
# produced one still carrying the previous catalogue -- both silent, because
# the .c files were untouched and make had no reason to think otherwise.
$(SRC_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) -c $(CFLAGS) -MMD -MP $< -o $@
-include $(wildcard $(SRC_DIR)/*.d)
###################
### linking ####
###################
$(PROG): $(LHTSLIB) $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LHTSLIB) $(CLIB)
# Archive every object except the CLI entry point (main.o has int main()).
LIBOBJECTS = $(filter-out $(SRC_DIR)/main.o, $(OBJECTS))
$(LIB): $(LHTSLIB) $(LIBOBJECTS)
ar rcs $@ $(LIBOBJECTS)
###################
### clean ####
###################
clean :
rm -f $(SRC_DIR)/*.o $(PROG) $(LIB)
$(MAKE) -C $(LHTSLIB_DIR) clean