xref: /freebsd/lib/libmagic/Makefile (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1# Copyright (c) David E. O'Brien, 2000-2004, 2006, 2009
2
3PACKAGE=lib${LIB}
4CONTRDIR=	${SRCTOP}/contrib/file
5.PATH: ${CONTRDIR}
6.PATH: ${CONTRDIR}/src
7.PATH: ${CONTRDIR}/doc
8
9LIB=	magic
10SHLIB_MAJOR=	4
11.if !make(build-tools)
12LIBADD=	z
13.endif
14MAN=	libmagic.3 magic.5
15
16SRCS=	apprentice.c apptype.c ascmagic.c buffer.c cdf.c cdf_time.c \
17	compress.c der.c encoding.c fsmagic.c funcs.c is_json.c \
18	is_csv.c \
19	is_tar.c magic.c print.c readcdf.c readelf.c seccomp.c softmagic.c
20INCS=	magic.h
21
22MAGICPATH?=	/usr/share/misc
23
24CFLAGS+= -DMAGIC='"${MAGICPATH}/magic"' -DHAVE_CONFIG_H
25CFLAGS+= -I${.CURDIR} -I${.OBJDIR} -I${CONTRDIR}/src
26
27WARNS?=		3
28
29CLEANFILES+=	magic magic.mgc
30
31FILES=		magic magic.mgc
32FILESDIR=	${MAGICPATH}
33
34MAGFILES=	${CONTRDIR}/magic/Header \
35		${CONTRDIR}/magic/Localstuff \
36		${CONTRDIR}/magic/Magdir/[a-z]*
37
38
39PACKAGE_VERSION!=	sed -n '/define.*PACKAGE_VERSION/{s,[^0-9.],,gp;q;}' ${.CURDIR}/config.h
40
41libmagic.pc: libmagic.pc.in
42	sed -e 's,@prefix@,/usr,g ; \
43		s,@exec_prefix@,$${prefix},g ; \
44		s,@libdir@,${LIBDIR},g ; \
45		s,@sharedlibdir@,${SHLIBDIR},g ; \
46		s,@includedir@,${INCLUDEDIR},g ; \
47		s,@VERSION@,${PACKAGE_VERSION},g ; \
48		s,@LIBS@,,g ;' \
49                ${.ALLSRC} > ${.TARGET}
50
51magic: ${MAGFILES}
52	cat ${.ALLSRC:O} > ${.TARGET}
53
54magic.mgc: magic
55	${BTOOLSPATH:U.}/mkmagic magic
56
57.if ${MACHINE} == "host" || ${MK_DIRDEPS_BUILD} == "no"
58CLEANFILES+=	mkmagic
59DEPENDOBJS+=	mkmagic
60build-tools: mkmagic
61mkmagic: apprentice.c cdf_time.c encoding.c funcs.c magic.c print.c ${INCS} ${BUILD_TOOLS_META}
62	${CC:N${CCACHE_BIN}} ${CFLAGS} -DCOMPILE_ONLY ${LDFLAGS} -o ${.TARGET} \
63	    ${.ALLSRC:N*.h:O:u} ${LDADD}
64
65.endif
66.if ${MK_DIRDEPS_BUILD} == "yes"
67BTOOLSPATH= ${HOST_OBJTOP}/${RELDIR}
68.else
69magic.mgc: mkmagic
70.endif
71
72FILEVER!= awk '$$1 == "\#define" && $$2 == "VERSION" { print $$3; exit }' \
73			${.CURDIR}/config.h
74CLEANFILES+=	${MAN}
75.for mp in ${MAN}
76${mp}: ${mp:C/[0-9]/man/}
77	sed -e 's/__FSECTION__/5/g' -e 's/__CSECTION__/1/g' \
78		-e 's/__VERSION__/${FILEVER}/g' \
79		-e 's,__MAGIC__,${MAGICPATH}/magic,g' ${.ALLSRC} > ${.TARGET}
80.endfor
81
82CLEANFILES+=	${INCS}
83.for inc in ${INCS}
84${inc}: ${inc}.in
85	sed -e 's,X.YY,${FILEVER:S,",,g:S,.,,g},g' ${.ALLSRC} > ${.TARGET}
86.endfor
87
88PCFILES=	libmagic.pc
89
90.include <bsd.lib.mk>
91