X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=Makefile;fp=Makefile;h=faff6265b525751fa789a5f5662c92be5468de1f;hb=775fd02ef24727639399d2664561d9c550cdafa8;hp=764d97e4a9542ea415ac7d5ad212a1a771aafdfa;hpb=888f532312c70f907519e0f40f1311b93bdb7870;p=modules.git diff --git a/Makefile b/Makefile index 764d97e..faff626 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,58 @@ -#CXXFLAGS = -fmodules-ts -std=c++20 -#CXX = g++ +BUILD_DIR := build +PREBUILT_DIR := $(BUILD_DIR)/prebuilt +DIRS := $(BUILD_DIR) $(PREBUILT_DIR) + +#USE_CLANG := YES + +ifdef USE_CLANG + +CXX := clang++ +CXXFLAGS := \ + -std=c++2b -stdlib=libc++ \ + -fimplicit-modules -fimplicit-module-maps \ + -fprebuilt-module-path=$(PREBUILT_DIR) \ + -fmodules-cache-path=$(PREBUILT_DIR) +# -fmodule-map-file=/usr/include/c++/v1/module.modulemap +# -fbuiltin-module-map + +MODFLAGS := -Xclang -emit-module-interface + +else # COMPILER != clang + +CXX := g++ +CXXFLAGS := -std=c++2b -fmodules-ts +MODFLAGS := + +# libstdc++ 12.2 does not bundle pre-built modules: +# g++ -std=c++2b -fmodules-ts -fmodule-header=system -x c++-system-header string iostream + +endif -CXX = clang++ -CXXFLAGS = -std=c++20 -fimplicit-modules -fprebuilt-module-path=. -fmodules-cache-path=foo APP = hellomodules -OBJS = main.o helloworld.o -MODS = helloworld.pcm +SRCS = main.cc helloworld.cc +MODS = helloworld -all: $(APP) +OBJS = $(patsubst %.cc, build/%.o, $(SRCS)) +PCMS = $(patsubst %, $(PREBUILT_DIR)/%.pcm, $(MODS)) + +all: $(DIRS) $(APP) clean: rm -f $(APP) rm -f $(OBJS) - rm -f $(MODS) + rm -f $(PCMS) + rm -rf $(PREBUILT_DIR) + rm -rf gcm.cache + +$(DIRS): + mkdir -p $(DIRS) -$(APP): $(OBJS) - $(CXX) $(CXXFLAGS) -o $@ $? +$(APP): $(OBJS) $(PCMS) + $(CXX) $(CXXFLAGS) -o $@ $(OBJS) -main.o: main.cc $(MODS) -helloworld.o: helloworld.cc +$(BUILD_DIR)/%.o: %.cc $(PCMS) + $(CXX) $(CXXFLAGS) -o $@ -c $< -helloworld.pcm: helloworld.cc - $(CXX) $(CXXFLAGS) -Xclang -emit-module-interface -c helloworld.cc -o helloworld.pcm +$(PREBUILT_DIR)/%.pcm: %.cc + $(CXX) $(MODFLAGS) $(CXXFLAGS) -o $@ -c $<