xref: /freebsd/contrib/libucl/Makefile.unix (revision 2e3f49888ec8851bafb22011533217487764fdb0)
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 -I./klib
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)/mum.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
35all: $(OBJDIR) $(OBJDIR)/$(SONAME)
36
37$(OBJDIR)/$(SONAME): $(OBJDIR)/$(SONAME_FULL)
38	$(LN) -sf $(SONAME_FULL) $(OBJDIR)/$(SONAME)
39
40$(OBJDIR)/$(SONAME_FULL): $(OBJECTS)
41	$(CC) -o $(OBJDIR)/$(SONAME_FULL) $(OBJECTS) $(LD_SHARED_FLAGS) $(LDFLAGS) $(SSL_LIBS) $(FETCH_LIBS)
42
43$(OBJDIR):
44	@$(MKDIR) -p $(OBJDIR)
45
46# Compile rules
47$(OBJDIR)/ucl_util.o: $(SRCDIR)/ucl_util.c $(HDEPS)
48	$(CC) -o $(OBJDIR)/ucl_util.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_util.c
49$(OBJDIR)/ucl_parser.o: $(SRCDIR)/ucl_parser.c $(HDEPS)
50	$(CC) -o $(OBJDIR)/ucl_parser.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_parser.c
51$(OBJDIR)/ucl_emitter.o: $(SRCDIR)/ucl_emitter.c $(HDEPS)
52	$(CC) -o $(OBJDIR)/ucl_emitter.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_emitter.c
53$(OBJDIR)/ucl_hash.o: $(SRCDIR)/ucl_hash.c $(HDEPS)
54	$(CC) -o $(OBJDIR)/ucl_hash.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_hash.c
55$(OBJDIR)/ucl_schema.o: $(SRCDIR)/ucl_schema.c $(HDEPS)
56	$(CC) -o $(OBJDIR)/ucl_schema.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_schema.c
57
58clean:
59	$(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
60	$(RMDIR) $(OBJDIR)
61
62# Utils
63
64chargen: utils/chargen.c $(OBJDIR)/$(SONAME)
65	$(CC) -o $(OBJDIR)/chargen $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) utils/chargen.c
66objdump: utils/objdump.c $(OBJDIR)/$(SONAME)
67	$(CC) -o $(OBJDIR)/objdump $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) utils/objdump.c $(LD_UCL_FLAGS)
68
69# Tests
70
71test: $(OBJDIR) $(OBJDIR)/$(SONAME) $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/test_generate $(OBJDIR)/test_schema
72
73run-test: test
74	TEST_DIR=$(TESTDIR) $(TESTDIR)/run_tests.sh $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/test_generate $(OBJDIR)/test_schema
75
76$(OBJDIR)/test_basic: $(TESTDIR)/test_basic.c $(OBJDIR)/$(SONAME)
77	$(CC) -o $(OBJDIR)/test_basic $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_basic.c $(LD_UCL_FLAGS)
78$(OBJDIR)/test_schema: $(TESTDIR)/test_schema.c $(OBJDIR)/$(SONAME)
79	$(CC) -o $(OBJDIR)/test_schema $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_schema.c $(LD_UCL_FLAGS)
80$(OBJDIR)/test_speed: $(TESTDIR)/test_speed.c $(OBJDIR)/$(SONAME)
81	$(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)
82$(OBJDIR)/test_generate: $(TESTDIR)/test_generate.c $(OBJDIR)/$(SONAME)
83	$(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)
84
85install: $(OBJDIR)/$(SONAME)
86	$(INSTALL) -m0755 $(SONAME) $(DESTDIR)/lib/$(SONAME)
87	$(INSTALL) -m0644 include/ucl.h $(DESTDIR)/include/ucl.h
88
89.PHONY: clean $(OBJDIR)
90