.PHONY: all ./Serenade ./Tool replace
-all: ./Tool ./Serenade
+all: ./Tool ./config.h ./Serenade
./Tool::
$(MAKE) -C ./Tool CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" SUFFIX="$(SUFFIX)"
+./config.h:
+ ./Tool/configgen $@
+
./Serenade::
$(MAKE) -C ./Serenade CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" SUFFIX="$(SUFFIX)"
clean:
$(MAKE) -C ./Tool clean
$(MAKE) -C ./Serenade clean
+ rm -f config.h
FILES = `find . -name "*.c" -or -name "*.h"`
/* --- END LICENSE --- */
#include <stdio.h>
+#include <stdbool.h>
+#include <ctype.h>
-int main(){}
+const char* asks[] = {
+ "y",
+ "HAS_REPL_SUPPORT",
+ "Do you want the REPL support?",
+ "n",
+ "HAS_FFI_SUPPORT",
+ "Do you want the FFI support?",
+ NULL
+};
+
+void show_dialog(int n){
+ fprintf(stderr, "[default is %c] %s ", asks[n * 3][0], asks[n * 3 + 2]);
+ fflush(stderr);
+}
+
+int main(int argc, char** argv){
+ FILE* out = stdout;
+ bool load = false;
+ if(argv[1] != NULL){
+ out = fopen(argv[1], "w");
+ if(out != NULL){
+ load = true;
+ }else{
+ fprintf(stderr, "%s: %s: couldn't open the file\n", argv[0], argv[1]);
+ return 1;
+ }
+ }
+ fprintf(out, "/* Autogenerated config */\n");
+ char c;
+ char oldc;
+ bool nl = false;
+ int n = 0;
+ show_dialog(n);
+ while(true){
+ oldc = c;
+ if(fread(&c, 1, 1, stdin) <= 0) break;
+ if(c == '\n'){
+ char ch = asks[n * 3][0];
+ if(nl){
+ ch = tolower(oldc);
+ }
+ fprintf(out, "#%s %s\n", ch == 'y' ? "define" : "undef", asks[n * 3 + 1]);
+ n++;
+ nl = false;
+ if(asks[n * 3] == NULL) break;
+ show_dialog(n);
+ }else{
+ nl = true;
+ }
+ }
+ if(load) fclose(out);
+}