Preprocess the package source files

I've a package composed by C source files and I'd need to get the preprocessed files of that instead of the compiled ones. I read the overriding build options guide but in this way I can add extra compilation options without changing the compilation directive from '-c' to '-E' (required to avoid gcc to go over the preprocessing step).

Can you give me some hints to figure it out?

You want the view the preprocessor output ? I am guessing there is a reason you need it from openwrt ??

you could just do this from a terminal in your src directory ...
from here-->

gcc -E -dM myfile.c

or stash the output in a file for later..

gcc -E -dM myfile.c > ./myfile_prep.output

If you need it from the ow gcc, you'll need to setup a build enviroment, and create a package ..or a makefile at the least.

Heres a complete example of how to create a simple package in openwrt and build it.

first you need to create the directory for your package inside of the packages directory, choose the most relevant directory . For this example, I will create a package in the utilities directory, lets call it "myPackage" for the sake of simplicity.

from openwrt root directory we cd into the packages/utils directory

cd packages/utils

create the directory

mkdir myPackage
cd myPackage

create the openwrt Makefile

touch Makefile
nano Makefile

create the following simple Makefile

#
# Copyright (C) 2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/package.mk

PKG_NAME:=myPacakge


define Package/myPackage
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=MyPackage. the best package ever
  ##DEPENDS:=+somedependent
  VERSION:=1.00.1
  MAINTAINER:=Me <greatestCoder@gmail.com>
endef

define Package/myPackage/description
  The best package ever created

endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	cp -r src/* $(PKG_BUILD_DIR)
endef

define Build/Compile
	$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource.c > $(PKG_BUILD_DIR)/myPackage_prep.out
	$(TARGET_CC) $(TARGET_CFLAGS) -o -Wall -Werror $(PKG_BUILD_DIR)/mySource.c -o $(PKG_BUILD_DIR)/myPackage
endef

define Package/myPackage/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/myPackage $(1)/usr/bin
endef

$(eval $(call BuildPackage,myPackage))

create the "src" directory

mkdir src
cd src

create the source file

touch mySource.c
nano mySource.c

create a simple helloworld application to test everything works.

#include <stdio.h>

#define HELLO "Hello,"
#define WORLD "Openwrt World"

int main(void)
{
	printf("%s%s\n", HELLO, WORLD);
	return 0;
}

now everything is ready, cd back to the openwrt root directory

cd ~/openwrt

its good practice to run a make menuconfig at this point, to sync everything, and it also confirms that the prior steps were done correctly.

make menuconfig

select the new package

utils-->myPackage   choose M or *

exit out of the menuconfig --> choose to save config when exiting.

make the package

make package/myPackage/compile V=s

if all goes as planned, the package will be built and inside the bin/packages/ /base/myPackage.ipk...

Now ... if you look in the build directory, I've left you a little gift.

/build_directory/<target>/myPackage/myPackage_prep.out

in this file, you'll find what you need.

#define __DBL_MIN_EXP__ (-1021)
#define __HQ_FBIT__ 15
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
#define __SFRACT_IBIT__ 0
#define __FLT_MIN__ 1.1754943508222875e-38F
#define __GCC_IEC_559_COMPLEX 0
#define __UFRACT_MAX__ 0XFFFFP-16UR
#define __UINT_LEAST8_TYPE__ unsigned char
#define __DQ_FBIT__ 63
#define __INTMAX_C(c) c ## LL
#define __ULFRACT_FBIT__ 32
#define __CHAR_BIT__ 8
#define __USQ_IBIT__ 0
#define __NEED___isoc_va_list 
#define __UINT8_MAX__ 0xff
#define __ACCUM_FBIT__ 15
#define __WINT_MAX__ 0xffffffffU
#define __FLT32_MIN_EXP__ (-125)
#define stderr (stderr)
#define R3000 1
#define _XOPEN_SOURCE 700
#define __USFRACT_FBIT__ 8
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __SIZE_MAX__ 0xffffffffU
#define __WCHAR_MAX__ 0x7fffffff
#define __LACCUM_IBIT__ 32
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __DBL_DENORM_MIN__ ((double)4.9406564584124654e-324L)
#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
#define __GCC_IEC_559 0
#define __FLT32X_DECIMAL_DIG__ 17
#define _IOFBF 0
#define __FLT_EVAL_METHOD__ 0
#define __TQ_IBIT__ 0
#define __LLACCUM_MAX__ 0X7FFFFFFFFFFFFFFFP-31LLK
#define __FLT64_DECIMAL_DIG__ 17
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
#define _MIPS_ISA _MIPS_ISA_MIPS32
#define __DEFINED_size_t 
#define __UINT_FAST64_MAX__ 0xffffffffffffffffULL
#define __SIG_ATOMIC_TYPE__ int
#define __LANGUAGE_C 1
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define _MIPS_TUNE "24kc"
#define _ABIO32 1
#define __FLT32X_MAX_EXP__ 1024
#define __LFRACT_IBIT__ 0
#define __GNUC_PATCHLEVEL__ 0
#define __FLT32_HAS_DENORM__ 1
#define __LFRACT_MAX__ 0X7FFFFFFFP-31LR
#define __USA_FBIT__ 16
#define __UINT_FAST8_MAX__ 0xff
#define __FLT32_MAX_10_EXP__ 38
#define __INT8_C(c) c
#define WORLD "great world"
#define __INT_LEAST8_WIDTH__ 8
#define __UINT_LEAST64_MAX__ 0xffffffffffffffffULL
#define __SA_FBIT__ 15
#define __restrict restrict
#define __SHRT_MAX__ 0x7fff
#define __LDBL_MAX__ 1.7976931348623157e+308L
#define __FRACT_MAX__ 0X7FFFP-15R
#define __USE_TIME_BITS64 1
#define __LDBL_IS_IEC_60559__ 1
#define __UFRACT_FBIT__ 16
#define __UFRACT_MIN__ 0.0UR
#define __UINT_LEAST8_MAX__ 0xff
#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
#define __mips_abicalls 1
#define __LANGUAGE_C__ 1
#define __UINTMAX_TYPE__ long long unsigned int
#define __LLFRACT_EPSILON__ 0x1P-63LLR
#define __linux 1
#define __FLT_EVAL_METHOD_TS_18661_3__ 0
#define __OPTIMIZE__ 1
#define __UINT32_MAX__ 0xffffffffU
#define __ULFRACT_MAX__ 0XFFFFFFFFP-32ULR
#define __TA_IBIT__ 64
#define __LDBL_MAX_EXP__ 1024
#define __WINT_MIN__ 0U
#define __FLT32X_IS_IEC_60559__ 1
#define __INT_LEAST16_WIDTH__ 16
#define __ULLFRACT_MIN__ 0.0ULLR
#define __SCHAR_MAX__ 0x7f
#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)
#define __INT64_C(c) c ## LL
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
#define __ATOMIC_SEQ_CST 5
#define _FORTIFY_SOURCE 1
#define __SIZEOF_INT__ 4
#define __FLT32X_MANT_DIG__ 53
#define __USACCUM_IBIT__ 8
#define __STDC_HOSTED__ 1
#define __DEFINED___isoc_va_list 
#define __LFRACT_MIN__ (-0.5LR-0.5LR)
#define __mips_fpr 32
#define __HA_IBIT__ 8
#define __DBL_DIG__ 15
#define __FLT_EPSILON__ 1.1920928955078125e-7F
#define __DEFINED_off_t 
#define __SHRT_WIDTH__ 16
#define TMP_MAX 10000
#define __FLT32_IS_IEC_60559__ 1
#define __USFRACT_IBIT__ 0
#define __LDBL_MIN__ 2.2250738585072014e-308L
#define __STDC_UTF_16__ 1
#define __DBL_IS_IEC_60559__ 1
#define __FRACT_MIN__ (-0.5R-0.5R)
#define __DA_IBIT__ 32
#define MIPSEB 1
#define __FLT32X_HAS_INFINITY__ 1
#define __INT32_MAX__ 0x7fffffff
#define __unix__ 1
#define __UQQ_FBIT__ 8
#define __INT_WIDTH__ 32
#define __UACCUM_MAX__ 0XFFFFFFFFP-16UK
#define __STDC_ISO_10646__ 201206L
#define __DECIMAL_DIG__ 17
#define __LFRACT_EPSILON__ 0x1P-31LR
#define __FLT64_EPSILON__ 2.2204460492503131e-16F64
#define __ULFRACT_MIN__ 0.0ULR
#define __LDBL_HAS_QUIET_NAN__ 1
#define __ULACCUM_IBIT__ 32
#define __FLT64_MANT_DIG__ 53
#define __UACCUM_EPSILON__ 0x1P-16UK
#define L_tmpnam 20
#define __GNUC__ 13
#define __ULLACCUM_MAX__ 0XFFFFFFFFFFFFFFFFP-32ULLK
#define __HQ_IBIT__ 0
#define __FLT_HAS_DENORM__ 1
#define __SIZEOF_LONG_DOUBLE__ 8
#define __SA_IBIT__ 16
#define _R3000 1
#define SEEK_CUR 1
#define __BIGGEST_ALIGNMENT__ 8
#define __FLT64_MAX_10_EXP__ 308
#define __GNUC_STDC_INLINE__ 1
#define __DQ_IBIT__ 0
#define __NEED_off_t 
#define __DBL_MAX__ ((double)1.7976931348623157e+308L)
#define __ULFRACT_IBIT__ 0
#define __INT_FAST32_MAX__ 0x7fffffff
#define __DBL_HAS_INFINITY__ 1
#define stdin (stdin)
#define __ACCUM_IBIT__ 16
#define __INTPTR_WIDTH__ 32
#define __UINT_LEAST32_MAX__ 0xffffffffU
#define __LACCUM_MAX__ 0X7FFFFFFFFFFFFFFFP-31LK
#define L_ctermid 20
#define __FLT32X_HAS_DENORM__ 1
#define __INT_FAST16_TYPE__ int
#define __DEFINED_ssize_t 
#define _FEATURES_H 
#define __LDBL_HAS_DENORM__ 1
#define __INT_LEAST32_MAX__ 0x7fffffff
#define __ACCUM_MAX__ 0X7FFFFFFFP-15K
#define __DBL_MAX_EXP__ 1024
#define __USACCUM_EPSILON__ 0x1P-8UHK
#define __WCHAR_WIDTH__ 32
#define __FLT32_MAX__ 3.4028234663852886e+38F32
#define __R3000__ 1
#define __GCC_ATOMIC_LONG_LOCK_FREE 2
#define __SFRACT_MAX__ 0X7FP-7HR
#define __FRACT_IBIT__ 0
#define __PTRDIFF_MAX__ 0x7fffffff
#define __UACCUM_MIN__ 0.0UK
#define __UACCUM_IBIT__ 16
#define __LLACCUM_MIN__ (-0X1P31LLK-0X1P31LLK)
#define __FLT32_HAS_QUIET_NAN__ 1
#define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
#define __SIZEOF_SIZE_T__ 4
#define __ULACCUM_MAX__ 0XFFFFFFFFFFFFFFFFP-32ULK
#define __SIZEOF_WINT_T__ 4
#define __LONG_LONG_WIDTH__ 64
#define __LONG_MAX 0x7fffffffL
#define _STDIO_H 
#define __FLT32_MAX_EXP__ 128
#define __ULLACCUM_MIN__ 0.0ULLK
#define __GXX_ABI_VERSION 1018
#define __UTA_FBIT__ 64
#define __FLT_MIN_EXP__ (-125)
#define __UFRACT_IBIT__ 0
#define __MIPSEB__ 1
#define __INT16_MAX__ 0x7fff
#define __INT_FAST64_TYPE__ long long int
#define _MIPSEB 1
#define __FLT64_DENORM_MIN__ 4.9406564584124654e-324F64
#define __DBL_MIN__ ((double)2.2250738585072014e-308L)
#define _MIPS_ARCH "mips32r2"
#define __SIZEOF_POINTER__ 4
#define __LITTLE_ENDIAN 1234
#define __NEED_FILE 
#define __DBL_HAS_QUIET_NAN__ 1
#define __FLT32X_EPSILON__ 2.2204460492503131e-16F32x
#define _MIPS_SPFPSET 32
#define __FLT64_MIN_EXP__ (-1021)
#define __LACCUM_MIN__ (-0X1P31LK-0X1P31LK)
#define __FRACT_FBIT__ 15
#define __ULLACCUM_FBIT__ 32
#define __FLT64_MIN_10_EXP__ (-307)
#define __ULLFRACT_EPSILON__ 0x1P-64ULLR
#define __REGISTER_PREFIX__ $
#define __UINT16_MAX__ 0xffff
#define __DBL_HAS_DENORM__ 1
#define __ACCUM_MIN__ (-0X1P15K-0X1P15K)
#define __LDBL_HAS_INFINITY__ 1
#define __SQ_IBIT__ 0
#define __FLT32_MIN__ 1.1754943508222875e-38F32
#define __UINT8_TYPE__ unsigned char
#define __UHA_FBIT__ 8
#define __FLT_DIG__ 6
#define __SFRACT_MIN__ (-0.5HR-0.5HR)
#define __R3000 1
#define __UTQ_FBIT__ 128
#define __DEC_EVAL_METHOD__ 2
#define __FLT_MANT_DIG__ 24
#define __LDBL_DECIMAL_DIG__ 17
#define __VERSION__ "13.2.0"
#define __UINT64_C(c) c ## ULL
#define __REDIR(x,y) __typeof__(x) x __asm__(#y)
#define __ULLFRACT_FBIT__ 64
#define _MIPS_TUNE_24KC 1
#define __FRACT_EPSILON__ 0x1P-15R
#define __ULACCUM_MIN__ 0.0ULK
#define _STDC_PREDEF_H 
#define __UDA_FBIT__ 32
#define _BSD_SOURCE 1
#define __LLACCUM_EPSILON__ 0x1P-31LLK
#define __GCC_ATOMIC_INT_LOCK_FREE 2
#define __FLT32_MANT_DIG__ 24
#define __FLOAT_WORD_ORDER__ __ORDER_BIG_ENDIAN__
#define __USFRACT_MIN__ 0.0UHR
#define __UQQ_IBIT__ 0
#define __USFRACT_MAX__ 0XFFP-8UHR
#define __SCHAR_WIDTH__ 8
#define __INT32_C(c) c
#define __ORDER_PDP_ENDIAN__ 3412
#define __UHQ_FBIT__ 16
#define __LLACCUM_FBIT__ 31
#define __INT_FAST32_TYPE__ int
#define __NEED_va_list 
#define __UINT_LEAST16_TYPE__ short unsigned int
#define unix 1
#define __SIZE_TYPE__ unsigned int
#define __UINT64_MAX__ 0xffffffffffffffffULL
#define __FLT_IS_IEC_60559__ 1
#define __UDQ_FBIT__ 64
#define __GNUC_WIDE_EXECUTION_CHARSET_NAME "UTF-32BE"
#define __INT8_TYPE__ signed char
#define __ELF__ 1
#define __mips_isa_rev 2
#define __SACCUM_EPSILON__ 0x1P-7HK
#define __ULFRACT_EPSILON__ 0x1P-32ULR
#define __LLFRACT_FBIT__ 63
#define __FLT_RADIX__ 2
#define __INT_LEAST16_TYPE__ short int
#define __LDBL_EPSILON__ 2.2204460492503131e-16L
#define __UINTMAX_C(c) c ## ULL
#define __SACCUM_MAX__ 0X7FFFP-7HK
#define __FLT32X_MIN__ 2.2250738585072014e-308F32x
#define __mips_compact_branches_never 1
#define __SIG_ATOMIC_MAX__ 0x7fffffff
#define __UACCUM_FBIT__ 16
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
#define __USER_LABEL_PREFIX__ 
#define __SIZEOF_PTRDIFF_T__ 4
#define SEEK_SET 0
#define __FLT32_HAS_INFINITY__ 1
#define __SIZEOF_LONG__ 4
#define _IONBF 2
#define __LACCUM_EPSILON__ 0x1P-31LK
#define __LDBL_DIG__ 15
#define __FLT64_IS_IEC_60559__ 1
#define __FLT32X_MIN_EXP__ (-1021)
#define __INT_FAST16_MAX__ 0x7fffffff
#define _MIPS_SZPTR 32
#define __FLT64_DIG__ 15
#define __UINT_FAST32_MAX__ 0xffffffffU
#define __UINT_LEAST64_TYPE__ long long unsigned int
#define NULL ((void*)0)
#define __SFRACT_EPSILON__ 0x1P-7HR
#define __FLT_HAS_QUIET_NAN__ 1
#define __FLT_MAX_10_EXP__ 38
#define __LONG_MAX__ 0x7fffffffL
#define __FLT_HAS_INFINITY__ 1
#define __GNUC_EXECUTION_CHARSET_NAME "UTF-8"
#define __unix 1
#define __UINT_FAST16_TYPE__ unsigned int
#define __INT_FAST32_WIDTH__ 32
#define __CHAR16_TYPE__ short unsigned int
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __SIZE_WIDTH__ 32
#define __NEED_size_t 
#define __INT_LEAST16_MAX__ 0x7fff
#define __INT64_MAX__ 0x7fffffffffffffffLL
#define __SACCUM_FBIT__ 7
#define __FLT32_DENORM_MIN__ 1.4012984643248171e-45F32
#define __SIG_ATOMIC_WIDTH__ 32
#define __INT_LEAST64_TYPE__ long long int
#define __INT16_TYPE__ short int
#define __INT_LEAST8_TYPE__ signed char
#define _mips 1
#define __STDC_VERSION__ 201710L
#define __SQ_FBIT__ 31
#define __INT_FAST8_MAX__ 0x7f
#define __INTPTR_MAX__ 0x7fffffff
#define __QQ_FBIT__ 7
#define linux 1
#define __UTA_IBIT__ 64
#define __FLT64_HAS_QUIET_NAN__ 1
#define _MIPS_SZINT 32
#define __DEFINED_FILE 
#define __FLT32_MIN_10_EXP__ (-37)
#define __FLT32X_DIG__ 15
#define __UINT16_C(c) c
#define __PTRDIFF_WIDTH__ 32
#define __LDBL_MANT_DIG__ 53
#define __SFRACT_FBIT__ 7
#define __SACCUM_MIN__ (-0X1P7HK-0X1P7HK)
#define __FLT64_HAS_INFINITY__ 1
#define __MIPSEB 1
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
#define FILENAME_MAX 4096
#define __GCC_HAVE_BUILTIN_MIPS_CACHE 1
#define L_cuserid 20
#define __INTPTR_TYPE__ int
#define __UINT16_TYPE__ short unsigned int
#define __WCHAR_TYPE__ int
#define __SIZEOF_FLOAT__ 4
#define __TQ_FBIT__ 127
#define __USQ_FBIT__ 32
#define __UINTPTR_MAX__ 0xffffffffU
#define __INT_FAST64_WIDTH__ 64
#define __BYTE_ORDER 4321
#define __ULLACCUM_IBIT__ 32
#define __FLT32_DECIMAL_DIG__ 9
#define __INT_FAST64_MAX__ 0x7fffffffffffffffLL
#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
#define BUFSIZ 1024
#define __FLT_NORM_MAX__ 3.4028234663852886e+38F
#define __UINT_FAST64_TYPE__ long long unsigned int
#define __INT_MAX__ 0x7fffffff
#define mips 1
#define __LACCUM_FBIT__ 31
#define __USACCUM_MIN__ 0.0UHK
#define _IOLBF 1
#define __UHA_IBIT__ 8
#define __INT64_TYPE__ long long int
#define __FLT_MAX_EXP__ 128
#define __UTQ_IBIT__ 0
#define _MIPS_SIM _ABIO32
#define __DBL_MANT_DIG__ 53
#define __INT_LEAST64_MAX__ 0x7fffffffffffffffLL
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
#define __mips__ 1
#define __WINT_TYPE__ unsigned int
#define __UINT_LEAST32_TYPE__ unsigned int
#define __SIZEOF_SHORT__ 2
#define __ULLFRACT_IBIT__ 0
#define __FLT32_NORM_MAX__ 3.4028234663852886e+38F32
#define __DEFINED_va_list 
#define __LDBL_MIN_EXP__ (-1021)
#define _MIPS_FPSET 16
#define __FLT64_MAX__ 1.7976931348623157e+308F64
#define __UDA_IBIT__ 32
#define stdout (stdout)
#define __WINT_WIDTH__ 32
#define __mips16 1
#define EOF (-1)
#define __INT_LEAST8_MAX__ 0x7f
#define __INT_LEAST64_WIDTH__ 64
#define __FLT32X_MAX_10_EXP__ 308
#define __SSP__ 1
#define __LFRACT_FBIT__ 31
#define __LDBL_MAX_10_EXP__ 308
#define __ATOMIC_RELAXED 0
#define __DBL_EPSILON__ ((double)2.2204460492503131e-16L)
#define __INT_LEAST32_TYPE__ int
#define __UINT8_C(c) c
#define __FLT64_MAX_EXP__ 1024
#define SEEK_END 2
#define __SIZEOF_WCHAR_T__ 4
#define __UINT64_TYPE__ long long unsigned int
#define __OPTIMIZE_SIZE__ 1
#define __LLFRACT_MAX__ 0X7FFFFFFFFFFFFFFFP-63LLR
#define __FLT64_NORM_MAX__ 1.7976931348623157e+308F64
#define __INTMAX_MAX__ 0x7fffffffffffffffLL
#define __INT_FAST8_TYPE__ signed char
#define __ULLACCUM_EPSILON__ 0x1P-32ULLK
#define __USACCUM_MAX__ 0XFFFFP-8UHK
#define __UHQ_IBIT__ 0
#define __LLACCUM_IBIT__ 32
#define P_tmpdir "/tmp"
#define __FLT64_HAS_DENORM__ 1
#define __FLT32_EPSILON__ 1.1920928955078125e-7F32
#define __DBL_DECIMAL_DIG__ 17
#define __STDC_UTF_32__ 1
#define __INT_FAST8_WIDTH__ 8
#define __FLT32X_MAX__ 1.7976931348623157e+308F32x
#define __TA_FBIT__ 63
#define __DBL_NORM_MAX__ ((double)1.7976931348623157e+308L)
#define _REDIR_TIME64 1
#define FOPEN_MAX 1000
#define __BIG_ENDIAN 4321
#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
#define _MIPS_ARCH_MIPS32R2 1
#define __mips_soft_float 1
#define __UDQ_IBIT__ 0
#define __INTMAX_WIDTH__ 64
#define __ORDER_BIG_ENDIAN__ 4321
#define __FLT32_DIG__ 6
#define __ACCUM_EPSILON__ 0x1P-15K
#define __UINT32_C(c) c ## U
#define __FLT_DENORM_MIN__ 1.4012984643248171e-45F
#define __LLFRACT_IBIT__ 0
#define __INT8_MAX__ 0x7f
#define __LONG_WIDTH__ 32
#define __UINT_FAST32_TYPE__ unsigned int
#define __FLT32X_NORM_MAX__ 1.7976931348623157e+308F32x
#define __CHAR32_TYPE__ unsigned int
#define __FLT_MAX__ 3.4028234663852886e+38F
#define LANGUAGE_C 1
#define __USACCUM_FBIT__ 8
#define __INT32_TYPE__ int
#define __SIZEOF_DOUBLE__ 8
#define __FLT_MIN_10_EXP__ (-37)
#define __UFRACT_EPSILON__ 0x1P-16UR
#define __FLT64_MIN__ 2.2250738585072014e-308F64
#define __INT_LEAST32_WIDTH__ 32
#define __INTMAX_TYPE__ long long int
#define _LANGUAGE_C 1
#define __FLT32X_HAS_QUIET_NAN__ 1
#define __ATOMIC_CONSUME 1
#define __GNUC_MINOR__ 2
#define __INT_FAST16_WIDTH__ 32
#define __UINTMAX_MAX__ 0xffffffffffffffffULL
#define __FLT32X_DENORM_MIN__ 4.9406564584124654e-324F32x
#define __inline inline
#define __HA_FBIT__ 7
#define __NEED_ssize_t 
#define __DBL_MAX_10_EXP__ 308
#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
#define __INT16_C(c) c
#define __STDC__ 1
#define __PTRDIFF_TYPE__ int
#define __LLFRACT_MIN__ (-0.5LLR-0.5LLR)
#define __mips 32
#define __DA_FBIT__ 31
#define __UINT32_TYPE__ unsigned int
#define _MIPS_SZLONG 32
#define __FLT32X_MIN_10_EXP__ (-307)
#define __UINTPTR_TYPE__ unsigned int
#define __USA_IBIT__ 16
#define __linux__ 1
#define __LDBL_MIN_10_EXP__ (-307)
#define __SIZEOF_LONG_LONG__ 8
#define __ULACCUM_EPSILON__ 0x1P-32ULK
#define __SACCUM_IBIT__ 8
#define __GCC_ATOMIC_LLONG_LOCK_FREE 1
#define __FLT_DECIMAL_DIG__ 9
#define __UINT_FAST16_MAX__ 0xffffffffU
#define __LDBL_NORM_MAX__ 1.7976931348623157e+308L
#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
#define __ULLFRACT_MAX__ 0XFFFFFFFFFFFFFFFFP-64ULLR
#define __UINT_FAST8_TYPE__ unsigned char
#define __USFRACT_EPSILON__ 0x1P-8UHR
#define __ULACCUM_FBIT__ 32
#define __QQ_IBIT__ 0
#define __ATOMIC_ACQ_REL 4
#define HELLO "hello,"
#define __ATOMIC_RELEASE 3

Hostle

1 Like

Hi Hostle and thank you for your quick reply.

I need the pre-processed files because I have to run a tool which yields some information about function's call dependencies amongst the project files, but it requires the pre-processed files in input. That's why I need owrt to output the preprocessed files instead of the compiled ones.

I already have the makefile of my package and it's already got compiled. However, I should hack the default compilation operation under the Build/Compile/Default definition in the package-defaults.mk file, but I don't manage to follow the code until the actual compilation instruction, then not be able to modify it with the -E option.

Can you help me on this?

Sure. do you mind posting your openwrt makefile ? I can show you what you need to edit. Or you can likely figure it out yourself using the makefile i posted.

you'll need to edit the Build/Compile section on your makefile.

define Build/Compile
	$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource.c > $(PKG_BUILD_DIR)/myPackage_prep.out
	$(TARGET_CC) $(TARGET_CFLAGS) -o -Wall -Werror $(PKG_BUILD_DIR)/mySource.c -o $(PKG_BUILD_DIR)/myPackage
endef

you'll want to use this line

$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource1.c > $(PKG_BUILD_DIR)/myPackage_prep.out

however, you'll need to modify it to suit your needs. You will need to add each source file, you want to dump the pp for, to the command. Or, alternatively, you can resuse the cmd for each src file and give each src file its own pp dump file.

option 1

$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource1.c  $(PKG_BUILD_DIR)/mySource2.c   $(PKG_BUILD_DIR)/mySourc3.c > $(PKG_BUILD_DIR)/myPackage_prep.out

the above command would produce the pp for mySource1.c, mySource2.c, and my source3.c, into a single file named myPackage_prep.out.

option 2

$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource1.c > $(PKG_BUILD_DIR)/myPackage_prep1.out

$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource2.c > $(PKG_BUILD_DIR)/myPackage_prep2.out

$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource3.c > $(PKG_BUILD_DIR)/myPackage_prep3.out

the above would produce a seperate dump of mySourec1.c in file myPackage_prep1.out, mySource2.c in file myPackage_prep2.out ...etc

Hi Hostle,

Should I share the specific package's makefile or the package-defaults.mk one?

I can modify the Build/Compile section of my makefile but I've to implement a way to take into account all the source files under my package without specifying them singularly. I think I should write a pattern rules into it, right?

In addition

$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource.c > $(PKG_BUILD_DIR)/myPackage_prep.out
$(TARGET_CC) $(TARGET_CFLAGS) -o -Wall -Werror $(PKG_BUILD_DIR)/mySource.c -o $(PKG_BUILD_DIR)/myPackage

does the second line output the compiled file?

just the Makefile for the package, really i just need to see the Build/Compile section of this makefile.

define Build/Compile
...
endef

Yes, that is correct. I included that, just so the example I provided was complete, for others to use as an example of building a simple package.

1 Like

I will be in vacation until August, 27th, then I think I can't provide you the Build/Compile section by the evening.

However, the current makefile of my package does not have a Build/Compile section, then it's processed by the Build/Compile/Default. Is there a way to modify the default compilation in order to even get the pre-compiled file?

Come on now ... enjoy your vacation!! I can most definitely edit the makefile to produce what you need... once you're back lol.

Hostle

I will be grateful if you provide me a way to change the behavior of the default compilation, but it would be fine to change the Build/Compile section of my package's makefile, too. In such case, I'll do some trials when I get back...regenerated and tanned :smiley:

Massimiliano

1 Like

The openwrt build system is, at its core, just a bunch of Makefiles. You control what is built, how things are built ..and so on, with Makefiles. Its really the first thing, and probably the most important thing to learn, concerning cc for openwrt.

Enjoy your vaction. we'll get you fixed up when you're back.

2 Likes

Yes of course, but as far as I've understood, if I don't provide a package's makefile with the Build/Compile section (that is optional), the Build/Compile/Default section comes into place, i.e. the inner makefiles of the owrt core.

this Makefile ...that makefile, this is for the most part just preference. There is many ways you can build/configure/compile, the recipe you choose is entirely up to you. I might add, more times than not, it depends on the package maintainers ideology. Myself, I develop for x64 linux first, i then create the openwrt Makefile to cross compile the src for openwrt. I do it this way because its keeps things separate, in regards to building for, ubuntu for example, vs building for openwrt. I use the makefile in the src to build for linux, and then use the openwrt Makefile to override the makefile in the src directory when i wish to cross-compile for ow. The next guy, may choose an entirely different recipe, that's really one of the reasons I enjoy developing for openwrt. The build system give you the freedom to build it your own way .

I Hostle, I came back!

Well, I tried to insert the following instruction in the package Makefile

define Build/Compile
$(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/mySource.c > (PKG_BUILD_DIR)/myPackage_prep.out
$(TARGET_CC) $(TARGET_CFLAGS) -o -Wall -Werror $(PKG_BUILD_DIR)/mySource.c -o $(PKG_BUILD_DIR)/myPackage
endef

Then I run

make package/<my_pck>/compile

to only compile my package. However, the Build/Compile fails because some headers in the mySource.c is not included in the $(TARGET_CFLAGS). I suppose that I should create a custom makefile to be called into the defined Build/Compile as outlined in the following guide.

What do you think? Can you suggest me other solutions?

going off of what was said in our previous discussion

you will leave the openwrt makefile as is, and make the edits in the actual src makefile.

can you post the src makefile ? I'll show you want you need to add

another, less correct option, would be to add a configure section to the openwrt makefile, and do it from there. But i believe the simplest option for you will be to add the commands to the actual src makefile.

In the owrt/owrt-telit/packages/m2m folder there are:

  • files folder, with no source files
  • Makefile file

the source files are in owrt/src/telit/m2m/... but there's any makefile here. There is only the package makefile in the owrt/owrt-telit/packages/m2m and it's written like the new package guide suggests. Do you need it to be posted?

It belongs to my company and I don't know if can share it...

Which makefile do you mean for 'src makefile'?

Is a package you have created ? is there in fact C source files, or is it just scripts and such ?

I'm working on a project which has moved from another team but that team created this new package as far as I know. In the files folder there are only txt files, then the sources are all in the owrt/owrt-telit/packages/m2m folder.

Just to be not awkward, this is the initial lines of the Makefile in owrt/owrt-telit/packages/m2m

include $(TOPDIR)/rules.mk

PKG_NAME:=m2m
PKG_VERSION:=1.0
PKG_RELEASE:=1
PKG_FIXUP:=autoreconf

LOCAL_SRC:=$(TOPDIR)/src/telit/m2m/
M2M_CONF_DIR=$(PKG_BUILD_DIR)/m2m_qclinux/private/m2mmain/config

ifeq ($(CONFIG_TARGET_sdx35),y)
TARGET_BASEMACHINE:=sdxbaagha
endif

include $(INCLUDE_DIR)/package.mk

...

define Package/m2m
	TITLE:=m2m
	SECTION:=TELIT
	CATEGORY:=TELIT-M2M
	DEPENDS:=+common +qmi-framework +qmi +log-telit +curl +libopenssl +libwolfssl +libqcmap_client +dsutils +loc-api-v02 +paho-mqtt-c +paho-mqtt-sn
	DEPENDS += +glib2 loc-pla-hdr +location-client-api +location-integration-api
endef

ok, I think I follow. So lets try and just hack the openwrt makefile a bit first... lets call it from the Build/Prepare section...

define Build/Prepare
    $(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/*.c > (PKG_BUILD_DIR)/myPackage_prep.out
endef

if the make file already contains this section, just append the command to the bottom of the section.

define Build/Prepare
    ...
    ...
    $(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/*.c > (PKG_BUILD_DIR)/myPackage_prep.out
endef

the above command will write the pp info for all .c files in the build directory. you'll need to confirm this path. Look inside ~/openwrt/build_dir//m2m. It may be the case, that the src files are in a directory named src within this directory ie..

~/openwrt/build_dir/target-mips_24kc_musl/m2m/src/mysource.c

if this is the case, you need to adjust the path used in the command. As is it is set to look inside ~/openwrt/build_dir//m2m/, if the source files are in a subdirectory named src, you will change the path like this..

  $(TARGET_CC) $(TARGET_CFLAGS) -E -dM $(PKG_BUILD_DIR)/src/*.c > (PKG_BUILD_DIR)/myPackage_prep.out

i hope that's clear enough to follow. I am working on three things at once lol.

I I should note ... you'll want to repair your makefile, and rebuild the package before the above. Its likely that your package is empty or not present in the build_dir since your last attempt to build failed.