Skip to content

Instantly share code, notes, and snippets.

@irondoge
Created August 5, 2017 09:54
Show Gist options
  • Save irondoge/16407778971e69b12c684fad4aa48810 to your computer and use it in GitHub Desktop.
Save irondoge/16407778971e69b12c684fad4aa48810 to your computer and use it in GitHub Desktop.
GNU Make C API - hello world
#include <stdio.h>
#include <string.h>
#include <gnumake.h>
int plugin_is_GPL_compatible;
#define FUNC_STATIC GMK_FUNC_DEFAULT
#define FUNC_REFLEXIVE GMK_FUNC_NOEXPAND
char *hello()
{
return (strdup("hello, world\n"));
}
char *say(char const *av0, unsigned int ac, char **av)
{
return (strdup(*av));
}
int moul_gmk_setup()
{
gmk_add_function ("hello", &hello, 0, 0, FUNC_STATIC);
gmk_add_function ("say", &say, 1, 1, FUNC_STATIC);
return (1);
}
void say_hello()
{
printf("hello, world\n");
}
CC := gcc
CFLAGS := -fpic
LD := $(CC)
LDFLAGS := -shared
LDLIBS :=
all:; @echo $(hello )
say:; @echo $(say "hello, world")
hello:; @$(MAKE) --no-print-directory do_hello
ifeq ($(MAKECMDGOALS),do_hello)
-load moul.so(say_hello)
do_hello:;@:
else
-load moul.so
endif
moul.so: expand_make.c
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
.PHONY: all say hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment