Skip to content

Commit

Permalink
Merge pull request #164 from steve-chavez/fix-makefile-compile
Browse files Browse the repository at this point in the history
fix: make check always compiles dependencies
  • Loading branch information
orangeduck authored Aug 4, 2023
2 parents 1a59a5f + 57ce9be commit 6912695
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ examples/maths
examples/smallc
examples/foobar
examples/tree_traversal
build/*
build/*
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ EXAMPLESEXE = $(EXAMPLES:.c=)

all: $(EXAMPLESEXE) check libs $(DIST)/$(PROJ).pc

$(DIST):
$(DIST)/.dirstamp:
$(MKDIR) $(DIST)
$(MKDIR) $(DIST)/examples
touch $@

check: $(DIST) $(DIST)/test-file $(DIST)/test-static $(DIST)/test-dynamic
check: $(DIST)/.dirstamp $(DIST)/test-file $(DIST)/test-static $(DIST)/test-dynamic
./$(DIST)/test-file
./$(DIST)/test-static
LD_LIBRARY_PATH=$(DIST) ./$(DIST)/test-dynamic
Expand All @@ -35,23 +36,23 @@ $(DIST)/test-dynamic: $(TESTS) $(DIST)/lib$(PROJ).so $(PROJ).h tests/ptest.h
$(DIST)/test-static: $(TESTS) $(DIST)/lib$(PROJ).a $(PROJ).h tests/ptest.h
$(CC) $(filter-out -Werror, $(CFLAGS)) $(TESTS) -lm -L$(DIST) -l$(PROJ) -static -o $(DIST)/test-static

examples/%: $(DIST) examples/%.c $(PROJ).c $(PROJ).h
$(CC) $(CFLAGS) $(filter-out $(DIST) $(PROJ).h, $^) -lm -o $(DIST)/$@
examples/%: $(DIST)/.dirstamp examples/%.c $(PROJ).c $(PROJ).h
$(CC) $(CFLAGS) $(filter-out $(DIST)/.dirstamp $(PROJ).h, $^) -lm -o $(DIST)/$@

$(DIST)/lib$(PROJ).so: $(DIST) $(PROJ).c $(PROJ).h
$(DIST)/lib$(PROJ).so: $(DIST)/.dirstamp $(PROJ).c $(PROJ).h
ifneq ($(OS),Windows_NT)
$(CC) $(CFLAGS) -fPIC -shared $(PROJ).c -o $(DIST)/lib$(PROJ).so
else
$(CC) $(CFLAGS) -shared $(PROJ).c -o $(DIST)/lib$(PROJ).so
endif

$(DIST)/lib$(PROJ).a: $(DIST) $(PROJ).c $(PROJ).h
$(DIST)/lib$(PROJ).a: $(DIST)/.dirstamp $(PROJ).c $(PROJ).h
$(CC) $(CFLAGS) -c $(PROJ).c -o $(DIST)/$(PROJ).o
$(AR) rcs $(DIST)/lib$(PROJ).a $(DIST)/$(PROJ).o

libs: $(DIST)/lib$(PROJ).so $(DIST)/lib$(PROJ).a

$(DIST)/$(PROJ).pc: $(DIST) $(PROJ).pc
$(DIST)/$(PROJ).pc: $(DIST)/.dirstamp $(PROJ).pc
cp $(PROJ).pc $(DIST)/$(PROJ).pc
sed -i '1i\prefix=$(PREFIX)/' $(DIST)/$(PROJ).pc

Expand Down

0 comments on commit 6912695

Please sign in to comment.