commit
bc4b28b069
20 changed files with 315 additions and 11 deletions
@ -0,0 +1,18 @@ |
||||
project('multiwrap', 'c') |
||||
|
||||
# Using multiple downloaded projects for great justice. |
||||
|
||||
if meson.get_compiler('c').get_id() != 'msvc' |
||||
add_global_arguments('-std=c99', language : 'c') |
||||
extra_libs = ['-lm'] |
||||
else |
||||
extra_libs = [] |
||||
endif |
||||
|
||||
luap = subproject('lua') |
||||
pngp = subproject('libpng') |
||||
|
||||
executable('prog', 'prog.c', |
||||
include_directories : [pngp.get_variable('incdir'), luap.get_variable('incdir')], |
||||
link_with :[pngp.get_variable('libpng'), luap.get_variable('lualib')], |
||||
link_args : extra_libs) |
@ -0,0 +1,66 @@ |
||||
#include<lua.h> |
||||
#include<stdio.h> |
||||
#include<stdlib.h> |
||||
#include<png.h> |
||||
#include<string.h> |
||||
#if !defined(_MSC_VER) |
||||
#include<unistd.h> |
||||
#endif |
||||
|
||||
static void *l_alloc (void *ud, void *ptr, size_t osize, |
||||
size_t nsize) { |
||||
(void)ud; |
||||
(void)osize; |
||||
if (nsize == 0) { |
||||
free(ptr); |
||||
return NULL; |
||||
} else { |
||||
return realloc(ptr, nsize); |
||||
} |
||||
} |
||||
|
||||
void open_image(const char *fname) { |
||||
png_image image; |
||||
|
||||
memset(&image, 0, (sizeof image)); |
||||
image.version = PNG_IMAGE_VERSION; |
||||
|
||||
if(png_image_begin_read_from_file(&image, fname) != 0) { |
||||
png_bytep buffer; |
||||
|
||||
image.format = PNG_FORMAT_RGBA; |
||||
buffer = malloc(PNG_IMAGE_SIZE(image)); |
||||
|
||||
if(png_image_finish_read(&image, NULL, buffer, 0, NULL) != 0) { |
||||
printf("Image %s read failed: %s\n", fname, image.message); |
||||
} |
||||
// png_free_image(&image);
|
||||
free(buffer); |
||||
} else { |
||||
printf("Image %s open failed: %s", fname, image.message); |
||||
} |
||||
} |
||||
|
||||
int printer(lua_State *l) { |
||||
if(!lua_isstring(l, 1)) { |
||||
fprintf(stderr, "Incorrect call.\n"); |
||||
return 0; |
||||
} |
||||
open_image(lua_tostring(l, 1)); |
||||
return 0; |
||||
} |
||||
|
||||
|
||||
int main(int argc, char **argv) { |
||||
lua_State *l = lua_newstate(l_alloc, NULL); |
||||
if(!l) { |
||||
printf("Lua state allocation failed.\n"); |
||||
return 1; |
||||
} |
||||
lua_register(l, "printer", printer); |
||||
lua_getglobal(l, "printer"); |
||||
lua_pushliteral(l, "foobar.png"); |
||||
lua_call(l, 1, 0); |
||||
lua_close(l); |
||||
return 0; |
||||
} |
@ -0,0 +1,11 @@ |
||||
[mesonwrap] |
||||
|
||||
directory = libpng-1.6.16 |
||||
|
||||
source_url = ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.16.tar.gz |
||||
source_filename = libpng-1.6.16.tar.gz |
||||
source_hash = 02f96b6bad5a381d36d7ba7a5d9be3b06f7fe6c274da00707509c23592a073ad |
||||
|
||||
patch_url = https://dl.dropboxusercontent.com/u/37517477/libpng-meson.tar.gz |
||||
patch_filename = libpng-meson.tar.gz |
||||
patch_hash = b91d1abb19711a5aaa4b8581000df0e15420e46d9ce6ecf688e33144ea688f06 |
@ -0,0 +1,10 @@ |
||||
[mesonwrap] |
||||
directory = lua-5.3.0 |
||||
|
||||
source_url = http://www.lua.org/ftp/lua-5.3.0.tar.gz |
||||
source_filename = lua-5.3.0.tar.gz |
||||
source_hash = ae4a5eb2d660515eb191bfe3e061f2b8ffe94dce73d32cfd0de090ddcc0ddb01 |
||||
|
||||
patch_url = https://dl.dropboxusercontent.com/u/37517477/lua53-meson.zip |
||||
patch_filename = lua53-meson.zip |
||||
patch_hash = 076d0d57d33ec996c556722c8eeb624a364c66fe9d2225e590b1bc9ae34fbd6e |
@ -0,0 +1,10 @@ |
||||
[mesonwrap] |
||||
directory = zlib-1.2.8 |
||||
|
||||
source_url = http://zlib.net/zlib-1.2.8.tar.gz |
||||
source_filename = zlib-1.2.8.tar.gz |
||||
source_hash = 36658cb768a54c1d4dec43c3116c27ed893e88b02ecfcb44f2166f9c0b7f2a0d |
||||
|
||||
patch_url = https://dl.dropboxusercontent.com/u/37517477/zlib128-meson.tar.gz |
||||
patch_filename = zlib128-meson.tar.gz |
||||
patch_hash = 03c868bf22d7e35c978e8b9572c4aea1181606c15c3dd19f0713a8479fe27edc |
@ -0,0 +1,7 @@ |
||||
#include<stdio.h> |
||||
#include"version.h" |
||||
|
||||
int main(int argc, char **argv) { |
||||
printf("Version is %s.\n", version_string); |
||||
return 0; |
||||
} |
@ -0,0 +1,15 @@ |
||||
project('run always', 'c') |
||||
|
||||
version = '1.0.0' |
||||
|
||||
vgen = find_program('version_gen.py') |
||||
|
||||
version_src = custom_target('Version string', |
||||
input : 'version.c.in', |
||||
output : 'version.c', |
||||
command : [vgen, '@INPUT@', '@OUTPUT@', version], |
||||
build_always : true, |
||||
) |
||||
|
||||
executable('versionprinter', 'main.c', version_src, |
||||
include_directories : include_directories('.')) |
@ -0,0 +1,3 @@ |
||||
#include"version.h" |
||||
|
||||
const char *version_string = "@VERSION@"; |
@ -0,0 +1,3 @@ |
||||
#pragma once |
||||
|
||||
const char *version_string; |
@ -0,0 +1,29 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import sys, os, subprocess |
||||
|
||||
def generate(infile, outfile, fallback): |
||||
workdir = os.path.split(infile)[0] |
||||
if workdir == '': |
||||
workdir = '.' |
||||
p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
||||
(stdo, _) = p.communicate() |
||||
# If we are working off an extracted tarball, git version number is not available. |
||||
if p.returncode == 0: |
||||
version = stdo.decode().strip() |
||||
else: |
||||
version = fallback |
||||
newdata = open(infile).read().replace('@VERSION@', version) |
||||
try: |
||||
olddata = open(outfile).read() |
||||
if olddata == newdata: |
||||
return |
||||
except Exception: |
||||
pass |
||||
open(outfile, 'w').write(newdata) |
||||
|
||||
if __name__ == '__main__': |
||||
infile = sys.argv[1] |
||||
outfile = sys.argv[2] |
||||
fallback = sys.argv[3] |
||||
generate(infile, outfile, fallback) |
@ -0,0 +1,8 @@ |
||||
project('vcstag', 'c') |
||||
|
||||
version_src = vcs_tag(input : 'vcstag.c.in', |
||||
output : 'vcstag.c', |
||||
fallback : '1.0.0') |
||||
|
||||
executable('tagprog', 'tagprog.c', version_src) |
||||
|
@ -0,0 +1,9 @@ |
||||
#include<stdio.h> |
||||
|
||||
const char *vcstag; |
||||
|
||||
int main(int argc, char **argv) { |
||||
printf("Version is %s\n", vcstag); |
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,2 @@ |
||||
const char *vcstag = "@VCS_TAG@"; |
||||
|
@ -0,0 +1,62 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
# Copyright 2015 The Meson development team |
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
import sys, os, subprocess |
||||
|
||||
def tag(infile, outfile, fallback): |
||||
tagid = get_string(infile, fallback) |
||||
newdata = open(infile).read().replace('@VCS_TAG@', tagid) |
||||
try: |
||||
olddata = open(outfile).read() |
||||
if olddata == newdata: |
||||
return |
||||
except Exception: |
||||
pass |
||||
open(outfile, 'w').write(newdata) |
||||
|
||||
def get_string(infile, fallback): |
||||
absfile = os.path.join(os.getcwd(), infile) |
||||
directory = os.path.split(absfile)[0] |
||||
segs = directory.replace('\\', '/').split('/') |
||||
for i in range(len(segs), -1, -1): |
||||
curdir = '/'.join(segs[:i]) |
||||
if os.path.isdir(os.path.join(curdir, '.git')): |
||||
output = subprocess.check_output(['git', 'describe'], |
||||
cwd = directory) |
||||
return output.decode().strip() |
||||
elif os.path.isdir(os.path.join(curdir, '.hg')): |
||||
output = subprocess.check_output(['hg', 'identify'], |
||||
cwd=directory) |
||||
return output.decode().strip() |
||||
elif os.path.isdir(os.path.join(curdir, '.bzr')): |
||||
output = subprocess.check_output(['bzr', 'revno'], |
||||
cwd=directory) |
||||
return output.decode().strip() |
||||
elif os.path.isdir(os.path.join(curdir, '.svn')): |
||||
output = subprocess.check_output(['svn', 'info'], |
||||
cwd=directory) |
||||
for line in output.decode().split('\n'): |
||||
(k, v) = line.split(':', 1) |
||||
if k.strip() == 'Revision': |
||||
return v.strip() |
||||
raise RuntimeError('Svn output malformed.') |
||||
return fallback |
||||
|
||||
if __name__ == '__main__': |
||||
infile = sys.argv[1] |
||||
outfile = sys.argv[2] |
||||
fallback = sys.argv[3] |
||||
tag(infile, outfile, fallback) |
Loading…
Reference in new issue