Sponsored Content
Operating Systems Linux how to enable #ifdef macro in the command line of make? Post 302154323 by princelinux on Saturday 29th of December 2007 03:20:52 AM
Old 12-29-2007
how to enable #ifdef macro in the command line of make?

[Keyword] Linux, C++, make, macro

In source code, we used some #ifdef macros. How can I enable #ifdef macro in the command line of "make" (NOTE: I do NOT want to change source code or makefile to define that macro from time to time).

e.g. test.cpp:
...
#ifdef TEST1
// code segment for test1
...
#endif
...
#ifdef TEST2
// code segment for test2
...
#endif
....

Question: How can I enable either macro via command line of make?
e.g. make ????? -> enable TEST1
make ????? -> enable TEST2

Thanks in advance!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Surrounding a chunk of code by #ifdef and #endif

Hello the great gurus :) I'm quite new to this, so perhaps I'm asking a simple and trivial question (which is good, because you'll answer for sure :)))) Anyway. I have an amount of *.c files (about 100), and what I want to do, is to surround a specific function call with #ifdef and #endif. ... (6 Replies)
Discussion started by: xxxaxa
6 Replies

2. Programming

Make-question - redefine a macro, using another macro..?

I think there is no problem to use any macro in a new macro definishion, but I have a problem with that. I can not understand why? I have a *.mak file that inludes file with many definitions and rules. ############################################## include dstndflt.mak ... One of the... (2 Replies)
Discussion started by: alex_5161
2 Replies

3. Homework & Coursework Questions

I need to make a script that has 4 command line arguments to function properly.

I have no idea what the following means. The teacher is too advanced for me to understand fully. We literally went from running a few commands over the last few months to starting shell scripting. I am not a programmer, I am more hardware oriented. I wish I knew what this question was asking... (3 Replies)
Discussion started by: Wookard
3 Replies

4. Shell Programming and Scripting

How to make command line interactive?

I have a file with stats for different month, I use the cat and grep combination to search for different month. cat <file> | grep "April" cat <file> | grep "May" cat <file> | grep "June" etc. How do you make this command interactive. So that I can give the values for the search. Thanks... (7 Replies)
Discussion started by: purelltab
7 Replies

5. Shell Programming and Scripting

Homework: Make a one-line Unix command - using pipe(s)

Task A: Make a one-line Unix command - using pipe(s) - to display the number of files in your home directory including the hidden files that begin with '.' Task B:Make a one-line Unix command - using pipe(s) - to display the number of unique zip codes in famous.dat (hint: use -u on sort) Task... (1 Reply)
Discussion started by: wises
1 Replies

6. Shell Programming and Scripting

How to use ifdef for bash variables in csh environment?

Hi Guys, I have a a bash script and i am exporting a variable in it. I am calling a csh script from this bash script. The variable "ABC" will be visible in csh script. ks.bash export ABC = abc ./kp.csh ab.csh echo $ABC setenv ABC =cde (i want to assign this value to ABC only if... (4 Replies)
Discussion started by: vdhingra123
4 Replies

7. UNIX for Dummies Questions & Answers

Why cant I use enable command

Why can I not use the enable command? *sofiazoe* (2 Replies)
Discussion started by: anglenasalt
2 Replies

8. Programming

Make a file accept only two arguments from the command line

DELETED (2 Replies)
Discussion started by: ProgMan2015
2 Replies

9. Homework & Coursework Questions

Make a file accept only two arguments from the command line

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) The script is executed in the Korn shell. 2) Name the shell script file is asg6s. 3) The asg6s file is... (7 Replies)
Discussion started by: ProgMan2015
7 Replies

10. UNIX for Advanced & Expert Users

Enable 'make uninstall' hook?

Heyas I'm currently trying to make 'make uninstall' work properly, as it doesnt remove empty directories. To do so, i've applied: uninstall-hook: if test -d $docdir; then rmdir $docdir; fi As stated (example) in automake - 'make uninstall': Howto remove empty directories - Stack... (2 Replies)
Discussion started by: sea
2 Replies
FEATURE_TEST_MACROS(7)					     Linux Programmer's Manual					    FEATURE_TEST_MACROS(7)

NAME
feature_test_macros - feature test macros SYNOPSIS
#include <features.h> DESCRIPTION
Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled. This can be useful for creating portable applications, by preventing nonstandard definitions from being exposed. Other macros can be used to expose nonstandard definitions that are not exposed by default. The precise effects of each of the feature test macros described below can be ascertained by inspecting the <features.h> header file. In order to be effective, a feature test macro must be defined before including any header files. This can either be done in the compila- tion command (cc -DMACRO=value) or by defining the macro within the source code before including any headers. Specification of feature test macro requirements in manual pages When a function requires that a feature test macro is defined, the manual page SYNOPSIS typically includes a note of the following form (this example from the chmod(2) manual page): #include <sys/stat.h> int chmod(const char *path, mode_t mode); int fchmod(int fd, mode_t mode); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): fchmod(): _BSD_SOURCE || _XOPEN_SOURCE >= 500 The || means that in order to obtain the declaration of fchmod(2) from <sys/stat.h>, either of the following macro definitions must be made before including any header files: #define _BSD_SOURCE #define _XOPEN_SOURCE 500 /* or any value > 500 */ Alternatively, equivalent definitions can be included in the compilation command: cc -D_BSD_SOURCE cc -D_XOPEN_SOURCE=500 # Or any value > 500 Note that, as described below, some feature test macros are defined by default, so that it may not always be necessary to explicitly spec- ify the feature test macro(s) shown in the SYNOPSIS. In a few cases, manual pages use a shorthand for expressing the feature test macro requirements (this example from readahead(2)): #define _GNU_SOURCE #include <fcntl.h> ssize_t readahead(int fd, off64_t *offset, size_t count); This format is employed in cases where only a single feature test macro can be used to expose the function declaration, and that macro is not defined by default. Feature test macros understood by glibc The following paragraphs explain how feature test macros are handled in Linux glibc 2.x, x > 0. Linux glibc understands the following feature test macros: __STRICT_ANSI__ ISO Standard C. This macro is implicitly defined by gcc(1) when invoked with, for example, the -std=c99 or -ansi flag. _POSIX_C_SOURCE Defining this macro causes header files to expose definitions as follows: o The value 1 exposes definitions conforming to POSIX.1-1990 and ISO C (1990). o The value 2 or greater additionally exposes definitions for POSIX.2-1992. o The value 199309L or greater additionally exposes definitions for POSIX.1b (real-time extensions). o The value 199506L or greater additionally exposes definitions for POSIX.1c (threads). o (Since glibc 2.3.3) The value 200112L or greater exposes definitions corresponding to the POSIX.1-2001 base specification (excluding the XSI extension). o (Since glibc 2.10) The value 200809L or greater exposes definitions corresponding to the POSIX.1-2008 base specification (exclud- ing the XSI extension). _POSIX_SOURCE Defining this obsolete macro with any value is equivalent to defining _POSIX_C_SOURCE with the value 1. _XOPEN_SOURCE Defining this macro causes header files to expose definitions as follows: o Defining with any value exposes definitions conforming to POSIX.1, POSIX.2, and XPG4. o The value 500 or greater additionally exposes definitions for SUSv2 (UNIX 98). o (Since glibc 2.2) The value 600 or greater additionally exposes definitions for SUSv3 (UNIX 03; i.e., the POSIX.1-2001 base spec- ification plus the XSI extension) and C99 definitions. o (Since glibc 2.10) The value 700 or greater additionally exposes definitions for SUSv4 (i.e., the POSIX.1-2008 base specification plus the XSI extension). _XOPEN_SOURCE_EXTENDED If this macro is defined, and _XOPEN_SOURCE is defined, then expose definitions corresponding to the XPG4v2 (SUSv1) UNIX extensions (UNIX 95). This macro is also implicitly defined if _XOPEN_SOURCE is defined with a value of 500 or more. _ISOC99_SOURCE Exposes C99 extensions to ISO C (1990). This macro is recognized since glibc 2.1.3; earlier glibc 2.1.x versions recognized an equivalent macro named _ISOC9X_SOURCE (because the C99 standard had not then been finalized). Although the use of the latter macro is obsolete, glibc continues to recognize it for backwards compatibility. _LARGEFILE64_SOURCE Expose definitions for the alternative API specified by the LFS (Large File Summit) as a "transitional extension" to the Single UNIX Specification. (See http://opengroup.org/platform/lfs.html.) The alternative API consists of a set of new objects (i.e., functions and types) whose names are suffixed with "64" (e.g., off64_t versus off_t, lseek64() versus lseek(), etc.). New programs should not employ this interface; instead _FILE_OFFSET_BITS=64 should be employed. _FILE_OFFSET_BITS Defining this macro with the value 64 automatically converts references to 32-bit functions and data types related to file I/O and file system operations into references to their 64-bit counterparts. This is useful for performing I/O on large files (> 2 Giga- bytes) on 32-bit systems. (Defining this macro permits correctly written programs to use large files with only a recompilation being required.) 64-bit systems naturally permit file sizes greater than 2 Gigabytes, and on those systems this macro has no effect. _BSD_SOURCE Defining this macro with any value causes header files to expose BSD-derived definitions. Defining this macro also causes BSD defi- nitions to be preferred in some situations where standards conflict, unless one or more of _SVID_SOURCE, _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _XOPEN_SOURCE_EXTENDED, or _GNU_SOURCE is defined, in which case BSD definitions are disfavored. _SVID_SOURCE Defining this macro with any value causes header files to expose System V-derived definitions. (SVID == System V Interface Defini- tion; see standards(7).) _ATFILE_SOURCE (since glibc 2.4) Defining this macro with any value causes header files to expose declarations of a range of functions with the suffix "at"; see ope- nat(2). Since glibc 2.10, this macro is also implicitly defined if _POSIX_C_SOURCE is defined with a value greater than or equal to 200809L. _GNU_SOURCE Defining this macro (with any value) is equivalent to defining _BSD_SOURCE, _SVID_SOURCE, _ATFILE_SOURCE, _LARGEFILE64_SOURCE, _ISOC99_SOURCE, _XOPEN_SOURCE_EXTENDED, _POSIX_SOURCE, _POSIX_C_SOURCE with the value 200809L (200112L in glibc versions before 2.10; 199506L in glibc versions before 2.5; 199309L in glibc versions before 2.1) and _XOPEN_SOURCE with the value 700 (600 in glibc versions before 2.10; 500 in glibc versions before 2.2). In addition, various GNU-specific extensions are also exposed. Where standards conflict, BSD definitions are disfavored. _REENTRANT Defining this macro exposes definitions of certain reentrant functions. For multithreaded programs, use cc -pthread instead. _THREAD_SAFE Synonym for _REENTRANT, provided for compatibility with some other implementations. _FORTIFY_SOURCE (since glibc 2.3.4) Defining this macro causes some lightweight checks to be performed to detect some buffer overflow errors when employing various string and memory manipulation functions. Not all buffer overflows are detected, just some common cases. In the current implemen- tation checks are added for calls to memcpy(3), mempcpy(3), memmove(3), memset(3), stpcpy(3), strcpy(3), strncpy(3), strcat(3), strncat(3), sprintf(3), snprintf(3), vsprintf(3), vsnprintf(3), and gets(3). If _FORTIFY_SOURCE is set to 1, with compiler opti- mization level 1 (gcc -O1) and above, checks that shouldn't change the behavior of conforming programs are performed. With _FOR- TIFY_SOURCE set to 2 some more checking is added, but some conforming programs might fail. Some of the checks can be performed at compile time, and result in compiler warnings; other checks take place at run time, and result in a run-time error if the check fails. Use of this macro requires compiler support, available with gcc(1) since version 4.0. Default definitions, implicit definitions, and combining definitions If no feature test macros are explicitly defined, then the following feature test macros are defined by default: _BSD_SOURCE, _SVID_SOURCE, _POSIX_SOURCE, and _POSIX_C_SOURCE=200809L (200112L in glibc versions before 2.10; 199506L in glibc versions before 2.4; 199309L in glibc versions before 2.1). If any of __STRICT_ANSI__, _ISOC99_SOURCE, _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _XOPEN_SOURCE_EXTENDED, _BSD_SOURCE, or _SVID_SOURCE is explicitly defined, then _BSD_SOURCE, and _SVID_SOURCE are not defined by default. If _POSIX_SOURCE and _POSIX_C_SOURCE are not explicitly defined, and either __STRICT_ANSI__ is not defined or _XOPEN_SOURCE is defined with a value of 500 or more, then * _POSIX_SOURCE is defined with the value 1; and * _POSIX_C_SOURCE is defined with one of the following values: o 2, if XOPEN_SOURCE is defined with a value less than 500; o 199506L, if XOPEN_SOURCE is defined with a value greater than or equal to 500 and less than 600; or o (since glibc 2.4) 200112L, if XOPEN_SOURCE is defined with a value greater than or equal to 600 and less than 700. o (Since glibc 2.10) 200809L, if XOPEN_SOURCE is defined with a value greater than or equal to 700. o Older versions of glibc do not know about the values 200112L and 200809L for _POSIX_C_SOURCE, and the setting of this macro will depend on the glibc version. o If _XOPEN_SOURCE is undefined, then the setting of _POSIX_C_SOURCE depends on the glibc version: 199506L, in glibc versions before 2.4; 200112L, in glibc 2.4 to 2.9; and 200809L, since glibc 2.10. Multiple macros can be defined; the results are additive. CONFORMING TO
POSIX.1 specifies _POSIX_C_SOURCE, _POSIX_SOURCE, and _XOPEN_SOURCE. _XOPEN_SOURCE_EXTENDED was specified by XPG4v2 (aka SUSv1). _FILE_OFFSET_BITS is not specified by any standard, but is employed on some other implementations. _BSD_SOURCE, _SVID_SOURCE, _ATFILE_SOURCE, _GNU_SOURCE, _FORTIFY_SOURCE, _REENTRANT, and _THREAD_SAFE are specific to Linux (glibc). NOTES
<features.h> is a Linux/glibc-specific header file. Other systems have an analogous file, but typically with a different name. This header file is automatically included by other header files as required: it is not necessary to explicitly include it in order to employ feature test macros. According to which of the above feature test macros are defined, <features.h> internally defines various other macros that are checked by other glibc header files. These macros have names prefixed by two underscores (e.g., __USE_MISC). Programs should never define these macros directly: instead, the appropriate feature test macro(s) from the list above should be employed. EXAMPLE
The program below can be used to explore how the various feature test macros are set depending on the glibc version and what feature test macros are explicitly set. The following shell session, on a system with glibc 2.10, shows some examples of what we would see: $ cc ftm.c $ ./a.out _POSIX_SOURCE defined _POSIX_C_SOURCE defined: 200809L _BSD_SOURCE defined _SVID_SOURCE defined _ATFILE_SOURCE defined $ cc -D_XOPEN_SOURCE=500 ftm.c $ ./a.out _POSIX_SOURCE defined _POSIX_C_SOURCE defined: 199506L _XOPEN_SOURCE defined: 500 $ cc -D_GNU_SOURCE ftm.c $ ./a.out _POSIX_SOURCE defined _POSIX_C_SOURCE defined: 200809L _ISOC99_SOURCE defined _XOPEN_SOURCE defined: 700 _XOPEN_SOURCE_EXTENDED defined _LARGEFILE64_SOURCE defined _BSD_SOURCE defined _SVID_SOURCE defined _ATFILE_SOURCE defined _GNU_SOURCE defined Program source /* ftm.c */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { #ifdef _POSIX_SOURCE printf("_POSIX_SOURCE defined "); #endif #ifdef _POSIX_C_SOURCE printf("_POSIX_C_SOURCE defined: %ldL ", (long) _POSIX_C_SOURCE); #endif #ifdef _ISOC99_SOURCE printf("_ISOC99_SOURCE defined "); #endif #ifdef _XOPEN_SOURCE printf("_XOPEN_SOURCE defined: %d ", _XOPEN_SOURCE); #endif #ifdef _XOPEN_SOURCE_EXTENDED printf("_XOPEN_SOURCE_EXTENDED defined "); #endif #ifdef _LARGEFILE64_SOURCE printf("_LARGEFILE64_SOURCE defined "); #endif #ifdef _FILE_OFFSET_BITS printf("_FILE_OFFSET_BITS defined: %d ", _FILE_OFFSET_BITS); #endif #ifdef _BSD_SOURCE printf("_BSD_SOURCE defined "); #endif #ifdef _SVID_SOURCE printf("_SVID_SOURCE defined "); #endif #ifdef _ATFILE_SOURCE printf("_ATFILE_SOURCE defined "); #endif #ifdef _GNU_SOURCE printf("_GNU_SOURCE defined "); #endif #ifdef _REENTRANT printf("_REENTRANT defined "); #endif #ifdef _THREAD_SAFE printf("_THREAD_SAFE defined "); #endif #ifdef _FORTIFY_SOURCE printf("_FORTIFY_SOURCE defined "); #endif exit(EXIT_SUCCESS); } SEE ALSO
libc(7), standards(7) The section "Feature Test Macros" under info libc. /usr/include/features.h COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2009-12-13 FEATURE_TEST_MACROS(7)
All times are GMT -4. The time now is 06:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy