I'm wanting to have only one version of source code that will compile for all different platforms with the determination of which platform-specific code will be compiled being determined by the makefile.
If, for example, I have the following contained in source code:
(the following in a .h file)
#define VALUE
(the following in a .cpp file)
#ifdef VALUE
cout << "something\n";
#else
cout << "something else\n";
#endif
The output is "something".
In an example I've seen with a makefile, "VALUE" is included in the makefile and, by all indications, produces the same output as the code above. One apparently need only to comment out the line containing VALUE to, sticking with the example above, print "something else."
Is this correct? If so, how should "VALUE" be included in the makefile?
Hopefully I'm making sense :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You will need the specific libraries for those multiple platforms for the makefile to do its thing !...
minGW alone with makefiles will not cover every platform.
j@ck_
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
probably you are talking about something like:
hello.c
---------
#include <stdio.h>
int
main()
{
#ifdef WIN
printf("Hello Windows world!\n");
#else
printf("Hello world!\n");
#endif
return 0;
}
-----------
When the preprocessor examines the above, it will compile the first "printf", if the variable WIN is defined, the second printf, otherwise.
You define the variable WIN by the syntax:
gcc -DWIN -o hello.exe hello.c
while the following will trigger not Windows specific printing message
gcc -o hello.exe hello.c
This feature is generally known as "conditional compilation", it is not a makefile specific issue, though its often use in makefiles to trigger compilation of platform specific stuff.
For instance, on *nix computers,. the directory separator is a slash ('/') instead of backslash ('\\'), as on Dos systems, so one may write a program like:
/* split name of files in its components */
----
...
{
....
/* extract path from a filename */
#ifdef DOS
/* look for backslashes as separators */
...
#elif NIX
/* look for slashes as separators */
...
#else
/* print a message telling that no OS has been
specified */
...
#endif
...
}
-----
If you use makefiles to build executable files (rather usual if a program has source code spread across multiple files) than you would put something like:
CPPFLAGS = -DDOS
as the preprocessor flags, in the Windows specific makefile or
CPPFLAGS = -DNIX
as preprocessor flags, in the Unix specific makefile.
Hope the above helps.
--
gisan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm wanting to have only one version of source code that will compile for all different platforms with the determination of which platform-specific code will be compiled being determined by the makefile.
If, for example, I have the following contained in source code:
(the following in a .h file)
#define VALUE
(the following in a .cpp file)
#ifdef VALUE
cout << "something\n";
#else
cout << "something else\n";
#endif
The output is "something".
In an example I've seen with a makefile, "VALUE" is included in the makefile and, by all indications, produces the same output as the code above. One apparently need only to comment out the line containing VALUE to, sticking with the example above, print "something else."
Is this correct? If so, how should "VALUE" be included in the makefile?
Hopefully I'm making sense :)
You will need the specific libraries for those multiple platforms for the makefile to do its thing !...
minGW alone with makefiles will not cover every platform.
j@ck_
Hello,
probably you are talking about something like:
hello.c
---------
#include <stdio.h>
int
main()
{
#ifdef WIN
printf("Hello Windows world!\n");
#else
printf("Hello world!\n");
#endif
return 0;
}
-----------
When the preprocessor examines the above, it will compile the first "printf", if the variable WIN is defined, the second printf, otherwise.
You define the variable WIN by the syntax:
gcc -DWIN -o hello.exe hello.c
while the following will trigger not Windows specific printing message
gcc -o hello.exe hello.c
This feature is generally known as "conditional compilation", it is not a makefile specific issue, though its often use in makefiles to trigger compilation of platform specific stuff.
For instance, on *nix computers,. the directory separator is a slash ('/') instead of backslash ('\\'), as on Dos systems, so one may write a program like:
/* split name of files in its components */
----
...
{
....
/* extract path from a filename */
#ifdef DOS
/* look for backslashes as separators */
...
#elif NIX
/* look for slashes as separators */
...
#else
/* print a message telling that no OS has been
specified */
...
#endif
...
}
-----
If you use makefiles to build executable files (rather usual if a program has source code spread across multiple files) than you would put something like:
CPPFLAGS = -DDOS
as the preprocessor flags, in the Windows specific makefile or
CPPFLAGS = -DNIX
as preprocessor flags, in the Unix specific makefile.
Hope the above helps.
--
gisan