]> Nishi Git Mirror - serenade.git/commitdiff
configgen works
authornishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Tue, 23 Apr 2024 02:55:26 +0000 (02:55 +0000)
committernishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Tue, 23 Apr 2024 02:55:26 +0000 (02:55 +0000)
git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@8 0f02c867-ac3d-714e-8a88-971ba1f6efcf

Makefile
Tool/configgen.c

index 3f0f09662b5197f9a0bb823dd63dd61c564a90a9..3c117fe319a883d17adb2c5bf7366e08fd244ff8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,17 +10,21 @@ SUFFIX =
 
 .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"`
 
index 0d84d51a8b89d04b5e1d5633b33f3272e0446eeb..c39df45f267fb93c455a8ad5648d4f41f16c1515 100644 (file)
 /* --- 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);
+}