-
Notifications
You must be signed in to change notification settings - Fork 88
Add support for libmagic. #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
5242f32
a66dca9
3271306
dde5b32
133e66b
28170f6
caa20a2
42754eb
f802f9f
cc258f0
5d8868a
500f290
b63b2a5
1aa159f
ea4b93b
4fa3909
9131bda
220cf6a
093af12
8c4f3c8
cde9100
fa61df7
a933c5d
ae22ff0
6968521
e883722
7871d11
554df3c
8845ccc
86dcebc
9d3e141
79398d7
6a2bcdc
78a1cd1
8dd4432
e4a9372
b936245
2e8d26b
7e63385
c4dddb9
3366268
9189dfa
e460673
bfcdab2
f8f278c
dccce2d
b1230e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| libpcre |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| PKGURL=https://github.com/threatstack/libmagic/archive/5.18.tar.gz | ||
| PKGHASH=ce734a1cc24bddbfd8b21f4ffdfe721ab74eeed9 | ||
|
|
||
| package_download $PKGURL $PKGHASH | ||
| package_patch | ||
|
|
||
| EXTRACONF= | ||
|
|
||
| if [ "$SYS_PLATFORM" != "$SYS_HOSTPLATFORM" ]; then | ||
| EXTRACONF="$EXTRACONF --host=$SYS_ARCH" | ||
| fi | ||
|
|
||
| # pretend libgnurx exists by masking libpcre | ||
|
|
||
| test -L $SYS_PREFIX/include/regex.h || ln -s pcreposix.h $SYS_PREFIX/include/regex.h | ||
|
|
||
| # Mabye instead of fooling the package, it should be patched | ||
| rmifexists $SYS_PREFIX/lib/libgnurx.a | ||
| rmifexists $SYS_PREFIX/lib/libgnurx | ||
| mkdir $SYS_PREFIX/lib/libgnurx | ||
| ( cd $SYS_PREFIX/lib/libgnurx | ||
| mkdir a | ||
| cd a | ||
| $SYS_AR -x ../../libpcre.a | ||
| cd .. | ||
| mkdir b | ||
| cd b | ||
| $SYS_AR -x ../../libpcreposix.a | ||
| cd .. | ||
| $SYS_AR rc ../libgnurx.a a/*.o b/*.o | ||
| ) | ||
|
|
||
| rm -r $SYS_PREFIX/lib/libgnurx | ||
|
|
||
| if [ `file --version|head -1` != file-5.18 ]; then | ||
| if [ ! -f $SYS_HOSTPREFIX/bin/file ]; then | ||
| ./configure --enable-static --disable-shared 'CFLAGS=-fPIC -O3 -DPCRE_STATIC' | ||
| package_make | ||
| cp src/file $SYS_HOSTPREFIX/bin || exit 1 | ||
| package_cleanup | ||
| package_download $PKGURL $PKGHASH | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't it already be downloaded by this time (as in line 4)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it should. Reading |
||
| package_patch | ||
| fi | ||
| FILE_COMPILE=$SYS_HOSTPREFIX/bin/file | ||
| fi | ||
|
|
||
| # configure | ||
|
|
||
| if [ "$SYS_PLATFORM" != "$SYS_HOSTPLATFORM" -a "X$FILE_COMPILE" != "X" ]; then | ||
| echo patching magic/Makefile.in to use $FILE_COMPILE | ||
| sed -i -es%'@IS_CROSS_COMPILE_TRUE@FILE_COMPILE = file${EXEEXT}'%"@IS_CROSS_COMPILE_TRUE@FILE_COMPILE = ${FILE_COMPILE}"% magic/Makefile.in | ||
| fi | ||
|
|
||
| package_configure --enable-static --disable-shared $EXTRACONF "'CFLAGS=-fPIC -O3 -DPCRE_STATIC'" | ||
|
|
||
|
|
||
| # build | ||
|
|
||
| package_make | ||
|
|
||
| # install | ||
|
|
||
| cp src/.libs/libmagic.a $SYS_PREFIX/lib | ||
| cp src/magic.h $SYS_PREFIX/include | ||
| test -f src/file.exe && cp src/file.exe $SYS_PREFIX/bin | ||
| test -d $SYS_PREFIX/etc || mkdir $SYS_PREFIX/etc | ||
| cp magic/magic.mgc $SYS_PREFIX/etc | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need this file embedded couldn't you compile it once and then include it in the module with an EMBED file? - Also does it need to be in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure. I don't really know where to put it. As you said: embedding might not be available from within the library directory. Hence we'll have to install it somewhere to be available for embedding later. |
||
|
|
||
| # Cleanup the fooling | ||
| rm -f $SYS_PREFIX/lib/libgnurx.a $SYS_PREFIX/include/regex.h | ||
|
|
||
| package_cleanup | ||
|
|
||
| unset EXTRACONF | ||
|
|
||
| #eof | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| PKGURL=https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz | ||
| PKGHASH=8f36ed69d3e938972fc511c19bfaa0ff27ff1d71 | ||
|
|
||
| package_download $PKGURL $PKGHASH | ||
|
|
||
| package_patch | ||
|
|
||
| EXTRACONF="--enable-utf --enable-jit " | ||
|
|
||
| if [ "$SYS_PLATFORM" != "$SYS_HOSTPLATFORM" ]; then | ||
| EXTRACONF="$EXTRACONF --host=$SYS_ARCH" | ||
| fi | ||
|
|
||
| # configure | ||
|
|
||
| package_configure $EXTRACONF | ||
|
|
||
| # build | ||
|
|
||
| NOQUIET=yes package_make | ||
|
|
||
| # install | ||
|
|
||
| cp .libs/libpcre.a .libs/libpcreposix.a $SYS_PREFIX/lib || exit 1 | ||
| cp pcre.h pcreposix.h pcrecpparg.h pcre_scanner.h pcre_stringpiece.h $SYS_PREFIX/include || exit 1 | ||
|
|
||
| package_cleanup | ||
|
|
||
| unset EXTRACONF | ||
|
|
||
| #eof |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| libmagic |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #| | ||
| LambdaNative - a cross-platform Scheme framework | ||
| Copyright (c) 2009-2014, University of British Columbia | ||
| Copyright (c) 2019 by Joerg F. Wittenberger | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or | ||
| without modification, are permitted provided that the | ||
| following conditions are met: | ||
|
|
||
| * Redistributions of source code must retain the above | ||
| copyright notice, this list of conditions and the following | ||
| disclaimer. | ||
|
|
||
| * Redistributions in binary form must reproduce the above | ||
| copyright notice, this list of conditions and the following | ||
| disclaimer in the documentation and/or other materials | ||
| provided with the distribution. | ||
|
|
||
| * Neither the name of the University of British Columbia nor | ||
| the names of its contributors may be used to endorse or | ||
| promote products derived from this software without specific | ||
| prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | ||
| CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
| MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
| CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| |# | ||
|
|
||
| ;; minimal bindings to libmagic | ||
|
|
||
| (c-declare #<<EOF | ||
| #include <magic.h> | ||
| EOF | ||
| ) | ||
|
|
||
| (define-macro (define-c-constant name type value) | ||
| `(define ,name ((c-lambda () ,type ,(string-append "___result = " value ";"))))) | ||
|
|
||
| (define-c-constant MAGIC_NONE int "MAGIC_NONE") | ||
| (define-c-constant MAGIC_DEBUG int "MAGIC_DEBUG") | ||
| (define-c-constant MAGIC_SYMLINK int "MAGIC_SYMLINK") | ||
| (define-c-constant MAGIC_COMPRESS int "MAGIC_COMPRESS") | ||
| (define-c-constant MAGIC_DEVICES int "MAGIC_DEVICES") | ||
| (define-c-constant MAGIC_MIME int "MAGIC_MIME") | ||
| (define-c-constant MAGIC_CONTINUE int "MAGIC_CONTINUE") | ||
| (define-c-constant MAGIC_CHECK int "MAGIC_CHECK") | ||
| (define-c-constant MAGIC_PRESERVE_ATIME int "MAGIC_PRESERVE_ATIME") | ||
| (define-c-constant MAGIC_RAW int "MAGIC_RAW") | ||
| (define-c-constant MAGIC_ERROR int "MAGIC_ERROR") | ||
|
|
||
| (define magic-open | ||
| (c-lambda (int) (pointer void) "magic_open")) | ||
|
|
||
| (define magic-load | ||
| (c-lambda ((pointer void) char-string) int "magic_load")) | ||
|
|
||
| (define magic-error | ||
| (c-lambda ((pointer void)) char-string "magic_error")) | ||
|
|
||
| (define magic-file | ||
| (c-lambda ((pointer void) char-string) char-string "magic_file")) | ||
|
|
||
| (define (magic-buffer ptr u8data) | ||
| ((c-lambda | ||
| ((pointer void) scheme-object int) | ||
| char-string | ||
| "___result = (char*)magic_buffer(___arg1, ___BODY_AS(___arg2,___tSUBTYPED), ___arg3);") | ||
| ptr u8data (u8vector-length u8data))) | ||
|
|
||
| (define magic-close | ||
| (c-lambda ((pointer void)) void "magic_close")) | ||
|
|
||
| (define magic-setflags | ||
| (c-lambda ((pointer void) int) int "magic_setflags")) | ||
|
|
||
| (define magic-errno | ||
| (c-lambda ((pointer void)) int "magic_errno")) | ||
|
|
||
| ;; eof |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure about this either. Why not include that library if you depend on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons:
At least I need
pcreanyway and I see limited reasons to have two libraries implementing the same functionality.I'd guess there might be license compatibility issues when linking against a GPLed library and
libgnurxis AFAIK.