packaging: Initial packaging
[platform/upstream/make.git] / loadapi.c
1 /* API for GNU Make dynamic objects.
2 Copyright (C) 2013 Free Software Foundation, Inc.
3 This file is part of GNU Make.
4
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
8 version.
9
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 #include "makeint.h"
18
19 #include "filedef.h"
20 #include "variable.h"
21 #include "dep.h"
22
23 /* Allocate a buffer in our context, so we can free it.  */
24 char *
25 gmk_alloc (unsigned int len)
26 {
27   return xmalloc (len);
28 }
29
30 /* Free a buffer returned by gmk_expand().  */
31 void
32 gmk_free (char *s)
33 {
34   free (s);
35 }
36
37 /* Evaluate a buffer as make syntax.
38    Ideally eval_buffer() will take const char *, but not yet.  */
39 void
40 gmk_eval (const char *buffer, const gmk_floc *floc)
41 {
42   char *s = xstrdup (buffer);
43   eval_buffer (s, floc);
44   free (s);
45 }
46
47 /* Expand a string and return an allocated buffer.
48    Caller must call gmk_free() with this buffer.  */
49 char *
50 gmk_expand (const char *ref)
51 {
52   return allocated_variable_expand (ref);
53 }
54
55 /* Register a function to be called from makefiles.  */
56 void
57 gmk_add_function (const char *name, gmk_func_ptr func,
58                   unsigned int min, unsigned int max, unsigned int flags)
59 {
60   define_new_function (reading_file, name, min, max, flags, func);
61 }