{"id":18879464,"url":"https://github.com/tjensen42/makefiles","last_synced_at":"2025-04-14T19:22:48.843Z","repository":{"id":49475109,"uuid":"517631009","full_name":"tjensen42/Makefiles","owner":"tjensen42","description":"Some simple Makefiles for compiling C/C++ with auto dependency generation. Feel free to use them as template.","archived":false,"fork":false,"pushed_at":"2022-08-25T06:48:58.000Z","size":44,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T07:51:09.512Z","etag":null,"topics":["c","compile","cpp","dependencies","makefile","makefile-template"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tjensen42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-25T11:07:46.000Z","updated_at":"2024-10-02T07:59:36.000Z","dependencies_parsed_at":"2022-08-12T20:11:37.101Z","dependency_job_id":null,"html_url":"https://github.com/tjensen42/Makefiles","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjensen42%2FMakefiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjensen42%2FMakefiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjensen42%2FMakefiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjensen42%2FMakefiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tjensen42","download_url":"https://codeload.github.com/tjensen42/Makefiles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248943415,"owners_count":21186958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","compile","cpp","dependencies","makefile","makefile-template"],"created_at":"2024-11-08T06:36:34.390Z","updated_at":"2025-04-14T19:22:48.814Z","avatar_url":"https://github.com/tjensen42.png","language":null,"readme":"# Makefile templates\n\n## Variables\n```Makefile\nNAME        := # Executable name\n\nCC          := # Program for compiling C programs; default ‘cc’\nCFLAGS      := # Extra flags to give to the C compiler\n\nCXX         := # Program for compiling C++ programs\nCXXFLAGS    := # Extra flags to give to the C++ compiler\n\nCPPFLAGS    := # Extra flags to give to the C preprocessor and programs that use it\nDEPFLAGS     = # Specific flags which convince the compiler to generate the dependency file\n\nLDFLAGS     := # Linker flags, path where to search for library: -L./libft\nLDLIBS      := # Library flags or names: -lm -lft\n\nVPATH       := # A list of directories to be searched for source files: ./src/ ./src/parser\nSRCS        := # specify all source files (*.c)\n\nODIR        := # Dir for .o files (object files)\nOBJS        := # $(SRCS:%.c=$(ODIR)/%.o) get object files from src files\n\nDDIR        := # Dir for .d files (dependency files)\nDEPS        := # $(SRCS:%.c=$(DDIR)/%.d) get dep files from src files\n\n```\n\n## Auto dependency generation \n* https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/\u003cbr\u003e(dependency flags explained at the bottom of the page)\n\n### Overview:\n\n```Makefile\n# Set the name of the target in the generated dependency file.\n-MT $@\n\n# Generate dependency information as a side-effect of compilation, not instead of compilation. This version omits system headers from the generated dependencies: if you prefer to preserve system headers as prerequisites, use -MD.\n-MMD\n\n# Adds a target for each prerequisite in the list, to avoid errors when deleting files.\n-MP\n\n# Write the generated dependency file $(DEPDIR)/$*.d.\n-MF $(DEPDIR)/$*.d\n\n# Generate list of dependency files\nDEPS := $(SRCS:%.c=$(DEPDIR)/%.d)\n\n# Declare the generated dependency file as a prerequisite of the target, so that if it’s missing the target will be rebuilt. \n... $(DEPDIR)/%.d\n\n# Declare the dependency directory as an order-only prerequisite of the target, so that it will be created when needed.\n... | $(DEPDIR)\n\n# Declare a rule for creating the dependency directory if it doesn’t exist:\n$(DEPDIR): ; @mkdir -p $@\n\n# Mention each dependency file as a target, so that make won’t fail if the file doesn’t exist.\n$(DEPFILES):\n\n# Include the dependency files that exist\n-include $(DEPS)\n```\n\n## Linux warn_unused_result fix\n\u003cimg width=\"1218\" alt=\"Screenshot 2022-07-25 at 20 44 35\" src=\"https://user-images.githubusercontent.com/56789534/180851762-8bc60ebe-39ec-44f9-babd-fa2a123e637c.png\"\u003e\n\n```Makefile\n# **************************************************************************** #\n#   SYSTEM SPECIFIC SETTINGS                                                   #\n# **************************************************************************** #\n\nifeq ($(shell uname -s), Linux)\n\tCFLAGS += -Wno-unused-result\nendif\n```\n\n## Parallel compilation with make -j\n```bash\n# It is recommended to use number of CPU cores for the num_of_processes\nmake -j\u003cnum_of_processes\u003e\n```\n```Makefile\n# Makefile builtin approach\nUNAME\t:= $(shell uname -s)\nNUMPROC\t:= 8\n\nifeq ($(UNAME), Linux)\n\tNUMPROC := $(shell grep -c ^processor /proc/cpuinfo)\nelse ifeq ($(UNAME), Darwin)\n\tNUMPROC := $(shell sysctl -n hw.ncpu)\nendif\n\nall:\n\t@$(MAKE) $(NAME) -j$(NUMPROC)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjensen42%2Fmakefiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftjensen42%2Fmakefiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjensen42%2Fmakefiles/lists"}