~sircmpwn/hare unlisted

c3f9c9d6fb70e1992a25bef0deb08dcf37a4bd07 — Drew DeVault 2 months ago 6d2c378
driver: support mixed hare/asm modules

The mixed module is bundled up into an archive.
1 files changed, 72 insertions(+), 12 deletions(-)

M src/hare.c
M src/hare.c => src/hare.c +72 -12
@@ 269,6 269,9 @@ module_from_namespace(struct ha_build_context *ctx,
	struct ha_inputs **nexti = &target->inputs;
	bucket->target = target;

	struct ha_inputs *sinputs = NULL;
	struct ha_inputs **nexts = &sinputs;

	struct ha_manifest_module_input *modinputs = NULL;
	struct ha_manifest_module_input **modinext = &modinputs;
	struct ha_manifest *manifest = ha_open_manifest(ident);


@@ 298,10 301,11 @@ module_from_namespace(struct ha_build_context *ctx,

		struct dirent *ent;
		while ((ent = readdir(d)) != NULL) {
			/* TODO: Other source types; s, ssa, c, user-defined */
			snprintf(path, sizeof(path), "%s/%s",
				p.we_wordv[0], ent->d_name);
			if (!has_suffix(path, ".ha")) {
			/* TODO: Other source types; ssa, c, user-defined */
			if (!has_suffix(path, ".ha")
					&& !has_suffix(path, ".s")) {
				continue;
			}



@@ 310,7 314,7 @@ module_from_namespace(struct ha_build_context *ctx,
			r = stat(path, &st);
			if (r != 0) {
				fprintf(stderr, "error: stat %s: %s\n",
						path, strerror(errno));
					path, strerror(errno));
				exit(1);
			}
			if (!S_ISREG(st.st_mode)) {


@@ 322,15 326,22 @@ module_from_namespace(struct ha_build_context *ctx,

			struct ha_manifest_input *input =
				ha_manifest_input_from_path(manifest, rpath, &st);
			*nexti = calloc(1, sizeof(struct ha_inputs));
			(*nexti)->input = input;
			nexti = &(*nexti)->next;

			struct ha_manifest_module_input *modinput =
				calloc(1, sizeof(struct ha_manifest_module_input));
			modinput->input = input;
			*modinext = modinput;
			modinext = &modinput->next;
			if (has_suffix(path, ".ha")) {
				*nexti = calloc(1, sizeof(struct ha_inputs));
				(*nexti)->input = input;
				nexti = &(*nexti)->next;

				struct ha_manifest_module_input *modinput =
					calloc(1, sizeof(struct ha_manifest_module_input));
				modinput->input = input;
				*modinext = modinput;
				modinext = &modinput->next;
			} else {
				*nexts = calloc(1, sizeof(struct ha_inputs));
				(*nexts)->input = input;
				nexts = &(*nexts)->next;
			}

			++nfiles;
		}


@@ 389,7 400,56 @@ module_from_namespace(struct ha_build_context *ctx,
	ha_target_add_dependency(as, target);
	struct ha_target *o = as_to_object(ctx, path, as->output);
	ha_target_add_dependency(o, as);
	return o;
	struct ha_target *out = o;

	/* Bundle with additional inputs into an archive */
	if (sinputs) {
		struct ha_target *ar =
			calloc(1, sizeof(struct ha_target));
		struct ha_inputs **nexto = &ar->inputs;
		snprintf(path, sizeof(path), "%s/%s.a",
				manifest->path, module->hash);
		struct ha_manifest_input *aroutput =
			calloc(1, sizeof(struct ha_manifest_input));
		aroutput->path = strdup(path);
		ar->output = aroutput;

		int a = 0;
		ar->argv = calloc(1, sizeof(char *) * (8 + nfiles));
		ar->argv[a++] = strdup("ar");
		ar->argv[a++] = strdup("-csr");
		ar->argv[a++] = strdup(path);

		ar->argv[a++] = strdup(o->output->path);
		ha_target_add_dependency(ar, o);

		struct ha_manifest_input *arin =
			calloc(1, sizeof(struct ha_manifest_input));
		*nexto = calloc(1, sizeof(struct ha_inputs));
		arin->path = strdup(o->output->path);
		(*nexto)->input = arin;
		nexto = &(*nexto)->next;

		struct ha_inputs *s = sinputs;
		while (s) {
			struct ha_target *o = as_to_object(ctx, NULL, s->input);
			ar->argv[a++] = strdup(o->output->path);
			ha_target_add_dependency(ar, o);

			arin = calloc(1, sizeof(struct ha_manifest_input));
			arin->path = strdup(o->output->path);
			*nexto = calloc(1, sizeof(struct ha_inputs));
			(*nexto)->input = arin;
			nexto = &(*nexto)->next;

			s = s->next;
		}

		ar->argv[a++] = NULL;
		out = ar;
	}

	return out;
}

static struct ha_target *