Makefile 4.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
include config.mak

.SUFFIXES: .so

AR=ar
LD=ld
RANLIB=ranlib

VPATH+= $(SRC_PATH_BARE)/src

CFLAGS += $(USEDEBUG) -Wall -funsigned-char
12 13
CFLAGS += -I$(CURDIR) -I$(SRC_PATH)/src
CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
14 15
CFLAGS += -DHAVE_CONFIG_H -DHAVE_DLFCN_H

16
L=libdvdread
17 18 19
DVDREAD_L=libdvdread
DVDREAD_LIB = $(DVDREAD_L).a
DVDREAD_SHLIB = $(DVDREAD_L).so
20
VPATH+= $(SRC_PATH_BARE)/src
21 22 23 24 25 26 27 28 29
DVDREAD_HEADERS = src/dvdread/dvd_reader.h \
	src/dvdread/ifo_print.h \
	src/dvdread/ifo_read.h \
	src/dvdread/ifo_types.h \
	src/dvdread/nav_print.h \
	src/dvdread/nav_read.h \
	src/dvdread/dvd_udf.h \
	src/dvdread/nav_types.h \
	src/dvdread/bitreader.h
30 31
DVDREAD_SRCS = dvd_input.c dvd_reader.c dvd_udf.c ifo_print.c ifo_read.c \
	md5.c nav_print.c nav_read.c bitreader.c
32
CFLAGS += -I$(SRC_PATH)/src
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

LIB = $(L).a
SHLIB = $(L).so

.OBJDIR=        obj
DEPFLAG = -M

OBJS = $(patsubst %.c,%.o, $(SRCS))
DVDREAD_OBJS = $(patsubst %.c,%.o, $(DVDREAD_SRCS))
SHOBJS = $(patsubst %.c,%.so, $(SRCS))
DVDREAD_SHOBJS = $(patsubst %.c,%.so, $(DVDREAD_SRCS))
DEPS= ${OBJS:%.o=%.d}
DVDREAD_DEPS= ${DVDREAD_OBJS:%.o=%.d}

BUILDDEPS = Makefile config.mak

ifeq ($(BUILD_SHARED),yes)
50
all:	$(SHLIB) $(DVDREAD_SHLIB) dvdread-config pkgconfig
51
install: $(SHLIB) $(DVDREAD_SHLIB) install-shared install-dvdread-config install-pkgconfig
52 53 54
endif

ifeq ($(BUILD_STATIC),yes)
55
all:	$(LIB) $(DVDREAD_LIB) dvdread-config pkgconfig
56
install: $(LIB) $(DVDREAD_LIB) install-static install-dvdread-config install-pkgconfig
57 58 59 60 61 62 63 64 65 66 67 68 69
endif

install: install-headers

# Let version.sh create version.h

SVN_ENTRIES = $(SRC_PATH_BARE)/.svn/entries
ifeq ($(wildcard $(SVN_ENTRIES)),$(SVN_ENTRIES))
version.h: $(SVN_ENTRIES)
endif

version.h:
	sh $(SRC_PATH)/version.sh $(SRC_PATH) "$(SHLIB_VERSION)"
70

71 72 73 74 75
$(SRCS) $(DVDREAD_SRCS): version.h


# General targets

76
${DVDREAD_LIB}: version.h $(DVDREAD_OBJS) $(BUILDDEPS)
77 78 79
	cd $(.OBJDIR) && $(AR) rc $@ $(DVDREAD_OBJS)
	cd $(.OBJDIR) && $(RANLIB) $@

80
${DVDREAD_SHLIB}: version.h $(DVDREAD_SHOBJS) $(BUILDDEPS)
81
	cd $(.OBJDIR) && $(CC) $(SHLDFLAGS) $(LDFLAGS) -ldl -Wl,-soname=$(DVDREAD_SHLIB).$(SHLIB_MAJOR) -o $@ $(DVDREAD_SHOBJS)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

.c.so:	$(BUILDDEPS)
	cd $(.OBJDIR) && $(CC) -fPIC -DPIC -MD $(CFLAGS) -c -o $@ $<

.c.o:	$(BUILDDEPS)
	cd $(.OBJDIR) && $(CC) -MD $(CFLAGS) -c -o $@ $<


# Install targets

install-headers:
	install -d $(DESTDIR)$(dvdread_incdir)
	install -m 644 $(DVDREAD_HEADERS) $(DESTDIR)$(dvdread_incdir)

install-shared: $(SHLIB)
	install -d $(DESTDIR)$(shlibdir)

	install $(INSTALLSTRIP) -m 755 $(.OBJDIR)/$(SHLIB) \
		$(DESTDIR)$(shlibdir)/$(SHLIB).$(SHLIB_VERSION)

	cd $(DESTDIR)$(shlibdir) && \
		ln -sf $(SHLIB).$(SHLIB_VERSION) $(SHLIB).$(SHLIB_MAJOR)
	cd $(DESTDIR)$(shlibdir) && \
		ln -sf $(SHLIB).$(SHLIB_MAJOR) $(SHLIB)

	install $(INSTALLSTRIP) -m 755 $(.OBJDIR)/$(DVDREAD_SHLIB) \
		$(DESTDIR)$(shlibdir)/$(DVDREAD_SHLIB).$(SHLIB_VERSION)
	cd $(DESTDIR)$(shlibdir) && \
		ln -sf $(DVDREAD_SHLIB).$(SHLIB_VERSION) $(DVDREAD_SHLIB).$(SHLIB_MAJOR)
	cd $(DESTDIR)$(shlibdir) && \
		ln -sf $(DVDREAD_SHLIB).$(SHLIB_MAJOR) $(DVDREAD_SHLIB)

install-static: $(LIB)
	install -d $(DESTDIR)$(libdir)

	install $(INSTALLSTRIP) -m 755 $(.OBJDIR)/$(LIB) $(DESTDIR)$(libdir)/$(LIB)
	install $(INSTALLSTRIP) -m 755 $(.OBJDIR)/$(DVDREAD_LIB) $(DESTDIR)$(libdir)/$(DVDREAD_LIB)


# Clean targets

clean:
124
	rm -rf  *~ $(.OBJDIR)/* version.h
125 126 127 128


distclean: clean
	find . -name "*~" | xargs rm -rf
129
	rm -rf config.mak $(.OBJDIR)
130

131 132
dvdread-config: $(.OBJDIR)/dvdread-config
$(.OBJDIR)/dvdread-config: $(BUILDDEPS)
133 134 135 136 137 138 139 140 141 142 143 144
	@echo '#!/bin/sh' > $(.OBJDIR)/dvdread-config
	@echo 'prefix='$(PREFIX) >> $(.OBJDIR)/dvdread-config
	@echo 'libdir='$(shlibdir) >> $(.OBJDIR)/dvdread-config
	@echo 'version='$(SHLIB_VERSION) >> $(.OBJDIR)/dvdread-config
	@echo >> $(.OBJDIR)/dvdread-config
	cat $(SRC_PATH_BARE)/misc/dvdread-config.sh >> $(.OBJDIR)/dvdread-config
	chmod 0755 $(.OBJDIR)/dvdread-config

install-dvdread-config: dvdread-config
	install -d $(DESTDIR)$(PREFIX)/bin
	install -m 0755 $(.OBJDIR)/dvdread-config $(DESTDIR)$(PREFIX)/bin/dvdread-config

145 146 147 148 149 150 151 152
pcedit = sed \
	-e 's,@prefix@,$(PREFIX),' \
	-e 's,@exec_prefix@,$(PREFIX),' \
	-e 's,@libdir@,$(shlibdir),' \
	-e 's,@includedir@,$(PREFIX)/include,' \
	-e 's,@VERSION@,$(SHLIB_VERSION),'

pkgconfig: $(.OBJDIR)/dvdread.pc
153
$(.OBJDIR)/dvdread.pc: misc/dvdread.pc.in $(BUILDDEPS)
154 155 156 157 158
	$(pcedit) $< > $@

install-pkgconfig: $(.OBJDIR)/dvdread.pc
	install -d $(DESTDIR)$(libdir)/pkgconfig
	install -m 0644 $(.OBJDIR)/dvdread.pc $(DESTDIR)$(libdir)/pkgconfig
Dominik Mierzejewski's avatar
Dominik Mierzejewski committed
159

160 161 162 163 164 165 166
vpath %.so ${.OBJDIR}
vpath %.o ${.OBJDIR}
vpath ${LIB} ${.OBJDIR}

# include dependency files if they exist
$(addprefix ${.OBJDIR}/, ${DEPS}): ;
-include $(addprefix ${.OBJDIR}/, ${DEPS})