Skip to content

Commit

Permalink
Makefile improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tbuktu committed Feb 21, 2014
1 parent 8a1edfb commit a7d4846
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
33 changes: 21 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
CFLAGS=-g -Wall -O2
LDFLAGS=-lrt
SRCDIR=src
TESTDIR=tests
LIB_OBJS=bitstring.o encparams.o hash.o idxgen.o key.o mgf.o ntru.o poly.o rand.o sha2big.o sha2.o
TEST_OBJS=test_bitstring.o test_hash.o test_idxgen.o test_key.o test_ntru.o test.o test_poly.o test_util.o

LIB_OBJS_PATHS=$(patsubst %,$(SRCDIR)/%,$(LIB_OBJS))
TEST_OBJS_PATHS=$(patsubst %,$(TESTDIR)/%,$(TEST_OBJS))

# Use -install_name on Mac OS, -soname everywhere else
UNAME := $(shell uname)
Expand All @@ -9,21 +16,23 @@ else
SONAME=-soname
endif

lib: src/bitstring.o src/encparams.o src/hash.o src/idxgen.o src/key.o src/mgf.o src/ntru.o src/poly.o src/rand.o src/sha2big.o src/sha2.o
$(CC) $(CFLAGS) -shared -Wl,$(SONAME),libntru.so -o libntru.so src/*.o $(LDFLAGS)
.PHONY: lib
lib: $(LIB_OBJS_PATHS)
$(CC) $(CFLAGS) -shared -Wl,$(SONAME),libntru.so -o libntru.so $(LIB_OBJS_PATHS) $(LDFLAGS)

test: lib tests/*.o
$(CC) $(CFLAGS) -o test.out tests/*.o -L./tests -L. -lntru -lm
LD_LIBRARY_PATH=. ./test.out
test: lib $(TEST_OBJS_PATHS)
$(CC) $(CFLAGS) -o test $(TEST_OBJS_PATHS) -L. -lntru -lm
LD_LIBRARY_PATH=. ./test

bench: lib src/bench.o
$(CC) $(CFLAGS) -o bench src/bench.o -L. -lntru
bench: lib $(SRCDIR)/bench.o
$(CC) $(CFLAGS) -o bench $(SRCDIR)/bench.o -L. -lntru

src/%.c src/%.o:
cd src && $(CC) $(CFLAGS) $(LDFLAGS) -c -fPIC $*.c
$(SRCDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c -fPIC $< -o $@

tests/%.c tests/%.o:
cd tests && $(CC) $(CFLAGS) $(LDFLAGS) -c -fPIC -I../src $*.c
tests/%.o: tests/%.c
$(CC) $(CFLAGS) -fPIC -I$(SRCDIR) -c $< -o $@

.PHONY: clean
clean:
rm -f src/*.o tests/*.o libntru.so test.out bench
rm -f $(SRCDIR)/*.o $(TESTDIR)/*.o libntru.so libntru.dll test test.exe bench bench.exe
35 changes: 23 additions & 12 deletions Makefile.win
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
CFLAGS=-g -Wall -O2
SRCDIR=src
TESTDIR=tests
LIB_OBJS=bitstring.o encparams.o hash.o idxgen.o key.o mgf.o ntru.o poly.o rand.o sha2big.o sha2.o
TEST_OBJS=test_bitstring.o test_hash.o test_idxgen.o test_key.o test_ntru.o test.o test_poly.o test_util.o

lib: src/bitstring.o src/encparams.o src/hash.o src/idxgen.o src/key.o src/mgf.o src/ntru.o src/poly.o src/rand.o src/sha2big.o src/sha2.o
$(CC) $(CFLAGS) -shared -o libntru.dll src/*.o $(LDFLAGS) -lws2_32 -ladvapi32
LIB_OBJS_PATHS=$(patsubst %,$(SRCDIR)/%,$(LIB_OBJS))
TEST_OBJS_PATHS=$(patsubst %,$(TESTDIR)/%,$(TEST_OBJS))

test: lib tests/*.o
$(CC) $(CFLAGS) -o test.exe tests/*.o -L./tests -L. -lntru -lm
lib: $(LIB_OBJS_PATHS)
$(CC) $(CFLAGS) -shared -o libntru.dll $(LIB_OBJS_PATHS) -lws2_32 -ladvapi32

test: lib $(TEST_OBJS_PATHS)
$(CC) $(CFLAGS) -o test.exe $(TEST_OBJS_PATHS) -L. -lntru -lm
test.exe

bench: lib src/bench.o
$(CC) $(CFLAGS) -o bench src/bench.o -L. -lntru
bench: lib $(SRCDIR)/bench.o
$(CC) $(CFLAGS) -o bench $(SRCDIR)/bench.o -L. -lntru

src/%.c src/%.o:
cd src && $(CC) $(CFLAGS) $(LDFLAGS) -c $*.c
$(SRCDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@

tests/%.c tests/%.o:
cd tests && $(CC) $(CFLAGS) $(LDFLAGS) -c -I../src $*.c
$(TESTDIR)/%.o: tests/%.c
$(CC) $(CFLAGS) -I$(SRCDIR) -c $< -o $@

.PHONY: clean
clean:
@if exist src\*.o del src\*.o
@if exist tests\*.o del tests\*.o
@if exist $(SRCDIR)\*.o del $(SRCDIR)\*.o
@if exist $(TESTDIR)\*.o del $(TESTDIR)\*.o
@if exist libntru.dll del libntru.dll
@if exist libntru.so del libntru.so
@if exist test.exe del test.exe
@if exist test del test
@if exist bench.exe del bench.exe
@if exist bench del bench

0 comments on commit a7d4846

Please sign in to comment.