static int bz_autotools__stage(void *user_data) { struct bz_env *env = user_data; const char *package_name; struct cork_path *build_dir; struct cork_path *staging_dir; bool verbose; struct cork_env *exec_env; struct cork_exec *exec; rii_check(bz_stage_message(env, "autotools")); rip_check(package_name = bz_env_get_string(env, "name", true)); clog_info("(%s) Stage using autotools", package_name); rip_check(build_dir = bz_env_get_path(env, "build_dir", true)); rip_check(staging_dir = bz_env_get_path(env, "staging_dir", true)); rie_check(verbose = bz_env_get_bool(env, "verbose", true)); /* Create the staging path */ rii_check(bz_create_directory(cork_path_get(staging_dir), 0750)); /* $ make install */ exec = cork_exec_new("make"); cork_exec_add_param(exec, "make"); cork_exec_add_param(exec, "install"); cork_exec_set_cwd(exec, cork_path_get(build_dir)); exec_env = cork_env_clone_current(); cork_env_add(exec_env, "DESTDIR", cork_path_get(staging_dir)); cork_exec_set_env(exec, exec_env); return bz_subprocess_run_exec(verbose, NULL, exec); }
static void sub_run(int argc, char **argv) { struct cork_env *env; struct cork_exec *exec; struct cork_subprocess_group *group; struct cork_subprocess *sp; if (argc == 0) { cork_command_show_help(&sub, "Missing command"); exit(EXIT_FAILURE); } rp_check_exit(env = cork_env_clone_current()); rp_check_exit(exec = cork_exec_new_with_param_array(argv[0], argv)); cork_exec_set_env(exec, env); if (sub_cwd != NULL) { cork_exec_set_cwd(exec, sub_cwd); } rp_check_exit(group = cork_subprocess_group_new()); rp_check_exit(sp = cork_subprocess_new_exec(exec, NULL, NULL, NULL)); cork_subprocess_group_add(group, sp); ri_check_exit(cork_subprocess_group_start(group)); ri_check_exit(cork_subprocess_group_wait(group)); cork_subprocess_group_free(group); }
static int bz_autotools__test(void *user_data) { struct bz_env *env = user_data; const char *package_name; struct cork_path *build_dir; bool verbose; struct cork_exec *exec; rii_check(bz_test_message(env, "autotools")); /* $ make check */ rip_check(package_name = bz_env_get_string(env, "name", true)); clog_info("(%s) Test using autotools", package_name); rip_check(build_dir = bz_env_get_path(env, "build_dir", true)); rie_check(verbose = bz_env_get_bool(env, "verbose", true)); exec = cork_exec_new("make"); cork_exec_add_param(exec, "make"); cork_exec_add_param(exec, "check"); cork_exec_set_cwd(exec, cork_path_get(build_dir)); return bz_subprocess_run_exec(verbose, NULL, exec); }
static int bz_autotools__build(void *user_data) { struct bz_env *env = user_data; struct bz_value *ctx = bz_env_as_value(env); const char *package_name; struct cork_path *build_dir; struct cork_path *source_dir; struct cork_path *configure; struct bz_value *configure_args; const char *pkgconfig_path; bool exists; bool verbose; struct cork_exec *exec; struct cork_env *exec_env; struct cork_buffer buf = CORK_BUFFER_INIT(); rii_check(bz_install_dependency_string("autoconf", ctx)); rii_check(bz_install_dependency_string("automake", ctx)); rii_check(bz_build_message(env, "autotools")); rip_check(package_name = bz_env_get_string(env, "name", true)); rip_check(build_dir = bz_env_get_path(env, "build_dir", true)); rip_check(source_dir = bz_env_get_path(env, "source_dir", true)); rip_check(configure = bz_env_get_path(env, "autotools.configure.configure", true)); rie_check(pkgconfig_path = bz_env_get_string(env, "pkgconfig.path", false)); rie_check(verbose = bz_env_get_bool(env, "verbose", true)); /* Create the build path */ rii_check(bz_create_directory(cork_path_get(build_dir), 0750)); clog_info("(%s) Configure using autotools", package_name); /* $ autoreconf -i */ rii_check(bz_file_exists(cork_path_get(configure), &exists)); if (!exists) { exec = cork_exec_new("autoreconf"); cork_exec_add_param(exec, "autoreconf"); cork_exec_add_param(exec, "-i"); cork_exec_set_cwd(exec, cork_path_get(source_dir)); ei_check(bz_subprocess_run_exec(verbose, NULL, exec)); } #define add_dir(buzzy_name, param_name) \ do { \ struct cork_path *value; \ ep_check(value = bz_env_get_path(env, buzzy_name, true)); \ cork_buffer_printf(&buf, "--" param_name "=%s", cork_path_get(value)); \ cork_exec_add_param(exec, buf.buf); \ } while (0) /* $ ./configure ... */ exec = cork_exec_new(cork_path_get(configure)); exec_env = cork_env_clone_current(); cork_exec_set_env(exec, exec_env); cork_exec_add_param(exec, cork_path_get(configure)); add_dir("prefix", "prefix"); add_dir("exec_prefix", "exec-prefix"); add_dir("bin_dir", "bindir"); add_dir("sbin_dir", "sbindir"); add_dir("lib_dir", "libdir"); add_dir("libexec_dir", "libexecdir"); add_dir("share_dir", "datadir"); add_dir("man_dir", "mandir"); /* Add custom configure arguments, if given. */ configure_args = bz_env_get_value(env, "autotools.configure.args"); if (configure_args != NULL) { struct bz_configure_add_arg state = { exec, env }; switch (bz_value_kind(configure_args)) { case BZ_VALUE_SCALAR: ei_check(bz_configure_add_arg(&state, configure_args)); break; case BZ_VALUE_ARRAY: ei_check(bz_array_value_map (configure_args, &state, bz_configure_add_arg)); break; case BZ_VALUE_MAP: bz_bad_config("autotools.configure.args cannot be a map"); goto error; default: cork_unreachable(); } } cork_exec_set_cwd(exec, cork_path_get(build_dir)); if (pkgconfig_path != NULL) { cork_env_add(exec_env, "PKG_CONFIG_PATH", pkgconfig_path); } ei_check(bz_subprocess_run_exec(verbose, NULL, exec)); /* $ make */ clog_info("(%s) Build using autotools", package_name); exec = cork_exec_new("make"); cork_exec_add_param(exec, "make"); cork_exec_set_cwd(exec, cork_path_get(build_dir)); ei_check(bz_subprocess_run_exec(verbose, NULL, exec)); cork_buffer_done(&buf); return 0; error: cork_buffer_done(&buf); return -1; }
static int bz_pacman__package(void *user_data) { struct bz_env *env = user_data; struct bz_value *ctx = bz_env_as_value(env); struct cork_path *staging_dir; struct cork_path *binary_package_dir; struct cork_path *package_build_dir; struct cork_path *pkgbuild; struct cork_path *package_file; const char *package_name; const char *version; const char *pkgrel; const char *pkgext; const char *architecture; const char *license; bool verbose; struct cork_env *exec_env; struct cork_exec *exec; struct cork_buffer buf = CORK_BUFFER_INIT(); bool staging_exists; rii_check(bz_install_dependency_string("pacman", ctx)); rii_check(bz_package_message(env, "pacman")); rip_check(package_name = bz_env_get_string(env, "name", true)); clog_info("(%s) Package using pacman", package_name); rip_check(staging_dir = bz_env_get_path(env, "staging_dir", true)); rip_check(binary_package_dir = bz_env_get_path(env, "binary_package_dir", true)); rip_check(package_build_dir = bz_env_get_path(env, "package_build_dir", true)); rip_check(pkgbuild = bz_env_get_path(env, "pacman.pkgbuild", true)); rip_check(package_file = bz_env_get_path(env, "pacman.package_file", true)); rip_check(version = bz_env_get_string(env, "pacman.version", true)); rip_check(pkgrel = bz_env_get_string(env, "pacman.pkgrel", true)); rip_check(pkgext = bz_env_get_string(env, "pacman.pkgext", true)); rip_check(architecture = bz_env_get_string(env, "pacman.arch", true)); rip_check(license = bz_env_get_string(env, "license", true)); rie_check(verbose = bz_env_get_bool(env, "verbose", true)); rii_check(bz_file_exists(cork_path_get(staging_dir), &staging_exists)); if (CORK_UNLIKELY(!staging_exists)) { cork_error_set_printf (ENOENT, "Staging directory %s does not exist", cork_path_get(staging_dir)); return -1; } /* NOTE: pacman runs ldconfig automatically, so unlike the other packagers, * we do NOT need to add an ldconfig call to the post-install and * post-remove scripts. */ /* Create the temporary directory and the packaging destination */ rii_check(bz_create_directory(cork_path_get(package_build_dir), 0750)); rii_check(bz_create_directory(cork_path_get(binary_package_dir), 0750)); /* Create a PKGBUILD file for this package */ cork_buffer_append_printf(&buf, "pkgname='%s'\n", package_name); cork_buffer_append_printf(&buf, "pkgver='%s'\n", version); cork_buffer_append_printf(&buf, "pkgrel='%s'\n", pkgrel); cork_buffer_append_printf(&buf, "arch=('%s')\n", architecture); cork_buffer_append_printf(&buf, "license=('%s')\n", license); rii_check(bz_pacman_fill_deps(env, &buf, "depends", "dependencies")); cork_buffer_append_printf(&buf, "package () {\n" " rm -rf \"${pkgdir}\"\n" " cp -a '%s' \"${pkgdir}\"\n" "}\n", cork_path_get(staging_dir) ); /* Add pre- and post-install scripts, if necessary. */ rii_check(bz_pacman_add_install_scripts(env, &buf)); ei_check(bz_create_file(cork_path_get(pkgbuild), &buf, 0640)); cork_buffer_done(&buf); exec_env = cork_env_clone_current(); cork_env_add(exec_env, "PKGDEST", cork_path_get(binary_package_dir)); cork_env_add(exec_env, "PKGEXT", pkgext); exec = cork_exec_new_with_params("makepkg", "-sf", NULL); cork_exec_set_cwd(exec, cork_path_get(package_build_dir)); cork_exec_set_env(exec, exec_env); clog_info("(%s) Create %s using pacman", package_name, cork_path_get(package_file)); return bz_subprocess_run_exec(verbose, NULL, exec); error: cork_buffer_done(&buf); return -1; }