summaryrefslogtreecommitdiff
path: root/myrbuild
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2012-09-27 18:54:21 -0400
committerOri Bernstein <orib@google.com>2012-09-27 18:54:21 -0400
commitbccf793446bc1afadce825b98000c3664544d114 (patch)
tree8de6a987680a5d3617770a825a690ee4e2b9a486 /myrbuild
parent78778360e002afa56e02847d22b283d2ace56a88 (diff)
downloadmc-bccf793446bc1afadce825b98000c3664544d114.tar.gz
Start working on a build tool.
Diffstat (limited to 'myrbuild')
-rw-r--r--myrbuild/Makefile6
-rw-r--r--myrbuild/muse.c145
-rw-r--r--myrbuild/myrbuild.c108
3 files changed, 111 insertions, 148 deletions
diff --git a/myrbuild/Makefile b/myrbuild/Makefile
index 7cc6da5..7af2e69 100644
--- a/myrbuild/Makefile
+++ b/myrbuild/Makefile
@@ -1,6 +1,6 @@
-INSTBIN=muse
-BIN=muse
-OBJ=muse.o
+INSTBIN=myrbuild
+BIN=myrbuild
+OBJ=myrbuild.o
DEPS=../parse/libparse.a
diff --git a/myrbuild/muse.c b/myrbuild/muse.c
deleted file mode 100644
index 42ae747..0000000
--- a/myrbuild/muse.c
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <ctype.h>
-#include <string.h>
-#include <assert.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "parse.h"
-
-/* FIXME: move into one place...? */
-Node *file;
-char *outfile;
-int merge;
-int debug;
-char debugopt[128];
-char **incpaths;
-size_t nincpaths;
-
-static void usage(char *prog)
-{
- printf("%s [-hIdos] [-o outfile] [-m] inputs\n", prog);
- printf("\t-h\tprint this help\n");
- printf("\t-m\ttreat the inputs as usefiles and merge them into outfile\n");
- printf("\t\tThe outfile must be the same name as each package merged.\n");
- printf("\t-I path\tAdd 'path' to use search path\n");
- printf("\t-d\tPrint debug dumps\n");
- printf("\t-o out\tOutput to outfile\n");
- printf("\t-s\tShow the contents of usefiles `inputs`\n");
-}
-
-static void dumpuse(char *path)
-{
- Stab *globls;
- FILE *f;
-
- globls = file->file.globls;
- f = fopen(path, "r");
- loaduse(f, globls);
- fclose(f);
- dumpstab(globls, stdout);
-}
-
-static void genuse(char *path)
-{
- Stab *globls;
- char *p;
- FILE *f;
- char buf[1024];
-
- globls = file->file.globls;
- tyinit(globls);
- tokinit(path);
- yyparse();
-
- infer(file);
- if (outfile) {
- p = outfile;
- } else {
- swapsuffix(buf, sizeof buf, path, ".myr", ".use");
- p = buf;
- }
- f = fopen(p, "w");
- writeuse(f, file);
- fclose(f);
-}
-
-static void mergeuse(char *path)
-{
- FILE *f;
- Stab *st;
-
- st = file->file.exports;
- f = fopen(path, "r");
- if (!f)
- die("Couldn't open %s\n", path);
- loaduse(f, st);
- fclose(f);
-}
-
-int main(int argc, char **argv)
-{
- FILE *f;
- int opt;
- int i;
-
- while ((opt = getopt(argc, argv, "d::hmo:I:")) != -1) {
- switch (opt) {
- case 'h':
- usage(argv[0]);
- exit(0);
- break;
- case 'm':
- merge = 1;
- break;
- case 'o':
- outfile = optarg;
- break;
- case 'd':
- debug = 1;
- while (optarg && *optarg)
- debugopt[*optarg++ & 0x7f] = 1;
- break;
- case 'I':
- lappend(&incpaths, &nincpaths, optarg);
- break;
- default:
- usage(argv[0]);
- exit(0);
- break;
- }
- }
-
- if (merge) {
- if (!outfile) {
- fprintf(stderr, "Output file needed when merging usefiles.");
- exit(1);
- }
-
- file = mkfile("internal");
- file->file.exports = mkstab();
- file->file.globls = mkstab();
- updatens(file->file.exports, outfile);
- for (i = optind; i < argc; i++)
- mergeuse(argv[i]);
- f = fopen(outfile, "w");
- writeuse(f, file);
- fclose(f);
- } else {
- for (i = optind; i < argc; i++) {
- file = mkfile(argv[i]);
- file->file.exports = mkstab();
- file->file.globls = mkstab();
- if (debugopt['s'])
- dumpuse(argv[i]);
- else
- genuse(argv[i]);
- }
- }
-
- return 0;
-}
diff --git a/myrbuild/myrbuild.c b/myrbuild/myrbuild.c
new file mode 100644
index 0000000..b727465
--- /dev/null
+++ b/myrbuild/myrbuild.c
@@ -0,0 +1,108 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <ctype.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <regex.h>
+
+#include "parse.h"
+
+/* make libparse happy */
+Node *file;
+
+char *libname;
+char *binname;
+char **incpaths;
+size_t nincpaths;
+
+regex_t usepat;
+
+static void usage(char *prog)
+{
+ printf("%s [-h] [-I path] [-l lib] [-b bin] inputs...\n", prog);
+ printf("\t-h\tprint this help\n");
+ printf("\t-b bin\tBuild a binary called 'bin'\n");
+ printf("\t-l lib\tBuild a library called 'name'\n");
+ printf("\t-I path\tAdd 'path' to use search path\n");
+}
+
+void getdeps(char *file)
+{
+ char buf[2048]; /* if you hit this limit, shoot yourself */
+
+ regmatch_t m[2];
+ char *usepath;
+ FILE *f;
+
+ f = fopen(file, "r");
+ if (!f)
+ die("Could not open file %s\n", file);
+
+ while (fgets(buf, sizeof buf, f)) {
+ if (regexec(&usepat, buf, 2, m, 0) == REG_NOMATCH)
+ continue;
+ usepath = strdupn(&buf[m[1].rm_so], m[1].rm_eo - m[1].rm_so);
+ printf("use = %s\n", usepath);
+ }
+}
+
+void compile()
+{
+}
+
+int main(int argc, char **argv)
+{
+ int opt;
+ int i;
+
+ while ((opt = getopt(argc, argv, "hb:l:I:")) != -1) {
+ switch (opt) {
+ case 'b':
+ binname = optarg;
+ break;
+ case 'l':
+ libname = optarg;
+ break;
+ case 'I':
+ lappend(&incpaths, &nincpaths, optarg);
+ break;
+ case 'h':
+ usage(argv[0]);
+ exit(0);
+ break;
+ default:
+ usage(argv[0]);
+ exit(0);
+ break;
+ }
+ }
+
+ if (libname && binname)
+ die("Can't specify both library and binary names");
+
+ switch (regcomp(&usepat, "^[[:space:]]*use[[:space:]]+([^[:space:]]+)", REG_EXTENDED)) {
+ case REG_BADBR: die("case REG_BADBR:"); break;
+ case REG_BADPAT: die("case REG_BADPAT:"); break;
+ case REG_BADRPT: die("case REG_BADRPT:"); break;
+ case REG_EBRACE: die("case REG_EBRACE:"); break;
+ case REG_EBRACK: die("case REG_EBRACK:"); break;
+ case REG_ECOLLATE: die("case REG_ECOLLATE:"); break;
+ case REG_EEND: die("case REG_EEND:"); break;
+ case REG_EESCAPE: die("case REG_EESCAPE:"); break;
+ case REG_EPAREN: die("case REG_EPAREN:"); break;
+ case REG_ERANGE: die("case REG_ERANGE:"); break;
+ case REG_ESIZE: die("case REG_ESIZE:"); break;
+ case REG_ESPACE: die("case REG_ESPACE:"); break;
+ case REG_ESUBREG: die("case REG_ESUBREG:"); break;
+ }
+ for (i = optind; i < argc; i++)
+ getdeps(argv[i]);
+
+ return 0;
+}