Skip to content

Commit 89d0c64

Browse files
authored
Merge pull request #247 from libtom/pr/custom_compile_flags
introduce LTC_CFLAGS and LTC_LDFLAGS
2 parents 24e69b2 + a2f4857 commit 89d0c64

File tree

6 files changed

+42
-39
lines changed

6 files changed

+42
-39
lines changed

makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ include makefile_include.mk
3939
ifeq ($(COVERAGE),1)
4040
all_test: LIB_PRE = -Wl,--whole-archive
4141
all_test: LIB_POST = -Wl,--no-whole-archive
42-
CFLAGS += -fprofile-arcs -ftest-coverage
42+
LTC_CFLAGS += -fprofile-arcs -ftest-coverage
4343
EXTRALIBS += -lgcov
4444
endif
4545

4646
#AES comes in two flavours... enc+dec and enc
4747
src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
48-
${silent} ${CC} ${CFLAGS} -DENCRYPT_ONLY -c $< -o $@
48+
${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@
4949

5050
.c.o:
5151
ifneq ($V,1)
5252
@echo " * ${CC} $@"
5353
endif
54-
${silent} ${CC} ${CFLAGS} -c $< -o $@
54+
${silent} ${CC} ${LTC_CFLAGS} -c $< -o $@
5555

5656
$(LIBNAME): $(OBJECTS)
5757
ifneq ($V,1)
@@ -67,21 +67,21 @@ timing: $(LIBNAME) $(TIMINGS)
6767
ifneq ($V,1)
6868
@echo " * ${CC} $@"
6969
endif
70-
${silent} $(CC) $(LDFLAGS) $(TIMINGS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING)
70+
${silent} $(CC) $(LTC_LDFLAGS) $(TIMINGS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING)
7171

7272
test: $(LIBNAME) $(TOBJECTS)
7373
ifneq ($V,1)
7474
@echo " * ${CC} $@"
7575
endif
76-
${silent} $(CC) $(LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST)
76+
${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST)
7777

7878
# build the demos from a template
7979
define DEMO_template
8080
$(1): demos/$(1).o $$(LIBNAME)
8181
ifneq ($V,1)
8282
@echo " * $${CC} $$@"
8383
endif
84-
$${silent} $$(CC) $$(CFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1)
84+
$${silent} $$(CC) $$(LTC_CFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1)
8585
endef
8686

8787
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
@@ -97,10 +97,10 @@ install_bins: .common_install_bins
9797
uninstall: .common_uninstall
9898

9999
profile:
100-
CFLAGS="$(CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov"
100+
LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov"
101101
./timing
102102
rm -f timing `find . -type f | grep [.][ao] | xargs`
103-
CFLAGS="$(CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov"
103+
LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov"
104104

105105
# target that pre-processes all coverage data
106106
lcov-single-create:
@@ -128,7 +128,7 @@ lcov-single:
128128

129129

130130
#make the code coverage of the library
131-
coverage: CFLAGS += -fprofile-arcs -ftest-coverage
131+
coverage: LTC_CFLAGS += -fprofile-arcs -ftest-coverage
132132
coverage: EXTRALIBS += -lgcov
133133
coverage: LIB_PRE = -Wl,--whole-archive
134134
coverage: LIB_POST = -Wl,--no-whole-archive

makefile.mingw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CFLAGS = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath
2525
EXTRALIBS = -L../libtommath -ltommath
2626

2727
#Compilation flags
28-
LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itests -DLTC_SOURCE
28+
LTC_CFLAGS = -Isrc/headers -Itests -DLTC_SOURCE $(CFLAGS)
2929
LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS)
3030
VERSION=1.18.0-rc1
3131

makefile.msvc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CFLAGS = /Ox /DUSE_LTM /DLTM_DESC /I../libtommath
2020
EXTRALIBS = ../libtommath/tommath.lib
2121

2222
#Compilation flags
23-
LTC_CFLAGS = $(CFLAGS) /nologo /Isrc/headers/ /Itests/ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /DLTC_SOURCE /W3
23+
LTC_CFLAGS = /nologo /Isrc/headers/ /Itests/ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /DLTC_SOURCE /W3 $(CFLAGS)
2424
LTC_LDFLAGS = advapi32.lib $(EXTRALIBS)
2525
VERSION=1.18.0-rc1
2626

makefile.shared

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ include makefile_include.mk
3838

3939
#ciphers come in two flavours... enc+dec and enc
4040
src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
41-
$(LTCOMPILE) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
41+
$(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
4242

4343
.c.o:
44-
$(LTCOMPILE) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -c $<
44+
$(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $<
4545

4646
LOBJECTS = $(OBJECTS:.o=.lo)
4747

4848
$(LIBNAME): $(OBJECTS)
49-
$(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT)
49+
$(LT) --mode=link --tag=CC $(CC) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT)
5050

5151
install: .common_install
5252
sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' libtomcrypt.pc.in > libtomcrypt.pc
@@ -59,18 +59,18 @@ uninstall: .common_uninstall
5959
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
6060

6161
test: $(LIBNAME) $(TOBJECTS)
62-
$(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS)
62+
$(LT) --mode=link --tag=CC $(CC) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS)
6363

6464
timing: $(TIMINGS) $(LIBNAME)
65-
$(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TIMING) $^ $(EXTRALIBS)
65+
$(LT) --mode=link --tag=CC $(CC) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $(TIMING) $^ $(EXTRALIBS)
6666

6767
# build the demos from a template
6868
define DEMO_template
6969
$(1): demos/$(1).o $$(LIBNAME)
7070
ifneq ($V,1)
7171
@echo " * $${CC} $$@"
7272
endif
73-
$$(LT) --mode=link --tag=CC $$(CC) $$(CFLAGS) $$(CPPFLAGS) $$(LDFLAGS) $$^ $$(EXTRALIBS) -o $(1)
73+
$$(LT) --mode=link --tag=CC $$(CC) $$(LTC_CFLAGS) $$(CPPFLAGS) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1)
7474
endef
7575

7676
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))

makefile.unix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CFLAGS = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath
3737
EXTRALIBS = ../libtommath/libtommath.a
3838

3939
#Compilation flags
40-
LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itests -DLTC_SOURCE
40+
LTC_CFLAGS = -Isrc/headers -Itests -DLTC_SOURCE $(CFLAGS)
4141
LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS)
4242
VERSION=1.18.0-rc1
4343

makefile_include.mk

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,68 +52,71 @@ endif
5252
# by giving them as a parameter to make:
5353
# make CFLAGS="-I./src/headers/ -DLTC_SOURCE ..." ...
5454
#
55-
CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE
55+
LTC_CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow -DLTC_SOURCE
5656

5757
ifdef OLD_GCC
58-
CFLAGS += -W
58+
LTC_CFLAGS += -W
5959
# older GCCs can't handle the "rotate with immediate" ROLc/RORc/etc macros
6060
# define this to help
61-
CFLAGS += -DLTC_NO_ROLC
61+
LTC_CFLAGS += -DLTC_NO_ROLC
6262
else
63-
CFLAGS += -Wextra
63+
LTC_CFLAGS += -Wextra
6464
# additional warnings
65-
CFLAGS += -Wsystem-headers -Wbad-function-cast -Wcast-align
66-
CFLAGS += -Wstrict-prototypes -Wpointer-arith
67-
CFLAGS += -Wdeclaration-after-statement
65+
LTC_CFLAGS += -Wsystem-headers -Wbad-function-cast -Wcast-align
66+
LTC_CFLAGS += -Wstrict-prototypes -Wpointer-arith
67+
LTC_CFLAGS += -Wdeclaration-after-statement
6868
endif
6969

70-
CFLAGS += -Wno-type-limits
70+
LTC_CFLAGS += -Wno-type-limits
7171

7272
ifdef LTC_DEBUG
7373
# compile for DEBUGGING (required for ccmalloc checking!!!)
74-
CFLAGS += -g3 -DLTC_NO_ASM
74+
LTC_CFLAGS += -g3 -DLTC_NO_ASM
7575
ifneq (,$(strip $(LTC_DEBUG)))
76-
CFLAGS += -DLTC_TEST_DBG=$(LTC_DEBUG)
76+
LTC_CFLAGS += -DLTC_TEST_DBG=$(LTC_DEBUG)
7777
else
78-
CFLAGS += -DLTC_TEST_DBG
78+
LTC_CFLAGS += -DLTC_TEST_DBG
7979
endif
8080
else
8181

8282
ifdef LTC_SMALL
8383
# optimize for SIZE
84-
CFLAGS += -Os -DLTC_SMALL_CODE
84+
LTC_CFLAGS += -Os -DLTC_SMALL_CODE
8585
else
8686

8787
ifndef IGNORE_SPEED
8888
# optimize for SPEED
89-
CFLAGS += -O3 -funroll-loops
89+
LTC_CFLAGS += -O3 -funroll-loops
9090

9191
# add -fomit-frame-pointer. hinders debugging!
92-
CFLAGS += -fomit-frame-pointer
92+
LTC_CFLAGS += -fomit-frame-pointer
9393
endif
9494

9595
endif # COMPILE_SMALL
9696
endif # COMPILE_DEBUG
9797

9898

9999
ifneq ($(findstring clang,$(CC)),)
100-
CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
100+
LTC_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
101101
endif
102102
ifeq ($(PLATFORM), Darwin)
103-
CFLAGS += -Wno-nullability-completeness
103+
LTC_CFLAGS += -Wno-nullability-completeness
104104
endif
105105

106106

107107
GIT_VERSION := $(shell [ -e .git ] && { printf git- ; git describe --tags --always --dirty ; } || echo $(VERSION))
108108
ifneq ($(GIT_VERSION),)
109-
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
109+
LTC_CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
110110
endif
111111

112+
LTC_CFLAGS := $(LTC_CFLAGS) $(CFLAGS)
112113

113-
ifneq ($(findstring -DLTC_PTHREAD,$(CFLAGS)),)
114-
LDFLAGS += -pthread
114+
ifneq ($(findstring -DLTC_PTHREAD,$(LTC_CFLAGS)),)
115+
LTC_LDFLAGS += -pthread
115116
endif
116117

118+
LTC_LDFLAGS := $(LTC_LDFLAGS) $(LDFLAGS)
119+
117120
#List of demo objects
118121
DSOURCES = $(wildcard demos/*.c)
119122
DOBJECTS = $(DSOURCES:.c=.o)
@@ -340,8 +343,8 @@ src/hashes/sha2/sha512_224.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_22
340343
src/hashes/sha2/sha512_256.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_256.c
341344
src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c
342345

343-
$(DOBJECTS): CFLAGS += -Itests
344-
$(TOBJECTS): CFLAGS += -Itests
346+
$(DOBJECTS): LTC_CFLAGS := -Itests $(LTC_CFLAGS)
347+
$(TOBJECTS): LTC_CFLAGS := -Itests $(LTC_CFLAGS)
345348

346349
#This rule makes the libtomcrypt library.
347350
library: $(LIBNAME)

0 commit comments

Comments
 (0)