Welcome to mirror list, hosted at ThFree Co, Russian Federation.

make.c « make « action « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9b7541db43c0d1bf8b4fe73d240e43123747cc0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
 * \file   make.c
 * \brief  Support functions for the makefile action.
 * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
 */

#include <assert.h>
#include <stdlib.h>
#include "premake.h"
#include "make.h"
#include "base/cstr.h"
#include "base/error.h"
#include "base/path.h"


/**
 * Given a source file filename, returns the name of the corresponding .o file.
 * \param   filename   The source code filename.
 * \returns The filename of the .o file.
 */
const char* make_get_obj_filename(const char* filename)
{
	const char* basename = path_basename(filename);
	const char* obj_name = cstr_format("$(OBJDIR)/%s.o", basename);
	return obj_name;
}


/**
 * Get the name of the project makefile for a particular project.
 * \param   sess   The current execution session context.
 * \param   prj    The project being requested.
 * \returns If this project is the only object which will generate output to
 *          its target location, then this function will return "Makefile" as
 *          the filename. If any other object shares this output location, it
 *          will return "ProjectName.make" instead, so that both objects may
 *          coexist in the same directory.
 */
const char* make_get_project_makefile(Session sess, Project prj)
{
	const char* my_path;
	const char* their_path;
	int si, sn;

	assert(sess);
	assert(prj);

	/* get the full makefile path for this project */
	my_path = project_get_filename(prj, "Makefile", NULL);

	/* see if any other solution wants to use this same path */
	sn = session_num_solutions(sess);
	for (si = 0; si < sn; ++si)
	{
		int pi, pn;

		Solution sln2 = session_get_solution(sess, si);
		their_path = solution_get_filename(sln2, "Makefile", NULL);
		if (cstr_eq(my_path, their_path))
		{
			/* conflict; use the alternate name */
			my_path = project_get_filename(prj, NULL, ".make");
			return my_path;
		}

		/* check any projects contained by this solution */
		pn = solution_num_projects(sln2);
		for (pi = 0; pi < pn; ++pi)
		{
			Project prj2 = solution_get_project(sln2, pi);
			if (prj != prj2)
			{
				their_path = project_get_filename(prj2, "Makefile", NULL);
				if (cstr_eq(my_path, their_path))
				{
					/* conflict; use the alternate name */
					my_path = project_get_filename(prj, NULL, ".make");
					return my_path;
				}
			}
		}
	}

	/* all good */
	return my_path;
}


/**
 * Build a list of project names contained by the solution.
 * \param   sln    The solution to query.
 * \returns A list of project names. The caller owns this list and must destroy it when done.
 */
Strings make_get_project_names(Solution sln)
{
	Strings result;
	int i, n;

	result = strings_create();
	n = solution_num_projects(sln);
	for (i = 0; i < n; ++i)
	{
		Project prj = solution_get_project(sln, i);
		const char* name = project_get_name(prj);
		strings_add(result, name);
	}

	return result;
}


/**
 * Get the name of the solution makefile for a particular solution. 
 * \param   sess   The current execution session context.
 * \param   sln    The solution being requested.
 * \returns If this solution is the only object which will generate output to
 *          its target location, then this function will return "Makefile" as
 *          the filename. If any other solution shares this output location, it
 *          will return "SolutionName.make" instead, so that both objects may
 *          coexist in the same directory.
 */
const char* make_get_solution_makefile(Session sess, Solution sln)
{
	const char* my_path;
	const char* their_path;
	int i, n;

	assert(sess);
	assert(sln);

	/* get the full makefile path for this solution */
	my_path = solution_get_filename(sln, "Makefile", NULL);

	/* see if any other solution wants to use this same path */
	n = session_num_solutions(sess);
	for (i = 0; i < n; ++i)
	{
		Solution them = session_get_solution(sess, i);
		if (them != sln)
		{
			their_path = solution_get_filename(them, "Makefile", NULL);
			if (cstr_eq(my_path, their_path))
			{
				/* conflict; use the alternate name */
				my_path = solution_get_filename(sln, NULL, ".make");
				return my_path;
			}
		}
	}

	/* all good */
	return my_path;
}