Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 85 lines (64 sloc) 2.158 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
AR = ar
CC = gcc
CFLAGS ?= -Wall -Os -fPIC
LDFLAGS = -L.
SHLIB_CFLAGS = -shared

INSTALL_EXEC = install -m 755 -o root -g root
INSTALL_DATA = install -m 644 -o root -g root
COPY_PRESERVELINKS = cp -d
INSTALL_SOLINKS = $(COPY_PRESERVELINKS)

MAJOR = 0
MINOR = 8
MICRO = 0

NAME = json
A_TARGETS = lib$(NAME).a
BIN_TARGETS = $(NAME)lint
PC_TARGET = lib$(NAME).pc
SO_LINKS = lib$(NAME).so lib$(NAME).so.$(MAJOR) lib$(NAME).so.$(MAJOR).$(MINOR)
SO_FILE = lib$(NAME).so.$(MAJOR).$(MINOR).$(MICRO)
HEADERS = $(NAME).h

PREFIX ?= /usr
DESTDIR ?=
INSTALLDIR ?= $(DESTDIR)$(PREFIX)

TARGETS = $(A_TARGETS) $(SO_FILE) $(SO_LINKS) $(BIN_TARGETS) $(PC_TARGET)

UNAME := $(shell uname)

all: $(TARGETS)

lib$(NAME).a: $(NAME).o
$(AR) rc $@ $+

lib$(NAME).so: lib$(NAME).so.$(MAJOR)
ln -sf $< $@

lib$(NAME).so.$(MAJOR): lib$(NAME).so.$(MAJOR).$(MINOR)
ln -sf $< $@

lib$(NAME).so.$(MAJOR).$(MINOR): lib$(NAME).so.$(MAJOR).$(MINOR).$(MICRO)
ln -sf $< $@

lib$(NAME).so.$(MAJOR).$(MINOR).$(MICRO): $(NAME).o
ifeq ($(UNAME), Darwin)
$(CC) $(CFLAGS) $(LDFLAGS) $(SHLIB_CFLAGS) -o $@ $^
else
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,lib$(NAME).so.$(MAJOR).$(MINOR).$(MICRO) $(SHLIB_CFLAGS) -o $@ $^
endif

$(NAME)lint: $(NAME)lint.o $(NAME).o
$(CC) $(CFLAGS) -o $@ $+

%.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<

.PHONY: lib$(NAME).pc
lib$(NAME).pc: lib$(NAME).pc.in
sed -e 's;@PREFIX@;$(PREFIX);' -e 's;@LIBJSON_VER_MAJOR@;$(MAJOR);' -e 's;@LIBJSON_VER_MINOR@;$(MINOR);' < $< > $@

.PHONY: tests clean install install-bin install-lib
tests: $(NAME)lint
(cd tests; ./runtest)

install-lib: $(SO_TARGETS) $(A_TARGETS) $(PC_TARGET)
mkdir -p $(INSTALLDIR)/lib/pkgconfig
$(INSTALL_DATA) -t $(INSTALLDIR)/lib/pkgconfig $(PC_TARGET)
mkdir -p $(INSTALLDIR)/include
$(INSTALL_DATA) -t $(INSTALLDIR)/include $(HEADERS)
mkdir -p $(INSTALLDIR)/lib
$(INSTALL_EXEC) -t $(INSTALLDIR)/lib $(SO_FILE)
$(INSTALL_DATA) -t $(INSTALLDIR)/lib $(A_TARGETS)
$(INSTALL_SOLINKS) $(SO_LINKS) $(INSTALLDIR)/lib

install-bin: $(BIN_TARGETS)
mkdir -p $(INSTALLDIR)/bin
$(INSTALL_EXEC) -t $(INSTALLDIR)/bin $(BIN_TARGETS)

install: install-lib install-bin

clean:
rm -f *.o $(TARGETS)
Something went wrong with that request. Please try again.