
comma := ,
empty :=
space := $(empty) $(empty) $(empty)

LIST_OPTIONS = grep '^  CINIT(' ../include/curl/curl.h | cut -f1 -d, | sed 's/CINIT(/CURLOPT_/'

define CURL_OPTIONS1
  #include <curl/curl.h>

  typedef struct {
     int  val;
     char name[40];
   } keyval;

  static const keyval options[] = {
endef

define CURL_OPTIONS2
   { 0, NULL }
  };

  int libcurl_has_option (int opt)
  {
    int i;
    for (i = 0; i < sizeof(options)/sizeof(options[0]); i++)
       if (opt == options[i].val)
         return (1);
    return (0);
  }
endef

all: curl_options.c

curl_options.c::
	$(file > $@, $(CURL_OPTIONS1))
	$(foreach o, $(shell $(LIST_OPTIONS)), $(file >> $@, $(space) { $(o) $(comma) "$(o)" } $(comma) ) )
	$(file >> $@, $(CURL_OPTIONS2))
	@echo '$@ done.'
