<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
快乐虾
http://blog.csdn.net/lights_joy/
本文适用于
ADI bf561 DSP
uclinux-2008r1.5-rc3
Visual DSP++ 5.0(update 5)
欢迎转载,但请保留作者信息
因为uclinux内核是个庞然大物,为避免一开始就遭受打击,所以决定先将所有的代码注释掉。但是与此同时要保留各个文件之间的依赖关系,因此必须保留#include这样的语句。再考虑到uclinux是通过宏定义来控制各种功能实现的,且宏定义不会对移植造成任何困扰,所以也保留了#if #define这样的语句。
为了使用vdsp的库文件,也为了能够用自己的配置覆盖uclinux的定义,需要在每个c文件的文件头加上:
#include <config.h>
config.h是自己创建的一个文件,放在linux内核的include目录下。
以下就是自己写的一小段代码,用于实现上述功能,在VS2008下可以使用,修正了上一版无法正确处理多行define的问题。
// hprocess.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <fstream>
#pragma warning(disable:4996)
using namespace std;
void ChangeFile(char* pFile)
{
char line[10000];
char* p, c;
printf("%s processing ... ", pFile);
ifstream f(pFile);
ofstream o("tmp.h");
c = pFile[strlen(pFile)-1];
if(c == 'c' || c == 'C')
o << "#include <config.h>" << endl;
bool bIsDefine = false;
do
{
f.getline(line, 10000);
if(bIsDefine)
{
if(line[strlen(line)-1] != '\\' && line[strlen(line)-2] != '\\')
bIsDefine = false;
}
else
{
if(strstr(line, "#define") && (line[strlen(line)-1] == '\\' || line[strlen(line)-2] == '\\'))
bIsDefine = true;
else
{
p = line;
while(*p == ' ') p++;
if(*p != '#')
o << "//";
}
}
o << line << endl;
}while(!f.eof());
f.close();
o.close();
CopyFile("tmp.h", pFile, FALSE);
printf("done!\n");
}
int ProcessFile(char* pDir)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH]; // directory specification
char NextPath[MAX_PATH]; // directory specification
DWORD dwError;
printf ("Target directory is %s.\n", pDir);
strcpy (DirSpec, pDir);
strcat (DirSpec, "*");
hFind = FindFirstFile(DirSpec, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid file handle. Error is %u\n", GetLastError());
return (-1);
}
else
{
do
{
if(strcmp(FindFileData.cFileName, ".") == 0 || strcmp(FindFileData.cFileName, "..") == 0) continue;
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(strcmp(FindFileData.cFileName, "vs2008") == 0) continue;
strcpy(NextPath, pDir);
strcat(NextPath, FindFileData.cFileName);
strcat(NextPath, "\\");
ProcessFile(NextPath);
}
else
{
int len = strlen(FindFileData.cFileName);
if(FindFileData.cFileName[len-2] == '.' && (FindFileData.cFileName[len-1] == 'h' || FindFileData.cFileName[len-1] == 'H' || FindFileData.cFileName[len-1] == 'C' || FindFileData.cFileName[len-1] == 'c'))
{
strcpy(NextPath, pDir);
strcat(NextPath, FindFileData.cFileName);
ChangeFile(NextPath);
}
}
}while (FindNextFile(hFind, &FindFileData) != 0);
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
printf ("FindNextFile error. Error is %u\n", dwError);
return (-1);
}
}
return (0);
}
int _tmain(int argc, _TCHAR* argv[])
{
ProcessFile("F:\\embed\\uClinux\\uClinux-dist-2008R1.5-RC3\\");
printf("all ok");
getchar();
return 0;
}
uclinux-2008R1.5-RC3(bf561)到VDSP5的移植(1):前言(<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><chsdate w:st="on" isrocdate="False" islunardate="False" day="12" month="1" year="2009">2009-1-12</chsdate>)