Skip to content

Commit

Permalink
Added install and uninstall targets to Makefile for easier instal…
Browse files Browse the repository at this point in the history
…lation
  • Loading branch information
dssgabriel committed Mar 16, 2022
1 parent c773b0b commit 244e3ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
32 changes: 20 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,38 @@ LIB = target/build/libvec.o
TEST = test/test.c

libvec.so: $(SRC)/vec.c $(SRC)/vec.h
@echo -e "\e[32m Compiling\e[0m libvec v0.1.0"
@printf "\e[32m Compiling\e[0m libvec v0.1.0\n"
@$(CC) $(CFLAGS) $(OFLAGS) -fPIC -shared -o $@ src/vec.c -lc
@echo -e " \e[32mFinished\e[0m release (optimized + debugflags)"
@printf " \e[32mFinished\e[0m release (optimized + debugflags)\n"

install: libvec.so
@printf "\e[32m Installing\e[0m libvec v0.1.0\n"
@cp libvec.so /usr/lib/

uninstall:
@printf "\e[32mUninstalling\e[0m libvec v0.1.0\n"
@rm -f /usr/lib/libvec.so

$(LIB): $(SRC)/vec.c $(SRC)/vec.h
@mkdir -p target/build
@echo -e "\e[32m Compiling\e[0m vec v0.1.0"
@printf "\e[32m Compiling\e[0m vec v0.1.0\n"
@$(CC) $(CFLAGS) -c $(SRC)/vec.c -o $@

test: $(LIB)
@mkdir -p target/test
@echo -e "\e[32m Compiling\e[0m test"
@printf "\e[32m Compiling\e[0m test\n"
@$(CC) $(CFLAGS) $^ $(TEST) -o target/test/main
@echo -e " \e[32mFinished\e[0m debug (unoptimized + debugflags)"
@echo -e " \e[32mRunning\e[0m target/test/main"
@printf " \e[32mFinished\e[0m debug (unoptimized + debugflags)\n"
@printf " \e[32mRunning\e[0m target/test/main\n"
@target/test/main

test_release:
test_release: libvec.so $(TEST)
@mkdir -p target/test
@echo -e "\e[32m Compiling\e[0m test"
@$(CC) $(CFLAGS) $(TEST) $^ -o target/test/main -L. -lvec
@echo -e " \e[32mFinished\e[0m release (optimized + debugflags)"
@echo -e " \e[32mRunning\e[0m target/test/main"
@target/test/main
@printf "\e[32m Compiling\e[0m test\n"
@$(CC) $(CFLAGS) -L. $^ -o target/test/main -lvec
@printf " \e[32mFinished\e[0m release (optimized + debugflags)\n"
@printf " \e[32mRunning\e[0m target/test/main\n"
@LD_LIBRARY_PATH=. target/test/main

clean:
@rm -Rf target/ *.so
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ Basically, it looks like this:
To install the library on your computer, please use the provided Makefile:
```sh
make
sudo make install
```

You can then either add the resulting `libvec.so` file to your
`$LD_LIBRARY_PATH` or copy/symlink it to `/usr/`, `/usr/lib/` or `/usr/local/lib/`.
When using the library in your own programs, you will only need to include
the `vec.h` file and compile with the `-lvec` option.

Expand Down

0 comments on commit 244e3ed

Please sign in to comment.