Roland Ver. 4.5 Informações Técnicas Página 149

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 212
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 148
Chapter 12: Extending GNU make 139
gmk_expand
This function takes a string and expands it using make expansion rules. The
result of the expansion is returned in a nil-terminated string buffer. The caller
is responsible for calling gmk_free with a pointer to the returned buffer when
done.
gmk_eval This function takes a buffer and evaluates it as a segment of makefile syntax.
This function can be used to define new variables, new rules, etc. It is equivalent
to using the eval make function.
Note that there is a difference between gmk_eval and calling gmk_expand with a string
using the eval function: in the latter case the string will be expanded twice; once by gmk_
expand and then again by the eval function. Using gmk_eval the buffer is only expanded
once, at most (as it’s read by the make parser).
Memory Management
Some systems allow for different memory management schemes. Thus you should never
pass memory that you’ve allocated directly to any make function, nor should you attempt
to directly free any memory returned to you by any make function. Instead, use the gmk_
alloc and gmk_free functions.
In particular, the string returned to make by a function registered using gmk_add_
function must be allocated using gmk_alloc, and the string returned from the make gmk_
expand function must be freed (when no longer needed) using gmk_free.
gmk_alloc
Return a pointer to a newly-allocated buffer. This function will always return
a valid pointer; if not enough memory is available make will exit.
gmk_free Free a buffer returned to you by make. Once the gmk_free function returns the
string will no longer be valid.
12.2.4 Example Loaded Object
Let’s suppose we wanted to write a new GNU make function that would create a temporary
file and return its name. We would like our function to take a prefix as an argument. First
we can write the function in a file mk_temp.c:
Vista de página 148
1 2 ... 144 145 146 147 148 149 150 151 152 153 154 ... 211 212

Comentários a estes Manuais

Sem comentários