Example #1
0
func (r *OpenSSLRecipe) Finalize(ctx *types.BuildContext, outDir string) error {
	srcdir := r.UnpackedDir(ctx, r.Info())
	ctx.AddDependentEnvVar(
		"CPPFLAGS",
		"-I"+filepath.Join(srcdir, "include"),
	)
	ctx.AddDependentEnvVar(
		"LDFLAGS",
		"-L"+srcdir+" -lcrypto -lssl",
	)
	return nil
}
Example #2
0
func (r *ZlibRecipe) Finalize(ctx *types.BuildContext, outDir string) error {
	srcdir := r.UnpackedDir(ctx, r.Info())
	ctx.AddDependentEnvVar(
		"CPPFLAGS",
		"-I"+srcdir,
	)
	ctx.AddDependentEnvVar(
		"LDFLAGS",
		"-L"+srcdir+" -lz",
	)
	return nil
}
Example #3
0
func (r *LzmaRecipe) Finalize(ctx *types.BuildContext, outDir string) error {
	srcdir := filepath.Join(ctx.SourceDir, fmt.Sprintf("xz-%s", r.Info().Version))
	ctx.AddDependentEnvVar(
		"CPPFLAGS",
		"-I"+filepath.Join(srcdir, "src", "liblzma", "api"),
	)
	ctx.AddDependentEnvVar(
		"LDFLAGS",
		"-L"+filepath.Join(srcdir, "src", "liblzma", ".libs")+" -llzma",
	)
	return nil
}
Example #4
0
func (r *IconvRecipe) Finalize(ctx *types.BuildContext, outDir string) error {
	srcdir := r.UnpackedDir(ctx, r.Info())
	ctx.AddDependentEnvVar(
		"CPPFLAGS",
		"-I"+filepath.Join(srcdir, "include"),
	)
	ctx.AddDependentEnvVar(
		"LDFLAGS",
		"-L"+filepath.Join(srcdir, "lib", ".libs")+" -liconv",
	)
	return nil
}
Example #5
0
func buildOne(name string, ctx *context) error {
	log.WithField("recipe", name).Info("Building single recipe")
	recipe := recipesRegistry[name]

	// Remove and re-create the source directory for this build.
	sourceDir := filepath.Join(ctx.config.BuildDir, name)
	if err := os.RemoveAll(sourceDir); err != nil {
		log.WithFields(logrus.Fields{
			"recipe": name,
			"err":    err,
		}).Error("Could not remove source directory")
		return err
	}
	if err := os.Mkdir(sourceDir, 0700); err != nil {
		log.WithFields(logrus.Fields{
			"recipe": name,
			"err":    err,
		}).Error("Could not create source directory")
		return err
	}

	info := recipe.Info()
	for i, source := range info.Sources {
		// Expand the source.
		expandedSource := os.Expand(source, func(vname string) string {
			if vname == "name" {
				return info.Name
			} else if vname == "version" {
				return info.Version
			}

			panic(fmt.Sprintf("unknown expansion variable: %s", vname))
		})

		// Fetch the source
		if err := ctx.cache.Fetch(
			name,
			expandedSource,
			info.Sums[i],
			sourceDir,
		); err != nil {
			log.WithFields(logrus.Fields{
				"recipe": name,
				"source": expandedSource,
				"hash":   info.Sums[i],
				"err":    err,
			}).Error("Could not fetch source")
			return err
		}

		filename, _ := SplitSource(expandedSource)
		sourcePath := filepath.Join(sourceDir, filename)

		// Unpack it.
		if err := util.UnpackArchive(sourcePath, sourceDir); err != nil {
			log.WithFields(logrus.Fields{
				"recipe": name,
				"source": expandedSource,
				"err":    err,
			}).Error("Could not unpack source")
			return err
		}
	}

	// Make the environment for this build.  We do this by taking the root
	// environment, and then merging in all flags from the recursive tree of
	// dependencies.
	deps := dependencyNames(name, ctx.config.Platform, ctx.config.Arch)
	env := ctx.rootEnv
	envMap := make(map[string]map[string]string)
	for _, dep := range deps {
		if flags, ok := ctx.packageEnv[dep]; ok {
			envMap[dep] = flags
			for k, v := range flags {
				env = env.Append(k, " "+v+" ")
			}
		}
	}

	// Set up cross compiler environment.
	prefix := CrossPrefix(ctx.config.Platform, ctx.config.Arch)
	env = setCrossEnv(prefix, env)

	// We special-case darwin here, since we're using osxcross.
	if ctx.config.Platform == "darwin" {
		env = env.
			Set("CC", prefix+"-clang").
			Set("CXX", prefix+"-clang++").
			Set("OSXCROSS_NO_INCLUDE_PATH_WARNINGS", "1")
	}

	// Set up the static flag
	var staticFlag string
	if ctx.config.Platform == "darwin" {
		staticFlag = " -flto -O3 -mmacosx-version-min=10.6 "
	} else {
		staticFlag = " -static "
	}

	// Set up the random seed we pass to each build.  This is a part of the
	// compiler command to ensure that it gets passed correctly.
	if DETERMINISTIC {
		randomSeed := fmt.Sprintf(
			" -frandom-seed=build-%s-%s-%s ",
			name,
			ctx.config.Platform,
			ctx.config.Arch,
		)
		env = env.Append("CC", randomSeed).Append("CXX", randomSeed)
	}

	// Run the build in this directory.
	buildCtx := types.BuildContext{
		SourceDir:     sourceDir,
		Env:           env,
		CrossPrefix:   prefix,
		StaticFlags:   staticFlag,
		Platform:      ctx.config.Platform,
		Arch:          ctx.config.Arch,
		DependencyEnv: envMap,
	}

	if err := recipe.Prepare(&buildCtx); err != nil {
		log.WithFields(logrus.Fields{
			"recipe": name,
			"err":    err,
		}).Error("Prepare failed")
		return err
	}
	if err := recipe.Build(&buildCtx); err != nil {
		log.WithFields(logrus.Fields{
			"recipe": name,
			"err":    err,
		}).Error("Build failed")
		return err
	}

	// Now, fill in the environment variable function.
	buildCtx.AddDependentEnvVar = func(key, value string) {
		mm, ok := ctx.packageEnv[name]
		if !ok {
			mm = make(map[string]string)
			ctx.packageEnv[name] = mm
		}

		mm[key] = value
	}

	// Create the output directory for this recipe.
	outDir := filepath.Join(
		ctx.config.OutputDir,
		name,
		info.Version,
	)
	if err := os.MkdirAll(outDir, 0755); err != nil {
		log.WithFields(logrus.Fields{
			"recipe": name,
			"outDir": outDir,
			"err":    err,
		}).Error("Could not create output directory")
		return err
	}

	if err := recipe.Finalize(&buildCtx, outDir); err != nil {
		log.WithFields(logrus.Fields{
			"recipe": name,
			"err":    err,
		}).Error("Finalize failed")
		return err
	}

	return nil
}