exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

mustach-original-Makefile (9178B)


      1 # version
      2 MAJOR := 1
      3 MINOR := 2
      4 REVIS := 10
      5 
      6 # Mustache spec
      7 VSPEC := v1.4.1
      8 
      9 # installation settings
     10 DESTDIR ?=
     11 PREFIX  ?= /usr/local
     12 BINDIR  ?= $(PREFIX)/bin
     13 LIBDIR  ?= $(PREFIX)/lib
     14 INCLUDEDIR ?= $(PREFIX)/include
     15 MANDIR  ?= $(PREFIX)/share/man
     16 PKGDIR  ?= $(LIBDIR)/pkgconfig
     17 
     18 # Tools (sed must be GNU sed)
     19 SED ?= sed
     20 INSTALL ?= install
     21 
     22 # initial settings
     23 VERSION := $(MAJOR).$(MINOR).$(REVIS)
     24 SOVER := .$(MAJOR)
     25 SOVEREV := .$(MAJOR).$(MINOR)
     26 
     27 HEADERS := mustach.h mustach-wrap.h
     28 SPLITLIB := libmustach-core.so$(SOVEREV)
     29 SPLITPC := libmustach-core.pc
     30 COREOBJS := mustach.o mustach-wrap.o
     31 SINGLEOBJS := $(COREOBJS)
     32 SINGLEFLAGS :=
     33 SINGLELIBS :=
     34 TESTSPECS :=
     35 ALL := manuals
     36 
     37 # availability of CJSON
     38 ifneq ($(cjson),no)
     39  cjson_cflags := $(shell pkg-config --silence-errors --cflags libcjson)
     40  cjson_libs := $(shell pkg-config --silence-errors --libs libcjson)
     41  ifdef cjson_libs
     42   cjson := yes
     43   tool ?= cjson
     44   HEADERS += mustach-cjson.h
     45   SPLITLIB += libmustach-cjson.so$(SOVEREV)
     46   SPLITPC += libmustach-cjson.pc
     47   SINGLEOBJS += mustach-cjson.o
     48   SINGLEFLAGS += ${cjson_cflags}
     49   SINGLELIBS += ${cjson_libs}
     50   TESTSPECS += test-specs/test-specs-cjson
     51  else
     52   ifeq ($(cjson),yes)
     53    $(error Can't find required library cjson)
     54   endif
     55   cjson := no
     56  endif
     57 endif
     58 
     59 # availability of JSON-C
     60 ifneq ($(jsonc),no)
     61  jsonc_cflags := $(shell pkg-config --silence-errors --cflags json-c)
     62  jsonc_libs := $(shell pkg-config --silence-errors --libs json-c)
     63  ifdef jsonc_libs
     64   jsonc := yes
     65   tool ?= jsonc
     66   HEADERS += mustach-json-c.h
     67   SPLITLIB += libmustach-json-c.so$(SOVEREV)
     68   SPLITPC += libmustach-json-c.pc
     69   SINGLEOBJS += mustach-json-c.o
     70   SINGLEFLAGS += ${jsonc_cflags}
     71   SINGLELIBS += ${jsonc_libs}
     72   TESTSPECS += test-specs/test-specs-json-c
     73  else
     74   ifeq ($(jsonc),yes)
     75    $(error Can't find required library json-c)
     76   endif
     77   jsonc := no
     78  endif
     79 endif
     80 
     81 # availability of JANSSON
     82 ifneq ($(jansson),no)
     83  jansson_cflags := $(shell pkg-config --silence-errors --cflags jansson)
     84  jansson_libs := $(shell pkg-config --silence-errors --libs jansson)
     85  ifdef jansson_libs
     86   jansson := yes
     87   tool ?= jansson
     88   HEADERS += mustach-jansson.h
     89   SPLITLIB += libmustach-jansson.so$(SOVEREV)
     90   SPLITPC += libmustach-jansson.pc
     91   SINGLEOBJS += mustach-jansson.o
     92   SINGLEFLAGS += ${jansson_cflags}
     93   SINGLELIBS += ${jansson_libs}
     94   TESTSPECS += test-specs/test-specs-jansson
     95  else
     96   ifeq ($(jansson),yes)
     97    $(error Can't find required library jansson)
     98   endif
     99   jansson := no
    100  endif
    101 endif
    102 
    103 # tool
    104 TOOLOBJS = mustach-tool.o $(COREOBJS)
    105 tool ?= none
    106 ifneq ($(tool),none)
    107   ifeq ($(tool),cjson)
    108     TOOLOBJS += mustach-cjson.o
    109     TOOLFLAGS := ${cjson_cflags} -DTOOL=MUSTACH_TOOL_CJSON
    110     TOOLLIBS := ${cjson_libs}
    111     TOOLDEP := mustach-cjson.h
    112   else ifeq ($(tool),jsonc)
    113     TOOLOBJS += mustach-json-c.o
    114     TOOLFLAGS := ${jsonc_cflags} -DTOOL=MUSTACH_TOOL_JSON_C
    115     TOOLLIBS := ${jsonc_libs}
    116     TOOLDEP := mustach-json-c.h
    117   else ifeq ($(tool),jansson)
    118     TOOLOBJS += mustach-jansson.o
    119     TOOLFLAGS := ${jansson_cflags} -DTOOL=MUSTACH_TOOL_JANSSON
    120     TOOLLIBS := ${jansson_libs}
    121     TOOLDEP := mustach-jansson.h
    122   else
    123    $(error Unknown library $(tool) for tool)
    124   endif
    125   ifneq ($($(tool)),yes)
    126     $(error No library found for tool $(tool))
    127   endif
    128   ALL += mustach
    129 endif
    130 
    131 # compute targets
    132 libs ?= all
    133 ifeq (${libs},split)
    134  ALL += ${SPLITLIB} ${SPLITPC}
    135 else ifeq (${libs},single)
    136  ALL += libmustach.so$(SOVEREV) libmustach.pc
    137 else ifeq (${libs},all)
    138  ALL += libmustach.so$(SOVEREV) libmustach.pc ${SPLITLIB} ${SPLITPC}
    139 else ifneq (${libs},none)
    140  $(error Unknown libs $(libs))
    141 endif
    142 
    143 # display target
    144 $(info tool    = ${tool})
    145 $(info libs    = ${libs})
    146 $(info jsonc   = ${jsonc})
    147 $(info jansson = ${jansson})
    148 $(info cjson   = ${cjson})
    149 
    150 # settings
    151 
    152 EFLAGS = -fPIC -Wall -Wextra -DVERSION=${VERSION}
    153 
    154 ifeq ($(shell uname),Darwin)
    155  LDFLAGS_single  += -install_name $(LIBDIR)/libmustach.so$(SOVEREV)
    156  LDFLAGS_core    += -install_name $(LIBDIR)/libmustach-core.so$(SOVEREV)
    157  LDFLAGS_cjson   += -install_name $(LIBDIR)/libmustach-cjson.so$(SOVEREV)
    158  LDFLAGS_jsonc   += -install_name $(LIBDIR)/libmustach-json-c.so$(SOVEREV)
    159  LDFLAGS_jansson += -install_name $(LIBDIR)/libmustach-jansson.so$(SOVEREV)
    160 else
    161  LDFLAGS_single  += -Wl,-soname,libmustach.so$(SOVER)
    162  LDFLAGS_core    += -Wl,-soname,libmustach-core.so$(SOVER)
    163  LDFLAGS_cjson   += -Wl,-soname,libmustach-cjson.so$(SOVER)
    164  LDFLAGS_jsonc   += -Wl,-soname,libmustach-json-c.so$(SOVER)
    165  LDFLAGS_jansson += -Wl,-soname,libmustach-jansson.so$(SOVER)
    166 endif
    167 
    168 # targets
    169 
    170 .PHONY: all
    171 all: ${ALL}
    172 
    173 mustach: $(TOOLOBJS)
    174 	$(CC) $(LDFLAGS) $(TOOLFLAGS) -o mustach $(TOOLOBJS) $(TOOLLIBS)
    175 
    176 libmustach.so$(SOVEREV): $(SINGLEOBJS)
    177 	$(CC) -shared $(LDFLAGS) $(LDFLAGS_single) -o $@ $^ $(SINGLELIBS)
    178 
    179 libmustach-core.so$(SOVEREV): $(COREOBJS)
    180 	$(CC) -shared $(LDFLAGS) $(LDFLAGS_core) -o $@ $(COREOBJS) $(lib_OBJ)
    181 
    182 libmustach-cjson.so$(SOVEREV): $(COREOBJS) mustach-cjson.o
    183 	$(CC) -shared $(LDFLAGS) $(LDFLAGS_cjson) -o $@ $^ $(cjson_libs)
    184 
    185 libmustach-json-c.so$(SOVEREV): $(COREOBJS) mustach-json-c.o
    186 	$(CC) -shared $(LDFLAGS) $(LDFLAGS_jsonc) -o $@ $^ $(jsonc_libs)
    187 
    188 libmustach-jansson.so$(SOVEREV): $(COREOBJS) mustach-jansson.o
    189 	$(CC) -shared $(LDFLAGS) $(LDFLAGS_jansson) -o $@ $^ $(jansson_libs)
    190 
    191 # pkgconfigs
    192 
    193 %.pc: pkgcfgs
    194 	$(SED) -E '/^==.*==$$/{h;d};x;/==$@==/{x;s/VERSION/$(VERSION)/;p;d};x;d' $< > $@
    195 
    196 # objects
    197 
    198 mustach.o: mustach.c mustach.h
    199 	$(CC) -c $(EFLAGS) $(CFLAGS) -o $@ $<
    200 
    201 mustach-wrap.o: mustach-wrap.c mustach.h mustach-wrap.h
    202 	$(CC) -c $(EFLAGS) $(CFLAGS) -o $@ $<
    203 
    204 mustach-tool.o: mustach-tool.c mustach.h mustach-json-c.h $(TOOLDEP)
    205 	$(CC) -c $(EFLAGS) $(CFLAGS) $(TOOLFLAGS) -o $@ $<
    206 
    207 mustach-cjson.o: mustach-cjson.c mustach.h mustach-wrap.h mustach-cjson.h
    208 	$(CC) -c $(EFLAGS) $(CFLAGS) $(cjson_cflags) -o $@ $<
    209 
    210 mustach-json-c.o: mustach-json-c.c mustach.h mustach-wrap.h mustach-json-c.h
    211 	$(CC) -c $(EFLAGS) $(CFLAGS) $(jsonc_cflags) -o $@ $<
    212 
    213 mustach-jansson.o: mustach-jansson.c mustach.h mustach-wrap.h mustach-jansson.h
    214 	$(CC) -c $(EFLAGS) $(CFLAGS) $(jansson_cflags) -o $@ $<
    215 
    216 # installing
    217 .PHONY: install
    218 install: all
    219 	$(INSTALL) -d $(DESTDIR)$(BINDIR)
    220 	if test "${tool}" != "none"; then \
    221 		$(INSTALL) -m0755 mustach $(DESTDIR)$(BINDIR)/; \
    222 	fi
    223 	$(INSTALL) -d $(DESTDIR)$(INCLUDEDIR)/mustach
    224 	$(INSTALL) -m0644 $(HEADERS)    $(DESTDIR)$(INCLUDEDIR)/mustach
    225 	$(INSTALL) -d $(DESTDIR)$(LIBDIR)
    226 	for x in libmustach*.so$(SOVEREV); do \
    227 		$(INSTALL) -m0755 $$x $(DESTDIR)$(LIBDIR)/ ;\
    228 		ln -sf $$x $(DESTDIR)$(LIBDIR)/$${x%.so.*}.so$(SOVER) ;\
    229 		ln -sf $$x $(DESTDIR)$(LIBDIR)/$${x%.so.*}.so ;\
    230 	done
    231 	$(INSTALL) -d $(DESTDIR)/$(PKGDIR)
    232 	$(INSTALL) -m0644 libmustach*.pc $(DESTDIR)/$(PKGDIR)
    233 	$(INSTALL) -d $(DESTDIR)/$(MANDIR)/man1
    234 	$(INSTALL) -m0644 mustach.1.gz $(DESTDIR)/$(MANDIR)/man1
    235 
    236 # deinstalling
    237 .PHONY: uninstall
    238 uninstall:
    239 	rm -f $(DESTDIR)$(BINDIR)/mustach
    240 	rm -f $(DESTDIR)$(LIBDIR)/libmustach*.so*
    241 	rm -rf $(DESTDIR)$(INCLUDEDIR)/mustach
    242 
    243 # testing
    244 ifeq ($(valgrind),no)
    245  NOVALGRIND := 1
    246 else ifeq ($(valgrind),yes)
    247  VALGRIND := 1
    248 endif
    249 export NOVALGRIND
    250 export VALGRIND
    251 
    252 .PHONY: test test-basic test-specs
    253 test: basic-tests spec-tests
    254 
    255 basic-tests: mustach
    256 	@$(MAKE) -C test1 test
    257 	@$(MAKE) -C test2 test
    258 	@$(MAKE) -C test3 test
    259 	@$(MAKE) -C test4 test
    260 	@$(MAKE) -C test5 test
    261 	@$(MAKE) -C test6 test
    262 	@$(MAKE) -C test7 test
    263 	@$(MAKE) -C test8 test
    264 
    265 spec-tests: $(TESTSPECS)
    266 
    267 test-specs/test-specs-%: test-specs/%-test-specs test-specs/specs
    268 	./$< test-specs/spec/specs/[a-z]*.json > $@.last || true
    269 	diff $@.ref $@.last
    270 
    271 test-specs/cjson-test-specs.o: test-specs/test-specs.c mustach.h mustach-wrap.h mustach-cjson.h
    272 	$(CC) -I. -c $(EFLAGS) $(CFLAGS) $(cjson_cflags) -DTEST=TEST_CJSON -o $@ $<
    273 
    274 test-specs/cjson-test-specs: test-specs/cjson-test-specs.o mustach-cjson.o $(COREOBJS)
    275 	$(CC) $(LDFLAGS) -o $@ $^ $(cjson_libs)
    276 
    277 test-specs/json-c-test-specs.o: test-specs/test-specs.c mustach.h mustach-wrap.h mustach-json-c.h
    278 	$(CC) -I. -c $(EFLAGS) $(CFLAGS) $(jsonc_cflags) -DTEST=TEST_JSON_C -o $@ $<
    279 
    280 test-specs/json-c-test-specs: test-specs/json-c-test-specs.o mustach-json-c.o $(COREOBJS)
    281 	$(CC) $(LDFLAGS) -o $@ $^ $(jsonc_libs)
    282 
    283 test-specs/jansson-test-specs.o: test-specs/test-specs.c mustach.h mustach-wrap.h mustach-jansson.h
    284 	$(CC) -I. -c $(EFLAGS) $(CFLAGS) $(jansson_cflags) -DTEST=TEST_JANSSON -o $@ $<
    285 
    286 test-specs/jansson-test-specs: test-specs/jansson-test-specs.o mustach-jansson.o $(COREOBJS)
    287 	$(CC) $(LDFLAGS) -o $@ $^ $(jansson_libs)
    288 
    289 .PHONY: test-specs/specs
    290 test-specs/specs:
    291 	if ! test -d test-specs/spec; then \
    292 		git -C test-specs clone https://github.com/mustache/spec.git; \
    293 	fi
    294 	git -C test-specs/spec checkout $(VSPEC) -B test;
    295 
    296 #cleaning
    297 .PHONY: clean
    298 clean:
    299 	rm -f mustach libmustach*.so* *.o *.pc
    300 	rm -f test-specs/*-test-specs test-specs/test-specs-*.last
    301 	rm -rf *.gcno *.gcda coverage.info gcov-latest
    302 	@$(MAKE) -C test1 clean
    303 	@$(MAKE) -C test2 clean
    304 	@$(MAKE) -C test3 clean
    305 	@$(MAKE) -C test4 clean
    306 	@$(MAKE) -C test5 clean
    307 	@$(MAKE) -C test6 clean
    308 	@$(MAKE) -C test7 clean
    309 	@$(MAKE) -C test8 clean
    310 
    311 # manpage
    312 .PHONY: manuals
    313 manuals: mustach.1.gz
    314 
    315 mustach.1.gz: mustach.1.scd
    316 	if which scdoc >/dev/null 2>&1; then scdoc < mustach.1.scd | gzip > mustach.1.gz; fi