| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | PROJ = mpc | 
					
						
							|  |  |  | CC ?= gcc | 
					
						
							| 
									
										
										
										
											2020-02-03 23:32:25 -06:00
										 |  |  | STD ?= -ansi | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | DIST = build | 
					
						
							| 
									
										
										
										
											2019-05-23 21:23:05 -05:00
										 |  |  | MKDIR  ?= mkdir -p | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | PREFIX ?= /usr/local | 
					
						
							| 
									
										
										
										
											2020-02-03 23:32:25 -06:00
										 |  |  | CFLAGS ?= $(STD) -pedantic -O3 -g -Wall -Werror -Wextra -Wformat=2 -Wshadow \
 | 
					
						
							| 
									
										
										
										
											2015-03-10 10:44:29 +00:00
										 |  |  |   -Wno-long-long -Wno-overlength-strings -Wno-format-nonliteral -Wcast-align \
 | 
					
						
							|  |  |  |   -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls \
 | 
					
						
							|  |  |  |   -Wnested-externs -Wmissing-include-dirs -Wswitch-default | 
					
						
							| 
									
										
										
										
											2014-10-14 23:16:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-19 20:57:40 +01:00
										 |  |  | TESTS = $(wildcard tests/*.c) | 
					
						
							| 
									
										
										
										
											2014-01-26 11:25:50 +00:00
										 |  |  | EXAMPLES = $(wildcard examples/*.c) | 
					
						
							|  |  |  | EXAMPLESEXE = $(EXAMPLES:.c=) | 
					
						
							| 
									
										
										
										
											2013-09-19 20:57:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 22:04:09 -06:00
										 |  |  | .PHONY: all check clean libs $(DIST)/$(PROJ).pc | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 15:31:25 -04:00
										 |  |  | all: $(EXAMPLESEXE) check libs $(DIST)/$(PROJ).pc | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-03 17:53:33 -05:00
										 |  |  | $(DIST)/.dirstamp: | 
					
						
							| 
									
										
										
										
											2020-07-19 08:57:42 -04:00
										 |  |  | 	$(MKDIR) $(DIST) | 
					
						
							| 
									
										
										
										
											2019-05-23 21:23:05 -05:00
										 |  |  | 	$(MKDIR) $(DIST)/examples | 
					
						
							| 
									
										
										
										
											2023-08-03 17:53:33 -05:00
										 |  |  | 	touch $@ | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-03 17:53:33 -05:00
										 |  |  | check: $(DIST)/.dirstamp $(DIST)/test-file $(DIST)/test-static $(DIST)/test-dynamic | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 	./$(DIST)/test-file | 
					
						
							|  |  |  | 	./$(DIST)/test-static | 
					
						
							|  |  |  | 	LD_LIBRARY_PATH=$(DIST) ./$(DIST)/test-dynamic | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 23:32:25 -06:00
										 |  |  | $(DIST)/test-file: $(TESTS) $(PROJ).c $(PROJ).h tests/ptest.h | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:12 +08:00
										 |  |  | 	$(CC) $(filter-out -Werror, $(CFLAGS)) $(TESTS) $(PROJ).c -lm -o $(DIST)/test-file | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 23:32:25 -06:00
										 |  |  | $(DIST)/test-dynamic: $(TESTS) $(DIST)/lib$(PROJ).so $(PROJ).h tests/ptest.h | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:12 +08:00
										 |  |  | 	$(CC) $(filter-out -Werror, $(CFLAGS)) $(TESTS) -lm -L$(DIST) -l$(PROJ) -o $(DIST)/test-dynamic | 
					
						
							| 
									
										
										
										
											2014-10-14 22:33:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 23:32:25 -06:00
										 |  |  | $(DIST)/test-static: $(TESTS) $(DIST)/lib$(PROJ).a $(PROJ).h tests/ptest.h | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:12 +08:00
										 |  |  | 	$(CC) $(filter-out -Werror, $(CFLAGS)) $(TESTS) -lm -L$(DIST) -l$(PROJ) -static -o $(DIST)/test-static | 
					
						
							| 
									
										
										
										
											2014-10-14 22:33:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-03 17:53:33 -05:00
										 |  |  | examples/%: $(DIST)/.dirstamp examples/%.c $(PROJ).c $(PROJ).h | 
					
						
							| 
									
										
										
										
											2023-08-03 20:46:54 -05:00
										 |  |  | 	$(CC) $(CFLAGS) $(filter-out $(DIST)/.dirstamp $(PROJ).h, $^) -lm -o $(DIST)/$@ | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-03 17:53:33 -05:00
										 |  |  | $(DIST)/lib$(PROJ).so: $(DIST)/.dirstamp $(PROJ).c $(PROJ).h | 
					
						
							| 
									
										
										
										
											2019-05-29 19:39:33 -05:00
										 |  |  | ifneq ($(OS),Windows_NT) | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:12 +08:00
										 |  |  | 	$(CC) $(CFLAGS) -fPIC -shared $(PROJ).c -o $(DIST)/lib$(PROJ).so | 
					
						
							| 
									
										
										
										
											2019-05-29 19:39:33 -05:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:12 +08:00
										 |  |  | 	$(CC) $(CFLAGS) -shared $(PROJ).c -o $(DIST)/lib$(PROJ).so | 
					
						
							| 
									
										
										
										
											2019-05-29 19:39:33 -05:00
										 |  |  | endif | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-03 17:53:33 -05:00
										 |  |  | $(DIST)/lib$(PROJ).a: $(DIST)/.dirstamp $(PROJ).c $(PROJ).h | 
					
						
							| 
									
										
										
										
											2019-08-07 17:55:12 +08:00
										 |  |  | 	$(CC) $(CFLAGS) -c $(PROJ).c -o $(DIST)/$(PROJ).o | 
					
						
							|  |  |  | 	$(AR) rcs $(DIST)/lib$(PROJ).a $(DIST)/$(PROJ).o | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-07 10:15:39 +00:00
										 |  |  | libs: $(DIST)/lib$(PROJ).so $(DIST)/lib$(PROJ).a | 
					
						
							| 
									
										
										
										
											2020-01-08 22:07:32 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-03 17:53:33 -05:00
										 |  |  | $(DIST)/$(PROJ).pc: $(DIST)/.dirstamp $(PROJ).pc | 
					
						
							| 
									
										
										
										
											2020-02-09 22:04:09 -06:00
										 |  |  | 	cp $(PROJ).pc $(DIST)/$(PROJ).pc | 
					
						
							|  |  |  | 	sed -i '1i\prefix=$(PREFIX)/' $(DIST)/$(PROJ).pc | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-19 20:57:40 +01:00
										 |  |  | clean: | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 	rm -rf -- $(DIST) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | install: all | 
					
						
							| 
									
										
										
										
											2023-07-22 23:53:57 -05:00
										 |  |  | 	install -d -m645 $(DESTDIR)$(PREFIX)/include | 
					
						
							|  |  |  | 	install -d -m645 $(DESTDIR)$(PREFIX)/lib/pkgconfig | 
					
						
							|  |  |  | 	install -d -m645 $(DESTDIR)$(PREFIX)/share/$(PROJ) | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 	install -m755 -t $(DESTDIR)$(PREFIX)/lib $(DIST)/lib* | 
					
						
							| 
									
										
										
										
											2021-11-29 11:48:54 -07:00
										 |  |  | 	install -m644 -t $(DESTDIR)$(PREFIX)/share/$(PROJ) $(PROJ).c $(PROJ).h | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 	install -m644 $(PROJ).h $(DESTDIR)$(PREFIX)/include/$(PROJ).h | 
					
						
							| 
									
										
										
										
											2023-03-31 15:31:25 -04:00
										 |  |  | 	install -m644 $(DIST)/$(PROJ).pc \
 | 
					
						
							|  |  |  | 	  $(DESTDIR)$(PREFIX)/lib/pkgconfig/$(PROJ).pc | 
					
						
							| 
									
										
										
										
											2018-11-09 11:19:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | uninstall: | 
					
						
							|  |  |  | 	rm -rf -- \
 | 
					
						
							|  |  |  | 		$(DESTDIR)$(PREFIX)/include/$(PROJ).h \
 | 
					
						
							|  |  |  | 		$(DESTDIR)$(PREFIX)/share/$(PROJ)/$(PROJ).{c,h} \
 | 
					
						
							|  |  |  | 		$(DESTDIR)$(PREFIX)/lib/lib$(PROJ).{so,a} |