Skip to content

Commit

Permalink
drop the need for testprof/makefile*
Browse files Browse the repository at this point in the history
  • Loading branch information
karel-m authored and sjaeckel committed May 11, 2017
1 parent 2c97498 commit bf45ea6
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 145 deletions.
75 changes: 41 additions & 34 deletions helper.pl
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,27 @@ sub prepare_msvc_files_xml {
}

sub patch_makefile {
my ($in_ref, $out_ref, $data) = @_;
open(my $src, '<', $in_ref);
open(my $dst, '>', $out_ref);
my $l = 0;
while (<$src>) {
if ($_ =~ /START_INS/) {
print {$dst} $_;
$l = 1;
print {$dst} $data;
} elsif ($_ =~ /END_INS/) {
print {$dst} $_;
$l = 0;
} elsif ($l == 0) {
print {$dst} $_;
my ($content, @variables) = @_;
for my $v (@variables) {
if ($v =~ /^([A-Z0-9_]+)\s*=.*$/si) {
my $name = $1;
$content =~ s/\n\Q$name\E\b.*?[^\\]\n/\n$v\n/s;
}
else {
die "patch_makefile failed: " . substr($v, 0, 30) . "..";
}
}
return $content;
}

sub version_form_tomcrypt_h {
my $h = read_file(shift);
if ($h =~ /\n#define\s*SCRYPT\s*"([0-9]+)\.([0-9]+)"/s) {
return "VERSION_MAJ=$1", "VERSION_MIN=$2", "VERSION=$1.$2", "VERSION_LT=0:$1$2";
}
else {
die "#define SCRYPT not found in tomcrypt.h";
}
close $dst;
close $src;
}

sub process_makefiles {
Expand All @@ -230,12 +233,20 @@ sub process_makefiles {
find({ no_chdir => 1, wanted => sub { push @h, $_ if -f $_ && $_ =~ /\.h$/ && $_ !~ /dh_static.h$/ } }, 'src');
my @all = ();
find({ no_chdir => 1, wanted => sub { push @all, $_ if -f $_ && $_ =~ /\.(c|h)$/ } }, 'src');
my @t = qw();
find({ no_chdir => 1, wanted => sub { push @t, $_ if $_ =~ /(no_prng|test_driver|x86_prof|_tests?).c$/ } }, 'testprof');

my @o = sort ('src/ciphers/aes/aes_enc.o', map { $_ =~ s/\.c$/.o/; $_ } @c);
my $var_o = prepare_variable("OBJECTS", @o);
my $var_o = prepare_variable("OBJECTS", @o);
my $var_h = prepare_variable("HEADERS", (sort @h));
(my $var_obj = $var_o) =~ s/\.o\b/.obj/sg;
my $var_h = prepare_variable("HEADERS", (sort @h, 'testprof/tomcrypt_test.h'));

my $var_to = prepare_variable("TOBJECTS", sort map { $_ =~ s/\.c$/.o/; $_ } @t);
(my $var_tobj = $var_to) =~ s/\.o\b/.obj/sg;

my @ver_version = version_form_tomcrypt_h("src/headers/tomcrypt.h");

# update MSVC project files
my $msvc_files = prepare_msvc_files_xml(\@all, qr/tab\.c$/, ['Debug|Win32', 'Release|Win32', 'Debug|x64', 'Release|x64']);
for my $m (qw/libtomcrypt_VS2008.vcproj/) {
my $old = read_file($m);
Expand All @@ -248,22 +259,18 @@ sub process_makefiles {
}
}

my @makefiles = qw( makefile makefile.icc makefile.shared makefile.unix makefile.mingw makefile.msvc );
for my $m (@makefiles) {
# update OBJECTS + HEADERS in makefile*
for my $m (qw/ makefile makefile.icc makefile.shared makefile.unix makefile.mingw makefile.msvc makefile.include /) {
my $old = read_file($m);
my $new;
if ($m eq 'makefile.msvc') {
patch_makefile(\$old, \$new, "$var_obj\n\n$var_h\n\n");
}
else {
patch_makefile(\$old, \$new, "$var_o\n\n$var_h\n\n");
}
my $new = $m eq 'makefile.msvc' ? patch_makefile($old, $var_obj, $var_h, $var_to, @ver_version)
: patch_makefile($old, $var_o, $var_h, $var_to, @ver_version);
if ($old ne $new) {
write_file($m, $new) if $write;
warn "changed: $m\n";
$changed_count++;
}
}

if ($write) {
return 0; # no failures
}
Expand All @@ -283,13 +290,13 @@ sub die_usage {
MARKER
}

GetOptions( "check-source" => \my $check_source,
"check-defines" => \my $check_defines,
"check-hashes" => \my $check_hashes,
"check-makefiles" => \my $check_makefiles,
"check-all" => \my $check_all,
"update-makefiles" => \my $update_makefiles,
"help" => \my $help
GetOptions( "s|check-source" => \my $check_source,
"d|check-defines" => \my $check_defines,
"h|check-hashes" => \my $check_hashes,
"m|check-makefiles" => \my $check_makefiles,
"a|check-all" => \my $check_all,
"u|update-makefiles" => \my $update_makefiles,
"h|help" => \my $help
) or die_usage;

my $failure;
Expand Down
6 changes: 3 additions & 3 deletions libtomcrypt.pc.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
prefix=/usr
prefix=@to-be-replaced@
exec_prefix=${prefix}
libdir=@LIBDIR@
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: LibTomCrypt
Description: public domain open source cryptographic toolkit
Version: 1.17
Version: @to-be-replaced@
Libs: -L${libdir} -ltomcrypt
Cflags: -I${includedir}
63 changes: 39 additions & 24 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ endif
ifndef LIBTEST
LIBTEST=libtomcrypt_prof.a
endif
LIBTEST_S=$(LIBTEST)

#List of objects to compile.
#START_INS
# List of objects to compile (all goes to libtomcrypt.a)
OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src/ciphers/blowfish.o \
src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/kasumi.o src/ciphers/khazad.o \
src/ciphers/kseed.o src/ciphers/multi2.o src/ciphers/noekeon.o src/ciphers/rc2.o src/ciphers/rc5.o \
Expand Down Expand Up @@ -190,13 +188,20 @@ src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream
src/stream/rc4/rc4.o src/stream/rc4/rc4_test.o src/stream/sober128/sober128.o \
src/stream/sober128/sober128_test.o

# List of test objects to compile (all goes to libtomcrypt_prof.a)
TOBJECTS=testprof/base64_test.o testprof/cipher_hash_test.o testprof/der_tests.o testprof/dh_test.o \
testprof/dsa_test.o testprof/ecc_test.o testprof/file_test.o testprof/katja_test.o testprof/mac_test.o \
testprof/misc_test.o testprof/modes_test.o testprof/multi_test.o testprof/no_prng.o \
testprof/pkcs_1_eme_test.o testprof/pkcs_1_emsa_test.o testprof/pkcs_1_oaep_test.o \
testprof/pkcs_1_pss_test.o testprof/pkcs_1_test.o testprof/rotate_test.o testprof/rsa_test.o \
testprof/store_test.o testprof/test_driver.o testprof/x86_prof.o

# The following headers will be installed by "make install"
HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \
src/headers/tomcrypt_cipher.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_hash.h \
src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h src/headers/tomcrypt_math.h \
src/headers/tomcrypt_misc.h src/headers/tomcrypt_pk.h src/headers/tomcrypt_pkcs.h \
src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h

#END_INS
src/headers/tomcrypt_prng.h

#Files left over from making the crypt.pdf.
LEFTOVERS=*.dvi *.log *.aux *.toc *.idx *.ilg *.ind *.out *.lof
Expand All @@ -223,7 +228,9 @@ src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c
#This rule makes the libtomcrypt library.
library: $(LIBNAME)

#Dependencies on *.h
$(OBJECTS): $(HEADERS)
$(TOBJECTS): $(HEADERS) testprof/tomcrypt_test.h

$(LIBNAME): $(OBJECTS)
ifneq ($V,1)
Expand All @@ -235,22 +242,27 @@ ifneq ($V,1)
endif
${silent} $(RANLIB) $@

.PHONY: testprof/$(LIBTEST)
testprof/$(LIBTEST):
${silent} CFLAGS="$(CFLAGS)" LIBTEST_S=$(LIBTEST_S) CC="$(CC)" LD="$(LD)" AR="$(AR)" ARFLAGS="$(ARFLAGS)" RANLIB="$(RANLIB)" V="$(V)" $(MAKE) -C testprof
$(LIBTEST): $(TOBJECTS)
ifneq ($V,1)
@echo " * ${AR} $@"
endif
${silent} $(AR) $(ARFLAGS) $@ $(TOBJECTS)
ifneq ($V,1)
@echo " * ${RANLIB} $@"
endif
${silent} $(RANLIB) $@

timing: library testprof/$(LIBTEST) $(TIMINGS)
timing: library $(LIBTEST) $(TIMINGS)
ifneq ($V,1)
@echo " * ${CC} $@"
endif
${silent} $(CC) $(LDFLAGS) $(TIMINGS) testprof/$(LIBTEST) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING)
${silent} $(CC) $(LDFLAGS) $(TIMINGS) $(LIBTEST) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING)

.PHONY: test
test: library testprof/$(LIBTEST) $(TESTS)
test: library $(LIBTEST) $(TESTS)
ifneq ($V,1)
@echo " * ${CC} $@"
endif
${silent} $(CC) $(LDFLAGS) $(TESTS) testprof/$(LIBTEST) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST)
${silent} $(CC) $(LDFLAGS) $(TESTS) $(LIBTEST) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST)

# build the demos from a template
define DEMO_template
Expand All @@ -277,19 +289,20 @@ install: library docs
else
install: library
endif
install -d $(DESTDIR)$(LIBPATH)
install -d $(DESTDIR)$(INCPATH)
install -d $(DESTDIR)$(DATAPATH)
install -m 644 $(LIBNAME) $(DESTDIR)$(LIBPATH)
install -m 644 $(HEADERS) $(DESTDIR)$(INCPATH)
install -d $(LIBPATH)
install -d $(INCPATH)
install -d $(DATAPATH)
install -m 644 $(LIBNAME) $(LIBPATH)
install -m 644 $(HEADERS) $(INCPATH)
ifndef NODOCS
install -m 644 doc/crypt.pdf $(DESTDIR)$(DATAPATH)
install -m 644 doc/crypt.pdf $(DATAPATH)
endif

install_test: testprof/$(LIBTEST)
install -d $(DESTDIR)$(LIBPATH)
install -d $(DESTDIR)$(INCPATH)
install -m 644 testprof/$(LIBTEST) $(DESTDIR)$(LIBPATH)
install_test: $(LIBTEST)
install -d $(LIBPATH)
install -d $(INCPATH)
install -m 644 $(LIBTEST) $(LIBPATH)
install -m 644 testprof/tomcrypt_test.h $(INCPATH)

install_hooks:
for s in `ls hooks/`; do ln -s ../../hooks/$$s .git/hooks/$$s; done
Expand Down Expand Up @@ -342,6 +355,8 @@ clean:
rm -f `find . -type f -name "*.obj" | xargs`
rm -f `find . -type f -name "*.lib" | xargs`
rm -f `find . -type f -name "*.exe" | xargs`
rm -f `find . -type f -name "*.dll" | xargs`
rm -f `find . -type f -name "*.so" | xargs`
rm -f `find . -type f -name "*.gcov" | xargs`
rm -f `find . -type f -name "*.gcda" | xargs`
rm -f `find . -type f -name "*.gcno" | xargs`
Expand Down
46 changes: 27 additions & 19 deletions makefile.icc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ ifndef LIBNAME
endif
ifndef LIBTEST
LIBTEST=libtomcrypt_prof.a
LIBTEST_S=$(LIBTEST)
endif
HASH=hashsum
CRYPT=encrypt
Expand All @@ -96,8 +95,7 @@ ifndef DATAPATH
DATAPATH=/usr/share/doc/libtomcrypt/pdf
endif

#List of objects to compile.
#START_INS
# List of objects to compile (all goes to libtomcrypt.a)
OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src/ciphers/blowfish.o \
src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/kasumi.o src/ciphers/khazad.o \
src/ciphers/kseed.o src/ciphers/multi2.o src/ciphers/noekeon.o src/ciphers/rc2.o src/ciphers/rc5.o \
Expand Down Expand Up @@ -249,13 +247,20 @@ src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream
src/stream/rc4/rc4.o src/stream/rc4/rc4_test.o src/stream/sober128/sober128.o \
src/stream/sober128/sober128_test.o

# List of test objects to compile (all goes to libtomcrypt_prof.a)
TOBJECTS=testprof/base64_test.o testprof/cipher_hash_test.o testprof/der_tests.o testprof/dh_test.o \
testprof/dsa_test.o testprof/ecc_test.o testprof/file_test.o testprof/katja_test.o testprof/mac_test.o \
testprof/misc_test.o testprof/modes_test.o testprof/multi_test.o testprof/no_prng.o \
testprof/pkcs_1_eme_test.o testprof/pkcs_1_emsa_test.o testprof/pkcs_1_oaep_test.o \
testprof/pkcs_1_pss_test.o testprof/pkcs_1_test.o testprof/rotate_test.o testprof/rsa_test.o \
testprof/store_test.o testprof/test_driver.o testprof/x86_prof.o

# The following headers will be installed by "make install"
HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \
src/headers/tomcrypt_cipher.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_hash.h \
src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h src/headers/tomcrypt_math.h \
src/headers/tomcrypt_misc.h src/headers/tomcrypt_pk.h src/headers/tomcrypt_pkcs.h \
src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h

#END_INS
src/headers/tomcrypt_prng.h

#Who do we install as?
ifdef INSTALL_USER
Expand Down Expand Up @@ -297,9 +302,13 @@ src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c
#This rule makes the libtomcrypt library.
library: $(LIBNAME)

.PHONY: testprof/$(LIBTEST)
testprof/$(LIBTEST):
cd testprof ; LIBTEST_S=$(LIBTEST) CFLAGS="$(CFLAGS)" CC="$(CC)" AR="$(AR)" $(MAKE) -f makefile.icc
#Dependencies on *.h
$(OBJECTS): $(HEADERS)
$(TOBJECTS): $(HEADERS) testprof/tomcrypt_test.h

$(LIBTEST): $(TOBJECTS)
$(AR) $(ARFLAGS) $@ $(TOBJECTS)
$(RANLIB) $@

$(LIBNAME): $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS)
Expand All @@ -320,24 +329,23 @@ small: library $(SMALLOBJECTS)
tv_gen: library $(TVS)
$(CC) $(TVS) $(LIBNAME) $(EXTRALIBS) -o $(TV)

timing: library $(TIMINGS) testprof/$(LIBTEST)
$(CC) $(TIMINGS) testprof/$(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TIMING)
timing: library $(TIMINGS) $(LIBTEST)
$(CC) $(TIMINGS) $(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TIMING)

.PHONY: test
test: library $(TESTS) testprof/$(LIBTEST)
$(CC) $(TESTS) testprof/$(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TEST)
test: library $(TESTS) $(LIBTEST)
$(CC) $(TESTS) $(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TEST)

all_test: test tv_gen hashsum crypt small timing

#This rule installs the library and the header files. This must be run
#as root in order to have a high enough permission to write to the correct
#directories and to set the owner and group to root.
install: library
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
install -g $(GROUP) -o $(USER) $(LIBTEST) $(DESTDIR)$(LIBPATH)
install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
install -d -g $(GROUP) -o $(USER) $(LIBPATH)
install -d -g $(GROUP) -o $(USER) $(INCPATH)
install -g $(GROUP) -o $(USER) $(LIBNAME) $(LIBPATH)
install -g $(GROUP) -o $(USER) $(LIBTEST) $(LIBPATH)
install -g $(GROUP) -o $(USER) $(HEADERS) $(INCPATH)

# $Source$
# $Revision$
Expand Down
23 changes: 7 additions & 16 deletions makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,13 @@ DEMOS=hashsum crypt small tv_gen sizes constants
TIMINGS=demos/timing.o
TESTS=demos/test.o

#LIBPATH-The directory for libtomcrypt to be installed to.
#INCPATH-The directory to install the header files for libtomcrypt.
#DATAPATH-The directory to install the pdf docs.
ifndef DESTDIR
DESTDIR=
endif

ifndef LIBPATH
LIBPATH=/usr/lib
endif
ifndef INCPATH
INCPATH=/usr/include
endif
ifndef DATAPATH
DATAPATH=/usr/share/doc/libtomcrypt/pdf
endif
#LIBPATH The directory for libtomcrypt to be installed to.
#INCPATH The directory to install the header files for libtomcrypt.
#DATAPATH The directory to install the pdf docs.
DESTDIR ?= /usr/local
LIBPATH ?= $(DESTDIR)/lib
INCPATH ?= $(DESTDIR)/include
DATAPATH ?= $(DESTDIR)/share/doc/libtomcrypt/pdf

#Who do we install as?
ifdef INSTALL_USER
Expand Down
Loading

0 comments on commit bf45ea6

Please sign in to comment.