liboptcfg

annotate Makefile @ 5:aca7267dfee0

fixed cross-compilation with mingw-w64
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 31 Aug 2017 05:59:19 +0300
parents 8fd2858c6a29
children
rev   line source
nuclear@1 1 # installation prefix, change it to install elsewhere
nuclear@1 2 PREFIX = /usr/local
nuclear@1 3 # -----------------------------
nuclear@1 4
nuclear@0 5 src = $(wildcard src/*.c)
nuclear@0 6 obj = $(src:.c=.o)
nuclear@0 7 name = optcfg
nuclear@0 8
nuclear@0 9 so_major = 0
nuclear@0 10 so_minor = 1
nuclear@0 11
nuclear@0 12 alib = lib$(name).a
nuclear@0 13
nuclear@5 14 sodir = lib
nuclear@5 15
nuclear@0 16 CFLAGS = -pedantic -Wall -g
nuclear@0 17
nuclear@5 18 sys := $(shell uname -s | sed 's/MINGW.*/mingw/')
nuclear@0 19 ifeq ($(sys), Darwin)
nuclear@0 20 solib = lib$(name).dylib
nuclear@0 21 shared = -dynamiclib
nuclear@5 22 else ifeq ($(sys), mingw)
nuclear@5 23 solib = lib$(name).dll
nuclear@5 24 shared = -shared
nuclear@5 25 sodir = bin
nuclear@0 26 else
nuclear@0 27 ldname = lib$(name).so
nuclear@0 28 soname = lib$(name).so.$(so_major)
nuclear@0 29 solib = lib$(name).so.$(so_major).$(so_minor)
nuclear@0 30 shared = -shared -Wl,-soname=$(soname)
nuclear@0 31 CFLAGS += -fPIC
nuclear@0 32 endif
nuclear@0 33
nuclear@0 34 .PHONY: all
nuclear@0 35 all: $(solib) $(alib)
nuclear@0 36
nuclear@0 37 $(solib): $(obj)
nuclear@0 38 $(CC) -o $@ $(shared) $(obj) $(LDFLAGS)
nuclear@0 39
nuclear@0 40 $(alib): $(obj)
nuclear@0 41 $(AR) rcs $@ $(obj)
nuclear@0 42
nuclear@0 43 .PHONY: clean
nuclear@0 44 clean:
nuclear@0 45 rm -f $(obj) $(alib) $(solib)
nuclear@0 46
nuclear@0 47 .PHONY: install
nuclear@0 48 install:
nuclear@5 49 mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib
nuclear@0 50 cp src/optcfg.h $(DESTDIR)$(PREFIX)/include/optcfg.h
nuclear@0 51 cp $(alib) $(DESTDIR)$(PREFIX)/lib/$(alib)
nuclear@5 52 cp $(solib) $(DESTDIR)$(PREFIX)/$(sodir)/$(solib)
nuclear@5 53 [ -n "$(soname)" ] && cd $(DESTDIR)$(PREFIX)/$(sodir) && \
nuclear@1 54 rm -f $(soname) $(ldname) && \
nuclear@0 55 ln -s $(solib) $(soname) && \
nuclear@0 56 ln -s $(soname) $(ldname) || true
nuclear@0 57
nuclear@0 58 .PHONY: uninstall
nuclear@0 59 uninstall:
nuclear@0 60 rm -f $(DESTDIR)$(PREFIX)/include/optcfg.h
nuclear@0 61 rm -f $(DESTDIR)$(PREFIX)/lib/$(alib)
nuclear@5 62 rm -f $(DESTDIR)$(PREFIX)/$(sodir)/$(solib)
nuclear@0 63 [ -n "$(soname)" ] && \
nuclear@5 64 rm -f $(DESTDIR)$(PREFIX)/$(sodir)/$(soname) && \
nuclear@5 65 rm -f $(DESTDIR)$(PREFIX)/$(sodir)/$(ldname) || true