From 28744951114e6919c6d293b5bb0b671e7ffb9b2b Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Fri, 23 Jan 2015 00:07:40 +0100 Subject: [PATCH] Remove per-architecture exec-prefixes from filesystem hierarchy. --- Makefile | 52 ++++++-------- build-aux/build-ports.sh | 8 ++- build-aux/compiler.mak | 7 +- build-aux/dirs.mak | 2 +- build-aux/platform.mak | 10 --- doc/user-guide | 7 +- init/init.c++ | 11 +-- kernel/Makefile | 4 +- kernel/kernel.cpp | 15 +--- tix/tix-build.cpp | 144 ++++++++++++++++++++++++++++++--------- tix/tix-collection.cpp | 25 +++++-- tix/tix-install.cpp | 32 ++++----- 12 files changed, 189 insertions(+), 128 deletions(-) diff --git a/Makefile b/Makefile index 3937b738..f860c4c6 100644 --- a/Makefile +++ b/Makefile @@ -41,12 +41,6 @@ include build-aux/dirs.mak export SYSROOT -ifeq ($(BUILD_IS_SORTIX),1) - export C_INCLUDE_PATH=$(SYSROOT)/include - export CPLUS_INCLUDE_PATH=$(SYSROOT)/include - export LIBRARY_PATH=$(SYSROOT)/$(HOST)/lib -endif - BUILD_NAME:=sortix_$(VERSION)_$(MACHINE) INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).initrd @@ -87,18 +81,18 @@ ifeq ($(BUILD_IS_SORTIX),0) exit 1; \ fi endif - mkdir -p "$(INSTALL_ROOTFS)/boot/$(HOST)" - rm -rf "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d" - mkdir -p "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d" - mkdir -p "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d/$(HOST)/bin" + mkdir -p "$(INSTALL_ROOTFS)/boot" + rm -rf "$(INSTALL_ROOTFS)/boot/sortix.initrd.d" + mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d" + mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/bin" for PROGRAM in init mbrfs extfs; do \ - cp "$(INSTALL_ROOTFS)/$(HOST)/bin/$$PROGRAM" "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d/$(HOST)/bin/$$PROGRAM"; \ + cp "$(INSTALL_ROOTFS)/bin/$$PROGRAM" "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/bin/$$PROGRAM"; \ done - mkdir -p "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d/etc" - mkdir -p "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d/etc/init" - cp "$(INSTALL_ROOTFS)/etc/rootfs.uuid" "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d/etc/init/rootfs.uuid" - mkinitrd --format=sortix-initrd-2 "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d" -o "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd" - rm -rf "$(INSTALL_ROOTFS)/boot/$(HOST)/sortix.initrd.d" + mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc" + mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc/init" + cp "$(INSTALL_ROOTFS)/etc/rootfs.uuid" "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc/init/rootfs.uuid" + mkinitrd --format=sortix-initrd-2 "$(INSTALL_ROOTFS)/boot/sortix.initrd.d" -o "$(INSTALL_ROOTFS)/boot/sortix.initrd" + rm -rf "$(INSTALL_ROOTFS)/boot/sortix.initrd.d" .PHONY: sysmerge sysmerge: sysroot @@ -133,16 +127,14 @@ install-build-tools: .PHONY: sysroot-fsh sysroot-fsh: mkdir -p "$(SYSROOT)" - for DIRNAME in boot etc include; do (\ - mkdir -p "$(SYSROOT)/$$DIRNAME" &&\ - mkdir -p "$(SYSROOT)/$$DIRNAME/$(HOST)" \ - ) || exit $$?; done; - mkdir -p "$(SYSROOT)/$(HOST)" - for DIRNAME in bin lib libexec; do (\ - mkdir -p "$(SYSROOT)/$(HOST)/$$DIRNAME" \ - ) || exit $$?; done; + mkdir -p "$(SYSROOT)/bin" + mkdir -p "$(SYSROOT)/boot" + mkdir -p "$(SYSROOT)/etc" mkdir -p "$(SYSROOT)/etc/skel" mkdir -p "$(SYSROOT)/home" + mkdir -p "$(SYSROOT)/include" + mkdir -p "$(SYSROOT)/lib" + mkdir -p "$(SYSROOT)/libexec" mkdir -p "$(SYSROOT)/mnt" mkdir -p "$(SYSROOT)/share" mkdir -p "$(SYSROOT)/src" @@ -293,7 +285,7 @@ release-all-archs: kernel: sysroot sortix.bin: kernel - cp "$(SYSROOT)/boot/$(HOST)/sortix.bin" sortix.bin + cp "$(SYSROOT)/boot/sortix.bin" sortix.bin # Initial ramdisk @@ -305,12 +297,6 @@ $(INITRD): sysroot echo "exclude /next" >> $(INITRD).filter echo "exclude /src/sysroot" >> $(INITRD).filter echo "exclude /tmp" >> $(INITRD).filter - for OTHER_PLATFORM in $(OTHER_PLATFORMS); do \ - echo "exclude /$$OTHER_PLATFORM" >> $(INITRD).filter; \ - echo "exclude /etc/$$OTHER_PLATFORM" >> $(INITRD).filter; \ - echo "exclude /include/$$OTHER_PLATFORM" >> $(INITRD).filter; \ - echo "exclude /tix/$$OTHER_PLATFORM" >> $(INITRD).filter; \ - done; if ! which mkinitrd; then echo You need to install mkinitrd; fi mkinitrd --format=sortix-initrd-2 --filter=$(INITRD).filter "$(SYSROOT)" -o $(INITRD) rm -f $(INITRD).filter @@ -330,7 +316,7 @@ $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz: sysroot $(INITRD) $(SORTIX_BUILDS_DIR rm -rf $(SORTIX_BUILDS_DIR)/tardir mkdir -p $(SORTIX_BUILDS_DIR)/tardir mkdir -p $(SORTIX_BUILDS_DIR)/tardir/boot - cp "$(SYSROOT)/boot/$(HOST)/sortix.bin" $(SORTIX_BUILDS_DIR)/tardir/boot/sortix.bin + cp "$(SYSROOT)/boot/sortix.bin" $(SORTIX_BUILDS_DIR)/tardir/boot/sortix.bin cp $(INITRD) $(SORTIX_BUILDS_DIR)/tardir/boot/sortix.initrd tar --create --xz --file $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz -C $(SORTIX_BUILDS_DIR)/tardir `ls $(SORTIX_BUILDS_DIR)/tardir` rm -rf $(SORTIX_BUILDS_DIR)/tardir @@ -344,7 +330,7 @@ $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso: sysroot $(INITRD) $(SORTIX_BUILDS_DIR) rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso cp -RT isosrc $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso - cp "$(SYSROOT)/boot/$(HOST)/sortix.bin" $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.bin + cp "$(SYSROOT)/boot/sortix.bin" $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.bin cp $(INITRD) $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.initrd grub-mkrescue -o $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso diff --git a/build-aux/build-ports.sh b/build-aux/build-ports.sh index 1e8e34dc..7074f042 100755 --- a/build-aux/build-ports.sh +++ b/build-aux/build-ports.sh @@ -134,16 +134,20 @@ mkdir -p "$SYSROOT" mkdir -p "$SORTIX_REPOSITORY_DIR" # Initialize Tix package management in the system root if absent. -[ -d "$SYSROOT/tix/$HOST" ] || -tix-collection "$SYSROOT" create --platform=$HOST --prefix= +[ -d "$SYSROOT/tix" ] || +tix-collection "$SYSROOT" create --platform=$HOST --prefix= --disable-multiarch # Build all the packages (if needed) and otherwise install them. for PACKAGE in $PACKAGES; do [ -f "$SORTIX_REPOSITORY_DIR/$PACKAGE.tix.tar.xz" ] || +# TODO: After releasing Sortix 1.0, remove the --exec-prefix option after fixing +# the tix-build exec-prefix default to just the prefix rather than the +# prefix plus a host subdirectory. tix-build \ --sysroot="$SYSROOT" \ --host=$HOST \ --prefix= \ + --exec-prefix= \ --destination="$SORTIX_REPOSITORY_DIR" \ "$SORTIX_PORTS_DIR/$PACKAGE" tix-install \ diff --git a/build-aux/compiler.mak b/build-aux/compiler.mak index 09bdeae8..104e9b3a 100644 --- a/build-aux/compiler.mak +++ b/build-aux/compiler.mak @@ -40,12 +40,10 @@ endif ifeq ($(HOST),i486-sortix) MACHINE:=i486 CPU:=x86 - OTHER_PLATFORMS=x86-64-sortix endif ifeq ($(HOST),x86_64-sortix) MACHINE:=x86_64 CPU:=x64 - OTHER_PLATFORMS=i486-sortix endif # Determine the prefix for build tools. @@ -101,6 +99,11 @@ endif ifndef HOSTOBJCOPY HOSTOBJCOPY:=$(HOST_TOOL_PREFIX)objcopy endif +ifdef SYSROOT + HOSTCC:=$(HOSTCC) --sysroot="$(SYSROOT)" + HOSTCXX:=$(HOSTCXX) --sysroot="$(SYSROOT)" + HOSTLD:=$(HOSTLD) --sysroot="$(SYSROOT)" +endif CC:=$(HOSTCC) CXX:=$(HOSTCXX) diff --git a/build-aux/dirs.mak b/build-aux/dirs.mak index c9b1478e..2e180fa0 100644 --- a/build-aux/dirs.mak +++ b/build-aux/dirs.mak @@ -1,6 +1,6 @@ ifeq ($(HOST_IS_SORTIX),1) DEFAULT_PREFIX= - DEFAULT_EXEC_PREFIX=$(PREFIX)/$(HOST) + DEFAULT_EXEC_PREFIX=$(PREFIX) else DEFAULT_PREFIX=/usr/local DEFAULT_EXEC_PREFIX=$(PREFIX) diff --git a/build-aux/platform.mak b/build-aux/platform.mak index 910b93e1..02aac2c3 100644 --- a/build-aux/platform.mak +++ b/build-aux/platform.mak @@ -47,13 +47,3 @@ TARGET?=$(HOST) BUILD_IS_SORTIX:=$(if $(shell echo $(BUILD) | grep sortix$),1,0) HOST_IS_SORTIX:=$(if $(shell echo $(HOST) | grep sortix$),1,0) TARGET_IS_SORTIX:=$(if $(shell echo $(TARGET) | grep sortix$),1,0) - -# Hack to allow easy filtering in the initrd. -ifeq ($(HOST),i486-sortix) - OTHER_PLATFORMS=x86-64-sortix - OTHER_PLATFORM_1=x86-64-sortix -endif -ifeq ($(HOST),x86_64-sortix) - OTHER_PLATFORMS=i486-sortix - OTHER_PLATFORM_1=i486-sortix -endif diff --git a/doc/user-guide b/doc/user-guide index f593d7e2..7ecc25b0 100644 --- a/doc/user-guide +++ b/doc/user-guide @@ -80,20 +80,19 @@ Filesystem Structure This as an incomplete list of the common top level directories in Sortix. +* `/bin` - Programs. * `/boot` - Kernel images, initrd images. * `/dev` - Device filesystem. * `/etc` - System-wide configuration. * `/home` - User directories. * `/include` - Header files. +* `/libexec` - Non-user programs. +* `/lib` - Shared libraries. * `/root` - Directory of the root user. * `/share` - Architecture independent files. * `/share/doc` - Documentation. * `/src` - System source code. * `/tmp` - Temporary files. -* `/$cputype` - Files for $cputype. -* `/$cputype/bin` - Programs for $cputype. -* `/$cputype/lib` - Shared libaries for $cputype. -* `/$cputype/libexec` - Non-user programs for $cputype. Some of these directories not be present or empty on your installation. diff --git a/init/init.c++ b/init/init.c++ index 4b0dd8b8..d616dfae 100644 --- a/init/init.c++ +++ b/init/init.c++ @@ -215,8 +215,7 @@ try_reboot_system: chroot(path); chdir("/"); - assert(getenv("cputype")); - char* init_path = print_string("/%s/bin/init", getenv("cputype")); + const char* init_path = "/bin/init"; execl(init_path, init_path, NULL); exit(127); } @@ -479,13 +478,7 @@ int init_main(int argc, char* argv[]) umask(022); // Set up the PATH variable. - const char* prefix = "/"; - const char* cputype = getenv("cputype"); - const char* suffix = "/bin"; - char* path = new char[strlen(prefix) + strlen(cputype) + strlen(suffix) + 1]; - stpcpy(stpcpy(stpcpy(path, prefix), cputype), suffix); - setenv("PATH", path, 1); - delete[] path; + setenv("PATH", "/bin", 1); // Set the terminal type. setenv("TERM", "sortix", 1); diff --git a/kernel/Makefile b/kernel/Makefile index ac1e1c20..24895ba0 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -214,5 +214,5 @@ install-headers: install-include-dirs headers install-kernel: install-kernel-binary install-kernel-binary: sortix.bin - mkdir -p $(DESTDIR)$(BOOTDIR)/$(HOST) - cp sortix.bin $(DESTDIR)$(BOOTDIR)/$(HOST) + mkdir -p $(DESTDIR)$(BOOTDIR) + cp sortix.bin $(DESTDIR)$(BOOTDIR)/sortix.bin diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 1b8ed5b8..48959e5f 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -648,14 +648,6 @@ static void BootThread(void* /*user*/) } } -#if defined(__i386__) - #define CPUTYPE_STR "i486-sortix" -#elif defined(__x86_64__) - #define CPUTYPE_STR "x86_64-sortix" -#else - #error No cputype environmental variable provided here. -#endif - static void InitThread(void* /*user*/) { // We are the init process's first thread. Let's load the init program from @@ -681,7 +673,7 @@ static void InitThread(void* /*user*/) dtable.Reset(); - const char* initpath = "/" CPUTYPE_STR "/bin/init"; + const char* initpath = "/bin/init"; Ref init = root->open(&ctx, initpath, O_EXEC | O_READ); if ( !init ) PanicF("Could not open %s in early kernel RAM filesystem:\n%s", @@ -711,9 +703,8 @@ static void InitThread(void* /*user*/) int argc = 1; const char* argv[] = { "init", NULL }; - const char* cputype = "cputype=" CPUTYPE_STR; - int envc = 1; - const char* envp[] = { cputype, NULL }; + int envc = 0; + const char* envp[] = { NULL }; struct thread_registers regs; assert((((uintptr_t) ®s) & (alignof(regs)-1)) == 0); diff --git a/tix/tix-build.cpp b/tix/tix-build.cpp index ab9411b3..320ee797 100644 --- a/tix/tix-build.cpp +++ b/tix/tix-build.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2013. + Copyright(C) Jonas 'Sortie' Termansen 2013, 2014, 2015. This file is part of Tix. @@ -107,6 +107,7 @@ typedef struct char* package_info_path; char* package_name; char* prefix; + char* exec_prefix; char* sysroot; char* tar; char* target; @@ -140,11 +141,22 @@ bool has_in_path(const char* program) _exit(1); } +void emit_compiler_wrapper_invocation(FILE* wrapper, + metainfo_t* minfo, + const char* name) +{ + fprintf(wrapper, "%s", name); + if ( minfo->sysroot ) + fprintf(wrapper, " --sysroot=\"$SYSROOT\""); + fprintf(wrapper, " \"$@\""); +} + void emit_compiler_warning_wrapper(metainfo_t* minfo, const char* bindir, const char* name) { - (void) minfo; + if ( !minfo->sysroot ) + return; if ( !has_in_path(name) ) return; const char* warnings_dir = getenv("TIX_WARNINGS_DIR"); @@ -156,14 +168,22 @@ void emit_compiler_warning_wrapper(metainfo_t* minfo, fprintf(wrapper, "#!/bin/bash\n"); fprint_shell_variable_assignment(wrapper, "PATH", getenv("PATH")); fprint_shell_variable_assignment(wrapper, "TIX_WARNINGS_DIR", warnings_dir); + if ( minfo->sysroot ) + fprint_shell_variable_assignment(wrapper, "SYSROOT", minfo->sysroot); fprintf(wrapper, "warnfile=$(mktemp --tmpdir=\"$TIX_WARNINGS_DIR\")\n"); - fprintf(wrapper, "(%s \"$@\") 2> >(tee $warnfile >&2)\n", name); + fprintf(wrapper, "("); + emit_compiler_wrapper_invocation(wrapper, minfo, name); + fprintf(wrapper, ") 2> >(tee $warnfile >&2)\n"); fprintf(wrapper, "exitstatus=$?\n"); fprintf(wrapper, "if test -s \"$warnfile\"; then\n"); fprintf(wrapper, " if test $exitstatus = 0; then\n"); - fprintf(wrapper, " (echo \"cd $(pwd) && %s $@\" && cat \"$warnfile\") > \"$warnfile.warn\"\n", name); + fprintf(wrapper, " (echo \"cd $(pwd) && "); + emit_compiler_wrapper_invocation(wrapper, minfo, name); + fprintf(wrapper, " && cat \"$warnfile\") > \"$warnfile.warn\"\n"); fprintf(wrapper, " else\n"); - fprintf(wrapper, " (echo \"cd $(pwd) && %s $@\" && cat \"$warnfile\") > \"$warnfile.err\"\n", name); + fprintf(wrapper, " (echo \"cd $(pwd) && "); + emit_compiler_wrapper_invocation(wrapper, minfo, name); + fprintf(wrapper, " && cat \"$warnfile\") > \"$warnfile.err\"\n"); fprintf(wrapper, " fi\n"); fprintf(wrapper, "fi\n"); fprintf(wrapper, "rm -f \"$warnfile\"\n"); @@ -184,6 +204,38 @@ void emit_compiler_warning_cross_wrapper(metainfo_t* minfo, free(cross_name); } +void emit_compiler_sysroot_wrapper(metainfo_t* minfo, + const char* bindir, + const char* name) +{ + if ( !has_in_path(name) ) + return; + char* wrapper_path = print_string("%s/%s", bindir, name); + FILE* wrapper = fopen(wrapper_path, "w"); + if ( !wrapper ) + error(1, errno, "`%s'", wrapper_path); + fprint_shell_variable_assignment(wrapper, "PATH", getenv("PATH")); + if ( minfo->sysroot ) + fprint_shell_variable_assignment(wrapper, "SYSROOT", minfo->sysroot); + fprintf(wrapper, "exec "); + emit_compiler_wrapper_invocation(wrapper, minfo, name); + fprintf(wrapper, "\n"); + fflush(wrapper); + fchmod_plus_x(fileno(wrapper)); + fclose(wrapper); + + free(wrapper_path); +} + +void emit_compiler_sysroot_cross_wrapper(metainfo_t* minfo, + const char* bindir, + const char* name) +{ + char* cross_name = print_string("%s-%s", minfo->host, name); + emit_compiler_sysroot_wrapper(minfo, bindir, cross_name); + free(cross_name); +} + void emit_pkg_config_wrapper(metainfo_t* minfo) { char* bindir = print_string("%s/tmppid.%ju.bin", minfo->tmp, (uintmax_t) getpid()); @@ -228,8 +280,8 @@ void emit_pkg_config_wrapper(metainfo_t* minfo) char* var_pkg_config = print_string("%s/pkg-config", bindir); char* var_pkg_config_for_build = print_string("%s/build-pkg-config", bindir); char* var_pkg_config_libdir = - print_string("%s%s/%s/lib/pkgconfig", - minfo->sysroot, minfo->prefix, minfo->host); + print_string("%s%s/lib/pkgconfig", + minfo->sysroot, minfo->exec_prefix); char* var_pkg_config_path = print_string("%s", var_pkg_config_libdir); char* var_pkg_config_sysroot_dir = print_string("%s", minfo->sysroot); setenv("PKG_CONFIG", var_pkg_config, 1); @@ -258,6 +310,12 @@ void emit_pkg_config_wrapper(metainfo_t* minfo) free(warnings_dir); } + emit_compiler_sysroot_cross_wrapper(minfo, bindir, "cc"); + emit_compiler_sysroot_cross_wrapper(minfo, bindir, "gcc"); + emit_compiler_sysroot_cross_wrapper(minfo, bindir, "c++"); + emit_compiler_sysroot_cross_wrapper(minfo, bindir, "g++"); + emit_compiler_sysroot_cross_wrapper(minfo, bindir, "ld"); + if ( getenv("TIX_WARNINGS_DIR") ) { emit_compiler_warning_wrapper(minfo, bindir, "cc"); @@ -297,6 +355,15 @@ void Configure(metainfo_t* minfo) bool with_sysroot = parse_boolean(dictionary_get(pkg_info, "pkg.configure.with-sysroot", "false")); + // After releasing Sortix 1.0, remove this and hard-code the default o + // false. This allows building Sortix 0.9 with its own ports using this + // tix-build version. + const char* with_sysroot_ld_bug_default = "false"; + if ( !strcmp(minfo->package_name, "binutils") ) + with_sysroot_ld_bug_default = "true"; + bool with_sysroot_ld_bug = + parse_boolean(dictionary_get(pkg_info, "pkg.configure.with-sysroot-ld-bug", + with_sysroot_ld_bug_default )); bool with_build_sysroot = parse_boolean(dictionary_get(pkg_info, "pkg.configure.with-build-sysroot", "false")); @@ -322,7 +389,7 @@ void Configure(metainfo_t* minfo) print_string("--host=%s", minfo->host), print_string("--target=%s", minfo->target), print_string("--prefix=%s", minfo->prefix), - print_string("--exec-prefix=%s/%s", minfo->prefix, minfo->host), + print_string("--exec-prefix=%s", minfo->exec_prefix), NULL }; string_array_t args = string_array_make(); @@ -333,18 +400,20 @@ void Configure(metainfo_t* minfo) string_array_append(&args, print_string("--with-build-sysroot=%s", minfo->sysroot)); if ( minfo->sysroot && with_sysroot ) - string_array_append(&args, "--with-sysroot=/"); - unsetenv("HOST_SYSTEM_ROOT"); + { + // TODO: Binutils has a bug where the empty string means that + // sysroot support is disabled and ld --sysroot won't work + // so set it to / here for compatibility. + if ( with_sysroot_ld_bug ) + string_array_append(&args, "--with-sysroot=/"); + else + string_array_append(&args, "--with-sysroot="); + } } else if ( minfo->sysroot && with_sysroot ) { string_array_append(&args, print_string("--with-sysroot=%s", minfo->sysroot)); - unsetenv("HOST_SYSTEM_ROOT"); - } - else if ( minfo->sysroot ) - { - setenv("HOST_SYSTEM_ROOT", minfo->sysroot, 1); } string_array_append_token_string(&args, conf_extra_args); string_array_append(&args, NULL); @@ -379,12 +448,6 @@ void Make(metainfo_t* minfo, const char* make_target, if ( dictionary_get(pkg_info, "pkg.make.needed-vars.CXX", NULL) ) setenv("CXX", strcmp(minfo->build, minfo->host) ? print_string("%s-g++", minfo->host) : "g++", 1); - bool with_sysroot = - parse_boolean(dictionary_get(pkg_info, "pkg.configure.with-sysroot", - "false")); - bool with_build_sysroot = - parse_boolean(dictionary_get(pkg_info, "pkg.configure.with-build-sysroot", - "false")); if ( chdir(minfo->build_dir) != 0 ) error(1, errno, "chdir: `%s'", minfo->build_dir); if ( subdir && chdir(subdir) != 0 ) @@ -395,13 +458,13 @@ void Make(metainfo_t* minfo, const char* make_target, setenv("HOST", minfo->host, 1); setenv("TARGET", minfo->target, 1); if ( minfo->prefix ) - setenv("PREFIX", minfo->prefix, 1), - setenv("EXEC_PREFIX", join_paths(minfo->prefix, minfo->host), 1); + setenv("PREFIX", minfo->prefix, 1); + else + unsetenv("PREFIX"); + if ( minfo->exec_prefix ) + setenv("EXEC_PREFIX", minfo->exec_prefix, 1); else - unsetenv("PREFIX"), unsetenv("EXEC_PREFIX"); - if ( !(with_sysroot || with_build_sysroot) && minfo->sysroot ) - setenv("HOST_SYSTEM_ROOT", minfo->sysroot, 1); if ( minfo->makeflags ) setenv("MAKEFLAGS", minfo->makeflags, 1); setenv("MAKE", minfo->make, 1); @@ -530,14 +593,20 @@ void BuildPackage(metainfo_t* minfo) setenv("TIX_BUILD_DIR", minfo->build_dir, 1); setenv("TIX_SOURCE_DIR", minfo->package_dir, 1); setenv("TIX_INSTALL_DIR", destdir, 1); + if ( minfo->sysroot ) + setenv("TIX_SYSROOT", minfo->sysroot, 1); + else + unsetenv("TIX_SYSROOT"); setenv("BUILD", minfo->build, 1); setenv("HOST", minfo->host, 1); setenv("TARGET", minfo->target, 1); if ( minfo->prefix ) - setenv("PREFIX", minfo->prefix, 1), - setenv("EXEC_PREFIX", join_paths(minfo->prefix, minfo->host), 1); + setenv("PREFIX", minfo->prefix, 1); + else + unsetenv("PREFIX"); + if ( minfo->exec_prefix ) + setenv("EXEC_PREFIX", minfo->exec_prefix, 1); else - unsetenv("PREFIX"), unsetenv("EXEC_PREFIX"); const char* cmd_argv[] = { @@ -693,7 +762,8 @@ int main(int argc, char* argv[]) minfo.makeflags = strdup_null(getenv_def("MAKEFLAGS", NULL)); minfo.make = strdup(getenv_def("MAKE", "make")); minfo.prefix = strdup_null(getenv_def("PREFIX", NULL)); - minfo.sysroot = strdup_null(getenv_def("HOST_SYSTEM_ROOT", NULL)); + minfo.exec_prefix = strdup_null(getenv_def("EXEC_PREFIX", NULL)); + minfo.sysroot = strdup_null(getenv_def("SYSROOT", NULL)); minfo.target = NULL; minfo.tar = strdup(getenv_def("TAR", "tar")); minfo.tmp = strdup(getenv_def("BUILDTMP", ".")); @@ -729,6 +799,7 @@ int main(int argc, char* argv[]) else if ( GET_OPTION_VARIABLE("--makeflags", &minfo.makeflags) ) { } else if ( GET_OPTION_VARIABLE("--make", &minfo.make) ) { } else if ( GET_OPTION_VARIABLE("--prefix", &minfo.prefix) ) { } + else if ( GET_OPTION_VARIABLE("--exec-prefix", &minfo.exec_prefix) ) { } else if ( GET_OPTION_VARIABLE("--start", &start_step_string) ) { } else if ( GET_OPTION_VARIABLE("--sysroot", &minfo.sysroot) ) { } else if ( GET_OPTION_VARIABLE("--target", &minfo.target) ) { } @@ -786,12 +857,23 @@ int main(int argc, char* argv[]) error(1, errno, "canonicalize_file_name: `%s'", argv[1]); if ( !minfo.build && !(minfo.build = GetBuildTriplet()) ) - error(1, errno, "unable to determine host, use --host or BUILD"); + error(1, errno, "unable to determine build, use --build or BUILD"); if ( !minfo.host && !(minfo.host = strdup_null(getenv("HOST"))) ) minfo.host = strdup(minfo.build); if ( !minfo.target && !(minfo.target = strdup_null(getenv("TARGET"))) ) minfo.target = strdup(minfo.host); + if ( minfo.prefix && !minfo.exec_prefix ) + { +// TODO: After releasing Sortix 1.0, switch to this branch that defaults the +// exec-prefix to the prefix. +#if 0 + minfo.exec_prefix = strdup(minfo.prefix); +#else // Sortix 0.9 compatibility. + minfo.exec_prefix = print_string("%s/%s", minfo.prefix, minfo.host); +#endif + } + if ( !IsDirectory(minfo.package_dir) ) error(1, errno, "`%s'", minfo.package_dir); diff --git a/tix/tix-collection.cpp b/tix/tix-collection.cpp index 1ad6801b..c75149ef 100644 --- a/tix/tix-collection.cpp +++ b/tix/tix-collection.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2013. + Copyright(C) Jonas 'Sortie' Termansen 2013, 2015. This file is part of Tix. @@ -65,6 +65,13 @@ int main(int argc, char* argv[]) char* collection = strdup_null(getenv_def("TIX_COLLECTION", NULL)); char* platform = NULL; char* prefix = NULL; + // TODO: After releasing Sortix 1.0, keep the --disable-multiarch option + // supported (but ignored), delete all uses of --disable-multiarch, + // delete the --enable-multiarch option, delete the use_multiarch=true + // case code. Simplify all of this code, remove the tixdb abstraction. + // TODO: After releasing Sortix 1.1, delete the --disable-multiarch option + // compatibility. + bool use_multiarch = true; const char* argv0 = argv[0]; for ( int i = 0; i < argc; i++ ) @@ -91,6 +98,8 @@ int main(int argc, char* argv[]) else if ( GET_OPTION_VARIABLE("--collection", &collection) ) { } else if ( GET_OPTION_VARIABLE("--platform", &platform) ) { } else if ( GET_OPTION_VARIABLE("--prefix", &prefix) ) { } + else if ( !strcmp(arg, "--enable-multiarch") ) { use_multiarch = true; } + else if ( !strcmp(arg, "--disable-multiarch") ) { use_multiarch = false; } else { fprintf(stderr, "%s: unknown option: `%s'\n", argv0, arg); @@ -130,9 +139,17 @@ int main(int argc, char* argv[]) if ( mkdir_p(tix_path, 0777) != 0 ) error(1, errno, "mkdir: `%s'", tix_path); - char* tixdb_path = join_paths(tix_path, platform); - if ( mkdir_p(tixdb_path, 0777) != 0 ) - error(1, errno, "mkdir: `%s'", tixdb_path); + char* tixdb_path; + if ( use_multiarch ) + { + tixdb_path = join_paths(tix_path, platform); + if ( mkdir_p(tixdb_path, 0777) != 0 ) + error(1, errno, "mkdir: `%s'", tixdb_path); + } + else + { + tixdb_path = strdup(tix_path); + } char* collection_conf_path = join_paths(tixdb_path, "collection.conf"); FILE* conf_fp = fopen(collection_conf_path, "wx"); diff --git a/tix/tix-install.cpp b/tix/tix-install.cpp index 972ed7fa..996fedf2 100644 --- a/tix/tix-install.cpp +++ b/tix/tix-install.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2013. + Copyright(C) Jonas 'Sortie' Termansen 2013, 2015. This file is part of Tix. @@ -52,13 +52,6 @@ void TipTixCollection(const char* prefix) "installing packages.", prefix); } -void TipTixWrongPlatform(const char* prefix, const char* platform) -{ - error(0, 0, "error: `%s' isn't a tix collection for platform `%s', use " - "tix-collection to add this platform before installing " - "packages.", prefix, platform); -} - void VerifyTixCollection(const char* prefix) { if ( !IsDirectory(prefix) ) @@ -80,16 +73,10 @@ void VerifyTixDirectory(const char* prefix, const char* tix_dir) } void VerifyTixDatabase(const char* prefix, - const char* tixdb_path, - const char* platform) + const char* tixdb_path) { if ( !IsDirectory(tixdb_path) ) - { - if ( errno == ENOENT ) - TipTixWrongPlatform(prefix, platform); - error(1, errno, "error: tix database for platform `%s' unavailable: " - "`%s'", platform, tixdb_path); - } + error(1, errno, "error: tix database unavailable: `%s'", tixdb_path); char* info_path = join_paths(tixdb_path, "collection.conf"); if ( !IsFile(info_path) ) { @@ -277,10 +264,19 @@ int main(int argc, char* argv[]) const char* package_platform = dictionary_get(&tixinfo, "tix.platform"); assert(package_platform); + // TODO: After releasing Sortix 1.0, delete this compatibility. char* tixdb_path = join_paths(tix_directory_path, package_platform); - free(tix_directory_path); + if ( IsDirectory(tixdb_path ) ) + { + free(tix_directory_path); + } + else + { + free(tixdb_path); + tixdb_path = tix_directory_path; + } - VerifyTixDatabase(collection, tixdb_path, package_platform); + VerifyTixDatabase(collection, tixdb_path); char* coll_conf_path = join_paths(tixdb_path, "collection.conf"); string_array_t coll_conf = string_array_make();