Skip to content

Commit 9e1393e

Browse files
committed
ported over ac2ver tool to generate PACKAGE_VERSION when compiling with Visual Studio
1 parent dde8b0c commit 9e1393e

10 files changed

+156
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ Makefile*
3636
/project/msvc/bin/
3737
/project/msvc/intermediate/
3838
*.user
39+
/libfaac/win32_ver.h

libfaac/frame.c

+16-12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#include "tns.h"
3333
#include "stereo.h"
3434

35+
#if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined(PACKAGE_VERSION)
36+
#include "win32_ver.h"
37+
#endif
38+
3539
static char *libfaacName = PACKAGE_VERSION;
3640
static char *libCopyright =
3741
"FAAC - Freeware Advanced Audio Coder (http://faac.sourceforge.net/)\n"
@@ -220,7 +224,7 @@ int FAACAPI faacEncSetConfiguration(faacEncHandle hpEncoder,
220224
hEncoder->sampleRate, hEncoder->srInfo->cb_width_long,
221225
hEncoder->srInfo->num_cb_long, hEncoder->srInfo->cb_width_short,
222226
hEncoder->srInfo->num_cb_short);
223-
227+
224228
/* load channel_map */
225229
for( i = 0; i < MAX_CHANNELS; i++ )
226230
hEncoder->config.channel_map[i] = config->channel_map[i];
@@ -291,7 +295,7 @@ faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
291295
/* find correct sampling rate depending parameters */
292296
hEncoder->srInfo = &srInfo[hEncoder->sampleRateIdx];
293297

294-
for (channel = 0; channel < numChannels; channel++)
298+
for (channel = 0; channel < numChannels; channel++)
295299
{
296300
hEncoder->coderInfo[channel].prev_window_shape = SINE_WINDOW;
297301
hEncoder->coderInfo[channel].window_shape = SINE_WINDOW;
@@ -306,7 +310,7 @@ faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
306310

307311
/* Initialize coder functions */
308312
fft_initialize( &hEncoder->fft_tables );
309-
313+
310314
hEncoder->psymodel->PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
311315
hEncoder->sampleRate, hEncoder->srInfo->cb_width_long,
312316
hEncoder->srInfo->num_cb_long, hEncoder->srInfo->cb_width_short,
@@ -333,7 +337,7 @@ int FAACAPI faacEncClose(faacEncHandle hpEncoder)
333337
fft_terminate(&hEncoder->fft_tables);
334338

335339
/* Free remaining buffer memory */
336-
for (channel = 0; channel < hEncoder->numChannels; channel++)
340+
for (channel = 0; channel < hEncoder->numChannels; channel++)
337341
{
338342
if (hEncoder->sampleBuff[channel])
339343
FreeMemory(hEncoder->sampleBuff[channel]);
@@ -346,7 +350,7 @@ int FAACAPI faacEncClose(faacEncHandle hpEncoder)
346350
}
347351

348352
/* Free handle */
349-
if (hEncoder)
353+
if (hEncoder)
350354
FreeMemory(hEncoder);
351355

352356
BlocStat();
@@ -397,14 +401,14 @@ int FAACAPI faacEncEncode(faacEncHandle hpEncoder,
397401
GetChannelInfo(channelInfo, numChannels, useLfe);
398402

399403
/* Update current sample buffers */
400-
for (channel = 0; channel < numChannels; channel++)
404+
for (channel = 0; channel < numChannels; channel++)
401405
{
402406
double *tmp;
403407

404408

405409
if (!hEncoder->sampleBuff[channel])
406410
hEncoder->sampleBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
407-
411+
408412
tmp = hEncoder->sampleBuff[channel];
409413

410414
hEncoder->sampleBuff[channel] = hEncoder->nextSampleBuff[channel];
@@ -440,7 +444,7 @@ int FAACAPI faacEncEncode(faacEncHandle hpEncoder,
440444
case FAAC_INPUT_32BIT:
441445
{
442446
int32_t *input_channel = (int32_t*)inputBuffer + hEncoder->config.channel_map[channel];
443-
447+
444448
for (i = 0; i < samples_per_channel; i++)
445449
{
446450
hEncoder->next3SampleBuff[channel][i] = (1.0/256) * (double)*input_channel;
@@ -475,11 +479,11 @@ int FAACAPI faacEncEncode(faacEncHandle hpEncoder,
475479
/* LFE psychoacoustic can run without it */
476480
if (!channelInfo[channel].lfe || channelInfo[channel].cpe)
477481
{
478-
hEncoder->psymodel->PsyBufferUpdate(
479-
&hEncoder->fft_tables,
480-
&hEncoder->gpsyInfo,
482+
hEncoder->psymodel->PsyBufferUpdate(
483+
&hEncoder->fft_tables,
484+
&hEncoder->gpsyInfo,
481485
&hEncoder->psyInfo[channel],
482-
hEncoder->next3SampleBuff[channel],
486+
hEncoder->next3SampleBuff[channel],
483487
bandWidth,
484488
hEncoder->srInfo->cb_width_short,
485489
hEncoder->srInfo->num_cb_short);

project/msvc/libfaac.vcxproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
<Lib>
6161
<SuppressStartupBanner>true</SuppressStartupBanner>
6262
</Lib>
63+
<PreBuildEvent>
64+
<Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
65+
<Message>Retrieving package version...</Message>
66+
</PreBuildEvent>
6367
</ItemDefinitionGroup>
6468
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
6569
<ClCompile>
@@ -76,6 +80,10 @@
7680
<Lib>
7781
<SuppressStartupBanner>true</SuppressStartupBanner>
7882
</Lib>
83+
<PreBuildEvent>
84+
<Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
85+
<Message>Retrieving package version...</Message>
86+
</PreBuildEvent>
7987
</ItemDefinitionGroup>
8088
<ItemGroup>
8189
<ClCompile Include="..\..\libfaac\bitstream.c" />
@@ -107,7 +115,7 @@
107115
<ClInclude Include="..\..\libfaac\stereo.h" />
108116
<ClInclude Include="..\..\libfaac\tns.h" />
109117
<ClInclude Include="..\..\libfaac\util.h" />
110-
<ClInclude Include="..\..\libfaac\version.h" />
118+
<ClInclude Include="..\..\libfaac\win32_ver.h" />
111119
</ItemGroup>
112120
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
113121
<ImportGroup Label="ExtensionTargets">

project/msvc/libfaac.vcxproj.filters

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@
7979
<ClInclude Include="..\..\libfaac\util.h">
8080
<Filter>Header Files</Filter>
8181
</ClInclude>
82-
<ClInclude Include="..\..\libfaac\version.h">
83-
<Filter>Header Files</Filter>
84-
</ClInclude>
8582
<ClInclude Include="..\..\include\faac.h">
8683
<Filter>Header Files</Filter>
8784
</ClInclude>
@@ -97,5 +94,8 @@
9794
<ClInclude Include="..\..\libfaac\stereo.h">
9895
<Filter>Header Files</Filter>
9996
</ClInclude>
97+
<ClInclude Include="..\..\libfaac\win32_ver.h">
98+
<Filter>Header Files</Filter>
99+
</ClInclude>
100100
</ItemGroup>
101101
</Project>

project/msvc/libfaac_dll.vcxproj

+9
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<ModuleDefinitionFile>.\libfaac.def</ModuleDefinitionFile>
6767
<TargetMachine>MachineX86</TargetMachine>
6868
</Link>
69+
<PreBuildEvent>
70+
<Message>Retrieving package version...</Message>
71+
<Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
72+
</PreBuildEvent>
6973
</ItemDefinitionGroup>
7074
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7175
<ClCompile>
@@ -86,6 +90,10 @@
8690
<GenerateDebugInformation>true</GenerateDebugInformation>
8791
<TargetMachine>MachineX86</TargetMachine>
8892
</Link>
93+
<PreBuildEvent>
94+
<Message>Retrieving package version...</Message>
95+
<Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
96+
</PreBuildEvent>
8997
</ItemDefinitionGroup>
9098
<ItemGroup>
9199
<ClCompile Include="..\..\libfaac\bitstream.c" />
@@ -117,6 +125,7 @@
117125
<ClInclude Include="..\..\libfaac\stereo.h" />
118126
<ClInclude Include="..\..\libfaac\tns.h" />
119127
<ClInclude Include="..\..\libfaac\util.h" />
128+
<ClInclude Include="..\..\libfaac\win32_ver.h" />
120129
</ItemGroup>
121130
<ItemGroup>
122131
<None Include="libfaac.def" />

project/msvc/libfaac_dll.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
<ClInclude Include="..\..\libfaac\stereo.h">
9595
<Filter>Header Files</Filter>
9696
</ClInclude>
97+
<ClInclude Include="..\..\libfaac\win32_ver.h">
98+
<Filter>Header Files</Filter>
99+
</ClInclude>
97100
</ItemGroup>
98101
<ItemGroup>
99102
<None Include="libfaac.def">

project/msvc/libfaac_dll_drm.vcxproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
<TargetMachine>MachineX86</TargetMachine>
6868
<ImportLibrary>$(OutDir)libfaacdrm.lib</ImportLibrary>
6969
</Link>
70+
<PreBuildEvent>
71+
<Message>Retrieving package version...</Message>
72+
<Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
73+
</PreBuildEvent>
7074
</ItemDefinitionGroup>
7175
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7276
<ClCompile>
@@ -88,6 +92,10 @@
8892
<TargetMachine>MachineX86</TargetMachine>
8993
<ImportLibrary>$(OutDir)libfaacdrm.lib</ImportLibrary>
9094
</Link>
95+
<PreBuildEvent>
96+
<Message>Retrieving package version...</Message>
97+
<Command>"$(SolutionDir)..\..\utils\win32\ac2ver.exe" "faac" "$(SolutionDir)..\..\configure.ac" &gt; "$(SolutionDir)..\..\libfaac\win32_ver.h"</Command>
98+
</PreBuildEvent>
9199
</ItemDefinitionGroup>
92100
<ItemGroup>
93101
<ClCompile Include="..\..\libfaac\bitstream.c" />
@@ -125,7 +133,7 @@
125133
<ClInclude Include="..\..\libfaac\stereo.h" />
126134
<ClInclude Include="..\..\libfaac\tns.h" />
127135
<ClInclude Include="..\..\libfaac\util.h" />
128-
<ClInclude Include="..\..\libfaac\version.h" />
136+
<ClInclude Include="..\..\libfaac\win32_ver.h" />
129137
</ItemGroup>
130138
<ItemGroup>
131139
<None Include="libfaac.def" />

project/msvc/libfaac_dll_drm.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
<ClInclude Include="..\..\libfaac\stereo.h">
119119
<Filter>Header Files</Filter>
120120
</ClInclude>
121+
<ClInclude Include="..\..\libfaac\win32_ver.h">
122+
<Filter>Header Files</Filter>
123+
</ClInclude>
121124
</ItemGroup>
122125
<ItemGroup>
123126
<None Include="libfaac.def">

utils/win32/ac2ver.c

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
** AC2VER - extract version number from AC_INIT macro (configure.ac)
3+
** Copyright (C) 2017 LoRd_MuldeR <[email protected]>
4+
**
5+
** This software is released under the CC0 1.0 Universal [CC0 1.0] licence!
6+
** https://creativecommons.org/publicdomain/zero/1.0/legalcode
7+
**/
8+
9+
#define BUFF_SIZE 4096
10+
#define _CRT_SECURE_NO_WARNINGS 1
11+
12+
#include <stdlib.h>
13+
#include <stdio.h>
14+
#include <string.h>
15+
#include <ctype.h>
16+
17+
static int clean_string(char *const str)
18+
{
19+
size_t i = 0, j = 0;
20+
while(str[i])
21+
{
22+
if(isalnum(str[i]) || strchr("._-", str[i]))
23+
{
24+
if(i != j)
25+
{
26+
str[j] = str[i];
27+
}
28+
++j;
29+
}
30+
++i;
31+
}
32+
str[j] = '\0';
33+
return !!j;
34+
}
35+
36+
static int parse_version(FILE *const input, const char *const format, char *const version)
37+
{
38+
char buffer[BUFF_SIZE];
39+
40+
while(!(feof(input) || ferror(input)))
41+
{
42+
const char *line = fgets(buffer, BUFF_SIZE, input);
43+
if(line)
44+
{
45+
while((*line) && (isspace(*line)))
46+
{
47+
++line; /*skip space*/
48+
}
49+
if(sscanf(line, format, version) == 1)
50+
{
51+
if(clean_string(version))
52+
{
53+
return 1; /*found!*/
54+
}
55+
}
56+
}
57+
}
58+
59+
version[0] = '\0';
60+
return 0;
61+
}
62+
63+
static int get_version(const wchar_t *const lib_name, const wchar_t *const file_name)
64+
{
65+
char format[128], version[BUFF_SIZE];
66+
67+
FILE *const input = _wfopen(file_name, L"r");
68+
if(!input)
69+
{
70+
fprintf(stderr, "Error: Failed to open input file!\n%S\n\n", file_name);
71+
return 0;
72+
}
73+
74+
_snprintf(format, 128, "AC_INIT ( %S , %%s", lib_name);
75+
//printf("<%s>\n", format);
76+
77+
if(parse_version(input, format, version))
78+
{
79+
printf("#define PACKAGE_VERSION \"%s\"\n", version);
80+
fclose(input);
81+
return 1;
82+
}
83+
else
84+
{
85+
fprintf(stderr, "Error: Version string could not be found!\n\n");
86+
fclose(input);
87+
return 0;
88+
}
89+
}
90+
91+
int wmain(int argc, wchar_t* argv[])
92+
{
93+
if((argc != 3) || (!argv[1][0]) || (!argv[2][0]))
94+
{
95+
wchar_t file_name[_MAX_FNAME], file_ext[_MAX_EXT];
96+
_wsplitpath(argv[0], NULL, NULL, file_name, file_ext);
97+
fprintf(stderr, "AC2VER [%s]\n\n", __DATE__);
98+
fprintf(stderr, "Usage: %S%S <lib_name> <path/to/configure.ac>\n\n", file_name, file_ext);
99+
return EXIT_FAILURE;
100+
}
101+
102+
return get_version(argv[1], argv[2]) ? EXIT_SUCCESS : EXIT_FAILURE;
103+
}

utils/win32/ac2ver.exe

59.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)