Skip to content

Commit 371aa73

Browse files
committed
Added support for LDFLAGS and config injection
1 parent fb650a6 commit 371aa73

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

src/cfg.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ int SMake_ParseConfig(smake_ctx_t *pCtx)
448448
pValueObj = XJSON_GetObject(pBuildObj, "compiler");
449449
if (pValueObj != NULL) xstrncpy(pCtx->sCompiler, sizeof(pCtx->sCompiler), XJSON_GetString(pValueObj));
450450

451+
pValueObj = XJSON_GetObject(pBuildObj, "inject");
452+
if (pValueObj != NULL) xstrncpy(pCtx->sInjectPath, sizeof(pCtx->sInjectPath), XJSON_GetString(pValueObj));
453+
454+
pValueObj = XJSON_GetObject(pBuildObj, "ldflags");
455+
if (pValueObj != NULL) xstrncpy(pCtx->sLDFlags, sizeof(pCtx->sLDFlags), XJSON_GetString(pValueObj));
456+
451457
pValueObj = XJSON_GetObject(pBuildObj, "overwrite");
452458
if (pValueObj != NULL) pCtx->bOverwrite = XJSON_GetBool(pValueObj);
453459

@@ -544,6 +550,8 @@ int SMake_WriteConfig(smake_ctx_t *pCtx)
544550
if (xstrused(pCtx->sName)) XJSON_AddObject(pBuildObj, XJSON_NewString(NULL, "name", pCtx->sName));
545551
if (xstrused(pCtx->sCompiler)) XJSON_AddObject(pBuildObj, XJSON_NewString(NULL, "compiler", pCtx->sCompiler));
546552
if (xstrused(pCtx->sOutDir)) XJSON_AddObject(pBuildObj, XJSON_NewString(NULL, "outputDir", pCtx->sOutDir));
553+
if (xstrused(pCtx->sInjectPath)) XJSON_AddObject(pBuildObj, XJSON_NewString(NULL, "inject", pCtx->sInjectPath));
554+
if (xstrused(pCtx->sLDFlags)) XJSON_AddObject(pBuildObj, XJSON_NewString(NULL, "ldflags", pCtx->sLDFlags));
547555

548556
if (XArray_Used(&pCtx->flagArr))
549557
{

src/info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#define SMAKE_VERSION_MAX 1
1313
#define SMAKE_VERSION_MIN 1
14-
#define SMAKE_BUILD_NUMBER 19
14+
#define SMAKE_BUILD_NUMBER 20
1515

1616
#ifndef _SMAKE_VERSION_H_
1717
#define _SMAKE_VERSION_H_

src/make.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ void SMake_InitContext(smake_ctx_t *pCtx)
6161
pCtx->sPath[0] = pCtx->sOutDir[0] = '.';
6262
pCtx->sPath[1] = pCtx->sOutDir[1] = XSTR_NUL;
6363

64+
pCtx->sInjectPath[0] = XSTR_NUL;
6465
pCtx->sHeaderDst[0] = XSTR_NUL;
6566
pCtx->sBinaryDst[0] = XSTR_NUL;
6667
pCtx->sCompiler[0] = XSTR_NUL;
68+
pCtx->sLDFlags[0] = XSTR_NUL;
6769
pCtx->sConfig[0] = XSTR_NUL;
6870
pCtx->sName[0] = XSTR_NUL;
6971
pCtx->sMain[0] = XSTR_NUL;
@@ -428,22 +430,36 @@ xbool_t SMake_WriteMake(smake_ctx_t *pCtx)
428430

429431
xbool_t bLDLibs = xstrused(sLd);
430432
if (xstrused(sLd)) XFile_Print(&file, "LD_LIBS = %s\n", sLd);
433+
XFile_Print(&file, "LDFLAGS =%s%s\n", xstrused(pCtx->sLDFlags) ? " " : "", pCtx->sLDFlags);
431434

432435
XFile_Print(&file, "LIBS = %s\n", sLibs);
433436
XFile_Print(&file, "NAME = %s\n", pCtx->sName);
434437
XFile_Print(&file, "ODIR = %s\n", pCtx->sOutDir);
435438
XFile_Print(&file, "OBJ = o\n\n");
436-
XFile_Print(&file, "OBJS = ");
439+
440+
if (xstrused(pCtx->sInjectPath) && XPath_Exists(pCtx->sInjectPath))
441+
{
442+
xbyte_buffer_t fileBuffer;
443+
XPath_LoadBuffer(pCtx->sInjectPath, &fileBuffer);
444+
445+
if (fileBuffer.pData != NULL)
446+
{
447+
XFile_Print(&file, "%s\n\n", (char*)fileBuffer.pData);
448+
XByteBuffer_Clear(&fileBuffer);
449+
}
450+
}
437451

438452
xlogi("Compiler flags: %s %s", sFlags, sIncludes);
439453
xlogi("Linked libraries: %s", sLibs);
440454
xlogi("Custom libraries: %s", sLd);
441455
xlogi("Binary file name: %s", pCtx->sName);
442456
xlogi("Output Directory: %s", pCtx->sOutDir);
457+
xlogi("Inject file: %s", xstrused(pCtx->sInjectPath) ? pCtx->sInjectPath : "None");
443458
xlogi("Compiler: %s", strlen(pCtx->sCompiler) ? pCtx->sCompiler : pCompiler);
444459

445460
XArray_Sort(&pCtx->objArr, SMake_CompareName, NULL);
446461
size_t i, nObjs = XArray_Used(&pCtx->objArr);
462+
XFile_Print(&file, "OBJS = ");
447463

448464
for (i = 0; i < nObjs; i++)
449465
{
@@ -482,8 +498,8 @@ xbool_t SMake_WriteMake(smake_ctx_t *pCtx)
482498

483499
if (bStatic) XFile_Print(&file, "\t$(AR) rcs $(ODIR)/$(NAME) $(OBJECTS)\n");
484500
else if (bShared) XFile_Print(&file, "\t$(%s) -shared -o $(ODIR)/$(NAME) $(OBJECTS)\n", pCompiler);
485-
else if (!bLDLibs) XFile_Print(&file, "\t$(%s) $(%s) -o $(ODIR)/$(NAME) $(OBJECTS) $(LIBS)\n", pCompiler, pCFlags);
486-
else XFile_Print(&file, "\t$(%s) $(%s) -o $(ODIR)/$(NAME) $(OBJECTS) $(LD_LIBS) $(LIBS)\n", pCompiler, pCFlags);
501+
else if (!bLDLibs) XFile_Print(&file, "\t$(%s) $(%s) $(LDFLAGS) -o $(ODIR)/$(NAME) $(OBJECTS) $(LIBS)\n", pCompiler, pCFlags);
502+
else XFile_Print(&file, "\t$(%s) $(%s) $(LDFLAGS) -o $(ODIR)/$(NAME) $(OBJECTS) $(LD_LIBS) $(LIBS)\n", pCompiler, pCFlags);
487503

488504
if (bInstallBinary || bInstallIncludes)
489505
{

src/make.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ typedef struct SMakeContext {
4040
char sCompiler[SMAKE_NAME_MAX];
4141
char sHeaderDst[SMAKE_PATH_MAX];
4242
char sBinaryDst[SMAKE_PATH_MAX];
43+
char sInjectPath[SMAKE_PATH_MAX];
44+
char sLDFlags[SMAKE_LINE_MAX];
4345
char sOutDir[SMAKE_PATH_MAX];
4446
char sConfig[SMAKE_PATH_MAX];
4547
char sPath[SMAKE_PATH_MAX];

0 commit comments

Comments
 (0)