xref: /freebsd/contrib/libucl/Makefile.unix (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1CC ?= gcc
2DESTDIR ?= /usr/local
3LD ?= gcc
4C_COMMON_FLAGS ?= -fPIC -Wall -W -Wno-unused-parameter -Wno-pointer-sign -I./include -I./uthash -I./src
5MAJOR_VERSION = 0
6MINOR_VERSION = 2
7PATCH_VERSION = 9
8VERSION = "$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)"
9SONAME = libucl.so
10SONAME_FULL = $(SONAME).$(MAJOR_VERSION)
11OBJDIR ?= .obj
12TESTDIR ?= tests
13SRCDIR ?= src
14INCLUDEDIR ?= include
15MKDIR ?= mkdir
16INSTALL ?= install
17RM ?= rm
18RMDIR ?= rmdir
19LN ?= ln
20LD_SHARED_FLAGS ?= -Wl,-soname,$(SONAME) -shared -lm
21LD_UCL_FLAGS ?= -L$(OBJDIR) -Wl,-rpath,$(OBJDIR) -lucl
22LD_ADD ?= -lrt
23COPT_FLAGS ?= -O2
24HDEPS = $(SRCDIR)/ucl_hash.h \
25		$(SRCDIR)/ucl_chartable.h \
26		$(SRCDIR)/ucl_internal.h \
27		$(INCLUDEDIR)/ucl.h \
28		$(SRCDIR)/xxhash.h
29OBJECTS = $(OBJDIR)/ucl_hash.o \
30		$(OBJDIR)/ucl_util.o \
31		$(OBJDIR)/ucl_parser.o \
32		$(OBJDIR)/ucl_emitter.o \
33		$(OBJDIR)/ucl_schema.o \
34		$(OBJDIR)/xxhash.o
35
36all: $(OBJDIR) $(OBJDIR)/$(SONAME)
37
38$(OBJDIR)/$(SONAME): $(OBJDIR)/$(SONAME_FULL)
39	$(LN) -sf $(SONAME_FULL) $(OBJDIR)/$(SONAME)
40
41$(OBJDIR)/$(SONAME_FULL): $(OBJECTS)
42	$(CC) -o $(OBJDIR)/$(SONAME_FULL) $(OBJECTS) $(LD_SHARED_FLAGS) $(LDFLAGS) $(SSL_LIBS) $(FETCH_LIBS)
43
44$(OBJDIR):
45	@$(MKDIR) -p $(OBJDIR)
46
47# Compile rules
48$(OBJDIR)/ucl_util.o: $(SRCDIR)/ucl_util.c $(HDEPS)
49	$(CC) -o $(OBJDIR)/ucl_util.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_util.c
50$(OBJDIR)/ucl_parser.o: $(SRCDIR)/ucl_parser.c $(HDEPS)
51	$(CC) -o $(OBJDIR)/ucl_parser.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_parser.c
52$(OBJDIR)/ucl_emitter.o: $(SRCDIR)/ucl_emitter.c $(HDEPS)
53	$(CC) -o $(OBJDIR)/ucl_emitter.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_emitter.c
54$(OBJDIR)/ucl_hash.o: $(SRCDIR)/ucl_hash.c $(HDEPS)
55	$(CC) -o $(OBJDIR)/ucl_hash.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_hash.c
56$(OBJDIR)/ucl_schema.o: $(SRCDIR)/ucl_schema.c $(HDEPS)
57	$(CC) -o $(OBJDIR)/ucl_schema.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_schema.c
58$(OBJDIR)/xxhash.o: $(SRCDIR)/xxhash.c $(HDEPS)
59	$(CC) -o $(OBJDIR)/xxhash.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/xxhash.c
60
61clean:
62	$(RM) $(OBJDIR)/*.o $(OBJDIR)/$(SONAME_FULL) $(OBJDIR)/$(SONAME) $(OBJDIR)/chargen $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/objdump $(OBJDIR)/test_generate $(OBJDIR)/test_schema || true
63	$(RMDIR) $(OBJDIR)
64
65# Utils
66
67chargen: utils/chargen.c $(OBJDIR)/$(SONAME)
68	$(CC) -o $(OBJDIR)/chargen $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) utils/chargen.c
69objdump: utils/objdump.c $(OBJDIR)/$(SONAME)
70	$(CC) -o $(OBJDIR)/objdump $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) utils/objdump.c $(LD_UCL_FLAGS)
71
72# Tests
73
74test: $(OBJDIR) $(OBJDIR)/$(SONAME) $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/test_generate $(OBJDIR)/test_schema
75
76run-test: test
77	TEST_DIR=$(TESTDIR) $(TESTDIR)/run_tests.sh $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/test_generate $(OBJDIR)/test_schema
78
79$(OBJDIR)/test_basic: $(TESTDIR)/test_basic.c $(OBJDIR)/$(SONAME)
80	$(CC) -o $(OBJDIR)/test_basic $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_basic.c $(LD_UCL_FLAGS)
81$(OBJDIR)/test_schema: $(TESTDIR)/test_schema.c $(OBJDIR)/$(SONAME)
82	$(CC) -o $(OBJDIR)/test_schema $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_schema.c $(LD_UCL_FLAGS)
83$(OBJDIR)/test_speed: $(TESTDIR)/test_speed.c $(OBJDIR)/$(SONAME)
84	$(CC) -o $(OBJDIR)/test_speed $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_speed.c $(LD_UCL_FLAGS) $(LD_ADD)
85$(OBJDIR)/test_generate: $(TESTDIR)/test_generate.c $(OBJDIR)/$(SONAME)
86	$(CC) -o $(OBJDIR)/test_generate $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_generate.c $(LD_UCL_FLAGS) $(LD_ADD)
87
88install: $(OBJDIR)/$(SONAME)
89	$(INSTALL) -m0755 $(SONAME) $(DESTDIR)/lib/$(SONAME)
90	$(INSTALL) -m0644 include/ucl.h $(DESTDIR)/include/ucl.h
91
92.PHONY: clean $(OBJDIR)
93