Browse Source

re-work makefile.mingw in the same style as makefile.unix

Karel Miko 8 năm trước cách đây
mục cha
commit
f544418d56
1 tập tin đã thay đổi với 77 bổ sung83 xóa
  1. 77 83
      makefile.mingw

+ 77 - 83
makefile.mingw

@@ -1,38 +1,42 @@
+# MAKEFILE for MS Windows (mingw + gcc + gmake)
 #
-# open a command prompt with gcc + gmake in PATH
-# and start: gmake -f makefile.mingw
-#
-
-EXTRALIBS=../libtommath/libtommath.a
-EXTRAINCLUDE=../libtommath
+# BEWARE: variables OBJECTS, TOBJECTS, HEADERS, VERSION are updated via ./updatemakes.sh
 
-CFLAGS = -Wall -Wextra -c -I./src/headers -I$(EXTRAINCLUDE) -I./testprof -DUSE_LTM -DLTM_DESC -DLTC_SOURCE -DLTC_NO_PROTOTYPES -O2 ${CFLAGS_OPTS}
-
-# Compiler and Linker Names
-CC=gcc
-LD=ld
-AR=ar
-ARFLAGS=rc
-RANLIB=ranlib
+### USAGE:
+# Open a command prompt with gcc + gmake in PATH and start:
+#
+# gmake -f makefile.mingw all
+# test.exe
+# gmake -f makefile.mingw install
+#
+#OR:
+#
+# gmake -f makefile.mingw CFLAGS="-O3 -DUSE_LTM -DLTM_DESC -Ic:/path/to/libtommath" EXTRALIBS="-Lc:/path/to/libtommath -ltommath" all
+# test.exe
+# gmake -f makefile.mingw DESTDIR=c:\devel\libtom install
+#
 
-LIBNAME=libtomcrypt.a
-LIBTEST=libtomcrypt_prof.a
+#The following can be overridden from command line e.g. make -f makefile.mingw CC=gcc ARFLAGS=rcs
+DESTDIR   = c:\mingw
+CC        = gcc
+AR        = ar
+ARFLAGS   = r
+RANLIB    = ranlib
+STRIP     = strip
+CFLAGS    = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath
+EXTRALIBS = -L../libtommath -ltommath
 
-HASH=hashsum
-CRYPT=encrypt
-SMALL=small
-PROF=x86_prof
-TV=tv_gen
-TIMING=timing
-TEST=test
+#Compilation flags
+LTC_CFLAGS  = $(CFLAGS) -Isrc/headers -Itestprof -DLTC_SOURCE
+LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS)
 
-#LIBPATH-The directory for libtomcrypt to be installed to.
-#INCPATH-The directory to install the header files for libtomcrypt.
-INSTPREFIX=c:\devel-libtom
-LIBPATH=$(INSTPREFIX)\lib
-INCPATH=$(INSTPREFIX)\include
+#Libraries to be created
+LIBMAIN_S =libtomcrypt.a
+LIBMAIN_I =libtomcrypt.dll.a
+LIBMAIN_D =libtomcrypt.dll
+LIBTEST_S =libtomcrypt_prof.a
 
-# List of objects to compile (all goes to libtomcrypt.a)
+#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 \
@@ -184,7 +188,7 @@ 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)
+#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 \
@@ -192,29 +196,24 @@ testprof/pkcs_1_eme_test.o testprof/pkcs_1_emsa_test.o testprof/pkcs_1_oaep_test
 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"
+#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
 
-TESTOBJECTS=demos/test.o
-HASHOBJECTS=demos/hashsum.o
-CRYPTOBJECTS=demos/encrypt.o
-SMALLOBJECTS=demos/small.o
-TVS=demos/tv_gen.o
-TIMINGS=demos/timing.o
-TESTS=demos/test.o
+.c.o:
+	$(CC) $(LTC_CFLAGS) -c $< -o $@
 
-#The default rule for make builds the libtomcrypt library.
-default:library
+#The default rule for make builds the libtomcrypt.a library (static)
+default: $(LIBMAIN_S)
 
-#ciphers come in two flavours... enc+dec and enc
+#SPECIAL: AES comes in two flavours - enc+dec and enc-only
 src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
-	$(CC) $(CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
+	$(CC) $(LTC_CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
 
-#These are the rules to make certain object files.
+#SPECIAL: these are the rules to make certain object files
 src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
 src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c
 src/hashes/whirl/whirl.o: src/hashes/whirl/whirl.c src/hashes/whirl/whirltab.c
@@ -223,58 +222,53 @@ src/hashes/sha2/sha512_224.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_22
 src/hashes/sha2/sha512_256.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_256.c
 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
 
-$(LIBTEST): $(TOBJECTS)
+#Create libtomcrypt_prof.a
+$(LIBTEST_S): $(TOBJECTS)
 	$(AR) $(ARFLAGS) $@ $(TOBJECTS)
 	$(RANLIB) $@
 
-%.o: %.c
-	${CC} ${CFLAGS} -c $< -o $@
-
-$(LIBNAME): $(OBJECTS)
+#Create libtomcrypt.a
+$(LIBMAIN_S): $(OBJECTS)
 	$(AR) $(ARFLAGS) $@ $(OBJECTS)
 	$(RANLIB) $@
 
-#This rule makes the hash program included with libtomcrypt
-hashsum: library $(HASHOBJECTS)
-	$(CC) $(HASHOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(HASH) $(WARN)
-
-#makes the crypt program
-crypt: library $(CRYPTOBJECTS)
-	$(CC) $(CRYPTOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(CRYPT) $(WARN)
-
-#makes the small program
-small: library $(SMALLOBJECTS)
-	$(CC) $(SMALLOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(SMALL) $(WARN)
-
-tv_gen: library $(TVS)
-	$(CC) $(LDFLAGS) $(TVS) $(LIBNAME) $(EXTRALIBS) -o $(TV)
+#Create DLL + import library libtomcrypt.dll.a
+$(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS)
+	$(CC) -s -shared -o $(LIBMAIN_D) $^ -Wl,--enable-auto-import,--export-all -Wl,--out-implib=$(LIBMAIN_I) $(LTC_LDFLAGS)
+	$(STRIP) -S $(LIBMAIN_D)
 
-timing: library $(LIBTEST) $(TIMINGS)
-	$(CC) $(LDFLAGS) $(TIMINGS) $(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TIMING)
+#Demo tools/utilities
+hashsum: demos/hashsum.o $(LIBMAIN_S)
+	$(CC) demos/hashsum.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
+crypt: demos/crypt.o $(LIBMAIN_S)
+	$(CC) demos/crypt.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
+small: demos/small.o $(LIBMAIN_S)
+	$(CC) demos/small.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
+tv_gen: demos/tv_gen.o $(LIBMAIN_S)
+	$(CC) demos/tv_gen.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
 
-.PHONY: test
-test: library $(LIBTEST) $(TESTS)
-	$(CC) $(LDFLAGS) $(TESTS) $(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TEST)
+#Tests + timing tests
+timing: demos/timing.o $(LIBTEST_S) $(LIBMAIN_S)
+	$(CC) demos/timing.o $(LIBTEST_S) $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
+	@echo NOTICE: start the tests by: timing.exe
+test: demos/test.o $(LIBMAIN_S) $(LIBTEST_S)
+	$(CC) demos/test.o $(LIBTEST_S) $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
+	@echo NOTICE: start the tests by: test.exe
 
-all_test: test tv_gen hashsum crypt small timing
-
-install: library
-	cmd /c if not exist "$(LIBPATH)" mkdir "$(LIBPATH)"
-	cmd /c if not exist "$(INCPATH)" mkdir "$(INCPATH)"
-	copy /Y $(LIBNAME) "$(LIBPATH)"
-	copy /Y src\headers\tomcrypt*.h "$(INCPATH)"
-
-install_test: $(LIBTEST)
-	cmd /c if not exist "$(LIBPATH)" mkdir "$(LIBPATH)"
-	copy /Y testprof\$(LIBTEST) "$(LIBPATH)"
+all: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) $(LIBTEST_S) hashsum crypt small tv_gen timing test
 
 clean:
-	cmd /c del /Q /S *.o *.a *.exe
-	$(MAKE) -C testprof -f makefile.mingw clean
+	@cmd /c del /Q /S *.o *.a *.exe *.dll 2>nul
+
+install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) $(LIBTEST_S)
+	cmd /c if not exist "$(DESTDIR)\bin" mkdir "$(DESTDIR)\bin"
+	cmd /c if not exist "$(DESTDIR)\lib" mkdir "$(DESTDIR)\lib"
+	cmd /c if not exist "$(DESTDIR)\include" mkdir "$(DESTDIR)\include"
+	copy /Y $(LIBMAIN_S) "$(DESTDIR)\lib"
+	copy /Y $(LIBMAIN_I) "$(DESTDIR)\lib"
+	copy /Y $(LIBMAIN_D) "$(DESTDIR)\bin"
+	copy /Y src\headers\tomcrypt*.h "$(DESTDIR)\include"